2012-10-01 22:02:15 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2008-06-06 16:40:11 +04:00
|
|
|
|
|
|
|
/*
|
2016-01-25 18:14:18 +03:00
|
|
|
* X.509 v3 Subject Key Usage Extension
|
2008-06-06 16:40:11 +04:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "prtypes.h"
|
|
|
|
#include "seccomon.h"
|
|
|
|
#include "secdert.h"
|
|
|
|
#include "secoidt.h"
|
|
|
|
#include "secasn1t.h"
|
|
|
|
#include "secasn1.h"
|
|
|
|
#include "secport.h"
|
2016-01-25 18:14:18 +03:00
|
|
|
#include "certt.h"
|
2008-06-06 16:40:11 +04:00
|
|
|
#include "genname.h"
|
|
|
|
#include "secerr.h"
|
|
|
|
|
|
|
|
SEC_ASN1_MKSUB(SEC_IntegerTemplate)
|
|
|
|
SEC_ASN1_MKSUB(SEC_OctetStringTemplate)
|
|
|
|
|
|
|
|
const SEC_ASN1Template CERTAuthKeyIDTemplate[] = {
|
|
|
|
{ SEC_ASN1_SEQUENCE, 0, NULL, sizeof(CERTAuthKeyID) },
|
|
|
|
{ SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 0,
|
2016-01-25 18:14:18 +03:00
|
|
|
offsetof(CERTAuthKeyID, keyID), SEC_ASN1_SUB(SEC_OctetStringTemplate) },
|
|
|
|
{ SEC_ASN1_OPTIONAL | SEC_ASN1_CONSTRUCTED | SEC_ASN1_CONTEXT_SPECIFIC | 1,
|
|
|
|
offsetof(CERTAuthKeyID, DERAuthCertIssuer), CERT_GeneralNamesTemplate },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ SEC_ASN1_OPTIONAL | SEC_ASN1_CONTEXT_SPECIFIC | SEC_ASN1_XTRN | 2,
|
2016-01-25 18:14:18 +03:00
|
|
|
offsetof(CERTAuthKeyID, authCertSerialNumber),
|
|
|
|
SEC_ASN1_SUB(SEC_IntegerTemplate) },
|
2008-06-06 16:40:11 +04:00
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
2016-01-25 18:14:18 +03:00
|
|
|
SECStatus
|
|
|
|
CERT_EncodeAuthKeyID(PLArenaPool *arena, CERTAuthKeyID *value,
|
|
|
|
SECItem *encodedValue)
|
2008-06-06 16:40:11 +04:00
|
|
|
{
|
|
|
|
SECStatus rv = SECFailure;
|
2016-01-25 18:14:18 +03:00
|
|
|
|
|
|
|
PORT_Assert(value);
|
|
|
|
PORT_Assert(arena);
|
|
|
|
PORT_Assert(value->DERAuthCertIssuer == NULL);
|
|
|
|
PORT_Assert(encodedValue);
|
2008-06-06 16:40:11 +04:00
|
|
|
|
|
|
|
do {
|
2016-01-25 18:14:18 +03:00
|
|
|
|
|
|
|
/* If both of the authCertIssuer and the serial number exist, encode
|
|
|
|
the name first. Otherwise, it is an error if one exist and the other
|
|
|
|
is not.
|
|
|
|
*/
|
|
|
|
if (value->authCertIssuer) {
|
|
|
|
if (!value->authCertSerialNumber.data) {
|
|
|
|
PORT_SetError(SEC_ERROR_EXTENSION_VALUE_INVALID);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
value->DERAuthCertIssuer =
|
|
|
|
cert_EncodeGeneralNames(arena, value->authCertIssuer);
|
|
|
|
if (!value->DERAuthCertIssuer) {
|
|
|
|
PORT_SetError(SEC_ERROR_EXTENSION_VALUE_INVALID);
|
|
|
|
break;
|
|
|
|
}
|
2016-02-26 13:23:11 +03:00
|
|
|
} else if (value->authCertSerialNumber.data) {
|
2016-01-25 18:14:18 +03:00
|
|
|
PORT_SetError(SEC_ERROR_EXTENSION_VALUE_INVALID);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SEC_ASN1EncodeItem(arena, encodedValue, value,
|
|
|
|
CERTAuthKeyIDTemplate) == NULL)
|
|
|
|
break;
|
|
|
|
rv = SECSuccess;
|
2008-06-06 16:40:11 +04:00
|
|
|
|
|
|
|
} while (0);
|
2016-01-25 18:14:18 +03:00
|
|
|
return (rv);
|
2008-06-06 16:40:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
CERTAuthKeyID *
|
2016-01-25 18:14:18 +03:00
|
|
|
CERT_DecodeAuthKeyID(PLArenaPool *arena, const SECItem *encodedValue)
|
2008-06-06 16:40:11 +04:00
|
|
|
{
|
2016-01-25 18:14:18 +03:00
|
|
|
CERTAuthKeyID *value = NULL;
|
|
|
|
SECStatus rv = SECFailure;
|
|
|
|
void *mark;
|
|
|
|
SECItem newEncodedValue;
|
|
|
|
|
|
|
|
PORT_Assert(arena);
|
2008-06-06 16:40:11 +04:00
|
|
|
|
|
|
|
do {
|
2016-01-25 18:14:18 +03:00
|
|
|
mark = PORT_ArenaMark(arena);
|
|
|
|
value = (CERTAuthKeyID *)PORT_ArenaZAlloc(arena, sizeof(*value));
|
|
|
|
if (value == NULL)
|
|
|
|
break;
|
|
|
|
value->DERAuthCertIssuer = NULL;
|
2008-06-06 16:40:11 +04:00
|
|
|
/* copy the DER into the arena, since Quick DER returns data that points
|
|
|
|
into the DER input, which may get freed by the caller */
|
|
|
|
rv = SECITEM_CopyItem(arena, &newEncodedValue, encodedValue);
|
2016-01-25 18:14:18 +03:00
|
|
|
if (rv != SECSuccess) {
|
|
|
|
break;
|
2008-06-06 16:40:11 +04:00
|
|
|
}
|
|
|
|
|
2016-01-25 18:14:18 +03:00
|
|
|
rv = SEC_QuickDERDecodeItem(arena, value, CERTAuthKeyIDTemplate,
|
|
|
|
&newEncodedValue);
|
|
|
|
if (rv != SECSuccess)
|
|
|
|
break;
|
|
|
|
|
|
|
|
value->authCertIssuer =
|
|
|
|
cert_DecodeGeneralNames(arena, value->DERAuthCertIssuer);
|
|
|
|
if (value->authCertIssuer == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* what if the general name contains other format but not URI ?
|
|
|
|
hl
|
|
|
|
*/
|
|
|
|
if ((value->authCertSerialNumber.data && !value->authCertIssuer) ||
|
|
|
|
(!value->authCertSerialNumber.data && value->authCertIssuer)) {
|
|
|
|
PORT_SetError(SEC_ERROR_EXTENSION_VALUE_INVALID);
|
|
|
|
break;
|
|
|
|
}
|
2008-06-06 16:40:11 +04:00
|
|
|
} while (0);
|
|
|
|
|
|
|
|
if (rv != SECSuccess) {
|
2016-01-25 18:14:18 +03:00
|
|
|
PORT_ArenaRelease(arena, mark);
|
|
|
|
return ((CERTAuthKeyID *)NULL);
|
|
|
|
}
|
2008-06-06 16:40:11 +04:00
|
|
|
PORT_ArenaUnmark(arena, mark);
|
|
|
|
return (value);
|
|
|
|
}
|