double ratchet first implementation
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
ycc
2026-03-04 22:30:22 +01:00
parent c0dcfe997c
commit f4fb42d72e
11 changed files with 375 additions and 14 deletions

View File

@@ -15,6 +15,7 @@ import (
"forge.redroom.link/yves/meowlib"
"github.com/ProtonMail/gopenpgp/v2/helper"
"github.com/google/uuid"
doubleratchet "github.com/status-im/doubleratchet"
)
const maxHiddenCount = 30
@@ -122,6 +123,21 @@ func (id *Identity) InvitePeer(MyName string, ContactName string, MessageServerU
peer.MyPullServers = MessageServerUids
peer.MyName = MyName
peer.InvitationMessage = InvitationMessage
// Generate DR keypair and root key for the initiator side
drKp, err := doubleratchet.DefaultCrypto{}.GenerateDH()
if err != nil {
return nil, err
}
peer.DrKpPrivate = base64.StdEncoding.EncodeToString(drKp.PrivateKey())
peer.DrKpPublic = base64.StdEncoding.EncodeToString(drKp.PublicKey())
drRootKey := make([]byte, 32)
if _, err = rand.Read(drRootKey); err != nil {
return nil, err
}
peer.DrRootKey = base64.StdEncoding.EncodeToString(drRootKey)
peer.DrInitiator = true
id.Peers.StorePeer(&peer)
return &peer, nil
@@ -187,6 +203,10 @@ func (id *Identity) AnswerInvitation(MyName string, ContactName string, MessageS
peer.MyPullServers = MessageServerIdxs
peer.MyName = MyName
peer.InvitationId = ReceivedContact.InvitationId
// Adopt DR material from the initiator's ContactCard
peer.DrRootKey = ReceivedContact.DrRootKey
peer.ContactDrPublicKey = ReceivedContact.DrPublicKey
peer.DrInitiator = false
id.Peers.StorePeer(&peer)
return &peer, nil