Skip to content

Commit bbd3d76

Browse files
committed
Add some option disables to the api test and the echoserver.
1 parent 717ea6a commit bbd3d76

2 files changed

Lines changed: 46 additions & 14 deletions

File tree

examples/echoserver/echoserver.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,6 +1610,11 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
16101610
userEcc = 1;
16111611
peerEcc = 1;
16121612
#endif
1613+
#ifndef HAVE_ECC
1614+
/* If wolfCrypt isn't built with ECC, force ECC off. */
1615+
userEcc = 0;
1616+
peerEcc = 0;
1617+
#endif
16131618

16141619
if (wolfSSH_Init() != WS_SUCCESS) {
16151620
fprintf(stderr, "Couldn't initialize wolfSSH.\n");

tests/api.c

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -537,14 +537,31 @@ static void test_wolfSSH_CTX_UsePrivateKey_buffer(void)
537537
{
538538
#ifndef WOLFSSH_NO_SERVER
539539
WOLFSSH_CTX* ctx;
540+
#ifdef HAVE_ECC
540541
byte* eccKey;
542+
word32 eccKeySz;
543+
#endif
544+
#ifndef NO_RSA
541545
byte* rsaKey;
542-
byte* lastKey;
543-
word32 eccKeySz, rsaKeySz, lastKeySz;
544-
545-
AssertIntEQ(0, ConvertHexToBin(serverKeyEccDer, &eccKey, &eccKeySz,
546-
serverKeyRsaDer, &rsaKey, &rsaKeySz,
547-
NULL, NULL, NULL, NULL, NULL, NULL));
546+
word32 rsaKeySz;
547+
#endif
548+
byte* lastKey = NULL;
549+
word32 lastKeySz = 0;
550+
551+
#ifdef HAVE_ECC
552+
AssertIntEQ(0,
553+
ConvertHexToBin(serverKeyEccDer, &eccKey, &eccKeySz,
554+
NULL, NULL, NULL,
555+
NULL, NULL, NULL,
556+
NULL, NULL, NULL));
557+
#endif
558+
#ifndef NO_RSA
559+
AssertIntEQ(0,
560+
ConvertHexToBin(serverKeyRsaDer, &rsaKey, &rsaKeySz,
561+
NULL, NULL, NULL,
562+
NULL, NULL, NULL,
563+
NULL, NULL, NULL));
564+
#endif
548565

549566
AssertNotNull(ctx = wolfSSH_CTX_new(WOLFSSH_ENDPOINT_SERVER, NULL));
550567
AssertNull(ctx->privateKey);
@@ -568,7 +585,7 @@ static void test_wolfSSH_CTX_UsePrivateKey_buffer(void)
568585
/* Fail: ctx set, key set, others bad */
569586
AssertIntNE(WS_SUCCESS,
570587
wolfSSH_CTX_UsePrivateKey_buffer(ctx,
571-
rsaKey, 0, TEST_BAD_FORMAT_NEXT));
588+
lastKey, 0, TEST_BAD_FORMAT_NEXT));
572589
AssertNull(ctx->privateKey);
573590
AssertIntEQ(0, ctx->privateKeySz);
574591
AssertIntEQ(0, ctx->useEcc);
@@ -582,39 +599,49 @@ static void test_wolfSSH_CTX_UsePrivateKey_buffer(void)
582599

583600
/* Fail: ctx set, key set, keySz set, format invalid */
584601
AssertIntNE(WS_SUCCESS, wolfSSH_CTX_UsePrivateKey_buffer(ctx,
585-
rsaKey, rsaKeySz, TEST_GOOD_FORMAT_PEM));
602+
lastKey, lastKeySz, TEST_GOOD_FORMAT_PEM));
586603
AssertNull(ctx->privateKey);
587604
AssertIntEQ(0, ctx->privateKeySz);
588605
AssertIntEQ(0, ctx->useEcc);
589606

590607
/* Pass */
608+
#ifdef HAVE_ECC
609+
lastKey = ctx->privateKey;
610+
lastKeySz = ctx->privateKeySz;
611+
591612
AssertIntEQ(WS_SUCCESS,
592613
wolfSSH_CTX_UsePrivateKey_buffer(ctx, eccKey, eccKeySz,
593614
TEST_GOOD_FORMAT_ASN1));
594615
AssertNotNull(ctx->privateKey);
595616
AssertIntNE(0, ctx->privateKeySz);
596-
#ifndef WOLFSSH_NO_ECDSA
597617
AssertIntEQ(serverKeyEccCurveId, ctx->useEcc);
618+
619+
AssertIntEQ(0, (lastKey == ctx->privateKey));
620+
AssertIntNE(lastKeySz, ctx->privateKeySz);
598621
#endif
599622

600-
#ifndef WOLFSSH_NO_RSA
623+
#ifndef NO_RSA
601624
lastKey = ctx->privateKey;
602625
lastKeySz = ctx->privateKeySz;
626+
603627
AssertIntEQ(WS_SUCCESS,
604628
wolfSSH_CTX_UsePrivateKey_buffer(ctx, rsaKey, rsaKeySz,
605629
TEST_GOOD_FORMAT_ASN1));
606630
AssertNotNull(ctx->privateKey);
607631
AssertIntNE(0, ctx->privateKeySz);
608632
AssertIntEQ(0, ctx->useEcc);
633+
609634
AssertIntEQ(0, (lastKey == ctx->privateKey));
610635
AssertIntNE(lastKeySz, ctx->privateKeySz);
611-
#else
612-
(void)lastKey;
613-
(void)lastKeySz;
614636
#endif
615637

616638
wolfSSH_CTX_free(ctx);
617-
FreeBins(eccKey, rsaKey, NULL, NULL);
639+
#ifdef HAVE_ECC
640+
FreeBins(eccKey, NULL, NULL, NULL);
641+
#endif
642+
#ifndef NO_RSA
643+
FreeBins(rsaKey, NULL, NULL, NULL);
644+
#endif
618645
#endif /* WOLFSSH_NO_SERVER */
619646
}
620647

0 commit comments

Comments
 (0)