Skip to content

Commit 2a7e09e

Browse files
add client cert store func
1 parent 971905f commit 2a7e09e

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

examples/client/common.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@
4141

4242
#ifdef WOLFSSH_CERTS
4343
#include <wolfssl/wolfcrypt/asn.h>
44+
#ifdef USE_WINDOWS_API
45+
#include <windows.h>
46+
#include <wincrypt.h>
47+
#include <ncrypt.h>
48+
#endif /* USE_WINDOWS_API */
4449
#endif
4550

4651
static byte userPublicKeyBuf[512];
@@ -805,3 +810,24 @@ void ClientFreeBuffers(const char* pubKeyName, const char* privKeyName,
805810
WFREE(userPrivateKey, heap, DYNTYPE_PRIVKEY);
806811
}
807812
}
813+
814+
#ifdef USE_WINDOWS_API
815+
#ifdef WOLFSSH_CERTS
816+
int ClientSetPrivateKeyFromStore(WOLFSSH_CTX* ctx,
817+
const wchar_t* storeName, DWORD dwFlags, const wchar_t* subjectName)
818+
{
819+
int ret = WS_SUCCESS;
820+
821+
if (ctx == NULL || storeName == NULL || subjectName == NULL) {
822+
return WS_BAD_ARGUMENT;
823+
}
824+
825+
ret = wolfSSH_CTX_UsePrivateKey_fromStore(ctx, storeName, dwFlags, subjectName);
826+
if (ret != WS_SUCCESS) {
827+
fprintf(stderr, "Error loading private key from certificate store: %d\n", ret);
828+
}
829+
830+
return ret;
831+
}
832+
#endif /* WOLFSSH_CERTS */
833+
#endif /* USE_WINDOWS_API */

examples/client/common.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ int ClientPublicKeyCheck(const byte* pubKey, word32 pubKeySz, void* ctx);
3232
void ClientIPOverride(int flag);
3333
void ClientFreeBuffers(const char* pubKeyName, const char* privKeyName,
3434
void* heap);
35+
#ifdef USE_WINDOWS_API
36+
#ifdef WOLFSSH_CERTS
37+
int ClientSetPrivateKeyFromStore(WOLFSSH_CTX* ctx,
38+
const wchar_t* storeName, DWORD dwFlags, const wchar_t* subjectName);
39+
#endif /* WOLFSSH_CERTS */
40+
#endif /* USE_WINDOWS_API */
3541

3642
#endif /* WOLFSSH_COMMON_H */
3743

0 commit comments

Comments
 (0)