Server side invitation step 3/4 preserve From public key / Client finalize in progress
	
		
			
	
		
	
	
		
	
		
			Some checks failed
		
		
	
	
		
			
				
	
				continuous-integration/drone/push Build is failing
				
			
		
		
	
	
				
					
				
			
		
			Some checks failed
		
		
	
	continuous-integration/drone/push Build is failing
				
			This commit is contained in:
		@@ -11,8 +11,6 @@ import (
 | 
			
		||||
)
 | 
			
		||||
import (
 | 
			
		||||
	"errors"
 | 
			
		||||
 | 
			
		||||
	"google.golang.org/protobuf/proto"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// InvitationAnswer
 | 
			
		||||
@@ -90,7 +88,7 @@ func InvitationAnswerFile(invitationFile string, nickname string, myNickname str
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// InvitationAnswerMessage
 | 
			
		||||
func InvitationAnswerMessage(invitationId string, invitationServerUid string) ([]byte, string, error) {
 | 
			
		||||
func InvitationAnswerMessage(invitationId string, invitationServerUid string, timeout int) ([]byte, string, error) {
 | 
			
		||||
 | 
			
		||||
	// find the peer with that invitation id
 | 
			
		||||
	var peer *client.Peer
 | 
			
		||||
@@ -121,19 +119,35 @@ func InvitationAnswerMessage(invitationId string, invitationServerUid string) ([
 | 
			
		||||
		return nil, "InvitationAnswerMessage: ProcessOutboundUserMessage", err
 | 
			
		||||
	}
 | 
			
		||||
	// Creating Server message for transporting the user message
 | 
			
		||||
	toServerMessage := invitationServer.BuildToServerMessageFromUserMessage(packedMsg)
 | 
			
		||||
	// move the payload to invitation
 | 
			
		||||
	toServerMessage.Messages = nil
 | 
			
		||||
	invitationPayload, err := proto.Marshal(packedMsg)
 | 
			
		||||
	toServerMessage, err := invitationServer.BuildToServerMessageInvitationAnswer(packedMsg, peer.MyIdentity.Public, timeout)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, "InvitationAnswerMessage: proto.Marshal", err
 | 
			
		||||
		return nil, "InvitationAnswerMessage: BuildToServerMessageInvitationAnswer", err
 | 
			
		||||
	}
 | 
			
		||||
	toServerMessage.Invitation.Payload = invitationPayload
 | 
			
		||||
	toServerMessage.Invitation = &meowlib.Invitation{Step: 3}
 | 
			
		||||
	toServerMessage.Invitation.From = peer.MyIdentity.Public
 | 
			
		||||
 | 
			
		||||
	// Server outbound processing
 | 
			
		||||
	bytemsg, err := invitationServer.ProcessOutboundMessage(toServerMessage)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, "InvitationAnswerMessage: ProcessOutboundMessage", err
 | 
			
		||||
	}
 | 
			
		||||
	return bytemsg, "", nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// InvitationAnswerMessageReadResponse
 | 
			
		||||
// Called by the invitation receiver
 | 
			
		||||
// invitationData: the data received from the server
 | 
			
		||||
// invitationServerUid: the uid of the server holding the invitation
 | 
			
		||||
func InvitationAnswerMessageReadResponse(invitationData []byte, invitationServerUid string) (*meowlib.Invitation, string, error) {
 | 
			
		||||
 | 
			
		||||
	server, err := client.GetConfig().GetIdentity().MessageServers.LoadServer(invitationServerUid)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, "InvitationGetMessageReadResponse: LoadServer", err
 | 
			
		||||
	}
 | 
			
		||||
	// Server inbound processing : get the invitation server
 | 
			
		||||
	serverMsg, err := server.ProcessInboundServerResponse(invitationData)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, "InvitationGetMessageReadResponse: ProcessInboundServerResponse", err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return serverMsg.Invitation, "", nil
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										72
									
								
								client/helpers/invitationFinalizeHelper.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										72
									
								
								client/helpers/invitationFinalizeHelper.go
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,72 @@
 | 
			
		||||
package helpers
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"forge.redroom.link/yves/meowlib"
 | 
			
		||||
	"forge.redroom.link/yves/meowlib/client"
 | 
			
		||||
	"google.golang.org/protobuf/proto"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
// InvitationGetAnswer
 | 
			
		||||
// Called by the invitation initiator
 | 
			
		||||
// invitationId: the id of the invitation
 | 
			
		||||
// serverUid: the uid of the server holding the invitation answer
 | 
			
		||||
func InvitationGetAnswer(invitationId string, serverUid string) ([]byte, string, error) {
 | 
			
		||||
 | 
			
		||||
	// check if already in msg servers
 | 
			
		||||
	srv, err := client.GetConfig().GetIdentity().MessageServers.LoadServer(serverUid)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, "InvitationGetAnswer: LoadServer", err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// buildserver message
 | 
			
		||||
	toSrvMsg, err := srv.BuildToServerMessageInvitationAnswerRequest(invitationId)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, "InvitationGetAnswer: BuildToServerMessageInvitationRequest", err
 | 
			
		||||
	}
 | 
			
		||||
	// processoutbound
 | 
			
		||||
	bytemsg, err := srv.ProcessOutboundMessage(toSrvMsg)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return nil, "InvitationGetAnswer: ProcessOutboundMessage", err
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return bytemsg, "", nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// InvitationGetAnswerReadResponse
 | 
			
		||||
// Called by the invitation initiator
 | 
			
		||||
// invitationAnswerData: the data received from the server
 | 
			
		||||
// invitationServerUid: the uid of the server holding the invitation
 | 
			
		||||
func InvitationGetAnswerReadResponse(invitationAnswerData []byte, invitationServerUid string) (string, error) {
 | 
			
		||||
 | 
			
		||||
	server, err := client.GetConfig().GetIdentity().MessageServers.LoadServer(invitationServerUid)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return "InvitationGetAnswerReadResponse: LoadServer", err
 | 
			
		||||
	}
 | 
			
		||||
	// Server inbound processing : get the invitation server
 | 
			
		||||
	serverMsg, err := server.ProcessInboundServerResponse(invitationAnswerData)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return "InvitationGetAnswerReadResponse: ProcessInboundServerResponse", err
 | 
			
		||||
	}
 | 
			
		||||
	// fmt.Println("Inbound OK, Invitation Step: ", serverMsg.Invitation.Step, len(serverMsg.Invitation.Payload))
 | 
			
		||||
	// fmt.Println("Invitation Check")
 | 
			
		||||
	// fmt.Println(hex.EncodeToString(serverMsg.Invitation.Payload))
 | 
			
		||||
	// contactCard decode
 | 
			
		||||
 | 
			
		||||
	// decode the payload
 | 
			
		||||
	var invitationAnswer meowlib.PackedUserMessage
 | 
			
		||||
	err = proto.Unmarshal(serverMsg.Invitation.Payload, &invitationAnswer)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return "InvitationGetAnswerReadResponse: Unmarshal", err
 | 
			
		||||
	}
 | 
			
		||||
	// retreive user public key to check usermessage signature
 | 
			
		||||
	//contactPublikKey := serverMsg.Invitation.From
 | 
			
		||||
 | 
			
		||||
	// process the packed user message
 | 
			
		||||
 | 
			
		||||
	// finalize the invitation
 | 
			
		||||
	//	id := client.GetConfig().GetIdentity()
 | 
			
		||||
 | 
			
		||||
	//	cc, err := id.FinalizeInvitation(serverMsg.Invitation.)
 | 
			
		||||
 | 
			
		||||
	return "", nil
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user