diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..824f2ca
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/nssh
diff --git a/main.go b/main.go
index de92528..b15af90 100644
--- a/main.go
+++ b/main.go
@@ -1,11 +1,6 @@
package main
import (
- "crypto/rand"
- "crypto/rsa"
- "crypto/x509"
- "encoding/binary"
- "encoding/pem"
"io/ioutil"
"log"
@@ -13,103 +8,9 @@ import (
"golang.org/x/crypto/ssh"
)
-func generatePrivateKey(bitSize int) (*rsa.PrivateKey, error) {
- // Private Key generation
- privateKey, err := rsa.GenerateKey(rand.Reader, bitSize)
- if err != nil {
- return nil, err
- }
-
- // Validate Private Key
- err = privateKey.Validate()
- if err != nil {
- return nil, err
- }
-
- log.Println("Private Key generated")
- return privateKey, nil
-}
-
-func encodePrivateKeyToPEM(privateKey *rsa.PrivateKey) []byte {
- // Get ASN.1 DER format
- privDER := x509.MarshalPKCS1PrivateKey(privateKey)
-
- // pem.Block
- privBlock := pem.Block{
- Type: "RSA PRIVATE KEY",
- Headers: nil,
- Bytes: privDER,
- }
-
- // Private key in PEM format
- privatePEM := pem.EncodeToMemory(&privBlock)
-
- return privatePEM
-}
-
-// parseDims extracts two uint32s from the provided buffer.
-func parseDims(b []byte) (uint32, uint32) {
- w := binary.BigEndian.Uint32(b)
- h := binary.BigEndian.Uint32(b[4:])
- return w, h
-}
-
const WebDir = "/hugo-website"
func main() {
- // shell := ipfsapi.NewShell("127.0.0.1:5001")
-
- // ctx, _ := context.WithDeadline(context.Background(), time.Now().Add(time.Hour))
- // _, err := shell.KeyGen(ctx, "website-index")
- // if err != nil {
- // log.Fatal(err)
- // }
-
- // id, err := shell.Add(
- // strings.NewReader(
- // "" +
- // "
heeeeeeeyaa
",
- // ),
- // )
- // if err != nil {
- // log.Fatal(err)
- // }
-
- // log.Println("added file by name " + id)
-
- // resp, err := shell.PublishWithDetails(id, "website/index.html", 24*365*10*time.Hour, time.Hour, true)
- // if err != nil {
- // log.Fatal(err)
- // }
-
- // log.Println(resp.Name)
-
- // obj, err := shell.ObjectGet("QmbJSh4EQvxz6cD6NyZ92smxBYfwTU6zr6No5APjANZ92D")
-
- // if err != nil {
- // log.Fatal(err)
- // }
-
- // log.Println(obj.Links)
-
- // err = shell.FilesMkdir(ctx, WebDir)
- // if err!= nil {
- // log.Fatal(err)
- // }
-
- // shell.FilesLs(ctx context.Context, path string, options ...ipfsapi.FilesOpt)
- // stats, err := shell.FilesStat(ctx, WebDir)
- // if err != nil {
- // if ipfsErr, ok := err.(*ipfsapi.Error); ok {
- // log.Println("IPFS error code: ", ipfsErr.Code, ipfsErr.Command)
-
- // }
-
- // log.Fatal(err)
- // }
-
- // log.Println(stats)
-
// Public key authentication is done by comparing
// the public key of a received connection
// with the entries in the authorized_keys file.
diff --git a/nssh b/nssh
deleted file mode 100755
index 70df362..0000000
Binary files a/nssh and /dev/null differ
diff --git a/sshd.go b/sshd.go
index b7337d5..f4214fd 100644
--- a/sshd.go
+++ b/sshd.go
@@ -1,6 +1,11 @@
package main
import (
+ "crypto/rand"
+ "crypto/rsa"
+ "crypto/x509"
+ "encoding/binary"
+ "encoding/pem"
"errors"
"fmt"
"io"
@@ -10,6 +15,47 @@ import (
"golang.org/x/crypto/ssh"
)
+func generatePrivateKey(bitSize int) (*rsa.PrivateKey, error) {
+ // Private Key generation
+ privateKey, err := rsa.GenerateKey(rand.Reader, bitSize)
+ if err != nil {
+ return nil, err
+ }
+
+ // Validate Private Key
+ err = privateKey.Validate()
+ if err != nil {
+ return nil, err
+ }
+
+ log.Println("Private Key generated")
+ return privateKey, nil
+}
+
+func encodePrivateKeyToPEM(privateKey *rsa.PrivateKey) []byte {
+ // Get ASN.1 DER format
+ privDER := x509.MarshalPKCS1PrivateKey(privateKey)
+
+ // pem.Block
+ privBlock := pem.Block{
+ Type: "RSA PRIVATE KEY",
+ Headers: nil,
+ Bytes: privDER,
+ }
+
+ // Private key in PEM format
+ privatePEM := pem.EncodeToMemory(&privBlock)
+
+ return privatePEM
+}
+
+// parseDims extracts two uint32s from the provided buffer.
+func parseDims(b []byte) (uint32, uint32) {
+ w := binary.BigEndian.Uint32(b)
+ h := binary.BigEndian.Uint32(b[4:])
+ return w, h
+}
+
type Sshd struct {
AuthorizedKeysMap map[string]bool
Filestore Filestore