mirror of
https://github.com/anyproto/any-sync.git
synced 2025-06-08 05:57:03 +09:00
remove priv keys from nodes conf
This commit is contained in:
parent
6eb84043f0
commit
92fb54a3e4
3 changed files with 22 additions and 16 deletions
|
@ -17,8 +17,7 @@ type configGetter interface {
|
|||
type NodeConfig struct {
|
||||
PeerId string `yaml:"peerId"`
|
||||
Addresses []string `yaml:"address"`
|
||||
SigningKey string `yaml:"signingKey,omitempty"`
|
||||
EncryptionKey string `yaml:"encryptionKey,omitempty"`
|
||||
EncryptionKey string `yaml:"encryptionPubKey,omitempty"`
|
||||
Types []NodeType `yaml:"types,omitempty"`
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/anytypeio/any-sync/util/keys/asymmetric/encryptionkey"
|
||||
"github.com/anytypeio/any-sync/util/keys/asymmetric/signingkey"
|
||||
"github.com/anytypeio/go-chash"
|
||||
"github.com/libp2p/go-libp2p/core/peer"
|
||||
)
|
||||
|
||||
const CName = "common.nodeconf"
|
||||
|
@ -106,17 +107,28 @@ func (s *service) GetById(id string) Configuration {
|
|||
}
|
||||
|
||||
func nodeFromConfigNode(n NodeConfig) (*Node, error) {
|
||||
decodedSigningKey, err := keys.DecodeKeyFromString(
|
||||
n.SigningKey,
|
||||
signingkey.UnmarshalEd25519PrivateKey,
|
||||
nil)
|
||||
p, err := peer.Decode(n.PeerId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ic, err := p.ExtractPublicKey()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
decodedEncryptionKey, err := keys.DecodeKeyFromString(
|
||||
icRaw, err := ic.Raw()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sigPubKey, err := signingkey.UnmarshalEd25519PublicKey(icRaw)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
encPubKey, err := keys.DecodeKeyFromString(
|
||||
n.EncryptionKey,
|
||||
encryptionkey.NewEncryptionRsaPrivKeyFromBytes,
|
||||
encryptionkey.NewEncryptionRsaPubKeyFromBytes,
|
||||
nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -125,7 +137,7 @@ func nodeFromConfigNode(n NodeConfig) (*Node, error) {
|
|||
return &Node{
|
||||
Addresses: n.Addresses,
|
||||
PeerId: n.PeerId,
|
||||
SigningKey: decodedSigningKey.GetPublic(),
|
||||
EncryptionKey: decodedEncryptionKey.GetPublic(),
|
||||
SigningKey: sigPubKey,
|
||||
EncryptionKey: encPubKey,
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -62,18 +62,13 @@ func (s *AccountTestService) Account() *accountdata.AccountData {
|
|||
}
|
||||
|
||||
func (s *AccountTestService) NodeConf(addrs []string) nodeconf.NodeConfig {
|
||||
encSk, err := keys.EncodeKeyToString(s.acc.SignKey)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
encEk, err := keys.EncodeKeyToString(s.acc.EncKey)
|
||||
encEk, err := keys.EncodeKeyToString(s.acc.EncKey.GetPublic())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return nodeconf.NodeConfig{
|
||||
PeerId: s.acc.PeerId,
|
||||
Addresses: addrs,
|
||||
SigningKey: encSk,
|
||||
EncryptionKey: encEk,
|
||||
Types: []nodeconf.NodeType{nodeconf.NodeTypeTree},
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue