Implement wolfSSL_d2i_X509_NAME

This commit is contained in:
Juliusz Sosinowicz
2020-04-10 23:02:58 +02:00
parent ca3a608408
commit 139a192185
7 changed files with 48 additions and 2 deletions

View File

@@ -1406,7 +1406,7 @@ AC_ARG_ENABLE([certgen],
[ ENABLED_CERTGEN=$enableval ], [ ENABLED_CERTGEN=$enableval ],
[ ENABLED_CERTGEN=no ] [ ENABLED_CERTGEN=no ]
) )
if test "$ENABLED_OPENVPN" = "yes" if test "$ENABLED_OPENVPN" = "yes" || test "$ENABLED_OPENSSH" = "yes"
then then
ENABLED_CERTGEN=yes ENABLED_CERTGEN=yes
fi fi

View File

@@ -37317,6 +37317,42 @@ static int CopyX509NameToCertName(WOLFSSL_X509_NAME* n, CertName* cName)
#endif /* WOLFSSL_CERT_GEN */ #endif /* WOLFSSL_CERT_GEN */
#if defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL) #if defined(OPENSSL_EXTRA) || defined(OPENSSL_ALL)
WOLFSSL_X509_NAME *wolfSSL_d2i_X509_NAME(WOLFSSL_X509_NAME **name,
unsigned char **in, long length)
{
WOLFSSL_X509_NAME* tmp = NULL;
DecodedCert cert;
WOLFSSL_ENTER("wolfSSL_d2i_X509_NAME");
if (!in || !*in || length <= 0) {
WOLFSSL_MSG("Bad argument");
return NULL;
}
InitDecodedCert(&cert, *in, length, NULL);
if (GetName(&cert, SUBJECT, length) != 0) {
WOLFSSL_MSG("WOLFSSL_X509_NAME parse error");
return NULL;
}
if (!(tmp = wolfSSL_X509_NAME_new())) {
WOLFSSL_MSG("wolfSSL_X509_NAME_new error");
return NULL;
}
XSTRNCPY(tmp->staticName, cert.subject, ASN_NAME_MAX);
tmp->staticName[ASN_NAME_MAX - 1] = '\0';
tmp->sz = (int)XSTRLEN(tmp->staticName) + 1;
if (name)
*name = tmp;
return tmp;
}
/* Compares the two X509 names. If the size of x is larger then y then a /* Compares the two X509 names. If the size of x is larger then y then a
* positive value is returned if x is smaller a negative value is returned. * positive value is returned if x is smaller a negative value is returned.
* In the case that the sizes are equal a the value of strcmp between the * In the case that the sizes are equal a the value of strcmp between the

View File

@@ -23033,6 +23033,7 @@ static void test_wolfSSL_X509_NAME(void)
XFILE f; XFILE f;
const X509_NAME* a; const X509_NAME* a;
const X509_NAME* b; const X509_NAME* b;
X509_NAME* d2i_name;
int sz; int sz;
unsigned char* tmp; unsigned char* tmp;
char file[] = "./certs/ca-cert.der"; char file[] = "./certs/ca-cert.der";
@@ -23068,6 +23069,9 @@ static void test_wolfSSL_X509_NAME(void)
abort(); abort();
} }
tmp = buf;
AssertNotNull(d2i_name = d2i_X509_NAME(NULL, &tmp, sz));
/* retry but with the function creating a buffer */ /* retry but with the function creating a buffer */
tmp = NULL; tmp = NULL;
AssertIntGT((sz = i2d_X509_NAME((X509_NAME*)b, &tmp)), 0); AssertIntGT((sz = i2d_X509_NAME((X509_NAME*)b, &tmp)), 0);
@@ -23077,6 +23081,7 @@ static void test_wolfSSL_X509_NAME(void)
AssertNotNull(b = X509_NAME_dup((X509_NAME*)a)); AssertNotNull(b = X509_NAME_dup((X509_NAME*)a));
AssertIntEQ(X509_NAME_cmp(a, b), 0); AssertIntEQ(X509_NAME_cmp(a, b), 0);
X509_NAME_free((X509_NAME*)b); X509_NAME_free((X509_NAME*)b);
X509_NAME_free(d2i_name);
X509_free(x509); X509_free(x509);

View File

@@ -5550,7 +5550,7 @@ int CalcHashId(const byte* data, word32 len, byte* hash)
/* process NAME, either issuer or subject /* process NAME, either issuer or subject
* returns 0 on success and negative values on fail */ * returns 0 on success and negative values on fail */
static int GetName(DecodedCert* cert, int nameType, int maxIdx) int GetName(DecodedCert* cert, int nameType, int maxIdx)
{ {
int length; /* length of all distinguished names */ int length; /* length of all distinguished names */
int dummy; int dummy;

View File

@@ -449,6 +449,7 @@ typedef STACK_OF(ACCESS_DESCRIPTION) AUTHORITY_INFO_ACCESS;
#define sk_X509_INFO_free wolfSSL_sk_X509_INFO_free #define sk_X509_INFO_free wolfSSL_sk_X509_INFO_free
#define i2d_X509_NAME wolfSSL_i2d_X509_NAME #define i2d_X509_NAME wolfSSL_i2d_X509_NAME
#define d2i_X509_NAME wolfSSL_d2i_X509_NAME
#define X509_NAME_new wolfSSL_X509_NAME_new #define X509_NAME_new wolfSSL_X509_NAME_new
#define X509_NAME_free wolfSSL_X509_NAME_free #define X509_NAME_free wolfSSL_X509_NAME_free
#define X509_NAME_dup wolfSSL_X509_NAME_dup #define X509_NAME_dup wolfSSL_X509_NAME_dup

View File

@@ -1318,6 +1318,9 @@ WOLFSSL_API void wolfSSL_X509_STORE_set_verify_cb(WOLFSSL_X509_STORE *st,
WOLFSSL_X509_STORE_CTX_verify_cb verify_cb); WOLFSSL_X509_STORE_CTX_verify_cb verify_cb);
WOLFSSL_API int wolfSSL_i2d_X509_NAME(WOLFSSL_X509_NAME* n, WOLFSSL_API int wolfSSL_i2d_X509_NAME(WOLFSSL_X509_NAME* n,
unsigned char** out); unsigned char** out);
WOLFSSL_API WOLFSSL_X509_NAME *wolfSSL_d2i_X509_NAME(WOLFSSL_X509_NAME **name,
unsigned char **in, long length);
WOLFSSL_API
#ifndef NO_RSA #ifndef NO_RSA
WOLFSSL_API int wolfSSL_RSA_print(WOLFSSL_BIO* bio, WOLFSSL_RSA* rsa, int offset); WOLFSSL_API int wolfSSL_RSA_print(WOLFSSL_BIO* bio, WOLFSSL_RSA* rsa, int offset);
#endif #endif

View File

@@ -1006,6 +1006,7 @@ struct TrustedPeerCert {
#endif #endif
WOLFSSL_LOCAL int CalcHashId(const byte* data, word32 len, byte* hash); WOLFSSL_LOCAL int CalcHashId(const byte* data, word32 len, byte* hash);
WOLFSSL_LOCAL int GetName(DecodedCert* cert, int nameType, int maxIdx);
WOLFSSL_ASN_API int wc_BerToDer(const byte* ber, word32 berSz, byte* der, WOLFSSL_ASN_API int wc_BerToDer(const byte* ber, word32 berSz, byte* der,
word32* derSz); word32* derSz);