char *serv_cert = NULL;
char *serv_key = NULL;
char *proxy_cert = NULL;
+ canl_principal princ = NULL;
+ int get_peer_princ = 0;
+ char *name = NULL;
timeout.tv_sec = DEF_TIMEOUT;
timeout.tv_usec = 0;
- while ((opt = getopt(argc, argv, "hp:s:c:k:t:")) != -1) {
+ while ((opt = getopt(argc, argv, "nhp:s:c:k:t:")) != -1) {
switch (opt) {
case 'h':
fprintf(stderr, "Usage: %s [-p port] [-c certificate]"
" [-k private key] [-d ca_dir] [-h] "
" [-s server] [-x proxy certificate] "
- " [-t timeout] \n", argv[0]);
+ "[-t timeout] [-n {print peer's princ name}] "
+ " \n", argv[0]);
exit(0);
case 'p':
port = atoi(optarg);
case 't':
timeout.tv_sec = atoi(optarg);
break;
+ case 'n':
+ get_peer_princ = 1;
+ break;
default: /* '?' */
fprintf(stderr, "Usage: %s [-p port] [-c certificate]"
" [-k private key] [-d ca_dir] [-h]"
" [-s server] [-x proxy certificate]"
- " [-t timeout] \n", argv[0]);
+ "[-t timeout] [-n {print peer's princ name}] "
+ " \n", argv[0]);
exit(-1);
}
}
}
}
- err = canl_io_connect(my_ctx, my_io_h, p_server, NULL, port, NULL, 0,
- NULL, &timeout);
- if (err) {
- printf("[CLIENT] connection to %s cannot be established:\n[CANL] %s\n",
- p_server, canl_get_error_message(my_ctx));
- goto end;
+ if (get_peer_princ) {
+ err = canl_io_connect(my_ctx, my_io_h, p_server, NULL, port, NULL, 0,
+ &princ, &timeout);
+ if (err) {
+ printf("[CLIENT] connection cannot be established:\n[CANL] %s\n",
+ canl_get_error_message(my_ctx));
+ goto end;
+ }
+
+ err = canl_princ_name(my_ctx, princ, &name);
+ printf("[CLIENT] connection established with %s\n", name);
+ free(name);
+ canl_princ_free(my_ctx, princ);
}
- else {
+ else{
+ err = canl_io_connect(my_ctx, my_io_h, p_server, NULL, port, NULL, 0,
+ NULL, &timeout);
+ if (err) {
+ printf("[CLIENT] connection cannot be established:\n[CANL] %s\n",
+ canl_get_error_message(my_ctx));
+ goto end;
+ }
printf("[CLIENT] connection established\n");
}
int buf_len = 0;
struct timeval timeout;
canl_principal princ = NULL;
+ int get_peer_princ = 0;
char *name = NULL;
timeout.tv_sec = DEF_TIMEOUT;
timeout.tv_usec = 0;
- while ((opt = getopt(argc, argv, "hp:c:k:d:t:")) != -1) {
+ while ((opt = getopt(argc, argv, "nhp:c:k:d:t:")) != -1) {
switch (opt) {
case 'h':
fprintf(stderr, "Usage: %s [-p port] [-c certificate]"
" [-k private key] [-d ca_dir] [-h] "
- "[-t timeout] \n", argv[0]);
+ "[-t timeout] [-n {print peer's princ name}] "
+ " \n", argv[0]);
exit(0);
case 'p':
port = atoi(optarg);
case 't':
timeout.tv_sec = atoi(optarg);
break;
+ case 'n':
+ get_peer_princ = 1;
+ break;
default: /* '?' */
fprintf(stderr, "Usage: %s [-p port] [-c certificate]"
" [-k private key] [-d ca_dir] [-h] "
- "[-t timeout] \n", argv[0]);
+ "[-t timeout] [-n {print peer's princ name}] "
+ " \n", argv[0]);
exit(-1);
}
}
/* canl_create_io_handler has to be called for my_io_h*/
/* TODO timeout in this function? and select around it*/
- err = canl_io_accept(my_ctx, my_io_h, new_fd, s_addr, 0, &princ, &timeout);
- if (err) {
- printf("[SERVER] connection cannot be established:\n[CANL] %s\n",
- canl_get_error_message(my_ctx));
- goto end;
- }
+ if (get_peer_princ) {
+ err = canl_io_accept(my_ctx, my_io_h, new_fd, s_addr,
+ 0, &princ, &timeout);
+ if (err) {
+ printf("[SERVER] connection cannot be established:\n[CANL] %s\n",
+ canl_get_error_message(my_ctx));
+ goto end;
+ }
+
- err = canl_princ_name(my_ctx, princ, &name);
- printf("[SERVER] connection established with %s\n", name);
- free(name);
- canl_princ_free(my_ctx, princ);
+ err = canl_princ_name(my_ctx, princ, &name);
+ printf("[SERVER] connection established with %s\n", name);
+ free(name);
+ canl_princ_free(my_ctx, princ);
+ }
+ else{
+ err = canl_io_accept(my_ctx, my_io_h, new_fd, s_addr,
+ 0, NULL, &timeout);
+ if (err) {
+ printf("[SERVER] connection cannot be established:\n[CANL] %s\n",
+ canl_get_error_message(my_ctx));
+ goto end;
+ }
+ printf("[SERVER] connection established\n");
+ }
strncpy(buf, "This is a testing message to send", sizeof(buf));
buf_len = strlen(buf) + 1;
}
io_cc->conn_ctx = ctx;
done = 1;
- /*TODO Not mandatory peer certificate for now*/
- /* if (peer) {
- err = mech->get_peer(glb_cc, io_cc, conn_ctx, peer);
- if (err)
- goto end;
- }
- */
+ /* If peer != NULL then client certificate is mandatory*/
+ if (peer) {
+ err = mech->get_peer(glb_cc, io_cc, ctx, peer);
+ if (err)
+ goto end;
+ }
+
break;
}
if (err == ETIMEDOUT)
if (err)
goto end;
- /*TODO Not mandatory peer certificate for now*/
+ /* If peer != NULL then client certificate is mandatory*/
if (peer) {
err = mech->get_peer(glb_cc, io_cc, conn_ctx, peer);
if (err)