removed additional methods so that the code reads linearly and fixed session not resuming error in client-psk-resume
parent
bdf4b25e00
commit
4352c413f9
|
|
@ -60,36 +60,11 @@ static inline unsigned int My_Psk_Client_Cb(WOLFSSL* ssl, const char* hint,
|
|||
return 4;
|
||||
}
|
||||
|
||||
/*
|
||||
* this function will send the inputted string to the server and then
|
||||
* recieve the string from the server outputing it to the termial
|
||||
*/
|
||||
int SendReceive(WOLFSSL* ssl)
|
||||
{
|
||||
char sendline[MAXLINE]="Hello Server"; /* string to send to the server */
|
||||
char recvline[MAXLINE]; /* string received from the server */
|
||||
|
||||
/* write string to the server */
|
||||
if (wolfSSL_write(ssl, sendline, MAXLINE) != sizeof(sendline)) {
|
||||
printf("Write Error to Server\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* flags if the Server stopped before the client could end */
|
||||
if (wolfSSL_read(ssl, recvline, MAXLINE) < 0 ) {
|
||||
printf("Client: Server Terminated Prematurely!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* show message from the server */
|
||||
printf("Server Message: %s\n", recvline);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv){
|
||||
|
||||
int sockfd, sock, ret;
|
||||
char sendline[MAXLINE]="Hello Server"; /* string to send to the server */
|
||||
char recvline[MAXLINE]; /* string received from the server */
|
||||
WOLFSSL* ssl;
|
||||
WOLFSSL* sslResume = 0;
|
||||
WOLFSSL_SESSION* session = 0;
|
||||
|
|
@ -146,7 +121,19 @@ int main(int argc, char **argv){
|
|||
wolfSSL_set_fd(ssl, sockfd);
|
||||
|
||||
/* takes inputting string and outputs it to the server */
|
||||
SendReceive(ssl);
|
||||
if (wolfSSL_write(ssl, sendline, sizeof(sendline)) != sizeof(sendline)) {
|
||||
printf("Write Error to Server\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* flags if the Server stopped before the client could end */
|
||||
if (wolfSSL_read(ssl, recvline, MAXLINE) < 0 ) {
|
||||
printf("Client: Server Terminated Prematurely!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* show message from the server */
|
||||
printf("Server Message: %s\n", recvline);
|
||||
|
||||
/* Save the session ID to reuse */
|
||||
session = wolfSSL_get_session(ssl);
|
||||
|
|
@ -158,9 +145,8 @@ int main(int argc, char **argv){
|
|||
/* close connection */
|
||||
close(sockfd);
|
||||
|
||||
/* cleanup without wolfSSL_Cleanup() for now */
|
||||
/* cleanup without wolfSSL_Cleanup() and wolfSSL_CTX_free() for now */
|
||||
wolfSSL_free(ssl);
|
||||
wolfSSL_CTX_free(ctx);
|
||||
|
||||
/*
|
||||
* resume session, start new connection and socket
|
||||
|
|
@ -186,25 +172,30 @@ int main(int argc, char **argv){
|
|||
return 1;
|
||||
}
|
||||
|
||||
/* takes inputting string and outputs it to the server */
|
||||
ret = SendReceive(sslResume);
|
||||
if (ret != 0) {
|
||||
if (wolfSSL_write(sslResume, sendline, sizeof(sendline)) != sizeof(sendline)) {
|
||||
printf("Write Error to Server\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* flags if the Server stopped before the client could end */
|
||||
if (wolfSSL_read(sslResume, recvline, MAXLINE) < 0 ) {
|
||||
printf("Client: Server Terminated Prematurely!\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* show message from the server */
|
||||
printf("Server Message: %s\n", recvline);
|
||||
/* check to see if the session id is being reused */
|
||||
if (wolfSSL_session_reused(sslResume)) {
|
||||
printf("reused session id\n");
|
||||
}
|
||||
else
|
||||
else{
|
||||
printf("didn't reuse session id!!!\n");
|
||||
|
||||
}
|
||||
/* shut down wolfSSL */
|
||||
wolfSSL_shutdown(sslResume);
|
||||
|
||||
/* shut down socket */
|
||||
close(sock);
|
||||
|
||||
/* clean up now with wolfSSL_Cleanup() */
|
||||
wolfSSL_free(sslResume);
|
||||
wolfSSL_CTX_free(ctx);
|
||||
|
|
|
|||
Loading…
Reference in New Issue