mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2026-05-04 04:50:49 +02:00
Merge pull request #1395 from JacobBarthelmeh/Certs
Add support for writing multiple OUs, DCs and for writing a unique EKU OID
This commit is contained in:
@@ -198,6 +198,9 @@
|
||||
|
||||
#include "wolfcrypt/test/test.h"
|
||||
|
||||
#if defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_MULTI_ATTRIB)
|
||||
static void initDefaultName(void);
|
||||
#endif
|
||||
|
||||
/* for async devices */
|
||||
static int devId = INVALID_DEVID;
|
||||
@@ -427,6 +430,10 @@ int wolfcrypt_test(void* args)
|
||||
#endif /* USE_FAST_MATH */
|
||||
#endif /* !NO_BIG_INT */
|
||||
|
||||
#if defined(WOLFSSL_CERT_GEN) && defined(WOLFSSL_MULTI_ATTRIB)
|
||||
initDefaultName();
|
||||
#endif
|
||||
|
||||
#ifdef WOLFSSL_ASYNC_CRYPT
|
||||
ret = wolfAsync_DevOpen(&devId);
|
||||
if (ret < 0) {
|
||||
@@ -7638,6 +7645,54 @@ byte GetEntropy(ENTROPY_CMD cmd, byte* out)
|
||||
|
||||
|
||||
#ifdef WOLFSSL_CERT_GEN
|
||||
#ifdef WOLFSSL_MULTI_ATTRIB
|
||||
static CertName certDefaultName;
|
||||
static void initDefaultName(void)
|
||||
{
|
||||
XMEMCPY(certDefaultName.country, "US", sizeof("US"));
|
||||
certDefaultName.countryEnc = CTC_PRINTABLE;
|
||||
XMEMCPY(certDefaultName.state, "Orgeon", sizeof("Orgeon"));
|
||||
certDefaultName.stateEnc = CTC_UTF8;
|
||||
XMEMCPY(certDefaultName.locality, "Portland", sizeof("Portland"));
|
||||
certDefaultName.localityEnc = CTC_UTF8;
|
||||
XMEMCPY(certDefaultName.sur, "Test", sizeof("Test"));
|
||||
certDefaultName.surEnc = CTC_UTF8;
|
||||
XMEMCPY(certDefaultName.org, "wolfSSL", sizeof("wolfSSL"));
|
||||
certDefaultName.orgEnc = CTC_UTF8;
|
||||
XMEMCPY(certDefaultName.unit, "Development", sizeof("Development"));
|
||||
certDefaultName.unitEnc = CTC_UTF8;
|
||||
XMEMCPY(certDefaultName.commonName, "www.wolfssl.com", sizeof("www.wolfssl.com"));
|
||||
certDefaultName.commonNameEnc = CTC_UTF8;
|
||||
XMEMCPY(certDefaultName.email, "info@wolfssl.com", sizeof("info@wolfssl.com"));
|
||||
|
||||
#ifdef WOLFSSL_TEST_CERT
|
||||
{
|
||||
NameAttrib* n;
|
||||
/* test having additional OUs and setting DC */
|
||||
n = &certDefaultName.name[0];
|
||||
n->id = ASN_ORGUNIT_NAME;
|
||||
n->type = CTC_UTF8;
|
||||
n->sz = sizeof("Development-2");
|
||||
XMEMCPY(n->value, "Development-2", sizeof("Development-2"));
|
||||
|
||||
#if CTC_MAX_ATTRIB > 3
|
||||
n = &certDefaultName.name[1];
|
||||
n->id = ASN_DOMAIN_COMPONENT;
|
||||
n->type = CTC_UTF8;
|
||||
n->sz = sizeof("com");
|
||||
XMEMCPY(n->value, "com", sizeof("com"));
|
||||
|
||||
n = &certDefaultName.name[2];
|
||||
n->id = ASN_DOMAIN_COMPONENT;
|
||||
n->type = CTC_UTF8;
|
||||
n->sz = sizeof("wolfssl");
|
||||
XMEMCPY(n->value, "wolfssl", sizeof("wolfssl"));
|
||||
|
||||
#endif
|
||||
}
|
||||
#endif /* WOLFSSL_TEST_CERT */
|
||||
}
|
||||
#else
|
||||
static const CertName certDefaultName = {
|
||||
"US", CTC_PRINTABLE, /* country */
|
||||
"Orgeon", CTC_UTF8, /* state */
|
||||
@@ -7648,6 +7703,7 @@ static const CertName certDefaultName = {
|
||||
"www.wolfssl.com", CTC_UTF8, /* commonName */
|
||||
"info@wolfssl.com" /* email */
|
||||
};
|
||||
#endif /* WOLFSSL_MULTI_ATTRIB */
|
||||
|
||||
#ifdef WOLFSSL_CERT_EXT
|
||||
#if (defined(HAVE_ED25519) && defined(WOLFSSL_TEST_CERT)) || \
|
||||
@@ -9521,6 +9577,15 @@ int rsa_test(void)
|
||||
if (wc_SetKeyUsage(&myCert,"cRLSign,keyCertSign") != 0) {
|
||||
ERROR_OUT(-5575, exit_rsa);
|
||||
}
|
||||
#ifdef WOLFSSL_EKU_OID
|
||||
{
|
||||
const char unique[] = "2.16.840.1.111111.100.1.10.1";
|
||||
if (wc_SetExtKeyUsageOID(&myCert, unique, sizeof(unique), 0,
|
||||
HEAP_HINT) != 0) {
|
||||
ERROR_OUT(-5651, exit_rsa);
|
||||
}
|
||||
}
|
||||
#endif /* WOLFSSL_EKU_OID */
|
||||
#endif /* WOLFSSL_CERT_EXT */
|
||||
|
||||
ret = 0;
|
||||
@@ -10113,6 +10178,15 @@ int rsa_test(void)
|
||||
"emailProtection,timeStamping,OCSPSigning") != 0) {
|
||||
ERROR_OUT(-5645, exit_rsa);
|
||||
}
|
||||
#ifdef WOLFSSL_EKU_OID
|
||||
{
|
||||
const char unique[] = "2.16.840.1.111111.100.1.10.1";
|
||||
if (wc_SetExtKeyUsageOID(&req, unique, sizeof(unique), 0,
|
||||
HEAP_HINT) != 0) {
|
||||
ERROR_OUT(-5652, exit_rsa);
|
||||
}
|
||||
}
|
||||
#endif /* WOLFSSL_EKU_OID */
|
||||
#endif /* WOLFSSL_CERT_EXT */
|
||||
|
||||
derSz = wc_MakeCertReq(&req, der, FOURK_BUF, &key, NULL);
|
||||
|
||||
Reference in New Issue
Block a user