diff --git a/.gitignore b/.gitignore index 188c9bd6a36f8131b1c4383749c34fb409b7e752..2ace18591c515a24f6c39e830b3a58ab00e35e5e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ -netcode/ +shared/netcode/ +.idea/ +.vscode/ diff --git a/README.md b/README.md index da5c979dfe7a222311a60fadd728dca91806c2f5..6a2f359976b1721385485f32b6cb109438ca1904 100644 --- a/README.md +++ b/README.md @@ -1,92 +1,33 @@ # mobile-sec-notifier +Two chat participants [A]lice and [B]ob. +Send encrypted messages indirectly via the server between A and B. +A and B in distinct networks. +# TODO: -## Getting started +- [ ] Protocol +- [ ] Server (python) +- [ ] Python-Client +- [ ] Android-Client -To make it easy for you to get started with GitLab, here's a list of recommended next steps. +# Prototype 1: -Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! +- [x] Python-Server & Python-Test-Client + - [x] Exchange messages server<->client using protobuf +- [x] Android-Client + - [x] Grab notifications + - [ ] Communicate with grpc service +- [ ] Create protocol -## Add your files +# Prototype 2: -- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files -- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: +- [ ] Python-Test-Client: + - [ ] Register to server / authenticate at the server + - [ ] Establish ephemeral key with target client + - Client-to-client key exchange (asym. encryption) + - [ ] Exchange messages using AES with ephemeral key -``` -cd existing_repo -git remote add origin https://gitlab.tugraz.at/te97tu/mobile-sec-notifier.git -git branch -M main -git push -uf origin main -``` +# Prototype 3: -## Integrate with your tools - -- [ ] [Set up project integrations](https://gitlab.tugraz.at/te97tu/mobile-sec-notifier/-/settings/integrations) - -## Collaborate with your team - -- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) -- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) -- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) -- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) -- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) - -## Test and Deploy - -Use the built-in continuous integration in GitLab. - -- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) -- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) -- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) -- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) -- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) - -*** - -# Editing this README - -When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template. - -## Suggestions for a good README -Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. - -## Name -Choose a self-explaining name for your project. - -## Description -Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. - -## Badges -On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. - -## Visuals -Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. - -## Installation -Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. - -## Usage -Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. - -## Support -Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. - -## Roadmap -If you have ideas for releases in the future, it is a good idea to list them in the README. - -## Contributing -State if you are open to contributions and what your requirements are for accepting them. - -For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. - -You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. - -## Authors and acknowledgment -Show your appreciation to those who have contributed to the project. - -## License -For open source projects, say how it is licensed. - -## Project status -If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. +- [ ] Harden against attacks (for reference: https://core.telegram.org/techfaq#protection-against-known-attacks) \ No newline at end of file diff --git a/client/python/client.py b/client/python/client.py index 578ac190f6830770920d0fc3606dcac9ef5f0055..15f13e5b573b013fca79937d431559a331a2504b 100644 --- a/client/python/client.py +++ b/client/python/client.py @@ -1,13 +1,65 @@ +import sys +sys.path.insert(0, '../..') +sys.path.insert(0, '../../shared/netcode') + +import queue import grpc -from netcode.netcode_pb2_grpc import NotifierComStub -from netcode.netcode_pb2 import * +from shared.netcode.netcode_pb2 import * +from shared.netcode.netcode_pb2_grpc import NotifierComStub + +usage = "Usage:\n- Sender:\n ./client.py 1\n- Receiver:\n ./client.py 0" -channel = grpc.insecure_channel('localhost:8080') -stub = NotifierComStub(channel) -def sendMessage(msg): - request = SendMessageRequest(msg) +def sendMessage(stub, msg): + request = Message(content=msg) response = stub.SendMessage(request) + if __name__ == "__main__": - sendMessage("test") \ No newline at end of file + # Check enough args + if len(sys.argv) < 2: + print("Error: Not enough arguments.") + print(usage) + exit(1) + + ######################################################################## + # SETTINGS + ######################################################################## + is_sender = sys.argv[1] + ######################################################################## + + # print info + print("-- SENDER --" if is_sender else "-- RECEIVER --") + + with grpc.insecure_channel('localhost:8080') as channel: + try: + grpc.channel_ready_future(channel).result(timeout=5) + except grpc.FutureTimeoutError: + print("Error: Connection to server failed.") + exit(1) + + stub = NotifierComStub(channel) + + if is_sender: + response = stub.OpenComm(OpenCommRequest(challenge=1)) + print(response) + + sendQueue = queue.SimpleQueue() + response_future = stub.SendMessage.future(iter(sendQueue.get, None)) + sendQueue.put_nowait(Message(content="init test")) + + print("Starting Prompt:") + while True: + text = input() + if text == "": + print("Stopping...") + break + print("Sending:", text) + sendQueue.put_nowait(Message(content=text)) + + else: + response = stub.AnswerComm(AnswerCommRequest(challenge=1)) + print(response) + + for message in stub.ReceiveMessage(Nothing()): + print(message.content) diff --git a/protocol.md b/protocol.md new file mode 100644 index 0000000000000000000000000000000000000000..6b5bd20b13d25c588ea9efc8d35013886bb51bbc --- /dev/null +++ b/protocol.md @@ -0,0 +1,18 @@ +# The Authentication and Message Exchange Protocol + +[A]lice wants to communicate with [B]ob privately. + +## Protocol Steps + +1. Authenticate to the server and establish communication. + 1. A tells the server to open a communication. + 2. A sends an id_code to the server. + 3. A gets a comm_id from the server. + 2. B tells the server to answer A's communication request. + 1. B receives A's challenge. + 2. B answers the solution to the server. + 3. The server checks the solution and accepts the communication establishment. +2. Generate and exchange an ephemeral key. +3. Instantiate symmetric encryption using the ephemeral key. +4. Authenticate each other directly. +5. (?) Check communication transcript (avoid malicious server). \ No newline at end of file diff --git a/server/server.py b/server/server.py index 072bee804da43af19ff0bf3d5acba171794b8d66..b04427aacfd38f3811eb6a272161300eb1065b02 100644 --- a/server/server.py +++ b/server/server.py @@ -2,17 +2,34 @@ import sys sys.path.insert(0, '..') sys.path.insert(0, '../shared/netcode') -import grpc from concurrent import futures - -from shared.netcode.netcode_pb2_grpc import * from shared.netcode.netcode_pb2 import * +from shared.netcode.netcode_pb2_grpc import * + class NotifierService(NotifierComServicer): - def SendMessage(self, request, context): - print(request.message) + def OpenComm(self, request, context): + # TODO: append id_code to list + # TODO: wait for id_code answered + # TODO: return comm_id + return CommResponse() + + def AnswerComm(self, request, context): + # TODO: check if if_code can be answered + # TODO: return comm_id + return CommResponse() + + def ReceiveMessage(self, request, context): + # TODO: read comm_id and wait for messages + yield Message(content="test") + + def SendMessage(self, request_iterator, context): + for msg in request_iterator: + # TODO: read comm_id and route message + print(msg.content) return Nothing() + if __name__ == "__main__": server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) add_NotifierComServicer_to_server( diff --git a/shared/netcode.proto b/shared/netcode.proto index 542ada6e56528a4145178d8da2ec8d5ebeae4b4c..fd30b6bfcbaff1ea4585d1344d9f0212315af626 100644 --- a/shared/netcode.proto +++ b/shared/netcode.proto @@ -7,12 +7,32 @@ option objc_class_prefix = "NC"; package netcode; -service NotifierCom { - rpc SendMessage (SendMessageRequest) returns (Nothing); +service NotifierCommunication { + rpc Open (OpenRequest) returns (CommResponse); + rpc Answer (AnswerRequest) returns (CommResponse); + rpc SendMessage (stream Message) returns (Nothing); + rpc ReceiveMessage (ReceiveRequest) returns (stream Message); } -message SendMessageRequest { - string message = 1; +message ReceiveRequest { + uint64 comm_id = 1; +} + +message Message { + uint64 comm_id = 1; + string content = 2; +} + +message OpenRequest { + int64 id_code = 1; +} + +message AnswerRequest { + int64 id_code = 1; +} + +message CommResponse { + uint64 comm_id = 1; } message Nothing {