Client to Server messaging
This commit is contained in:
parent
53a2da8b93
commit
3ef38350c6
1
.gitignore
vendored
1
.gitignore
vendored
@ -9,3 +9,4 @@ out/doc/server_deployment/server_deployment.png
|
|||||||
*.json
|
*.json
|
||||||
test
|
test
|
||||||
id.enc
|
id.enc
|
||||||
|
invitation.png
|
||||||
|
@ -29,6 +29,13 @@ func InternalServerFromUrl(url string) *InternalServer {
|
|||||||
return &is
|
return &is
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func InternalServerFromServer(server *meowlib.Server) *InternalServer {
|
||||||
|
var is InternalServer
|
||||||
|
is.ServerData = *server
|
||||||
|
is.Me = meowlib.NewKeyPair()
|
||||||
|
return &is
|
||||||
|
}
|
||||||
|
|
||||||
func (sl *InternalServerList) AddUrls(urls []string) {
|
func (sl *InternalServerList) AddUrls(urls []string) {
|
||||||
for _, url := range urls {
|
for _, url := range urls {
|
||||||
sl.Servers = append(sl.Servers, *InternalServerFromUrl(url))
|
sl.Servers = append(sl.Servers, *InternalServerFromUrl(url))
|
||||||
@ -56,7 +63,7 @@ func (ints *InternalServer) AsymDecryptMessage(Message []byte, Signature []byte)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Creates a basic message to server from a single packed user message and returns it as protobuf serialized byte array
|
// Creates a basic message to server from a single packed user message and returns it as protobuf serialized byte array
|
||||||
func (ints *InternalServer) CreateMessageSendingMessage(usermsg *meowlib.PackedUserMessage) ([]byte, error) {
|
func (ints *InternalServer) BuildMessageSendingMessage(usermsg *meowlib.PackedUserMessage) ([]byte, error) {
|
||||||
var msg meowlib.ToServerMessage
|
var msg meowlib.ToServerMessage
|
||||||
msg.Type = "1"
|
msg.Type = "1"
|
||||||
msg.From = ints.Me.Public
|
msg.From = ints.Me.Public
|
||||||
@ -69,7 +76,7 @@ func (ints *InternalServer) CreateMessageSendingMessage(usermsg *meowlib.PackedU
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Creates a basic message to server from a single packed user message and returns it as protobuf serialized byte array
|
// Creates a basic message to server from a single packed user message and returns it as protobuf serialized byte array
|
||||||
func (ints *InternalServer) CreateMessageRequestMessage(lookupKeys []string) ([]byte, error) {
|
func (ints *InternalServer) BuildMessageRequestMessage(lookupKeys []string) ([]byte, error) {
|
||||||
var msg meowlib.ToServerMessage
|
var msg meowlib.ToServerMessage
|
||||||
msg.Type = "1"
|
msg.Type = "1"
|
||||||
msg.From = ints.Me.Public
|
msg.From = ints.Me.Public
|
||||||
@ -80,3 +87,15 @@ func (ints *InternalServer) CreateMessageRequestMessage(lookupKeys []string) ([]
|
|||||||
}
|
}
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ints *InternalServer) PackServerMessage(payload []byte, signature []byte) (protoPackedMessage []byte, err error) {
|
||||||
|
var msg meowlib.PackedServerMessage
|
||||||
|
msg.From = ints.Me.Public
|
||||||
|
msg.Payload = payload
|
||||||
|
msg.Signature = signature
|
||||||
|
out, err := proto.Marshal(&msg)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
@ -48,15 +48,12 @@ func TestEndToEnd(t *testing.T) {
|
|||||||
ReceivedContact.ContactPublicKey = FirstFriendContactKp.Public
|
ReceivedContact.ContactPublicKey = FirstFriendContactKp.Public
|
||||||
ReceivedContact.EncryptionPublicKey = FirstFriendEncryptionKp.Public
|
ReceivedContact.EncryptionPublicKey = FirstFriendEncryptionKp.Public
|
||||||
ReceivedContact.LookupPublicKey = FirstFriendLookupKp.Public
|
ReceivedContact.LookupPublicKey = FirstFriendLookupKp.Public
|
||||||
ReceivedContact.AddUrls([]string{"http://myfriend.org/meow/"})
|
FriendServer1KP := meowlib.NewKeyPair()
|
||||||
|
FriendServer1 := meowlib.Server{Name: "FriendServer1", Url: "http://myfriend.org/meow/", PublicKey: FriendServer1KP.Public, Description: "Fancy description", ConfidenceLevel: 1}
|
||||||
|
ReceivedContact.PullServers = append(ReceivedContact.PullServers, &FriendServer1)
|
||||||
// end Friend simulated invitation
|
// end Friend simulated invitation
|
||||||
|
|
||||||
// End simulating contact invitation response
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
// Finalize the contact with the invitation response
|
// Finalize the contact with the invitation response
|
||||||
//
|
|
||||||
Me.FinalizeInvitation(MyFirstFriend, &ReceivedContact)
|
Me.FinalizeInvitation(MyFirstFriend, &ReceivedContact)
|
||||||
err = Me.Save("id.enc")
|
err = Me.Save("id.enc")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -69,44 +66,39 @@ func TestEndToEnd(t *testing.T) {
|
|||||||
|
|
||||||
// create message to simulated friend
|
// create message to simulated friend
|
||||||
sentmessage := "Hello friend!"
|
sentmessage := "Hello friend!"
|
||||||
EncMsg, Signature, Servers, err := MyFirstFriend.AsymEncryptMessage([]byte(sentmessage))
|
EncMsg, EncMsgSignature, FriendServers, err := MyFirstFriend.AsymEncryptMessage([]byte(sentmessage))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err.Error())
|
fmt.Println(err.Error())
|
||||||
}
|
}
|
||||||
|
fmt.Println(len(FriendServers))
|
||||||
|
packedMsg := MyFirstFriend.Pack(EncMsg, EncMsgSignature)
|
||||||
|
|
||||||
fmt.Println(len(Servers))
|
srv := FriendServers[0]
|
||||||
// simulated friend decoding the message
|
intS1 := client.InternalServerFromServer(srv)
|
||||||
//ReadMessage
|
|
||||||
|
|
||||||
// simulates if peer can decrypt my message
|
// Creating Server message
|
||||||
//Message := "toto"
|
toServerMessage, err := intS1.BuildMessageSendingMessage(&packedMsg)
|
||||||
//Signature := "test"
|
// Encrypting it
|
||||||
decMess, err2 := MyFirstFriend.AsymDecryptMessage([]byte(EncMsg), Signature)
|
encToServerMessage, encToServerMessageSignature, err := intS1.AsymEncryptMessage(toServerMessage)
|
||||||
|
// Packing it
|
||||||
|
protoPackedServerMsg, err := intS1.PackServerMessage(encToServerMessage, encToServerMessageSignature)
|
||||||
|
// Sending to server => fake action (network protocol trnasfer are not part of meowlib)
|
||||||
|
// You have to implement the netwok layer
|
||||||
|
println(len(protoPackedServerMsg))
|
||||||
|
|
||||||
|
//
|
||||||
|
// Simulating server side processing
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Back to client, decoding server response
|
||||||
|
//
|
||||||
|
decMess, err2 := MyFirstFriend.AsymDecryptMessage([]byte(EncMsg), EncMsgSignature)
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
fmt.Println(err2.Error())
|
fmt.Println(err2.Error())
|
||||||
}
|
}
|
||||||
fmt.Println(decMess)
|
fmt.Println(decMess)
|
||||||
// simulates a new server to send a message to
|
|
||||||
var intS1 client.InternalServer
|
|
||||||
intS1.ServerData.Name = "My friend's Server 1"
|
|
||||||
intS1.ServerData.Description = "My friend's Server 1"
|
|
||||||
intS1.Me = meowlib.NewKeyPair()
|
|
||||||
intS1.ServerData.Url = "http://myfriend.org/meow/"
|
|
||||||
KP := meowlib.NewKeyPair()
|
|
||||||
intS1.ServerData.PublicKey = KP.Public
|
|
||||||
|
|
||||||
// sends a message to server 1
|
|
||||||
SrvEncrypted, SrvSign, err3 := intS1.AsymEncryptMessage([]byte(sentmessage))
|
|
||||||
if err3 != nil {
|
|
||||||
fmt.Println(err3.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
// tests simulated server decrypted message
|
|
||||||
SrvDecrypted, err4 := intS1.AsymDecryptMessage(SrvEncrypted, SrvSign)
|
|
||||||
if err4 != nil {
|
|
||||||
fmt.Println(err4.Error())
|
|
||||||
}
|
|
||||||
fmt.Println("--- SrvDecryptedMess = ", string(SrvDecrypted))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user