Compare commits

..

1 Commits

Author SHA1 Message Date
Dan Ballard cf200dcfe4 log and stub of identity gen 2017-11-27 00:16:15 -08:00
1 changed files with 20 additions and 12 deletions

View File

@ -37,6 +37,7 @@ func CreateIdentity(core *Ricochet) (*Identity, error) {
log.Printf("Failed loading identity: %v", err)
return nil, err
}
log.Println("me: ", me)
contactList, err := LoadContactList(core)
if err != nil {
@ -46,6 +47,7 @@ func CreateIdentity(core *Ricochet) (*Identity, error) {
me.contactList = contactList
contactList.StartConnections()
log.Println("me: ", me)
go me.publishService(me.privateKey)
return me, nil
}
@ -53,22 +55,27 @@ func CreateIdentity(core *Ricochet) (*Identity, error) {
func (me *Identity) loadIdentity() error {
config := me.core.Config.Read()
if keyData := config.Secrets.GetServicePrivateKey(); keyData != nil {
var err error
me.privateKey, _, err = pkcs1.DecodePrivateKeyDER(keyData)
if err != nil {
return err
}
me.address, err = AddressFromKey(&me.privateKey.PublicKey)
if err != nil {
return err
}
keyData := config.Secrets.GetServicePrivateKey();
log.Printf("Loaded identity %s", me.address)
} else {
if keyData != nil {
log.Printf("Initializing new identity")
privateKey, err := utils.GeneratePrivateKey()
}
var err error
me.privateKey, _, err = pkcs1.DecodePrivateKeyDER(keyData)
if err != nil {
return err
}
me.address, err = AddressFromKey(&me.privateKey.PublicKey)
if err != nil {
return err
}
log.Printf("Loaded identity %s", me.address)
return nil
}
@ -105,6 +112,7 @@ func (me *Identity) setPrivateKey(key *rsa.PrivateKey) error {
// BUG(special): No error handling for failures under publishService
func (me *Identity) publishService(key *rsa.PrivateKey) {
log.Println("publishService(", key, ")")
// This call will block until a control connection is available and the
// ADD_ONION command has returned. After creating the listener, it will
// be automatically re-published if the control connection is lost and