review comments addressed

Signed-off-by: Matthew R. Kasun <mkasun@nusak.ca>
This commit is contained in:
Matthew R. Kasun
2022-04-20 09:26:23 -04:00
parent b47c72ead2
commit adfa5236f8
3 changed files with 8 additions and 7 deletions

View File

@@ -37,7 +37,6 @@ services:
MQ_HOST: "mq" MQ_HOST: "mq"
HOST_NETWORK: "off" HOST_NETWORK: "off"
MANAGE_IPTABLES: "on" MANAGE_IPTABLES: "on"
PORT_FORWARD_SERVICES: ""
VERBOSITY: "1" VERBOSITY: "1"
ports: ports:
- "51821-51830:51821-51830/udp" - "51821-51830:51821-51830/udp"

View File

@@ -50,6 +50,7 @@ func Register(cfg *config.ClientConfig, key string) error {
return JoinNetwork(cfg, key, false) return JoinNetwork(cfg, key, false)
} }
// RegisterWithServer calls the register endpoint with privatekey and commonname - api returns ca and client certificate
func RegisterWithServer(private *ed25519.PrivateKey, cfg *config.ClientConfig) error { func RegisterWithServer(private *ed25519.PrivateKey, cfg *config.ClientConfig) error {
data := config.RegisterRequest{ data := config.RegisterRequest{
Key: *private, Key: *private,

View File

@@ -17,10 +17,11 @@ import (
"golang.zx2c4.com/wireguard/wgctrl/wgtypes" "golang.zx2c4.com/wireguard/wgctrl/wgtypes"
) )
// certificate validity in days // CERTTIFICAT_VALIDITY duration of certificate validity in days
const CERTIFICATE_VALIDITY = 365 const CERTIFICATE_VALIDITY = 365
type ( type (
// Key is the struct for an edwards representation point
Key struct { Key struct {
point *edwards25519.Point point *edwards25519.Point
} }
@@ -34,7 +35,7 @@ func NewKey() *Key {
return &Key{(&edwards25519.Point{}).ScalarBaseMult(s)} return &Key{(&edwards25519.Point{}).ScalarBaseMult(s)}
} }
// Ed25519PrivateKey returns the private key in Edwards form used for EdDSA. // Key.Ed25519PrivateKey returns the private key in Edwards form used for EdDSA.
func (n *Key) Ed25519PrivateKey() (ed25519.PrivateKey, error) { func (n *Key) Ed25519PrivateKey() (ed25519.PrivateKey, error) {
if n.point == nil { if n.point == nil {
return ed25519.PrivateKey{}, errors.New("nil point") return ed25519.PrivateKey{}, errors.New("nil point")
@@ -45,7 +46,7 @@ func (n *Key) Ed25519PrivateKey() (ed25519.PrivateKey, error) {
return ed25519.NewKeyFromSeed(n.point.Bytes()), nil return ed25519.NewKeyFromSeed(n.point.Bytes()), nil
} }
// Curve25519PrivateKey returns the private key in Montogomery form used for ECDH. // Key.Curve25519PrivateKey returns the private key in Montogomery form used for ECDH.
func (n *Key) Curve25519PrivateKey() (wgtypes.Key, error) { func (n *Key) Curve25519PrivateKey() (wgtypes.Key, error) {
if n.point == nil { if n.point == nil {
return wgtypes.Key{}, errors.New("nil point") return wgtypes.Key{}, errors.New("nil point")
@@ -56,7 +57,7 @@ func (n *Key) Curve25519PrivateKey() (wgtypes.Key, error) {
return wgtypes.ParseKey(base64.StdEncoding.EncodeToString(n.point.BytesMontgomery())) return wgtypes.ParseKey(base64.StdEncoding.EncodeToString(n.point.BytesMontgomery()))
} }
// Save : saves the private key to path. // Key.Save : saves the private key to path.
func (n *Key) Save(path string) error { func (n *Key) Save(path string) error {
f, err := os.Create(path) f, err := os.Create(path)
if err != nil { if err != nil {
@@ -67,7 +68,7 @@ func (n *Key) Save(path string) error {
return nil return nil
} }
// Reads the private key from path. // ReadFrom reads a private key from path.
func ReadFrom(path string) (*Key, error) { func ReadFrom(path string) (*Key, error) {
key, err := os.ReadFile(path) key, err := os.ReadFile(path)
if err != nil { if err != nil {
@@ -80,7 +81,7 @@ func ReadFrom(path string) (*Key, error) {
return &Key{point}, nil return &Key{point}, nil
} }
// NewName creates a new pkix.Name // NewName creates a new pkix.Name with common name, country, and organization
func NewName(commonName, country, org string) pkix.Name { func NewName(commonName, country, org string) pkix.Name {
res := NewCName(commonName) res := NewCName(commonName)
res.Country = []string{country} res.Country = []string{country}