Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add client cert to client-tls13-resume example #485

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 26 additions & 5 deletions tls/client-tls13-resume.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@

#define DEFAULT_PORT 11111

#define CERT_FILE "../certs/ca-cert.pem"
#define CERT_FILE "../certs/client-cert.pem"
#define KEY_FILE "../certs/client-key.pem"
#define CA_FILE "../certs/ca-cert.pem"


#if defined(WOLFSSL_TLS13) && defined(HAVE_SECRET_CALLBACK)
Expand Down Expand Up @@ -138,6 +140,9 @@ int main(int argc, char** argv)
}


#ifdef DEBUG_WOLFSSL
wolfSSL_Debugging_ON();
#endif

/* Initialize wolfSSL */
wolfSSL_Init();
Expand All @@ -160,14 +165,30 @@ int main(int argc, char** argv)
goto exit;
}

/* Load client certificates into WOLFSSL_CTX */
if ((ret = wolfSSL_CTX_load_verify_locations(ctx, CERT_FILE, NULL))
/* Load client certificate into WOLFSSL_CTX */
if ((ret = wolfSSL_CTX_use_certificate_file(ctx, CERT_FILE, WOLFSSL_FILETYPE_PEM))
!= WOLFSSL_SUCCESS) {
fprintf(stderr, "ERROR: failed to load %s, please check the file.\n",
CERT_FILE);
goto exit;
}

/* Load client key into WOLFSSL_CTX */
if ((ret = wolfSSL_CTX_use_PrivateKey_file(ctx, KEY_FILE, WOLFSSL_FILETYPE_PEM))
!= WOLFSSL_SUCCESS) {
fprintf(stderr, "ERROR: failed to load %s, please check the file.\n",
KEY_FILE);
goto exit;
}

/* Load client certificates into WOLFSSL_CTX */
if ((ret = wolfSSL_CTX_load_verify_locations(ctx, CA_FILE, NULL))
!= WOLFSSL_SUCCESS) {
fprintf(stderr, "ERROR: failed to load %s, please check the file.\n",
CA_FILE);
goto exit;
}



/* Initialize the server address struct with zeros */
Expand Down Expand Up @@ -312,8 +333,8 @@ int main(int argc, char** argv)

/* Set up to resume the session */
if ((ret = wolfSSL_set_session(sslRes, session)) != WOLFSSL_SUCCESS) {
fprintf(stderr, "Failed to set session, make sure session tickets "
"(--enable-session-ticket) is enabled\n");
fprintf(stderr, "Failed to set session (%d), make sure session tickets "
"(--enable-session-ticket) is enabled\n", ret);
/*goto exit;*/ /* not fatal */
}

Expand Down