{"id":24515978,"url":"https://github.com/ph4r05/chat-roulette-client","last_synced_at":"2026-07-12T01:31:15.989Z","repository":{"id":141760866,"uuid":"74214749","full_name":"ph4r05/chat-roulette-client","owner":"ph4r05","description":"PV181 client application for DH demonstration","archived":false,"fork":false,"pushed_at":"2016-11-19T15:24:21.000Z","size":4418,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-28T21:34:21.484Z","etag":null,"topics":["bouncy-castle","chat-roulette","demo","diffie-hellman","educational-materials","java","jca","protocol","security"],"latest_commit_sha":null,"homepage":null,"language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ph4r05.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-11-19T14:51:17.000Z","updated_at":"2017-02-21T21:23:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"7ee305a9-341b-4ce8-90c1-09ade0719b46","html_url":"https://github.com/ph4r05/chat-roulette-client","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ph4r05/chat-roulette-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ph4r05%2Fchat-roulette-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ph4r05%2Fchat-roulette-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ph4r05%2Fchat-roulette-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ph4r05%2Fchat-roulette-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ph4r05","download_url":"https://codeload.github.com/ph4r05/chat-roulette-client/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ph4r05%2Fchat-roulette-client/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35379590,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-11T02:00:05.354Z","response_time":104,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bouncy-castle","chat-roulette","demo","diffie-hellman","educational-materials","java","jca","protocol","security"],"created_at":"2025-01-22T01:20:20.211Z","updated_at":"2026-07-12T01:31:15.980Z","avatar_url":"https://github.com/ph4r05.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Diffie-Hellman exercise - chat roulette client for PV181\n\nClient communication library for chat-roulette algorithm demonstrating use \nof DH key agreement in practice.\n\n## Introduction\n\nFor the client-server communication take a look at the [chat-roulette-python] \nrepository readme, it contains brief protocol overview. \n\nThe basic communication with the server is already handled in this client \nrepository so you don't have to take care about ping protocol. \n\nFeel free to use existing code snippets to send missing messages and finish the \nhomework assignment.\n\n## Protocol\n\nAll the binary values are in the protocol encoded in Base64. To convert \n`byte[]` to Base64 string, use for example `DatatypeConverter.printBase64Binary(res);`.\nFor reverse conversion use `DatatypeConverter.parseBase64Binary(theString);`.\n\nOn successfull pairing, the server sends you a message\n\n```json\n{\"uco\":\"1\",\"cmd\":\"pair\"}\n````\n\nThen initiator starts the protocol by sending his DH public key part to the responder:\n\n```json\n{\"uco\":\"1\",\"sub\":\"dh1\",\"session\":\"alpha\",\"dhpub\":\"MIIBpjCCARsGCSqGSIb3DQEDATCCAQwCgYEA/X9TgR11EilS30qcLuzk5/YRt1I870QAwx4/gLZRJmlFXUAiUftZPY1Y+r/F9bow9subVWzXgTuAHTRv8mZgt2uZUKWkn5/oBHsQIsJPu6nX/rfGG/g7V+fGqKYVDwT7g/bTxR7DAjVUE1oWkTL2dfOuK2HXKu/yIgMZndFIAccCgYEA9+GghdabPd7LvKtcNrhXuXmUr7v6OuqC+VdMCz0HgmdRWVeOutRZT+ZxBxCBgLRJFnEj6EwoFhO3zwkyjMim4TwWeotUfI0o4KOuHiuzpnWRbqN/C/ohNWLx+2J6ASQ7zKTxvqhRkImog9/hWuWfBpKLZl6Ae1UlZAFMO/7PSSoCAgIAA4GEAAKBgF28kIT49kNTZe3L6MP0xi7oSsxlZF+5kO70QXEkZ2fa89xuNghKJdq8B0ySHQKo+G+btpGb25B/TcZgj/FwbguwPDQkZgWcC4UwCXeWTpgQe0H6kmqnyR4SusrdMAAa1qFmiBNiYdUGo5ZRQ+GX69nJoYFdbRAwLKoQ2jonn4yx\",\"cmd\":\"comm\",\"nonce\":-235611940}\n```\n\nThis is already implemented in the code so you see how to handle incoming messages\nand send new ones. The message above was sent by the following code:\n\n```java\nJSONObject dh1 = preparePeerMsg(SUB_DH1);\ndh1.put(FIELD_DHPUB, pubKeyBase64);\ncomm.enqueue(dh1);\n```\n\nThe messages are simple JSON objects, `preparePeerMsg` prepares a new JSON message \nskeleton for you (fills in required fields like `uco, session, nonce, cmd`) and sets `sub` field to the value\n`SUB_DH1` - meaning this is the first DH message (from initiator to responder).\nThe public key is set to the message, to the field with name `FIELD_DHPUB` and\nmessage is enqueued to the sending queue.\n\nAfter responder receives the DH1, he replies with DH2 message (containing his DH pub key):\n\n```json\n{\"uco\":\"325219\",\"sub\":\"dh2\",\"session\":\"alpha\",\"cmd\":\"comm\",\"dhpub\":\"MIIBpjCCARsGCSqGSIb3DQEDATCCAQwCgYEA/X9TgR11EilS30qcLuzk5/YRt1I870QAwx4/gLZRJmlFXUAiUftZPY1Y+r/F9bow9subVWzXgTuAHTRv8mZgt2uZUKWkn5/oBHsQIsJPu6nX/rfGG/g7V+fGqKYVDwT7g/bTxR7DAjVUE1oWkTL2dfOuK2HXKu/yIgMZndFIAccCgYEA9+GghdabPd7LvKtcNrhXuXmUr7v6OuqC+VdMCz0HgmdRWVeOutRZT+ZxBxCBgLRJFnEj6EwoFhO3zwkyjMim4TwWeotUfI0o4KOuHiuzpnWRbqN/C/ohNWLx+2J6ASQ7zKTxvqhRkImog9/hWuWfBpKLZl6Ae1UlZAFMO/7PSSoCAgIAA4GEAAKBgFYrv6THBfdntqwmw0G+ZFQesdn2kgX0v5HFsNfMQPoEOMjNa8GKfPmSlZFsRCAoTdeEr3x8/72SKRpf6tDe03lU2bqITMTdDWIp1ToH1oIiAGqdPLg9/9Um5648iLugCjJRPstItLzxQtpZ1h7+OWuExdX+ark3pbp8SS8KQDtw\",\"nonce\":2107416065}\n```\n\nAfter DH key agreement finishes on both sides they has to verify they have the same shared secret key.\nThis is done by exchanging `dhc` message (`SUB_DH_CONF`) with the field `dhverif` (`FIELD_DHVERIF`)\ncontaining the result of the following operation:\n\n```\nHmacSHA1(secretKey, getConnectionId().getBytes())\n```\n\nIn other words - they verify the secret key by HMAC-ing (using HmacSHA1, `Mac` engine class)\nthe connection string, using the secret key. Note: we cannot HMAC string directly,\nso we need to convert it to byte array, thats why we are hmacing `getConnectionId().getBytes()`.\n\nThe side which receives DH2 message sends the verification message `SUB_DH_CONF` first.\n\nThe side which receives the `SUB_DH_CONF` verification message is supposed to compute HMAC on his own \nand compare it with the given value. Do it in such a way it does not leak infromation\nby time side channel (constant time array comparison).\n\nThen it sends back his own `SUB_DH_CONF` message with his own HMAC (base64 encoded).\n\nThe final message looks like this:\n\n```json\n{\"uco\":\"1\",\"sub\":\"dhc\",\"session\":\"alpha\",\"dhverif\":\"Vk7Nz8peqNAYG2R1iXLbhbHHzao=\",\"cmd\":\"comm\",\"nonce\":1749921803}\n```\n\nThe protocol finishes by each side receiving `SUB_DH_CONF` verification message.\n\n\n[chat-roulette-python]: https://github.com/ph4r05/chat-roulette-python\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fph4r05%2Fchat-roulette-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fph4r05%2Fchat-roulette-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fph4r05%2Fchat-roulette-client/lists"}