x509: Fix some whitespaces and do some minor style cleanups in acert

This commit is contained in:
Martin Willi
2014-03-31 11:14:57 +02:00
parent 883a63adc1
commit 3134379ac7
+40 -36
View File
@@ -169,21 +169,19 @@ extern void x509_parse_generalNames(chunk_t blob, int level0, bool implicit,
/** /**
* parses a directoryName * parses a directoryName
*/ */
static bool parse_directoryName(chunk_t blob, int level, bool implicit, identification_t **name) static bool parse_directoryName(chunk_t blob, int level, bool implicit,
identification_t **name)
{ {
bool has_directoryName;
linked_list_t *list = linked_list_create();
x509_parse_generalNames(blob, level, implicit, list);
has_directoryName = list->get_count(list) > 0;
if (has_directoryName)
{
enumerator_t *enumerator = list->create_enumerator(list);
identification_t *directoryName; identification_t *directoryName;
enumerator_t *enumerator;
bool first = TRUE; bool first = TRUE;
linked_list_t *list;
while (enumerator->enumerate(enumerator, (void**)&directoryName)) list = linked_list_create();
x509_parse_generalNames(blob, level, implicit, list);
enumerator = list->create_enumerator(list);
while (enumerator->enumerate(enumerator, &directoryName))
{ {
if (first) if (first)
{ {
@@ -194,17 +192,18 @@ static bool parse_directoryName(chunk_t blob, int level, bool implicit, identifi
{ {
DBG1(DBG_ASN, "more than one directory name - first selected"); DBG1(DBG_ASN, "more than one directory name - first selected");
directoryName->destroy(directoryName); directoryName->destroy(directoryName);
break;
} }
} }
enumerator->destroy(enumerator); enumerator->destroy(enumerator);
} list->destroy(list);
else
if (first)
{ {
DBG1(DBG_ASN, "no directoryName found"); DBG1(DBG_ASN, "no directoryName found");
return FALSE;
} }
return TRUE;
list->destroy(list);
return has_directoryName;
} }
/** /**
@@ -368,7 +367,8 @@ static bool parse_certificate(private_x509_ac_t *this)
} }
break; break;
case AC_OBJ_HOLDER_ISSUER: case AC_OBJ_HOLDER_ISSUER:
if (!parse_directoryName(object, level, FALSE, &this->holderIssuer)) if (!parse_directoryName(object, level, FALSE,
&this->holderIssuer))
{ {
goto end; goto end;
} }
@@ -377,13 +377,15 @@ static bool parse_certificate(private_x509_ac_t *this)
this->holderSerial = object; this->holderSerial = object;
break; break;
case AC_OBJ_ENTITY_NAME: case AC_OBJ_ENTITY_NAME:
if (!parse_directoryName(object, level, TRUE, &this->entityName)) if (!parse_directoryName(object, level, TRUE,
&this->entityName))
{ {
goto end; goto end;
} }
break; break;
case AC_OBJ_ISSUER_NAME: case AC_OBJ_ISSUER_NAME:
if (!parse_directoryName(object, level, FALSE, &this->issuerName)) if (!parse_directoryName(object, level, FALSE,
&this->issuerName))
{ {
goto end; goto end;
} }
@@ -446,7 +448,8 @@ static bool parse_certificate(private_x509_ac_t *this)
DBG2(DBG_ASN, " need to parse crlDistributionPoints"); DBG2(DBG_ASN, " need to parse crlDistributionPoints");
break; break;
case OID_AUTHORITY_KEY_ID: case OID_AUTHORITY_KEY_ID:
this->authKeyIdentifier = x509_parse_authorityKeyIdentifier(object, this->authKeyIdentifier =
x509_parse_authorityKeyIdentifier(object,
level, &this->authKeySerialNumber); level, &this->authKeySerialNumber);
break; break;
case OID_TARGET_INFORMATION: case OID_TARGET_INFORMATION:
@@ -499,14 +502,15 @@ static chunk_t build_directoryName(asn1_t tag, chunk_t name)
static chunk_t build_holder(private_x509_ac_t *this) static chunk_t build_holder(private_x509_ac_t *this)
{ {
x509_t* x509 = (x509_t*)this->holderCert; x509_t* x509 = (x509_t*)this->holderCert;
identification_t *issuer = this->holderCert->get_issuer(this->holderCert); identification_t *issuer, *subject;
identification_t *subject = this->holderCert->get_subject(this->holderCert);
issuer = this->holderCert->get_issuer(this->holderCert);
subject = this->holderCert->get_subject(this->holderCert);
return asn1_wrap(ASN1_SEQUENCE, "mm", return asn1_wrap(ASN1_SEQUENCE, "mm",
asn1_wrap(ASN1_CONTEXT_C_0, "mm", asn1_wrap(ASN1_CONTEXT_C_0, "mm",
build_directoryName(ASN1_SEQUENCE, issuer->get_encoding(issuer)), build_directoryName(ASN1_SEQUENCE, issuer->get_encoding(issuer)),
asn1_simple_object(ASN1_INTEGER, x509->get_serial(x509)) asn1_simple_object(ASN1_INTEGER, x509->get_serial(x509))),
),
build_directoryName(ASN1_CONTEXT_C_1, subject->get_encoding(subject))); build_directoryName(ASN1_CONTEXT_C_1, subject->get_encoding(subject)));
} }
@@ -515,10 +519,12 @@ static chunk_t build_holder(private_x509_ac_t *this)
*/ */
static chunk_t build_v2_form(private_x509_ac_t *this) static chunk_t build_v2_form(private_x509_ac_t *this)
{ {
identification_t *subject = this->signerCert->get_subject(this->signerCert); identification_t *subject;
subject = this->signerCert->get_subject(this->signerCert);
return asn1_wrap(ASN1_CONTEXT_C_0, "m", return asn1_wrap(ASN1_CONTEXT_C_0, "m",
build_directoryName(ASN1_SEQUENCE, subject->get_encoding(subject))); build_directoryName(ASN1_SEQUENCE,
subject->get_encoding(subject)));
} }
/** /**
@@ -531,7 +537,6 @@ static chunk_t build_attr_cert_validity(private_x509_ac_t *this)
asn1_from_time(&this->notAfter, ASN1_GENERALIZEDTIME)); asn1_from_time(&this->notAfter, ASN1_GENERALIZEDTIME));
} }
/** /**
* build attribute type * build attribute type
*/ */
@@ -548,7 +553,8 @@ static chunk_t build_attribute_type(int type, chunk_t content)
static chunk_t build_attributes(private_x509_ac_t *this) static chunk_t build_attributes(private_x509_ac_t *this)
{ {
return asn1_wrap(ASN1_SEQUENCE, "m", return asn1_wrap(ASN1_SEQUENCE, "m",
build_attribute_type(OID_GROUP, this->groups->get_encoding(this->groups))); build_attribute_type(OID_GROUP,
this->groups->get_encoding(this->groups)));
} }
/** /**
@@ -621,14 +627,11 @@ static chunk_t build_attr_cert_info(private_x509_ac_t *this)
*/ */
static chunk_t build_ac(private_x509_ac_t *this) static chunk_t build_ac(private_x509_ac_t *this)
{ {
chunk_t signatureValue; chunk_t signatureValue, attributeCertificateInfo;
chunk_t attributeCertificateInfo;
attributeCertificateInfo = build_attr_cert_info(this); attributeCertificateInfo = build_attr_cert_info(this);
this->signerKey->sign(this->signerKey, SIGN_RSA_EMSA_PKCS1_SHA1, this->signerKey->sign(this->signerKey, SIGN_RSA_EMSA_PKCS1_SHA1,
attributeCertificateInfo, &signatureValue); attributeCertificateInfo, &signatureValue);
return asn1_wrap(ASN1_SEQUENCE, "mmm", return asn1_wrap(ASN1_SEQUENCE, "mmm",
attributeCertificateInfo, attributeCertificateInfo,
asn1_algorithmIdentifier(OID_SHA1_WITH_RSA), asn1_algorithmIdentifier(OID_SHA1_WITH_RSA),
@@ -692,7 +695,8 @@ METHOD(certificate_t, has_subject, id_match_t,
METHOD(certificate_t, has_issuer, id_match_t, METHOD(certificate_t, has_issuer, id_match_t,
private_x509_ac_t *this, identification_t *issuer) private_x509_ac_t *this, identification_t *issuer)
{ {
if (issuer->get_type(issuer) == ID_KEY_ID && this->authKeyIdentifier.ptr && if (issuer->get_type(issuer) == ID_KEY_ID &&
this->authKeyIdentifier.ptr &&
chunk_equals(this->authKeyIdentifier, issuer->get_encoding(issuer))) chunk_equals(this->authKeyIdentifier, issuer->get_encoding(issuer)))
{ {
return ID_MATCH_PERFECT; return ID_MATCH_PERFECT;
@@ -808,9 +812,10 @@ METHOD(certificate_t, equals, bool,
{ {
return TRUE; return TRUE;
} }
if (other->equals == (void*)equals) if (other->equals == _equals)
{ /* skip allocation if we have the same implementation */ { /* skip allocation if we have the same implementation */
return chunk_equals(this->encoding, ((private_x509_ac_t*)other)->encoding); return chunk_equals(this->encoding,
((private_x509_ac_t*)other)->encoding);
} }
if (!other->get_encoding(other, CERT_ASN1_DER, &encoding)) if (!other->get_encoding(other, CERT_ASN1_DER, &encoding))
{ {
@@ -968,4 +973,3 @@ x509_ac_t *x509_ac_gen(certificate_type_t type, va_list args)
destroy(ac); destroy(ac);
return NULL; return NULL;
} }