int main(int argc, char** argv) { int sockfd; struct sockaddr_in servAddr; if (argc != 2) { printf("usage: udpcli <IP address>\n"); return 1; } if ( (sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { printf("cannot create a socket."); return 1; } memset(&servAddr, sizeof(servAddr), 0); servAddr.sin_family = AF_INET; servAddr.sin_port = htons(SERV_PORT); inet_pton(AF_INET, argv[1], &servAddr.sin_addr); DatagramClient(stdin, sockfd, (struct sockaddr*) &servAddr, sizeof(servAddr)); return 0; }
int main (int argc, char** argv) { int sockfd = 0; struct sockaddr_in servAddr; const char* host = argv[1]; CYASSL* ssl = 0; CYASSL_CTX* ctx = 0; CYASSL* sslResume = 0; CYASSL_SESSION* session = 0; int resumeSession = 0; char cert_array[] = "../cyassl/certs/ca-cert.pem"; char* certs = cert_array; char* srTest = "testing session resume"; if (argc != 2) { printf("usage: udpcli <IP address>\n"); return 1; } CyaSSL_Init(); /* CyaSSL_Debugging_ON();*/ if ( (ctx = CyaSSL_CTX_new(CyaDTLSv1_2_client_method())) == NULL) { fprintf(stderr, "CyaSSL_CTX_new error.\n"); return(EXIT_FAILURE); } if (CyaSSL_CTX_load_verify_locations(ctx,certs, 0) != SSL_SUCCESS) { fprintf(stderr, "Error loading %s, please check the file.\n", certs); return(EXIT_FAILURE); } ssl = CyaSSL_new(ctx); if (ssl == NULL) { printf("unable to get ssl object"); return 1; } memset(&servAddr, 0, sizeof(servAddr)); servAddr.sin_family = AF_INET; servAddr.sin_port = htons(SERV_PORT); if (inet_pton(AF_INET, host, &servAddr.sin_addr) < 1) { printf("Error and/or invalid IP address"); return 1; } CyaSSL_dtls_set_peer(ssl, &servAddr, sizeof(servAddr)); if ( (sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { printf("cannot create a socket."); return 1; } CyaSSL_set_fd(ssl, sockfd); CyaSSL_set_using_nonblock(ssl, 1); fcntl(sockfd, F_SETFL, O_NONBLOCK); NonBlockingDTLS_Connect(ssl); DatagramClient(ssl); while ( (CyaSSL_write(ssl, srTest, sizeof(srTest))) != sizeof(srTest)) { printf("failed to write"); return 1; } session = CyaSSL_get_session(ssl); sslResume = CyaSSL_new(ctx); CyaSSL_shutdown(ssl); CyaSSL_free(ssl); close(sockfd); memset(&servAddr, 0, sizeof(servAddr)); servAddr.sin_family = AF_INET; servAddr.sin_port = htons(SERV_PORT); if (inet_pton(AF_INET, host, &servAddr.sin_addr) < 1) { printf("Error and/or invalid IP address"); return 1; } CyaSSL_dtls_set_peer(sslResume, &servAddr, sizeof(servAddr)); if ( (sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { printf("cannot create a socket."); return 1; } CyaSSL_set_fd(sslResume, sockfd); CyaSSL_set_session(sslResume, session); CyaSSL_set_using_nonblock(sslResume, 1); fcntl(sockfd, F_SETFL, O_NONBLOCK); NonBlockingDTLS_Connect(sslResume); if(CyaSSL_session_reused(sslResume)) printf("reused session id\n"); else printf("didn't reuse session id!!!\n"); DatagramClient(sslResume); while ((CyaSSL_write(sslResume, srTest, sizeof(srTest))) != sizeof(srTest)) { printf("failed to write"); return 1; } sleep(1); CyaSSL_shutdown(sslResume); CyaSSL_free(sslResume); close(sockfd); CyaSSL_CTX_free(ctx); CyaSSL_Cleanup(); return 0; }
int main (int argc, char** argv) { int sockfd = 0; struct sockaddr_in servAddr; const char* host = argv[1]; CYASSL* ssl = 0; CYASSL_CTX* ctx = 0; CYASSL* sslResume = 0; CYASSL_SESSION* session = 0; char* srTest = "testing session resume"; char cert_array[] = "../certs/ca-cert.pem"; char* certs = cert_array; if (argc != 2) { printf("usage: udpcli <IP address>\n"); return 1; } CyaSSL_Init(); /* CyaSSL_Debugging_ON(); */ if ( (ctx = CyaSSL_CTX_new(CyaDTLSv1_2_client_method())) == NULL) { fprintf(stderr, "CyaSSL_CTX_new error.\n"); return 1; } if (CyaSSL_CTX_load_verify_locations(ctx, certs, 0) != SSL_SUCCESS) { fprintf(stderr, "Error loading %s, please check the file.\n", certs); return 1; } ssl = CyaSSL_new(ctx); if (ssl == NULL) { printf("unable to get ssl object"); return 1; } memset(&servAddr, 0, sizeof(servAddr)); servAddr.sin_family = AF_INET; servAddr.sin_port = htons(SERV_PORT); if ( (inet_pton(AF_INET, host, &servAddr.sin_addr)) < 1) { printf("Error and/or invalid IP address"); return 1; } CyaSSL_dtls_set_peer(ssl, &servAddr, sizeof(servAddr)); if ( (sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { printf("cannot create a socket."); return 1; } CyaSSL_set_fd(ssl, sockfd); if (CyaSSL_connect(ssl) != SSL_SUCCESS) { int err1 = CyaSSL_get_error(ssl, 0); char buffer[80]; printf("err = %d, %s\n", err1, CyaSSL_ERR_error_string(err1, buffer)); printf("SSL_connect failed"); return 1; } DatagramClient(ssl); CyaSSL_write(ssl, srTest, sizeof(srTest)); session = CyaSSL_get_session(ssl); sslResume = CyaSSL_new(ctx); CyaSSL_shutdown(ssl); CyaSSL_free(ssl); close(sockfd); memset(&servAddr, 0, sizeof(servAddr)); servAddr.sin_family = AF_INET; servAddr.sin_port = htons(SERV_PORT); if ( (inet_pton(AF_INET, host, &servAddr.sin_addr)) < 1) { printf("Error and/or invalid IP address"); return 1; } CyaSSL_dtls_set_peer(sslResume, &servAddr, sizeof(servAddr)); if ( (sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) { printf("cannot create a socket."); return 1; } CyaSSL_set_fd(sslResume, sockfd); CyaSSL_set_session(sslResume, session); if (CyaSSL_connect(sslResume) != SSL_SUCCESS) { printf("SSL_connect failed"); return 1; } if(CyaSSL_session_reused(sslResume)) printf("reused session id\n"); else printf("didn't reuse session id!!!\n"); DatagramClient(sslResume); CyaSSL_write(sslResume, srTest, sizeof(srTest)); CyaSSL_shutdown(sslResume); CyaSSL_free(sslResume); close(sockfd); CyaSSL_CTX_free(ctx); CyaSSL_Cleanup(); return 0; }