diff --git a/README.md b/README.md index 85a2c80..4b60f93 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,8 @@ The dsfx-server requires a listening host, port, and a master key (ECDSA private ./dsfx-server -host localhost -port 8000 -masterKey /path/to/masterkey.pem +> Note, if you need to generate a new ECDSA key, you can use the following command: `go run ./cmd/genid > path/to/masterkey.pem` + Command-line flags for dsfx-server: -host (default "localhost") @@ -107,7 +109,7 @@ Contributions to dsfx are welcome and encouraged! ### How to Contribute 1. **Fork the Repository:** Create your own branch from the latest code in `main`. -2. **Make Your Changes:** Follow the [TigerStyle for Go](./TIGERSTYLE.md) guidelines to ensure code consistency and quality. +2. **Make Your Changes:** Follow the [TigerStyle for Go](./tigerstyle.md) guidelines to ensure code consistency and quality. 3. **Write Tests:** Ensure that new features and bug fixes include proper tests. 4. **Submit a Pull Request:** Document your changes clearly in your pull request. @@ -119,4 +121,4 @@ Please use the Git repository's issue tracker to report bugs or to suggest new f ## License -dsfx is distributed under the MIT License. See [LICENSE](LICENSE) for details. +dsfx is distributed under the MIT License. See [LICENSE](./LICENSE) for details. diff --git a/dsfx-server/config.go b/dsfx-server/config.go deleted file mode 100644 index a2d45b6..0000000 --- a/dsfx-server/config.go +++ /dev/null @@ -1,52 +0,0 @@ -package main - -import ( - "crypto/ecdsa" - "crypto/x509" - "encoding/json" - "encoding/pem" - "fmt" - "os" -) - -type Config struct { - Host string `json:"host"` - Port int `json:"port"` - MasterKeyPath string `json:"masterKeyPath"` - DataDirectory string `json:"dataDirectory"` -} - -// LoadConfig loads the configuration from the given path. -func LoadConfig(path string) (*Config, error) { - var config Config - configFile, err := os.Open(path) - if err != nil { - return nil, err - } - defer configFile.Close() - err = json.NewDecoder(configFile).Decode(&config) - if err != nil { - return nil, err - } - return &config, nil -} - -func LoadMasterKey(path string) (*ecdsa.PrivateKey, error) { - masterKeyFile, err := os.ReadFile(path) - if err != nil { - return nil, err - } - - // The second argument is not an error. - derEncoded, _ := pem.Decode(masterKeyFile) - if derEncoded == nil { - return nil, fmt.Errorf("failed to decode master key file") - } - - masterKey, err := x509.ParseECPrivateKey(derEncoded.Bytes) - if err != nil { - return nil, err - } - - return masterKey, nil -} diff --git a/dsfx-server/main.go b/dsfx-server/main.go index 09c850e..abb2584 100644 --- a/dsfx-server/main.go +++ b/dsfx-server/main.go @@ -2,6 +2,9 @@ package main import ( "context" + "crypto/ecdsa" + "crypto/x509" + "encoding/pem" "flag" "fmt" "log/slog" @@ -98,3 +101,23 @@ func handleConnection(ctx context.Context, conn net.Conn) error { return nil } + +func LoadMasterKey(path string) (*ecdsa.PrivateKey, error) { + masterKeyFile, err := os.ReadFile(path) + if err != nil { + return nil, err + } + + // The second argument is not an error. + derEncoded, _ := pem.Decode(masterKeyFile) + if derEncoded == nil { + return nil, fmt.Errorf("failed to decode master key file") + } + + masterKey, err := x509.ParseECPrivateKey(derEncoded.Bytes) + if err != nil { + return nil, err + } + + return masterKey, nil +} diff --git a/shared/dnet/handshake.go b/shared/dnet/handshake.go index a2ed087..cbe2a08 100644 --- a/shared/dnet/handshake.go +++ b/shared/dnet/handshake.go @@ -14,19 +14,6 @@ import ( "koti.casa/numenor-labs/dsfx/shared/dlog" ) -type Hand struct { - State byte - Identity *ecdsa.PrivateKey - AuthMessage []byte -} - -func NewHandshake(identity *ecdsa.PrivateKey) *Hand { - return &Hand{ - State: 0, - Identity: identity, - } -} - // Handshake initiates the handshake process between the given actor // and the remote actor. func Handshake(