Skip to content

Commit 16ff5e5

Browse files
use proper free for cert store version, fix echoserver on mac os
1 parent e7aa41e commit 16ff5e5

3 files changed

Lines changed: 22 additions & 37 deletions

File tree

examples/echoserver/echoserver.c

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3027,29 +3027,6 @@ static void ShowUsage(void)
30273027
}
30283028

30293029

3030-
#ifdef WOLFSSH_WINDOWS_CERT_STORE
3031-
/* Detects whether argv or the environment requests a host key from the
3032-
* Windows certificate store, without doing the full option parse that
3033-
* echoserver_test() does later. Used to decide, before any file-based
3034-
* key lookup, whether the root directory search for PEM key files should
3035-
* be skipped. */
3036-
static int EchoserverUsingCertStore(int argc, char** argv)
3037-
{
3038-
int i;
3039-
const char* spec;
3040-
3041-
for (i = 1; i < argc; i++) {
3042-
if (WSTRNCMP(argv[i], "-W", 2) == 0) {
3043-
return 1;
3044-
}
3045-
}
3046-
3047-
spec = getenv("WOLFSSH_CERT_STORE");
3048-
return (spec != NULL && spec[0] != '\0');
3049-
}
3050-
#endif /* WOLFSSH_WINDOWS_CERT_STORE */
3051-
3052-
30533030
static INLINE void SignalTcpReady(tcp_ready* ready, word16 port)
30543031
{
30553032
#if defined(_POSIX_THREADS) && defined(NO_MAIN_DRIVER) && \
@@ -3332,6 +3309,18 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
33323309
}
33333310
#endif
33343311

3312+
#if !defined(WOLFSSL_NUCLEUS) && !defined(INTEGRITY) && !defined(__INTEGRITY)
3313+
#ifdef WOLFSSH_WINDOWS_CERT_STORE
3314+
/* When using the Windows certificate store for host keys, no
3315+
* file-based keys are needed, so skip the root directory search
3316+
* that looks for ./keys/server-key-rsa.pem. */
3317+
if (certStoreSpec == NULL)
3318+
#endif
3319+
{
3320+
ChangeToWolfSshRoot();
3321+
}
3322+
#endif
3323+
33353324
#if defined(WOLFSSH_TPM) && defined(WOLFSSH_WINDOWS_CERT_STORE)
33363325
/* Both register a host key on the same CTX; loading both would leave
33373326
* which key the server presents up to algorithm negotiation. The SFTP
@@ -4015,19 +4004,10 @@ int wolfSSH_Echoserver(int argc, char** argv)
40154004
#ifdef DEBUG_WOLFSSH
40164005
wolfSSH_Debugging_ON();
40174006
#endif
4018-
#if !defined(WOLFSSL_NUCLEUS) && !defined(INTEGRITY) && !defined(__INTEGRITY)
4019-
#ifdef WOLFSSH_WINDOWS_CERT_STORE
4020-
/* When using the Windows certificate store for host keys, the
4021-
* echoserver does not need file-based keys, so skip the root
4022-
* directory search that looks for ./keys/server-key-rsa.pem. */
4023-
if (!EchoserverUsingCertStore(argc, argv))
4024-
#endif
4025-
{
4026-
ChangeToWolfSshRoot();
4027-
}
4028-
#endif
40294007

40304008
#ifndef NO_WOLFSSH_SERVER
4009+
/* echoserver_test() changes to the wolfSSH root directory itself,
4010+
* once it knows whether -W selected a Windows cert store host key. */
40314011
echoserver_test(&args);
40324012
#else
40334013
printf("wolfSSH compiled without server support\n");

src/ssh.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3389,7 +3389,7 @@ static int CertKeyCanSign(PCCERT_CONTEXT pCertContext)
33893389
* later, so reject it here rather than misreport it as usable. */
33903390
if (dwKeySpec != CERT_NCRYPT_KEY_SPEC) {
33913391
if (fCallerFree) {
3392-
CryptReleaseContext(hKey, 0);
3392+
NCryptFreeObject(hKey);
33933393
}
33943394
return WS_CERT_KEY_NONE;
33953395
}

tests/unit.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12380,12 +12380,17 @@ static int test_IdentifyAsn1Key(void)
1238012380

1238112381
/* Guard by the actual users -- the promote tests, the root-CA half of
1238212382
* test_SetCertManager(), and test_ParseECCPubKeyCert() -- to avoid
12383-
* -Wunused-function. */
12383+
* -Wunused-function. The last disjunct matches test_ParseECCPubKeyCert()'s
12384+
* guard exactly, so this stays a superset regardless of WOLFSSH_TEST_INTERNAL
12385+
* or the linked wolfSSL version (relevant for ide/winvs, which never defines
12386+
* WOLFSSH_TEST_INTERNAL for unit-test). */
1238412387
#if defined(WOLFSSH_TEST_CERTMAN_PROMOTE) || \
1238512388
(defined(WOLFSSH_TEST_SET_CERTMAN) && \
1238612389
defined(WOLFSSH_TEST_CERTMAN_ROOTCA)) || \
1238712390
(defined(WOLFSSH_TEST_INTERNAL) && defined(WOLFSSH_CERTS) && \
12388-
!defined(NO_FILESYSTEM) && !defined(WOLFSSH_NO_ECDSA_SHA2_NISTP256))
12391+
!defined(NO_FILESYSTEM) && !defined(WOLFSSH_NO_ECDSA_SHA2_NISTP256)) || \
12392+
(defined(WOLFSSH_CERTS) && !defined(NO_FILESYSTEM) && \
12393+
!defined(WOLFSSH_NO_ECDSA_SHA2_NISTP256))
1238912394

1239012395
/* Read a whole file into a freshly malloc'd buffer. Caller frees *buf. */
1239112396
static int certmanLoadFile(const char* fn, byte** buf, word32* bufSz)

0 commit comments

Comments
 (0)