summaryrefslogtreecommitdiff
path: root/receiver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'receiver.cpp')
-rw-r--r--receiver.cpp42
1 files changed, 33 insertions, 9 deletions
diff --git a/receiver.cpp b/receiver.cpp
index a86cf57..78e6aa7 100644
--- a/receiver.cpp
+++ b/receiver.cpp
@@ -262,26 +262,50 @@ static void import_sessions(const char *root_dir) {
262 closedir(dirp); 262 closedir(dirp);
263} 263}
264 264
265int main(int args, char **argv) { 265int main(int argc, char **argv) {
266 mbedtls_ctr_drbg_context ctr_drbg; 266 mbedtls_ctr_drbg_context ctr_drbg;
267 mbedtls_entropy_context entropy; 267 mbedtls_entropy_context entropy;
268 mbedtls_pk_context pk; 268 mbedtls_pk_context pk;
269 int ret = 0; 269 int ret = 0, clport = PORT;
270 unsigned char result[256]; 270 unsigned char result[256];
271 unsigned char input[256]; 271 unsigned char input[256];
272 size_t inputlen = 0; 272 size_t inputlen = 0;
273 char * privkey_file = 0;
274 char * me = argv[0];
275
276 char ch;
277 while ((ch = getopt(argc, argv, "p:k:")) != -1) {
278 switch (ch) {
279 case 'k':
280 privkey_file = optarg;
281 break;
282 case 'p':
283 clport = std::stoi(optarg);
284 break;
285 default:
286 errx(-1, "Syntax: %s [sessionlogdir] xx", me);
287 break;
288 }
289 }
290 argc -= optind;
291 argv += optind;
273 292
274 if (args != 2) 293 if (argc != 1)
275 errx(-1, "Syntax: %s [sessionlogdir]", argv[0]); 294 errx(-1, "Syntax: %s [sessionlogdir]", me);
276 chdir(argv[1]); 295 chdir(argv[0]);
277 296
278 mbedtls_pk_init( &pk ); 297 mbedtls_pk_init( &pk );
279 mbedtls_entropy_init( &entropy ); 298 mbedtls_entropy_init( &entropy );
280 mbedtls_ctr_drbg_init( &ctr_drbg ); 299 mbedtls_ctr_drbg_init( &ctr_drbg );
281 mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, pp, sizeof(pp)); 300 mbedtls_ctr_drbg_seed(&ctr_drbg, mbedtls_entropy_func, &entropy, pp, sizeof(pp));
282 301
283 if ((ret = mbedtls_pk_parse_key(&pk, privkey, sizeof(privkey), NULL, 0) ) != 0 ) 302 if (privkey_file) {
284 errx(-1, "Fatal: mbedtls_pk_parse_key returned -0x%04x\n", -ret ); 303 if ((ret = mbedtls_pk_parse_keyfile(&pk, privkey_file, NULL) ) != 0 )
304 errx(-1, "Fatal: mbedtls_pk_parse_keyfile returned -0x%04x\n", -ret );
305 } else {
306 if ((ret = mbedtls_pk_parse_key(&pk, privkey, sizeof(privkey), NULL, 0) ) != 0 )
307 errx(-1, "Fatal: mbedtls_pk_parse_key returned -0x%04x\n", -ret );
308 }
285 309
286 int sock = socket(AF_INET, SOCK_DGRAM, 0); 310 int sock = socket(AF_INET, SOCK_DGRAM, 0);
287 if (sock < 0) 311 if (sock < 0)
@@ -290,9 +314,9 @@ int main(int args, char **argv) {
290 struct sockaddr_in servaddr, peer; 314 struct sockaddr_in servaddr, peer;
291 servaddr.sin_family = AF_INET; 315 servaddr.sin_family = AF_INET;
292 servaddr.sin_addr.s_addr = INADDR_ANY; 316 servaddr.sin_addr.s_addr = INADDR_ANY;
293 servaddr.sin_port = htons(PORT); 317 servaddr.sin_port = htons(clport);
294 if (bind(sock, (const struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) 318 if (bind(sock, (const struct sockaddr *)&servaddr, sizeof(servaddr)) < 0)
295 errx(-1, "Fatal: Can't bind to port %d\n", PORT); 319 errx(-1, "Fatal: Can't bind to port %d\n", clport);
296 320
297 import_sessions("."); 321 import_sessions(".");
298 322