Skip to content

Commit 82b15ef

Browse files
committed
Add acmeIdentifier to asn=original
1 parent c4400a1 commit 82b15ef

3 files changed

Lines changed: 62 additions & 0 deletions

File tree

wolfcrypt/src/asn.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25291,6 +25291,9 @@ typedef struct DerCert {
2529125291
#endif
2529225292
byte certPolicies[MAX_CERTPOL_NB*MAX_CERTPOL_SZ]; /* Certificate Policies */
2529325293
byte crlInfo[CTC_MAX_CRLINFO_SZ]; /* CRL Distribution Points */
25294+
#ifdef WOLFSSL_ACME_OID
25295+
byte acmeId[MAX_ACMEID_SZ]; /* RFC 8737 id-pe-acmeIdentifier */
25296+
#endif
2529425297
#endif
2529525298
#ifdef WOLFSSL_CERT_REQ
2529625299
byte attrib[MAX_ATTRIB_SZ]; /* Cert req attributes encoded */
@@ -25321,6 +25324,9 @@ typedef struct DerCert {
2532125324
#endif
2532225325
int certPoliciesSz; /* encoded CertPolicies extension length*/
2532325326
int crlInfoSz; /* encoded CRL Dist Points length */
25327+
#ifdef WOLFSSL_ACME_OID
25328+
int acmeIdSz; /* encoded acmeIdentifier length */
25329+
#endif
2532425330
#endif
2532525331
#ifdef WOLFSSL_ALT_NAMES
2532625332
int altNamesSz; /* encoded AltNames extension length */

wolfcrypt/src/asn_orig.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5295,6 +5295,31 @@ static int SetAKID(byte* output, word32 outSz, byte *input, word32 length,
52955295
return (int)idx + enc_valSz;
52965296
}
52975297

5298+
#ifdef WOLFSSL_ACME_OID
5299+
/* encode RFC 8737 id-pe-acmeIdentifier extension, return total bytes written
5300+
* RFC8737 : critical */
5301+
static int SetAcmeIdentifier(byte* output, word32 outSz, const byte* digest,
5302+
word32 digestSz)
5303+
{
5304+
byte inner[1 + MAX_LENGTH_SZ + WC_SHA256_DIGEST_SIZE];
5305+
word32 innerSz;
5306+
const byte acmeId_oid[] = { 0x06, 0x08, 0x2B, 0x06, 0x01, 0x05, 0x05, 0x07,
5307+
0x01, 0x1F, 0x01, 0x01, 0xFF, 0x04 };
5308+
5309+
if (output == NULL || digest == NULL)
5310+
return BAD_FUNC_ARG;
5311+
if (digestSz != WC_SHA256_DIGEST_SIZE)
5312+
return BAD_FUNC_ARG;
5313+
5314+
innerSz = SetOctetString(digestSz, inner);
5315+
XMEMCPY(inner + innerSz, digest, digestSz);
5316+
innerSz += digestSz;
5317+
5318+
return SetOidValue(output, outSz, acmeId_oid, sizeof(acmeId_oid),
5319+
inner, innerSz);
5320+
}
5321+
#endif /* WOLFSSL_ACME_OID */
5322+
52985323
/* encode Key Usage, return total bytes written
52995324
* RFC5280 : critical */
53005325
static int SetKeyUsage(byte* output, word32 outSz, word16 input)
@@ -6340,6 +6365,22 @@ static int EncodeCert(Cert* cert, DerCert* der, RsaKey* rsaKey, ecc_key* eccKey,
63406365
der->certPoliciesSz = 0;
63416366
#endif /* WOLFSSL_CERT_EXT */
63426367

6368+
#ifdef WOLFSSL_ACME_OID
6369+
/* RFC 8737 id-pe-acmeIdentifier (TLS-ALPN-01 challenge cert).
6370+
* Always critical=TRUE. */
6371+
if (cert->acmeIdentifierSz == WC_SHA256_DIGEST_SIZE) {
6372+
der->acmeIdSz = SetAcmeIdentifier(der->acmeId, sizeof(der->acmeId),
6373+
cert->acmeIdentifier,
6374+
(word32)cert->acmeIdentifierSz);
6375+
if (der->acmeIdSz <= 0)
6376+
return EXTENSIONS_E;
6377+
6378+
der->extensionsSz += der->acmeIdSz;
6379+
}
6380+
else
6381+
der->acmeIdSz = 0;
6382+
#endif
6383+
63436384
/* put extensions */
63446385
if (der->extensionsSz > 0) {
63456386

@@ -6436,6 +6477,17 @@ static int EncodeCert(Cert* cert, DerCert* der, RsaKey* rsaKey, ecc_key* eccKey,
64366477
return EXTENSIONS_E;
64376478
}
64386479
#endif /* WOLFSSL_CERT_EXT */
6480+
6481+
#ifdef WOLFSSL_ACME_OID
6482+
/* put ACME Identifier */
6483+
if (der->acmeIdSz) {
6484+
ret = SetExtensions(der->extensions, sizeof(der->extensions),
6485+
&der->extensionsSz,
6486+
der->acmeId, der->acmeIdSz);
6487+
if (ret <= 0)
6488+
return EXTENSIONS_E;
6489+
}
6490+
#endif
64396491
}
64406492

64416493
der->total = der->versionSz + der->serialSz + der->sigAlgoSz +

wolfssl/wolfcrypt/asn.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,10 @@ enum Misc_ASN {
13101310
#endif
13111311
MAX_CERTPOL_NB = CTC_MAX_CERTPOL_NB,/* Max number of Cert Policy */
13121312
MAX_CERTPOL_SZ = CTC_MAX_CERTPOL_SZ,
1313+
#endif
1314+
#ifdef WOLFSSL_ACME_OID
1315+
MAX_ACMEID_SZ = 19 + WC_SHA256_DIGEST_SIZE, /* Max encoded
1316+
acmeIdentifier size */
13131317
#endif
13141318
OCSP_NONCE_EXT_SZ = 35, /* OCSP Nonce Extension size */
13151319
MAX_OCSP_EXT_SZ = 58, /* Max OCSP Extension length */

0 commit comments

Comments
 (0)