1
0
Fork 0
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:
Sergey Cherepanov 2023-02-23 16:55:10 +03:00 committed by Mikhail Iudin
parent 6eb84043f0
commit 92fb54a3e4
No known key found for this signature in database
GPG key ID: FAAAA8BAABDFF1C0
3 changed files with 22 additions and 16 deletions

View file

@ -17,8 +17,7 @@ type configGetter interface {
type NodeConfig struct { type NodeConfig struct {
PeerId string `yaml:"peerId"` PeerId string `yaml:"peerId"`
Addresses []string `yaml:"address"` Addresses []string `yaml:"address"`
SigningKey string `yaml:"signingKey,omitempty"` EncryptionKey string `yaml:"encryptionPubKey,omitempty"`
EncryptionKey string `yaml:"encryptionKey,omitempty"`
Types []NodeType `yaml:"types,omitempty"` Types []NodeType `yaml:"types,omitempty"`
} }

View file

@ -8,6 +8,7 @@ import (
"github.com/anytypeio/any-sync/util/keys/asymmetric/encryptionkey" "github.com/anytypeio/any-sync/util/keys/asymmetric/encryptionkey"
"github.com/anytypeio/any-sync/util/keys/asymmetric/signingkey" "github.com/anytypeio/any-sync/util/keys/asymmetric/signingkey"
"github.com/anytypeio/go-chash" "github.com/anytypeio/go-chash"
"github.com/libp2p/go-libp2p/core/peer"
) )
const CName = "common.nodeconf" const CName = "common.nodeconf"
@ -106,17 +107,28 @@ func (s *service) GetById(id string) Configuration {
} }
func nodeFromConfigNode(n NodeConfig) (*Node, error) { func nodeFromConfigNode(n NodeConfig) (*Node, error) {
decodedSigningKey, err := keys.DecodeKeyFromString( p, err := peer.Decode(n.PeerId)
n.SigningKey, if err != nil {
signingkey.UnmarshalEd25519PrivateKey, return nil, err
nil) }
ic, err := p.ExtractPublicKey()
if err != nil { if err != nil {
return nil, err 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, n.EncryptionKey,
encryptionkey.NewEncryptionRsaPrivKeyFromBytes, encryptionkey.NewEncryptionRsaPubKeyFromBytes,
nil) nil)
if err != nil { if err != nil {
return nil, err return nil, err
@ -125,7 +137,7 @@ func nodeFromConfigNode(n NodeConfig) (*Node, error) {
return &Node{ return &Node{
Addresses: n.Addresses, Addresses: n.Addresses,
PeerId: n.PeerId, PeerId: n.PeerId,
SigningKey: decodedSigningKey.GetPublic(), SigningKey: sigPubKey,
EncryptionKey: decodedEncryptionKey.GetPublic(), EncryptionKey: encPubKey,
}, nil }, nil
} }

View file

@ -62,18 +62,13 @@ func (s *AccountTestService) Account() *accountdata.AccountData {
} }
func (s *AccountTestService) NodeConf(addrs []string) nodeconf.NodeConfig { func (s *AccountTestService) NodeConf(addrs []string) nodeconf.NodeConfig {
encSk, err := keys.EncodeKeyToString(s.acc.SignKey) encEk, err := keys.EncodeKeyToString(s.acc.EncKey.GetPublic())
if err != nil {
panic(err)
}
encEk, err := keys.EncodeKeyToString(s.acc.EncKey)
if err != nil { if err != nil {
panic(err) panic(err)
} }
return nodeconf.NodeConfig{ return nodeconf.NodeConfig{
PeerId: s.acc.PeerId, PeerId: s.acc.PeerId,
Addresses: addrs, Addresses: addrs,
SigningKey: encSk,
EncryptionKey: encEk, EncryptionKey: encEk,
Types: []nodeconf.NodeType{nodeconf.NodeTypeTree}, Types: []nodeconf.NodeType{nodeconf.NodeTypeTree},
} }