forked from wolfSSL/wolfssl
compatibility functions for ssl cert and private key
This commit is contained in:
65
src/ssl.c
65
src/ssl.c
@@ -5684,6 +5684,71 @@ int wolfSSL_CTX_SetTmpDH_file(WOLFSSL_CTX* ctx, const char* fname, int format)
|
||||
#ifdef OPENSSL_EXTRA
|
||||
/* put SSL type in extra for now, not very common */
|
||||
|
||||
#ifndef NO_CERTS
|
||||
int wolfSSL_use_PrivateKey(WOLFSSL* ssl, WOLFSSL_EVP_PKEY* pkey)
|
||||
{
|
||||
WOLFSSL_STUB("wolfSSL_use_PrivateKey");
|
||||
(void)ssl;
|
||||
(void)pkey;
|
||||
return SSL_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
int wolfSSL_use_PrivateKey_ASN1(int pri, WOLFSSL* ssl, unsigned char* der,
|
||||
long derSz)
|
||||
{
|
||||
WOLFSSL_STUB("wolfSSL_use_PrivateKey_ASN1");
|
||||
(void)ssl;
|
||||
(void)pri;
|
||||
(void)der;
|
||||
(void)derSz;
|
||||
return SSL_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
#ifndef NO_RSA
|
||||
int wolfSSL_use_RSAPrivateKey_ASN1(WOLFSSL* ssl, WOLFSSL_RSA* rsa)
|
||||
{
|
||||
WOLFSSL_STUB("wolfSSL_use_RSAPrivateKey");
|
||||
(void)ssl;
|
||||
(void)rsa;
|
||||
return SSL_FAILURE;
|
||||
}
|
||||
#endif
|
||||
|
||||
int wolfSSL_use_certificate_ASN1(WOLFSSL* ssl, unsigned char* der, int derSz)
|
||||
{
|
||||
long idx;
|
||||
|
||||
WOLFSSL_ENTER("wolfSSL_use_certificate_ASN1");
|
||||
if (der != NULL && ssl != NULL) {
|
||||
if (ProcessBuffer(NULL, der, derSz, SSL_FILETYPE_ASN1, CERT_TYPE, ssl,
|
||||
&idx, 0) == SSL_SUCCESS)
|
||||
return SSL_SUCCESS;
|
||||
}
|
||||
|
||||
(void)idx;
|
||||
return SSL_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
int wolfSSL_use_certificate(WOLFSSL* ssl, WOLFSSL_X509* x509)
|
||||
{
|
||||
long idx;
|
||||
|
||||
WOLFSSL_ENTER("wolfSSL_use_certificate");
|
||||
if (x509 != NULL && ssl != NULL && x509->derCert != NULL) {
|
||||
if (ProcessBuffer(NULL, x509->derCert->buffer, x509->derCert->length,
|
||||
SSL_FILETYPE_ASN1, CERT_TYPE, ssl, &idx, 0) == SSL_SUCCESS)
|
||||
return SSL_SUCCESS;
|
||||
}
|
||||
|
||||
(void)idx;
|
||||
return SSL_FAILURE;
|
||||
}
|
||||
#endif /* NO_CERTS */
|
||||
|
||||
|
||||
int wolfSSL_use_certificate_file(WOLFSSL* ssl, const char* file, int format)
|
||||
{
|
||||
WOLFSSL_ENTER("wolfSSL_use_certificate_file");
|
||||
|
44
tests/api.c
44
tests/api.c
@@ -2245,6 +2245,49 @@ static void test_wolfSSL_DES(void)
|
||||
#endif /* defined(OPENSSL_EXTRA) && !defined(NO_DES3) */
|
||||
}
|
||||
|
||||
|
||||
static void test_wolfSSL_certs(void)
|
||||
{
|
||||
#if defined(OPENSSL_EXTRA) && !defined(NO_CERTS) && \
|
||||
!defined(NO_FILESYSTEM) && !defined(NO_RSA)
|
||||
X509* x509;
|
||||
WOLFSSL* ssl;
|
||||
WOLFSSL_CTX* ctx;
|
||||
|
||||
printf(testingFmt, "wolfSSL_certs()");
|
||||
|
||||
AssertNotNull(ctx = SSL_CTX_new(wolfSSLv23_server_method()));
|
||||
AssertTrue(SSL_CTX_use_certificate_file(ctx, svrCert, SSL_FILETYPE_PEM));
|
||||
AssertTrue(SSL_CTX_use_PrivateKey_file(ctx, svrKey, SSL_FILETYPE_PEM));
|
||||
AssertNotNull(ssl = SSL_new(ctx));
|
||||
|
||||
|
||||
/* create and use x509 */
|
||||
x509 = wolfSSL_X509_load_certificate_file(svrCert, SSL_FILETYPE_PEM);
|
||||
AssertNotNull(x509);
|
||||
AssertIntEQ(SSL_use_certificate(ssl, x509), SSL_SUCCESS);
|
||||
|
||||
|
||||
#if defined(USE_CERT_BUFFERS_2048)
|
||||
AssertIntEQ(SSL_use_certificate_ASN1(ssl,
|
||||
(unsigned char*)server_cert_der_2048,
|
||||
sizeof_server_cert_der_2048), SSL_SUCCESS);
|
||||
#endif
|
||||
|
||||
/* needs tested after stubs filled out @TODO
|
||||
SSL_use_PrivateKey
|
||||
SSL_use_PrivateKey_ASN1
|
||||
SSL_use_RSAPrivateKey_ASN1
|
||||
*/
|
||||
|
||||
SSL_free(ssl);
|
||||
SSL_CTX_free(ctx);
|
||||
wolfSSL_FreeX509(x509);
|
||||
|
||||
printf(resultFmt, passed);
|
||||
#endif /* defined(OPENSSL_EXTRA) && !defined(NO_CERTS) */
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*
|
||||
| Main
|
||||
*----------------------------------------------------------------------------*/
|
||||
@@ -2291,6 +2334,7 @@ void ApiTest(void)
|
||||
|
||||
/* compatibility tests */
|
||||
test_wolfSSL_DES();
|
||||
test_wolfSSL_certs();
|
||||
|
||||
AssertIntEQ(test_wolfSSL_Cleanup(), SSL_SUCCESS);
|
||||
printf(" End API Tests\n");
|
||||
|
@@ -110,6 +110,12 @@ typedef WOLFSSL_X509_STORE_CTX X509_STORE_CTX;
|
||||
#define SSL_CTX_get_verify_mode wolfSSL_CTX_get_verify_mode
|
||||
#define SSL_CTX_get_verify_depth wolfSSL_CTX_get_verify_depth
|
||||
#define SSL_get_certificate wolfSSL_get_certificate
|
||||
#define SSL_use_certificate wolfSSL_use_certificate
|
||||
#define SSL_use_certificate_ASN1 wolfSSL_use_certificate_ASN1
|
||||
|
||||
#define SSL_use_PrivateKey wolfSSL_use_PrivateKey
|
||||
#define SSL_use_PrivateKey_ASN1 wolfSSL_use_PrivateKey_ASN1
|
||||
#define SSL_use_RSAPrivateKey_ASN1 wolfSSL_use_RSAPrivateKey_ASN1
|
||||
|
||||
#define SSLv3_server_method wolfSSLv3_server_method
|
||||
#define SSLv3_client_method wolfSSLv3_client_method
|
||||
|
@@ -1892,6 +1892,21 @@ WOLFSSL_API char* wolfSSL_ASN1_TIME_to_string(WOLFSSL_ASN1_TIME* time,
|
||||
#endif /* WOLFSSL_MYSQL_COMPATIBLE */
|
||||
|
||||
#ifdef OPENSSL_EXTRA
|
||||
|
||||
#ifndef NO_CERTS
|
||||
WOLFSSL_API int wolfSSL_use_certificate(WOLFSSL* ssl, WOLFSSL_X509* x509);
|
||||
WOLFSSL_API int wolfSSL_use_certificate_ASN1(WOLFSSL* ssl, unsigned char* der,
|
||||
int derSz);
|
||||
WOLFSSL_API int wolfSSL_use_PrivateKey(WOLFSSL* ssl, WOLFSSL_EVP_PKEY* pkey);
|
||||
WOLFSSL_API int wolfSSL_use_PrivateKey_ASN1(int pri, WOLFSSL* ssl,
|
||||
unsigned char* der, long derSz);
|
||||
#ifndef NO_RSA
|
||||
WOLFSSL_API int wolfSSL_use_RSAPrivateKey_ASN1(WOLFSSL* ssl, WOLFSSL_RSA* rsa);
|
||||
#endif
|
||||
#endif /* NO_CERTS */
|
||||
|
||||
WOLFSSL_API WOLFSSL_DH *wolfSSL_DSA_dup_DH(const WOLFSSL_DSA *r);
|
||||
|
||||
WOLFSSL_API int wolfSSL_SESSION_get_master_key(const WOLFSSL_SESSION* ses,
|
||||
unsigned char* out, int outSz);
|
||||
WOLFSSL_API int wolfSSL_SESSION_get_master_key_length(const WOLFSSL_SESSION* ses);
|
||||
|
Reference in New Issue
Block a user