Refactor of the wc_ParseCertPIV to support detection of Identiv format header. Added flag to indicate Identiv type. Added wolfCrypt test for wc_ParseCertPIV function with Identiv PIV template.

This commit is contained in:
David Garske
2018-10-02 17:01:56 -07:00
parent 0c72dee315
commit f0350c1efb
3 changed files with 66 additions and 41 deletions

View File

@@ -14478,9 +14478,36 @@ int wc_ParseCertPIV(wc_CertPIV* piv, const byte* buf, word32 totalSz)
XMEMSET(piv, 0, sizeof(wc_CertPIV)); XMEMSET(piv, 0, sizeof(wc_CertPIV));
/* Certificate - Total Length (0A 82 05FA) */ /* Detect Identiv PIV (with 0x0A, 0x0B and 0x0C sections) */
/* Certificate (0A 82 05FA) */
if (GetASNHeader(buf, ASN_PIV_CERT, &idx, &length, totalSz) >= 0) { if (GetASNHeader(buf, ASN_PIV_CERT, &idx, &length, totalSz) >= 0) {
/* Certificate Buffer (53 82 05F6) */ /* Identiv Type PIV card */
piv->isIdentiv = 1;
piv->cert = &buf[idx];
piv->certSz = length;
idx += length;
/* Nonce (0B 14) */
if (GetASNHeader(buf, ASN_PIV_NONCE, &idx, &length, totalSz) >= 0) {
piv->nonce = &buf[idx];
piv->nonceSz = length;
idx += length;
}
/* Signed Nonce (0C 82 0100) */
if (GetASNHeader(buf, ASN_PIV_SIGNED_NONCE, &idx, &length, totalSz) >= 0) {
piv->signedNonce = &buf[idx];
piv->signedNonceSz = length;
idx += length;
}
idx = 0;
buf = piv->cert;
totalSz = piv->certSz;
}
/* Certificate Buffer Total Size (53 82 05F6) */
if (GetASNHeader(buf, ASN_APPLICATION | ASN_PRINTABLE_STRING, &idx, if (GetASNHeader(buf, ASN_APPLICATION | ASN_PRINTABLE_STRING, &idx,
&length, totalSz) < 0) { &length, totalSz) < 0) {
return ASN_PARSE_E; return ASN_PARSE_E;
@@ -14513,21 +14540,6 @@ int wc_ParseCertPIV(wc_CertPIV* piv, const byte* buf, word32 totalSz)
piv->certErrDetSz = length; piv->certErrDetSz = length;
idx += length; idx += length;
} }
}
/* Nonce (0B 14) */
if (GetASNHeader(buf, ASN_PIV_NONCE, &idx, &length, totalSz) >= 0) {
piv->nonce = &buf[idx];
piv->nonceSz = length;
idx += length;
}
/* Signed Nonce (0C 82 0100) */
if (GetASNHeader(buf, ASN_PIV_SIGNED_NONCE, &idx, &length, totalSz) >= 0) {
piv->signedNonce = &buf[idx];
piv->signedNonceSz = length;
idx += length;
}
return 0; return 0;
} }

View File

@@ -20331,12 +20331,24 @@ int cryptodev_test(void)
#ifdef WOLFSSL_CERT_PIV #ifdef WOLFSSL_CERT_PIV
int certpiv_test(void) int certpiv_test(void)
{ {
/* TODO: Add test for wc_ParseCertPIV */ int ret;
#if 0
wc_CertPIV piv; wc_CertPIV piv;
ret = wc_ParseCertPIV(&piv, buf, totalSz);
#endif /* Template for Identiv PIV cert, nonce and signature */
return 0; const byte pivCert[] = {
0x0A, 0x0D,
0x53, 0x04, /* NIST PIV Cert */
0x70, 0x02, /* Certificate */
0x30, 0x00,
0x71, 0x01, 0x00, /* Cert Info */
0xFE, 0x00, /* Error Detection */
0x0B, 0x01, 0x00, /* Nonce */
0x0C, 0x01, 0x00, /* Signed Nonce */
};
ret = wc_ParseCertPIV(&piv, pivCert, sizeof(pivCert));
return ret;
} }
#endif /* WOLFSSL_CERT_PIV */ #endif /* WOLFSSL_CERT_PIV */

View File

@@ -486,14 +486,15 @@ typedef struct _wc_CertPIV {
word32 certSz; word32 certSz;
const byte* certErrDet; const byte* certErrDet;
word32 certErrDetSz; word32 certErrDetSz;
const byte* nonce; const byte* nonce; /* Identiv Only */
word32 nonceSz; word32 nonceSz; /* Identiv Only */
const byte* signedNonce; const byte* signedNonce; /* Identiv Only */
word32 signedNonceSz; word32 signedNonceSz; /* Identiv Only */
/* flags */ /* flags */
word16 compression:2; word16 compression:2;
word16 isX509:1; word16 isX509:1;
word16 isIdentiv:1;
} wc_CertPIV; } wc_CertPIV;
WOLFSSL_API int wc_ParseCertPIV(wc_CertPIV* cert, const byte* buf, word32 totalSz); WOLFSSL_API int wc_ParseCertPIV(wc_CertPIV* cert, const byte* buf, word32 totalSz);