invitation process upgrade
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
ycc
2026-04-02 18:50:04 +02:00
committed by yc
parent 9f130a80b7
commit 1906431061
21 changed files with 1185 additions and 638 deletions

View File

@@ -56,8 +56,10 @@ type Peer struct {
DbIds []string `json:"db_ids,omitempty"`
Type string `json:"type,omitempty"`
PersonnaeDbId string `json:"personnae_db_id,omitempty"`
// Invitation temporary keypair (step 1 only — discarded after step 3)
InvitationKp *meowlib.KeyPair `json:"invitation_kp,omitempty"`
// Double Ratchet state
DrKpPublic string `json:"dr_kp_public,omitempty"`
DrKpPublic string `json:"dr_kp_public,omitempty"`
DrKpPrivate string `json:"dr_kp_private,omitempty"`
DrRootKey string `json:"dr_root_key,omitempty"`
DrInitiator bool `json:"dr_initiator,omitempty"`
@@ -171,9 +173,28 @@ func (p *Peer) BuildSingleFileMessage(filename string, message []byte) ([]meowli
return msgs, nil
}
// Builds an invitation answer user message.
// it takes as input a contactcard generated by Identity.AnswerInvitation
func (p *Peer) BuildInvitationAnswerMessage(myContactCard *meowlib.ContactCard) (*meowlib.UserMessage, error) {
// BuildInvitationStep2Message builds the invitee's answer UserMessage (STEP_2_SEND).
// The ContactCard is encrypted with the initiator's temp public key via ProcessOutboundUserMessage.
func (p *Peer) BuildInvitationStep2Message(myContactCard *meowlib.ContactCard) (*meowlib.UserMessage, error) {
var msg meowlib.UserMessage
var invitation meowlib.Invitation
invitation.Step = 2
out, err := proto.Marshal(myContactCard)
if err != nil {
return nil, err
}
invitation.Uuid = p.InvitationId
invitation.Payload = out
msg.Destination = p.ContactLookupKey
msg.Invitation = &invitation
msg.From = p.MyIdentity.Public
msg.Type = "1"
return &msg, nil
}
// BuildInvitationStep3Message builds the initiator's full ContactCard UserMessage (STEP_3_SEND).
// Sent through the invitee's servers after the initiator has finalized their keypairs.
func (p *Peer) BuildInvitationStep3Message(myContactCard *meowlib.ContactCard) (*meowlib.UserMessage, error) {
var msg meowlib.UserMessage
var invitation meowlib.Invitation
invitation.Step = 3
@@ -190,6 +211,42 @@ func (p *Peer) BuildInvitationAnswerMessage(myContactCard *meowlib.ContactCard)
return &msg, nil
}
// BuildInvitationStep4Message builds the invitee's confirmation UserMessage (STEP_4).
// Sent through the initiator's servers to signal the invitation is complete.
func (p *Peer) BuildInvitationStep4Message() (*meowlib.UserMessage, error) {
var msg meowlib.UserMessage
var invitation meowlib.Invitation
invitation.Step = 4
invitation.Uuid = p.InvitationId
msg.Destination = p.ContactLookupKey
msg.Invitation = &invitation
msg.From = p.MyIdentity.Public
msg.Type = "1"
return &msg, nil
}
// ProcessInboundStep2UserMessage decrypts the invitee's step-2 answer using the
// initiator's temporary InvitationKp private key. inviteePublicKey is the sender's
// identity public key (carried in Invitation.From by the server).
func (p *Peer) ProcessInboundStep2UserMessage(packed *meowlib.PackedUserMessage, inviteePublicKey string) (*meowlib.UserMessage, error) {
dec, err := meowlib.AsymDecryptAndCheck(p.InvitationKp.Private, inviteePublicKey, packed.Payload, packed.Signature)
if err != nil {
return nil, err
}
return p.DeserializeUserMessage(dec)
}
// ProcessInboundStep3UserMessage decrypts the initiator's step-3 full ContactCard using
// the invitee's MyEncryptionKp. Signature verification is skipped because the
// initiator's identity key is not yet known — it is extracted from the decrypted payload.
func (p *Peer) ProcessInboundStep3UserMessage(packed *meowlib.PackedUserMessage) (*meowlib.UserMessage, error) {
dec, err := meowlib.AsymDecrypt(p.MyEncryptionKp.Private, packed.Payload)
if err != nil {
return nil, err
}
return p.DeserializeUserMessage(dec)
}
//
// Messages encryption and packaging
//