Merge pull request #290 from kojo1/examples-pq

pull/294/head
Anthony Hu 2022-02-15 08:56:23 -05:00 committed by GitHub
commit 6105a7c406
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 10 deletions

View File

@ -123,10 +123,15 @@ int main(int argc, char** argv)
WOLFSSL_CTX* ctx = NULL;
WOLFSSL* ssl = NULL;
char *cert_file = CERT_FILE;
/* Check for proper calling convention */
if (argc != 2) {
printf("usage: %s <IPv4 address>\n", argv[0]);
if (argc != 2 && argc != 3) {
printf("usage: %s <IPv4 address> [<Root cert>]\n", argv[0]);
printf("Default Root cert: %s\n", cert_file);
return 0;
} else if (argc == 3) {
cert_file = argv[2];
}
/* Create a socket that uses an internet IPv4 address,
@ -134,7 +139,8 @@ int main(int argc, char** argv)
* 0 means choose the default protocol. */
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
fprintf(stderr, "ERROR: failed to create the socket\n");
ret = -1; goto exit;
ret = -1;
goto exit;
}
/* Initialize the server address struct with zeros */
@ -173,10 +179,10 @@ int main(int argc, char** argv)
}
/* Load client certificates into WOLFSSL_CTX */
if ((ret = wolfSSL_CTX_load_verify_locations(ctx, CERT_FILE, NULL))
if ((ret = wolfSSL_CTX_load_verify_locations(ctx, cert_file, NULL))
!= WOLFSSL_SUCCESS) {
fprintf(stderr, "ERROR: failed to load %s, please check the file.\n",
CERT_FILE);
cert_file);
goto exit;
}

View File

@ -25,7 +25,7 @@
#include <wolfssl/wolfcrypt/error-crypt.h>
#include <wolfssl/test.h>
int main(void)
int main(int argc, char **argv)
{
int ret;
WOLFSSL_CERT_MANAGER* cm = NULL;
@ -33,6 +33,15 @@ int main(void)
const char* caCert = "./falcon_level5_root_cert.pem";
const char* verifyCert = "./falcon_level5_entity_cert.pem";
if(argc == 3) {
caCert = argv[1];
verifyCert = argv[2];
} else if (argc != 1) {
printf("usage: %s [<CA Cert> <verify Cert>]\n", argv[0]);
printf("Default CA Cert: %s, verify Cert: %s\n", caCert, verifyCert);
return 0;
}
wolfSSL_Init();
#ifdef DEBUG_WOLFSSL
wolfSSL_Debugging_ON();

View File

@ -155,10 +155,22 @@ int main(int argc, char** argv)
WOLFSSL_CTX* ctx = NULL;
WOLFSSL* ssl = NULL;
char *cert_file = CERT_FILE;
char *key_file = KEY_FILE;
#ifdef HAVE_SIGNAL
signal(SIGINT, sig_handler);
#endif
if(argc == 3) {
cert_file = argv[1];
key_file = argv[2];
} else if (argc != 1) {
printf("usage: %s <IPv4 address> [<cert file> <key file>]\n", argv[0]);
printf("Default cert file: %s, key file: %s\n", cert_file, key_file);
return 0;
}
/* Initialize wolfSSL */
wolfSSL_Init();
@ -178,18 +190,18 @@ int main(int argc, char** argv)
}
/* Load server certificates into WOLFSSL_CTX */
if ((ret = wolfSSL_CTX_use_certificate_file(ctx, CERT_FILE, WOLFSSL_FILETYPE_PEM))
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);
cert_file);
goto exit;
}
/* Load server key into WOLFSSL_CTX */
if ((ret = wolfSSL_CTX_use_PrivateKey_file(ctx, KEY_FILE, WOLFSSL_FILETYPE_PEM))
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);
key_file);
goto exit;
}