Skip to content
Snippets Groups Projects
Commit fd3f7318 authored by Jono Wenger's avatar Jono Wenger
Browse files

Merge branch 'XX-4244/savePrivateKey' into 'project/Channels'

XX-4244 / Private keys storage

See merge request !409
parents 47b5fde5 a0a649a5
No related branches found
No related tags found
4 merge requests!510Release,!419rewrote the health tracker to both consider if there are waiting rounds and...,!409XX-4244 / Private keys storage,!340Project/channels
......@@ -13,12 +13,14 @@ import (
jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/channels"
"gitlab.com/elixxir/client/cmix/rounds"
"gitlab.com/elixxir/client/storage/versioned"
"gitlab.com/elixxir/client/xxdk"
cryptoBroadcast "gitlab.com/elixxir/crypto/broadcast"
cryptoChannel "gitlab.com/elixxir/crypto/channel"
"gitlab.com/elixxir/crypto/rsa"
"gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/id/ephemeral"
"gitlab.com/xx_network/primitives/netTime"
"sync"
"time"
)
......@@ -359,9 +361,43 @@ func GenerateChannel(cmixID int, name, description string) ([]byte, error) {
PrivateKey: string(pk.MarshalPem()),
}
err = saveChannelPrivateKey(cmix, c.ReceptionID, pk)
if err != nil {
return nil, err
}
return json.Marshal(&gen)
}
const (
channelPrivateKeyStoreVersion = 0
channelPrivateKeyStoreKey = "channelPrivateKey"
)
func saveChannelPrivateKey(cmix *Cmix, channelID *id.ID, pk rsa.PrivateKey) error {
return cmix.api.GetStorage().Set(
makeChannelPrivateKeyStoreKey(channelID),
&versioned.Object{
Version: channelPrivateKeyStoreVersion,
Timestamp: netTime.Now(),
Data: pk.MarshalPem(),
})
}
func loadChannelPrivateKey(cmix Cmix, channelID *id.ID) (rsa.PrivateKey, error) {
obj, err := cmix.api.GetStorage().Get(
makeChannelPrivateKeyStoreKey(channelID))
if err != nil {
return nil, err
}
return rsa.GetScheme().UnmarshalPrivateKeyPEM(obj.Data)
}
func makeChannelPrivateKeyStoreKey(channelID *id.ID) string {
return channelPrivateKeyStoreKey + "/" + channelID.String()
}
type ChannelInfo struct {
Name string
Description string
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment