Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions examples/client/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,10 @@ THREAD_RETURN WOLFSSH_THREAD client_test(void* args)
err_sys("You must specify a password for the TPM key");
}
#endif
#ifdef WOLFSSH_NO_RSA
userEcc = 1;
#endif

ret = ClientSetPrivateKey(privKeyName, userEcc, NULL, tpmKeyAuth);
if (ret != 0) {
err_sys("Error setting private key");
Expand Down
30 changes: 30 additions & 0 deletions examples/client/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -1008,12 +1008,23 @@ int ClientSetPrivateKey(const char* privKeyName, int userEcc,
(void)tpmKeyAuth; /* Not used */

if (privKeyName == NULL) {
#if defined(WOLFSSH_NO_RSA) && defined(WOLFSSH_NO_ECC)
/* No built-in key to load. Leave the client to authenticate
* some other way rather than failing here. */
userPrivateKeySz = 0;
userPrivateKeyType = NULL;
(void)userEcc;
(void)heap;
#else
if (userEcc) {
#ifndef WOLFSSH_NO_ECC
userPrivateKeySz = sizeof(userPrivateKeyBuf);
ret = wolfSSH_ReadKey_buffer(hanselPrivateEcc, hanselPrivateEccSz,
WOLFSSH_FORMAT_ASN1, &userPrivateKey, &userPrivateKeySz,
&userPrivateKeyType, &userPrivateKeyTypeSz, heap);
#else
fprintf(stderr, "ECC not compiled in, no default private key\n");
ret = WS_NOT_COMPILED;
Comment thread
yosuke-wolfssl marked this conversation as resolved.
Comment thread
yosuke-wolfssl marked this conversation as resolved.
#endif
}
else {
Expand All @@ -1022,9 +1033,13 @@ int ClientSetPrivateKey(const char* privKeyName, int userEcc,
ret = wolfSSH_ReadKey_buffer(hanselPrivateRsa, hanselPrivateRsaSz,
WOLFSSH_FORMAT_ASN1, &userPrivateKey, &userPrivateKeySz,
&userPrivateKeyType, &userPrivateKeyTypeSz, heap);
#else
fprintf(stderr, "RSA not compiled in, no default private key\n");
ret = WS_NOT_COMPILED;
#endif
}
isPrivate = 1;
#endif
}
else {
#if defined(WOLFSSH_TPM)
Expand Down Expand Up @@ -1065,6 +1080,14 @@ int ClientUsePubKey(const char* pubKeyName, int userEcc, void* heap)
int ret = 0;

if (pubKeyName == NULL) {
#if defined(WOLFSSH_NO_RSA) && defined(WOLFSSH_NO_ECC)
/* No built-in key to load. Leave the client to authenticate
* some other way rather than failing here. */
userPublicKeySz = 0;
userPublicKeyType = NULL;
(void)userEcc;
(void)heap;
#else
byte* p = userPublicKey;
userPublicKeySz = sizeof(userPublicKeyBuf);

Expand All @@ -1074,6 +1097,9 @@ int ClientUsePubKey(const char* pubKeyName, int userEcc, void* heap)
(word32)strlen(hanselPublicEcc), WOLFSSH_FORMAT_SSH,
&p, &userPublicKeySz,
&userPublicKeyType, &userPublicKeyTypeSz, heap);
#else
fprintf(stderr, "ECC not compiled in, no default public key\n");
ret = WS_NOT_COMPILED;
#endif
}
else {
Expand All @@ -1082,9 +1108,13 @@ int ClientUsePubKey(const char* pubKeyName, int userEcc, void* heap)
(word32)strlen(hanselPublicRsa), WOLFSSH_FORMAT_SSH,
&p, &userPublicKeySz,
&userPublicKeyType, &userPublicKeyTypeSz, heap);
#else
fprintf(stderr, "RSA not compiled in, no default public key\n");
ret = WS_NOT_COMPILED;
#endif
}
isPrivate = 1;
#endif
}
else {
#if !defined(NO_FILESYSTEM) && !defined(WOLFSSH_USER_FILESYSTEM)
Expand Down
9 changes: 7 additions & 2 deletions examples/scpclient/scpclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ THREAD_RETURN WOLFSSH_THREAD scp_client(void* args)
byte nonBlock = 0;
enum copyDir dir = copyNone;
int ch;
int userEcc = 0;
char* pubKeyName = NULL;
char* privKeyName = NULL;
char* certName = NULL;
Expand Down Expand Up @@ -218,7 +219,11 @@ THREAD_RETURN WOLFSSH_THREAD scp_client(void* args)
err_sys("Empty path values");
}

ret = ClientSetPrivateKey(privKeyName, 0, NULL, NULL);
#ifdef WOLFSSH_NO_RSA
userEcc = 1;
#endif

ret = ClientSetPrivateKey(privKeyName, userEcc, NULL, NULL);
if (ret != 0) {
err_sys("Error setting private key");
}
Expand All @@ -231,7 +236,7 @@ THREAD_RETURN WOLFSSH_THREAD scp_client(void* args)
else
#endif
{
ret = ClientUsePubKey(pubKeyName, 0, NULL);
ret = ClientUsePubKey(pubKeyName, userEcc, NULL);
}
if (ret != 0) {
err_sys("Error setting public key");
Expand Down
2 changes: 1 addition & 1 deletion examples/sftpclient/sftpclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -1709,7 +1709,7 @@ THREAD_RETURN WOLFSSH_THREAD sftpclient_test(void* args)
else
#endif
{
ret = ClientUsePubKey(pubKeyName, 0, heap);
ret = ClientUsePubKey(pubKeyName, userEcc, heap);
}
if (ret != 0) {
err_sys("Error setting public key");
Expand Down
Loading