forked from wolfSSL/wolfssl
implement CTX check private key function
This commit is contained in:
48
src/ssl.c
48
src/ssl.c
@ -6336,15 +6336,49 @@ int wolfSSL_CertManagerLoadCA(WOLFSSL_CERT_MANAGER* cm, const char* file,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifndef NO_WOLFSSL_STUB
|
/* Check private against public in certificate for match
|
||||||
int wolfSSL_CTX_check_private_key(WOLFSSL_CTX* ctx)
|
*
|
||||||
|
* ctx WOLFSSL_CTX structure to check private key in
|
||||||
|
*
|
||||||
|
* Returns SSL_SUCCESS on good private key and SSL_FAILURE if miss matched. */
|
||||||
|
int wolfSSL_CTX_check_private_key(const WOLFSSL_CTX* ctx)
|
||||||
{
|
{
|
||||||
/* TODO: check private against public for RSA match */
|
DecodedCert der;
|
||||||
(void)ctx;
|
word32 size;
|
||||||
WOLFSSL_STUB("SSL_CTX_check_private_key");
|
byte* buff;
|
||||||
return SSL_SUCCESS;
|
int ret;
|
||||||
}
|
|
||||||
|
WOLFSSL_ENTER("wolfSSL_CTX_check_private_key");
|
||||||
|
|
||||||
|
if (ctx == NULL) {
|
||||||
|
return SSL_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifndef NO_CERTS
|
||||||
|
size = ctx->certificate->length;
|
||||||
|
buff = ctx->certificate->buffer;
|
||||||
|
InitDecodedCert(&der, buff, size, ctx->heap);
|
||||||
|
if (ParseCertRelative(&der, CERT_TYPE, NO_VERIFY, NULL) != 0) {
|
||||||
|
FreeDecodedCert(&der);
|
||||||
|
return SSL_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
size = ctx->privateKey->length;
|
||||||
|
buff = ctx->privateKey->buffer;
|
||||||
|
ret = wc_CheckPrivateKey(buff, size, &der);
|
||||||
|
FreeDecodedCert(&der);
|
||||||
|
|
||||||
|
if (ret == 1) {
|
||||||
|
return SSL_SUCCESS;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return SSL_FAILURE;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
WOLFSSL_MSG("NO_CERTS is defined, can not check private key");
|
||||||
|
return SSL_FAILURE;
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef HAVE_CRL
|
#ifdef HAVE_CRL
|
||||||
|
|
||||||
|
10
tests/api.c
10
tests/api.c
@ -13563,8 +13563,14 @@ static void test_wolfSSL_certs(void)
|
|||||||
printf(testingFmt, "wolfSSL_certs()");
|
printf(testingFmt, "wolfSSL_certs()");
|
||||||
|
|
||||||
AssertNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
|
AssertNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
|
||||||
AssertTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile, WOLFSSL_FILETYPE_PEM));
|
AssertTrue(SSL_CTX_use_certificate_file(ctx, svrCertFile, SSL_FILETYPE_PEM));
|
||||||
AssertTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, WOLFSSL_FILETYPE_PEM));
|
AssertTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
|
||||||
|
#ifndef HAVE_USER_RSA
|
||||||
|
AssertTrue(SSL_CTX_use_PrivateKey_file(ctx, cliKeyFile, SSL_FILETYPE_PEM));
|
||||||
|
AssertIntEQ(SSL_CTX_check_private_key(ctx), SSL_FAILURE);
|
||||||
|
AssertTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKeyFile, SSL_FILETYPE_PEM));
|
||||||
|
AssertIntEQ(SSL_CTX_check_private_key(ctx), SSL_SUCCESS);
|
||||||
|
#endif
|
||||||
AssertNotNull(ssl = SSL_new(ctx));
|
AssertNotNull(ssl = SSL_new(ctx));
|
||||||
|
|
||||||
AssertIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
|
AssertIntEQ(wolfSSL_check_private_key(ssl), WOLFSSL_SUCCESS);
|
||||||
|
@ -1369,7 +1369,7 @@ WOLFSSL_API long wolfSSL_CTX_get_options(WOLFSSL_CTX* ctx);
|
|||||||
WOLFSSL_API long wolfSSL_CTX_clear_options(WOLFSSL_CTX*, long);
|
WOLFSSL_API long wolfSSL_CTX_clear_options(WOLFSSL_CTX*, long);
|
||||||
|
|
||||||
#ifndef NO_CERTS
|
#ifndef NO_CERTS
|
||||||
WOLFSSL_API int wolfSSL_CTX_check_private_key(WOLFSSL_CTX*);
|
WOLFSSL_API int wolfSSL_CTX_check_private_key(const WOLFSSL_CTX*);
|
||||||
#endif /* !NO_CERTS */
|
#endif /* !NO_CERTS */
|
||||||
|
|
||||||
WOLFSSL_API void wolfSSL_ERR_free_strings(void);
|
WOLFSSL_API void wolfSSL_ERR_free_strings(void);
|
||||||
|
Reference in New Issue
Block a user