From 3966299a91ba708a8391d6b4d53c93cf540719fb Mon Sep 17 00:00:00 2001 From: ycc Date: Mon, 29 Aug 2022 15:40:29 +0200 Subject: [PATCH] last-before-sharing --- .gitignore | 8 + doc/general_deployment.puml | 21 + doc/protocol.tex | 2 +- doc/server_deployment.puml | 36 + doc/{archi01.puml => usecase01.puml} | 0 doc/{archi02.puml => usecase02.puml} | 0 doc/{archi03.puml => usecase03.puml} | 0 endtoend_test.go | 4 +- https.go | 4 - identity.go | 6 +- invitation.png | Bin 530 -> 0 bytes messages.json | 0 messages.pb.go | 1191 ++++++++++++++++++++++++++ pb/messages.py | 17 + peer.go | 16 +- 15 files changed, 1287 insertions(+), 18 deletions(-) create mode 100644 .gitignore create mode 100644 doc/general_deployment.puml create mode 100644 doc/server_deployment.puml rename doc/{archi01.puml => usecase01.puml} (100%) rename doc/{archi02.puml => usecase02.puml} (100%) rename doc/{archi03.puml => usecase03.puml} (100%) delete mode 100644 invitation.png create mode 100644 messages.json create mode 100644 messages.pb.go create mode 100644 pb/messages.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..672abc9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +doc/protocol.aux +doc/protocol.fdb_latexmk +doc/protocol.fls +doc/protocol.log +doc/protocol.pdf +doc/protocol.synctex.gz +out/doc/general_deployment/general_deployment.png +out/doc/server_deployment/server_deployment.png diff --git a/doc/general_deployment.puml b/doc/general_deployment.puml new file mode 100644 index 0000000..418771c --- /dev/null +++ b/doc/general_deployment.puml @@ -0,0 +1,21 @@ +@startuml + +cloud net as "Network" + +component mapp as "Mobile Application" +component capp as "CLI Application" +component dapp as "Desktop Application" +component proxy1 as "Http Web Service Proxy" +component proxy2 as "Http Web Service Proxy" +component ws1 as "Company 1 Web Services" #LightGray +component ws2 as "Company 2 Web Client" #LightGray +component srv1 as "Server" +net -- srv1 +net -- mapp +net -- capp +net -- dapp +net -- proxy1 +net -- proxy2 +ws1 -- proxy1 +ws2 -- proxy2 +ws2 ..> ws1 diff --git a/doc/protocol.tex b/doc/protocol.tex index deef7fa..f7ea59b 100644 --- a/doc/protocol.tex +++ b/doc/protocol.tex @@ -120,7 +120,7 @@ The Ekp is used to cypher your conversation. \subsection{Conversation lookup} A contact conversation Lookup Key Pair(Lkp) is also associated with your conversation. The Lkp public key is used to identify your conversation on a server. -the private key allows you to sign your tequest and prove the server that you are the legitimate recipient for a message. +the private key allows you to sign your request and prove the server that you are the legitimate recipient for a message. This Lkp can be changed anytime by it's owner and the new public key will be sent along the last message. The Lkp and the Ekp are only changed, once the change has beeen acknowledged by your contact. diff --git a/doc/server_deployment.puml b/doc/server_deployment.puml new file mode 100644 index 0000000..5a3c8f0 --- /dev/null +++ b/doc/server_deployment.puml @@ -0,0 +1,36 @@ +@startuml + +cloud Network +component lb as "Load Balancer" +component http1 as "HTTP Server" +component http2 as "HTTP Server" +component ws1 as "Websocket Server" +component ws2 as "Websocket Server" +component ws3 as "Websocket Server" +component ws4 as "..." +database q as "Message Queue" +component d1 as "Message Dispatcher" +component d2 as "Message Dispatcher" +component d3 as "Message Dispatcher" +component d4 as "Message Dispatcher" +component d5 as "..." + +lb -- http1 +lb -- http2 +lb -- ws1 +lb -- ws2 +lb -- ws3 +lb -- ws4 +http1 -- q +http2 -- q +ws1 -- q +ws2 -- q +ws3 -- q +q -- d1 +q -- d2 +q -- d3 +q -- d4 +q -- d5 +Network -- lb + +@enduml \ No newline at end of file diff --git a/doc/archi01.puml b/doc/usecase01.puml similarity index 100% rename from doc/archi01.puml rename to doc/usecase01.puml diff --git a/doc/archi02.puml b/doc/usecase02.puml similarity index 100% rename from doc/archi02.puml rename to doc/usecase02.puml diff --git a/doc/archi03.puml b/doc/usecase03.puml similarity index 100% rename from doc/archi03.puml rename to doc/usecase03.puml diff --git a/endtoend_test.go b/endtoend_test.go index 2e0f9e3..30ca649 100644 --- a/endtoend_test.go +++ b/endtoend_test.go @@ -35,7 +35,7 @@ func TestEndToEnd(t *testing.T) { // // Simulate peer invitation response : generate the friend's keypair fmt.Println("Simulating first friend answer...") - var receivedContact Contact + var receivedContact ContactCard firstFriendContactKp := NewKeyPair() firstFriendEncryptionKp := NewKeyPair() firstFriendLookupKp := NewKeyPair() @@ -48,7 +48,7 @@ func TestEndToEnd(t *testing.T) { for _, srv := range friendsMessageServers.Servers { receivedContact.PullServers = append(receivedContact.PullServers, srv.ServerData) } - // End simulating concact invitation response + // End simulating contact invitation response // // diff --git a/https.go b/https.go index f9222a1..c3aabff 100644 --- a/https.go +++ b/https.go @@ -25,13 +25,9 @@ func (https *Https) Send(msg []byte) ([]byte, error) { } func (https *Https) Start(callback *func() []InternalMessage) { - for { - } } func (https *Https) Stop() { - for { - } } diff --git a/identity.go b/identity.go index 7461475..3a098b0 100644 --- a/identity.go +++ b/identity.go @@ -28,9 +28,9 @@ func CreateIdentity(nickname string) *Identity { return &id } -func (id *Identity) InvitePeer(myName string, contactName string, messageServerIdxs []int) (*Peer, *Contact) { +func (id *Identity) InvitePeer(myName string, contactName string, messageServerIdxs []int) (*Peer, *ContactCard) { var peer Peer - var myContactCard Contact + var myContactCard ContactCard peer.Me = NewKeyPair() peer.EncryptionKp = NewKeyPair() peer.LookupKp = NewKeyPair() @@ -48,7 +48,7 @@ func (id *Identity) InvitePeer(myName string, contactName string, messageServerI return &id.Peers[len(id.Peers)-1], &myContactCard } -func (*Identity) FinalizeInvitation(peer *Peer, receivedContact *Contact) { +func (*Identity) FinalizeInvitation(peer *Peer, receivedContact *ContactCard) { peer.Contact = *receivedContact } diff --git a/invitation.png b/invitation.png deleted file mode 100644 index d9bde5902d183e1206ab712636a8920b95d5ee09..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 530 zcmV+t0`2{YP)U8PPD4 zxfv0ujP}P^{|rmp&-tHf5)r{ zc{2EVTHQ@3_r;;R-QV-JthX^ND($nDnXoD}d{N(|uKXJY9GW<}*&7vKEA-j4;-=yE zi|V2Gb~Vb&2RsuU7$aRN^VE;p0(fvAcwF$f?|!T%onu4##B%A3#m0?@{U?-*{tKB& zs!Z5sEH@db1K|NQ$NoU8`>ffB3{7Jei-Wz6S`C`;z;{BMT^V`URh;xx$#5QZ6 zU#CwqvnqGl8FN2U0tnNXbRjTT$+EdjF2togX8qc^=v$1qyxS4VgU*<{?0l}6DR<|( zKrr!J&}tNEmdxrqK`j45fL2(n@?Ud;SWX@hOx!1!_)~(3rwAs#Aei`sVB!Lt7}=VE@b&08cu=lwa{=5daVW;ZbPe~q2U2EG#L#yL6cQ9d<(MLM#B$5 zZI{sSCA3RA8lHoauA$-YLDv*CoPwq_(Qp@(rizBwp{dr;a0b-c5gLB meowlib.ServerMessage.ConversationRequest + 8, // 1: meowlib.ServerMessage.PollResponse:type_name -> meowlib.ServerMessage.PollResponseEntry + 9, // 2: meowlib.ServerMessage.Messages:type_name -> meowlib.ServerMessage.PostedMessage + 3, // 3: meowlib.MinimalContact.TrustedServers:type_name -> meowlib.Server + 10, // 4: meowlib.UserMessage.Status:type_name -> meowlib.UserMessage.ConversationStatus + 4, // 5: meowlib.UserMessage.contact:type_name -> meowlib.MinimalContact + 11, // 6: meowlib.UserMessage.group:type_name -> meowlib.UserMessage.Group + 7, // 7: meowlib.ServerMessage.PollResponseEntry.value:type_name -> meowlib.ServerMessage.ConversationResponse + 1, // 8: meowlib.ServerMessage.PostedMessage.Messages:type_name -> meowlib.PackedUserMessage + 4, // 9: meowlib.UserMessage.Group.members:type_name -> meowlib.MinimalContact + 10, // [10:10] is the sub-list for method output_type + 10, // [10:10] is the sub-list for method input_type + 10, // [10:10] is the sub-list for extension type_name + 10, // [10:10] is the sub-list for extension extendee + 0, // [0:10] is the sub-list for field type_name +} + +func init() { file_messages_proto_init() } +func file_messages_proto_init() { + if File_messages_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_messages_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*PackedServerMessage); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_messages_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*PackedUserMessage); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_messages_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ServerMessage); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_messages_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Server); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_messages_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*MinimalContact); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_messages_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UserMessage); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_messages_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ServerMessage_ConversationRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_messages_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ServerMessage_ConversationResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_messages_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ServerMessage_PostedMessage); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_messages_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UserMessage_ConversationStatus); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_messages_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*UserMessage_Group); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_messages_proto_rawDesc, + NumEnums: 0, + NumMessages: 12, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_messages_proto_goTypes, + DependencyIndexes: file_messages_proto_depIdxs, + MessageInfos: file_messages_proto_msgTypes, + }.Build() + File_messages_proto = out.File + file_messages_proto_rawDesc = nil + file_messages_proto_goTypes = nil + file_messages_proto_depIdxs = nil +} diff --git a/pb/messages.py b/pb/messages.py new file mode 100644 index 0000000..70377cc --- /dev/null +++ b/pb/messages.py @@ -0,0 +1,17 @@ +from socket import MsgFlag +import protoparser +import json + +def parseMessage(pb, parent): + if hasattr(pb, 'messages'): + for msg in pb.messages: + print(pb.messages) + + + +pb = protoparser.parse_from_file("pb/messages.proto") +#print(json.dumps(pb)) +print(json.dumps(pb.messages)) + +with open('messages.json', 'w') as f: + f.write(pb) \ No newline at end of file diff --git a/peer.go b/peer.go index 3e97d31..7869b31 100644 --- a/peer.go +++ b/peer.go @@ -16,7 +16,7 @@ import ( "github.com/makiuchi-d/gozxing/qrcode" ) -type Contact struct { +type ContactCard struct { Name string `json:"name,omitempty"` ContactPublicKey string `json:"contact_public_key,omitempty"` EncryptionPublicKey string `json:"encryption_public_key,omitempty"` @@ -27,7 +27,7 @@ type Contact struct { type Peer struct { Name string `json:"name,omitempty"` Me KeyPair `json:"me,omitempty"` - Contact Contact `json:"contact,omitempty"` + Contact ContactCard `json:"contact,omitempty"` Visible bool `json:"visible,omitempty"` VisiblePassword string `json:"visible_password,omitempty"` PasswordType string `json:"password_type,omitempty"` @@ -45,8 +45,8 @@ type Peer struct { type PeerList []Peer type Group struct { - Name string `json:"name,omitempty"` - Members []Contact `json:"members,omitempty"` + Name string `json:"name,omitempty"` + Members []ContactCard `json:"members,omitempty"` } func (pl *PeerList) GetFromPublicKey(publickey string) *Peer { @@ -81,7 +81,7 @@ func (peer *Peer) SendText(text string) { fmt.Println(im.MessageData.Destination) } -func (contact *Contact) WritePng(filename string) { +func (contact *ContactCard) WritePng(filename string) { jsonContact, _ := json.Marshal(contact) //imgdata := base64.StdEncoding.EncodeToString(jsonContact) size := int(math.Sqrt(float64(len(jsonContact))/3)) + 1 @@ -120,7 +120,7 @@ func (contact *Contact) WritePng(filename string) { } -func (contact *Contact) WriteQr(filename string) { +func (contact *ContactCard) WriteQr(filename string) { jsonContact, _ := json.Marshal(contact) qwriter := qrcode.NewQRCodeWriter() code, err := qwriter.Encode(string(jsonContact), gozxing.BarcodeFormat_QR_CODE, 512, 512, nil) @@ -136,8 +136,8 @@ func (contact *Contact) WriteQr(filename string) { } -func ReadQr(fielname string) Contact { - var contact Contact +func ReadQr(fielname string) ContactCard { + var contact ContactCard // open and decode image file file, _ := os.Open("qrcode.jpg") img, _, _ := image.Decode(file)