modified: yggdrasil/keys.go
This commit is contained in:
parent
00972c7192
commit
ee70b80e31
1 changed files with 20 additions and 5 deletions
|
|
@ -49,11 +49,26 @@ func GetYggdrasilAddress(config *viper.Viper) string {
|
||||||
|
|
||||||
cfg := yggConfig.GenerateConfig()
|
cfg := yggConfig.GenerateConfig()
|
||||||
|
|
||||||
cfg.AdminListen = ygg.GetString("admin_listen")
|
cfg.PrivateKeyPath = ygg.GetString("private_key_file")
|
||||||
cfg.Listen = ygg.GetStringSlice("listen")
|
keyFile, err := os.ReadFile(cfg.PrivateKeyPath)
|
||||||
cfg.Peers = ygg.GetStringSlice("peers")
|
if err != nil {
|
||||||
cfg.AllowedPublicKeys = ygg.GetStringSlice("allowed-public-keys")
|
panic(err)
|
||||||
cfg.PrivateKeyPath = ygg.GetString("private-key-file")
|
}
|
||||||
|
keyHex := strings.TrimSpace(string(keyFile))
|
||||||
|
keyBytes, err := hex.DecodeString(keyHex)
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("failed to decode private key hex: %w", err))
|
||||||
|
}
|
||||||
|
if len(keyBytes) != ed25519.PrivateKeySize {
|
||||||
|
panic(fmt.Errorf("invalid private key length: got %d, expected %d", len(keyBytes), ed25519.PrivateKeySize))
|
||||||
|
}
|
||||||
|
copy(cfg.PrivateKey[:], keyBytes)
|
||||||
|
|
||||||
|
// Заполняем Certificate из PrivateKey
|
||||||
|
err = cfg.GenerateSelfSignedCertificate()
|
||||||
|
if err != nil {
|
||||||
|
panic(fmt.Errorf("failed to generate certificate from private key: %w", err))
|
||||||
|
}
|
||||||
|
|
||||||
logger := log.Default()
|
logger := log.Default()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue