{"id":16408665,"url":"https://github.com/creativeprojects/encryption","last_synced_at":"2025-02-24T00:44:34.974Z","repository":{"id":65134268,"uuid":"376117868","full_name":"creativeprojects/encryption","owner":"creativeprojects","description":"Encrypt your http traffic without using SSL/TLS","archived":false,"fork":false,"pushed_at":"2021-06-16T21:13:17.000Z","size":15,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-05T21:44:44.722Z","etag":null,"topics":["encryption","http"],"latest_commit_sha":null,"homepage":"","language":"Go","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/creativeprojects.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}},"created_at":"2021-06-11T18:59:17.000Z","updated_at":"2021-06-16T21:14:05.000Z","dependencies_parsed_at":"2022-12-31T07:31:13.050Z","dependency_job_id":null,"html_url":"https://github.com/creativeprojects/encryption","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creativeprojects%2Fencryption","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creativeprojects%2Fencryption/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creativeprojects%2Fencryption/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creativeprojects%2Fencryption/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/creativeprojects","download_url":"https://codeload.github.com/creativeprojects/encryption/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240400292,"owners_count":19795331,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["encryption","http"],"created_at":"2024-10-11T06:17:29.305Z","updated_at":"2025-02-24T00:44:34.912Z","avatar_url":"https://github.com/creativeprojects.png","language":"Go","readme":"# encryption-handler\n\nProof of concept of a poor man's encryption over http (without using SSL/TLS).\n* The traffic is encrypted using AES-256 (GCM).\n* The key is generated with scrypt using a passphrase and a salt.\n* Unless specified, each message is encrypted with a new unique nonce.\n* Both salt and nonce are sent (in clear) as http header\n\n## Server side\n\n```go\npackage main\n\nimport (\n\t\"crypto/rand\"\n\t\"fmt\"\n\t\"io\"\n\t\"log\"\n\t\"net/http\"\n\n\t\"github.com/creativeprojects/encryption\"\n)\n\nfunc main() {\n\tmux := http.NewServeMux()\n\tmux.HandleFunc(\"/\", func(w http.ResponseWriter, r *http.Request) {\n\t\twriteString(w, \"This message is going to be encrypted if your client supports it!\")\n\t})\n\n\tport := 3001\n\tpassphrase := []byte(\"I have been eating too much chocolate\")\n\n\t// generate a random salt\n\tsalt := make([]byte, 41)\n\tif _, err := io.ReadFull(rand.Reader, salt); err != nil {\n\t\tpanic(err)\n\t}\n\n\t// create the encryption handler around your usual handler\n\thandler, err := encryption.NewHandler(passphrase, salt, mux)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tlog.Printf(\"Service is listening on port %d...\", port)\n\tlog.Println(http.ListenAndServe(fmt.Sprintf(\":%d\", port), handler))\n}\n\nfunc writeString(w http.ResponseWriter, payload string) {\n\tw.Header().Set(\"Content-Type\", \"text/plain; charset=utf8\")\n\t_, _ = io.WriteString(w, payload+\"\\n\")\n}\n\n\n```\n\nSee the standard response:\n\n```\n% curl -v http://localhost:3001\n*   Trying ::1...\n* TCP_NODELAY set\n* Connected to localhost (::1) port 3001 (#0)\n\u003e GET / HTTP/1.1\n\u003e Host: localhost:3001\n\u003e User-Agent: curl/7.64.1\n\u003e Accept: */*\n\u003e\n\u003c HTTP/1.1 200 OK\n\u003c Content-Type: text/plain; charset=utf8\n\u003c Date: Wed, 16 Jun 2021 16:20:52 GMT\n\u003c Content-Length: 66\n\u003c\nThis message is going to be encrypted if your client supports it!\n* Connection #0 to host localhost left intact\n* Closing connection 0\n```\n\nSee the encrypted response:\n\n```\n% curl -v -H \"Accept-Encoding: aesgcm\" http://localhost:3001\n*   Trying ::1...\n* TCP_NODELAY set\n* Connected to localhost (::1) port 3001 (#0)\n\u003e GET / HTTP/1.1\n\u003e Host: localhost:3001\n\u003e User-Agent: curl/7.64.1\n\u003e Accept: */*\n\u003e Accept-Encoding: aesgcm\n\u003e\n\u003c HTTP/1.1 200 OK\n\u003c Content-Encoding: aesgcm\n\u003c Content-Type: text/plain; charset=utf8\n\u003c Vary: Accept-Encoding\n\u003c X-Content-Encryption: 2e79168e7d19a7538892583e611020e4fa3c58cb0b45e9de1281d2d12d6cfbbf76b3e098a074c35f25|37a94bfa35ed7e69c23b99f6\n\u003c Date: Wed, 16 Jun 2021 16:19:46 GMT\n\u003c Content-Length: 82\n\u003c\nWarning: Binary output can mess up your terminal. Use \"--output -\" to tell\nWarning: curl to output it to your terminal anyway, or consider \"--output\nWarning: \u003cFILE\u003e\" to save to a file.\n* Failed writing body (0 != 82)\n* Closing connection 0\n```\n\n## Client side\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\t\"net/http\"\n\n\t\"github.com/creativeprojects/encryption\"\n)\n\nconst serverURL = \"http://localhost:3001/\"\n\nfunc main() {\n\tlog.Printf(\"Calling %s\", serverURL)\n\n\treq, err := http.NewRequest(http.MethodGet, serverURL, nil)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// add the accept-encoding header saying we accept our encrypted content\n\tencryption.AddAcceptEncryptionHeader(req.Header)\n\n\tresp, err := http.DefaultClient.Do(req)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\t// decrypt the response\n\tpassphrase := []byte(\"I have been eating too much chocolate\")\n\tmessage, err := encryption.DecryptResponse(resp, passphrase)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tlog.Printf(\"Answer: %q\\n\", string(message))\n}\n\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreativeprojects%2Fencryption","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcreativeprojects%2Fencryption","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreativeprojects%2Fencryption/lists"}