Unify PKCS#9 set_attribute* methods to a single add_attribute
This way the PKCS#9 implementation does not have to know the encoding types for values
This commit is contained in:
@@ -930,17 +930,16 @@ METHOD(pkcs7_t, build_signedData, bool,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
hasher->destroy(hasher);
|
hasher->destroy(hasher);
|
||||||
this->attributes->set_attribute(this->attributes,
|
this->attributes->add_attribute(this->attributes,
|
||||||
OID_PKCS9_MESSAGE_DIGEST,
|
OID_PKCS9_MESSAGE_DIGEST,
|
||||||
messageDigest);
|
asn1_wrap(ASN1_OCTET_STRING, "m", messageDigest));
|
||||||
free(messageDigest.ptr);
|
|
||||||
|
|
||||||
/* take the current time as signingTime */
|
/* take the current time as signingTime */
|
||||||
now = time(NULL);
|
now = time(NULL);
|
||||||
signingTime = asn1_from_time(&now, ASN1_UTCTIME);
|
signingTime = asn1_from_time(&now, ASN1_UTCTIME);
|
||||||
this->attributes->set_attribute_raw(this->attributes,
|
this->attributes->add_attribute(this->attributes,
|
||||||
OID_PKCS9_SIGNING_TIME, signingTime);
|
OID_PKCS9_SIGNING_TIME, signingTime);
|
||||||
this->attributes->set_attribute_raw(this->attributes,
|
this->attributes->add_attribute(this->attributes,
|
||||||
OID_PKCS9_CONTENT_TYPE,
|
OID_PKCS9_CONTENT_TYPE,
|
||||||
asn1_build_known_oid(OID_PKCS7_DATA));
|
asn1_build_known_oid(OID_PKCS7_DATA));
|
||||||
|
|
||||||
|
|||||||
@@ -68,32 +68,6 @@ struct attribute_t {
|
|||||||
chunk_t encoding;
|
chunk_t encoding;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* return the ASN.1 encoding of a PKCS#9 attribute
|
|
||||||
*/
|
|
||||||
static asn1_t get_attribute_type(int oid)
|
|
||||||
{
|
|
||||||
switch (oid)
|
|
||||||
{
|
|
||||||
case OID_PKCS9_CONTENT_TYPE:
|
|
||||||
return ASN1_OID;
|
|
||||||
case OID_PKCS9_SIGNING_TIME:
|
|
||||||
return ASN1_UTCTIME;
|
|
||||||
case OID_PKI_MESSAGE_TYPE:
|
|
||||||
case OID_PKI_STATUS:
|
|
||||||
case OID_PKI_FAIL_INFO:
|
|
||||||
return ASN1_PRINTABLESTRING;
|
|
||||||
case OID_PKI_SENDER_NONCE:
|
|
||||||
case OID_PKI_RECIPIENT_NONCE:
|
|
||||||
case OID_PKCS9_MESSAGE_DIGEST:
|
|
||||||
return ASN1_OCTET_STRING;
|
|
||||||
case OID_PKI_TRANS_ID:
|
|
||||||
return ASN1_PRINTABLESTRING;
|
|
||||||
default:
|
|
||||||
return ASN1_EOC;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy an attribute_t object.
|
* Destroy an attribute_t object.
|
||||||
*/
|
*/
|
||||||
@@ -185,23 +159,14 @@ METHOD(pkcs9_t, get_attribute, chunk_t,
|
|||||||
return chunk_empty;
|
return chunk_empty;
|
||||||
}
|
}
|
||||||
|
|
||||||
METHOD(pkcs9_t, set_attribute_raw, void,
|
METHOD(pkcs9_t, add_attribute, void,
|
||||||
private_pkcs9_t *this, int oid, chunk_t value)
|
private_pkcs9_t *this, int oid, chunk_t value)
|
||||||
{
|
{
|
||||||
attribute_t *attribute = attribute_create(oid, value);
|
this->attributes->insert_last(this->attributes,
|
||||||
|
attribute_create(oid, value));
|
||||||
this->attributes->insert_last(this->attributes, attribute);
|
|
||||||
chunk_free(&value);
|
chunk_free(&value);
|
||||||
}
|
}
|
||||||
|
|
||||||
METHOD(pkcs9_t, set_attribute, void,
|
|
||||||
private_pkcs9_t *this, int oid, chunk_t value)
|
|
||||||
{
|
|
||||||
chunk_t attr = asn1_simple_object(get_attribute_type(oid), value);
|
|
||||||
|
|
||||||
set_attribute_raw(this, oid, attr);
|
|
||||||
}
|
|
||||||
|
|
||||||
METHOD(pkcs9_t, destroy, void,
|
METHOD(pkcs9_t, destroy, void,
|
||||||
private_pkcs9_t *this)
|
private_pkcs9_t *this)
|
||||||
{
|
{
|
||||||
@@ -222,8 +187,7 @@ pkcs9_t *pkcs9_create(void)
|
|||||||
.public = {
|
.public = {
|
||||||
.get_encoding = _get_encoding,
|
.get_encoding = _get_encoding,
|
||||||
.get_attribute = _get_attribute,
|
.get_attribute = _get_attribute,
|
||||||
.set_attribute = _set_attribute,
|
.add_attribute = _add_attribute,
|
||||||
.set_attribute_raw = _set_attribute_raw,
|
|
||||||
.destroy = _destroy,
|
.destroy = _destroy,
|
||||||
},
|
},
|
||||||
.attributes = linked_list_create(),
|
.attributes = linked_list_create(),
|
||||||
|
|||||||
@@ -50,17 +50,9 @@ struct pkcs9_t {
|
|||||||
* Adds a PKCS#9 attribute.
|
* Adds a PKCS#9 attribute.
|
||||||
*
|
*
|
||||||
* @param oid OID of the attribute
|
* @param oid OID of the attribute
|
||||||
* @param value value of the attribute (gets cloned)
|
* @param value value of the attribute, with ASN1 type (gets owned)
|
||||||
*/
|
*/
|
||||||
void (*set_attribute) (pkcs9_t *this, int oid, chunk_t value);
|
void (*add_attribute) (pkcs9_t *this, int oid, chunk_t value);
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a ASN.1 encoded PKCS#9 attribute.
|
|
||||||
*
|
|
||||||
* @param oid OID of the attribute
|
|
||||||
* @param value ASN.1 encoded value of the attribute (gets adopted)
|
|
||||||
*/
|
|
||||||
void (*set_attribute_raw) (pkcs9_t *this, int oid, chunk_t value);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroys the PKCS#9 attribute list.
|
* Destroys the PKCS#9 attribute list.
|
||||||
|
|||||||
@@ -205,7 +205,8 @@ static bool add_senderNonce_attribute(pkcs9_t *pkcs9)
|
|||||||
}
|
}
|
||||||
rng->destroy(rng);
|
rng->destroy(rng);
|
||||||
|
|
||||||
pkcs9->set_attribute(pkcs9, OID_PKI_SENDER_NONCE, senderNonce);
|
pkcs9->add_attribute(pkcs9, OID_PKI_SENDER_NONCE,
|
||||||
|
asn1_wrap(ASN1_OCTET_STRING, "c", senderNonce));
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -232,8 +233,10 @@ chunk_t scep_build_request(chunk_t data, chunk_t transID, scep_msg_t msg,
|
|||||||
}
|
}
|
||||||
|
|
||||||
pkcs9 = pkcs9_create();
|
pkcs9 = pkcs9_create();
|
||||||
pkcs9->set_attribute(pkcs9, OID_PKI_TRANS_ID, transID);
|
pkcs9->add_attribute(pkcs9, OID_PKI_TRANS_ID,
|
||||||
pkcs9->set_attribute(pkcs9, OID_PKI_MESSAGE_TYPE, msgType);
|
asn1_wrap(ASN1_PRINTABLESTRING, "c", transID));
|
||||||
|
pkcs9->add_attribute(pkcs9, OID_PKI_MESSAGE_TYPE,
|
||||||
|
asn1_wrap(ASN1_PRINTABLESTRING, "c", msgType));
|
||||||
if (!add_senderNonce_attribute(pkcs9))
|
if (!add_senderNonce_attribute(pkcs9))
|
||||||
{
|
{
|
||||||
pkcs9->destroy(pkcs9);
|
pkcs9->destroy(pkcs9);
|
||||||
|
|||||||
Reference in New Issue
Block a user