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 (
 | 
					import (
 | 
				
			||||||
	"errors"
 | 
						"errors"
 | 
				
			||||||
 | 
					 | 
				
			||||||
	"google.golang.org/protobuf/proto"
 | 
					 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// InvitationAnswer
 | 
					// InvitationAnswer
 | 
				
			||||||
@@ -90,7 +88,7 @@ func InvitationAnswerFile(invitationFile string, nickname string, myNickname str
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// InvitationAnswerMessage
 | 
					// 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
 | 
						// find the peer with that invitation id
 | 
				
			||||||
	var peer *client.Peer
 | 
						var peer *client.Peer
 | 
				
			||||||
@@ -121,19 +119,35 @@ func InvitationAnswerMessage(invitationId string, invitationServerUid string) ([
 | 
				
			|||||||
		return nil, "InvitationAnswerMessage: ProcessOutboundUserMessage", err
 | 
							return nil, "InvitationAnswerMessage: ProcessOutboundUserMessage", err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	// Creating Server message for transporting the user message
 | 
						// Creating Server message for transporting the user message
 | 
				
			||||||
	toServerMessage := invitationServer.BuildToServerMessageFromUserMessage(packedMsg)
 | 
						toServerMessage, err := invitationServer.BuildToServerMessageInvitationAnswer(packedMsg, peer.MyIdentity.Public, timeout)
 | 
				
			||||||
	// move the payload to invitation
 | 
					 | 
				
			||||||
	toServerMessage.Messages = nil
 | 
					 | 
				
			||||||
	invitationPayload, err := proto.Marshal(packedMsg)
 | 
					 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, "InvitationAnswerMessage: proto.Marshal", err
 | 
							return nil, "InvitationAnswerMessage: BuildToServerMessageInvitationAnswer", err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	toServerMessage.Invitation.Payload = invitationPayload
 | 
					
 | 
				
			||||||
	toServerMessage.Invitation = &meowlib.Invitation{Step: 3}
 | 
						// Server outbound processing
 | 
				
			||||||
	toServerMessage.Invitation.From = peer.MyIdentity.Public
 | 
					 | 
				
			||||||
	bytemsg, err := invitationServer.ProcessOutboundMessage(toServerMessage)
 | 
						bytemsg, err := invitationServer.ProcessOutboundMessage(toServerMessage)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		return nil, "InvitationAnswerMessage: ProcessOutboundMessage", err
 | 
							return nil, "InvitationAnswerMessage: ProcessOutboundMessage", err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	return bytemsg, "", nil
 | 
						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
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -198,6 +198,36 @@ func (ints *Server) BuildToServerMessageInvitationRequest(shortcode string, pass
 | 
				
			|||||||
	return &msg, nil
 | 
						return &msg, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// BuildToServerMessageInvitationAnswer creates an invitation answer to server and returns it as a meowlib.ToServerMessage
 | 
				
			||||||
 | 
					// it takes as input a contactcard generated by Identity.InvitePeer
 | 
				
			||||||
 | 
					func (ints *Server) BuildToServerMessageInvitationAnswer(invitationAnswer *meowlib.PackedUserMessage, myPublicKeyForThatPeer string, timeout int) (*meowlib.ToServerMessage, error) {
 | 
				
			||||||
 | 
						var msg meowlib.ToServerMessage
 | 
				
			||||||
 | 
						var inv meowlib.Invitation
 | 
				
			||||||
 | 
						invitationPayload, err := proto.Marshal(invitationAnswer)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							return nil, err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						inv.Step = 3
 | 
				
			||||||
 | 
						msg.Type = "1"
 | 
				
			||||||
 | 
						msg.From = ints.UserKp.Public
 | 
				
			||||||
 | 
						inv.From = myPublicKeyForThatPeer
 | 
				
			||||||
 | 
						inv.Payload = invitationPayload
 | 
				
			||||||
 | 
						msg.Invitation = &inv
 | 
				
			||||||
 | 
						return &msg, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// BuildToServerMessageInvitationAnswerRequest requests invitation answer with provided id from server and returns it as a meowlib.ToServerMessage
 | 
				
			||||||
 | 
					func (ints *Server) BuildToServerMessageInvitationAnswerRequest(invitationId string) (*meowlib.ToServerMessage, error) {
 | 
				
			||||||
 | 
						var msg meowlib.ToServerMessage
 | 
				
			||||||
 | 
						var inv meowlib.Invitation
 | 
				
			||||||
 | 
						msg.Type = "1"
 | 
				
			||||||
 | 
						msg.From = ints.UserKp.Public
 | 
				
			||||||
 | 
						inv.Step = 4
 | 
				
			||||||
 | 
						inv.Uuid = invitationId
 | 
				
			||||||
 | 
						msg.Invitation = &inv
 | 
				
			||||||
 | 
						return &msg, nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// PackServerMessage
 | 
					// PackServerMessage
 | 
				
			||||||
func (ints *Server) PackServerMessage(payload []byte, signature []byte) (protoPackedMessage []byte, err error) {
 | 
					func (ints *Server) PackServerMessage(payload []byte, signature []byte) (protoPackedMessage []byte, err error) {
 | 
				
			||||||
	var msg meowlib.PackedServerMessage
 | 
						var msg meowlib.PackedServerMessage
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -145,18 +145,27 @@ func (r *RedisRouter) Route(msg *meowlib.ToServerMessage) (*meowlib.FromServerMe
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
		// accept invitation => store accepted invitation for initiator
 | 
							// accept invitation => store accepted invitation for initiator
 | 
				
			||||||
		case 3:
 | 
							case 3:
 | 
				
			||||||
			expiry := r.StoreAnswerToInvitation(msg.Invitation.Uuid, int(msg.Invitation.Timeout), msg.Invitation.Payload, r.InvitationTimeout)
 | 
								data, err := proto.Marshal(msg.Invitation)
 | 
				
			||||||
 | 
								if err != nil {
 | 
				
			||||||
 | 
									return nil, err
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								expiry := r.StoreAnswerToInvitation(msg.Invitation.Uuid, int(msg.Invitation.Timeout), data, r.InvitationTimeout)
 | 
				
			||||||
			from_server.Invitation = &meowlib.Invitation{}
 | 
								from_server.Invitation = &meowlib.Invitation{}
 | 
				
			||||||
			from_server.Invitation.Expiry = expiry.UTC().Unix()
 | 
								from_server.Invitation.Expiry = expiry.UTC().Unix()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		// get accepted invitation => send accepted invitation to initiator
 | 
							// get accepted invitation => send accepted invitation to initiator
 | 
				
			||||||
		case 4:
 | 
							case 4:
 | 
				
			||||||
			from_server.Invitation = &meowlib.Invitation{}
 | 
								from_server.Invitation = &meowlib.Invitation{}
 | 
				
			||||||
			answer, err := r.GetAnswerToInvitation(msg.Invitation.Uuid)
 | 
								var answer meowlib.Invitation
 | 
				
			||||||
 | 
								storedAanswer, err := r.GetAnswerToInvitation(msg.Invitation.Uuid)
 | 
				
			||||||
			if err != nil {
 | 
								if err != nil {
 | 
				
			||||||
				from_server.Invitation.Payload = []byte("invitation answer not found")
 | 
									from_server.Invitation.Payload = []byte("invitation answer not found")
 | 
				
			||||||
			} else {
 | 
								} else {
 | 
				
			||||||
				from_server.Invitation.Payload = answer
 | 
									err := proto.Unmarshal(storedAanswer, &answer)
 | 
				
			||||||
 | 
									if err != nil {
 | 
				
			||||||
 | 
										from_server.Invitation.Payload = []byte("invitation answer corrupted")
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									from_server.Invitation = &answer
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user