review3 renames

This commit is contained in:
N
2022-09-06 17:07:35 +02:00
parent 37fadc5bb3
commit 8778ae0aef
10 changed files with 586 additions and 553 deletions

View File

@ -15,21 +15,21 @@ func TestEndToEnd(t *testing.T) {
// Create my own identity
//
fmt.Println("Trying to load identity from file.")
me, err := client.LoadIdentity("id.enc")
Me, err := client.LoadIdentity("id.enc")
if err != nil {
fmt.Println("Failed : creating New identity...")
me = client.CreateIdentity("myname")
Me = client.CreateIdentity("myname")
//
// define my preferences (servers)
//
me.MessageServers.Name = "Message Servers"
me.MessageServers.AddUrls([]string{"http://127.0.0.1/meow/", "mqtt://127.0.0.1", "meow://127.0.0.1"})
Me.MessageServers.Name = "Message Servers"
Me.MessageServers.AddUrls([]string{"http://127.0.0.1/meow/", "mqtt://127.0.0.1", "meow://127.0.0.1"})
//
// create an invitation for a friend, I want him/her to know me as Bender
//
fmt.Println("Creating an invitation for the first friend...")
myFirstFriend, invitation := me.InvitePeer("Bender", "myfirstfriend", []int{1, 2})
MyFirstFriend, invitation := Me.InvitePeer("Bender", "myfirstfriend", []int{1, 2})
// print my invitation
a, _ := json.Marshal(invitation)
fmt.Println(string(a))
@ -38,17 +38,17 @@ func TestEndToEnd(t *testing.T) {
//
// Simulate peer invitation response : generate the friend's keypair
fmt.Println("Simulating first friend answer...")
var receivedContact meowlib.ContactCard
var ReceivedContact meowlib.ContactCard
// Friend simulated invitation
firstFriendContactKp := meowlib.NewKeyPair()
firstFriendEncryptionKp := meowlib.NewKeyPair()
firstFriendLookupKp := meowlib.NewKeyPair()
receivedContact.Name = "I'm the friend"
receivedContact.ContactPublicKey = firstFriendContactKp.Public
receivedContact.EncryptionPublicKey = firstFriendEncryptionKp.Public
receivedContact.LookupPublicKey = firstFriendLookupKp.Public
receivedContact.AddUrls([]string{"http://myfriend.org/meow/"})
FirstFriendContactKp := meowlib.NewKeyPair()
FirstFriendEncryptionKp := meowlib.NewKeyPair()
FirstFriendLookupKp := meowlib.NewKeyPair()
ReceivedContact.Name = "I'm the friend"
ReceivedContact.ContactPublicKey = FirstFriendContactKp.Public
ReceivedContact.EncryptionPublicKey = FirstFriendEncryptionKp.Public
ReceivedContact.LookupPublicKey = FirstFriendLookupKp.Public
ReceivedContact.AddUrls([]string{"http://myfriend.org/meow/"})
// end Friend simulated invitation
// End simulating contact invitation response
@ -57,19 +57,19 @@ func TestEndToEnd(t *testing.T) {
//
// Finalize the contact with the invitation response
//
me.FinalizeInvitation(myFirstFriend, &receivedContact)
err = me.Save("id.enc")
Me.FinalizeInvitation(MyFirstFriend, &ReceivedContact)
err = Me.Save("id.enc")
if err != nil {
fmt.Println(err.Error())
}
a, _ = json.Marshal(me)
a, _ = json.Marshal(Me)
ioutil.WriteFile("id.json", a, 0644)
fmt.Println(string(a))
// create message to simulated friend
sentmessage := "Hello friend!"
lookupK, EncMsg, MsgSignature, Servers, err := myFirstFriend.CreateMessage([]byte(sentmessage))
lookupK, EncMsg, Signature, Servers, err := MyFirstFriend.AsymEncryptMessage([]byte(sentmessage))
if err != nil {
fmt.Println(err.Error())
}
@ -81,12 +81,33 @@ func TestEndToEnd(t *testing.T) {
// simulates if peer can decrypt my message
//Message := "toto"
//Signature := "test"
decMess, err2 := meowlib.DecryptAndCheck(myFirstFriend.EncryptionKp.Private, myFirstFriend.Contact.EncryptionPublicKey, []byte(EncMsg), MsgSignature)
decMess, err2 := MyFirstFriend.AsymDecryptMessage([]byte(EncMsg), Signature)
if err2 != nil {
fmt.Println(err2.Error())
}
fmt.Println(decMess)
//
fmt.Println("--- myFriend.decryptedMess = ", string(decMess))
// simulates a new server to send a message to
var intS1 client.InternalServer
intS1.ServerData.Name = "IntS1"
intS1.ServerData.Description = "Internal Serveur 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))
}
}