@@ -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-
30533030static 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" );
0 commit comments