Updated the CERT payload to work for both IKEv1 and IKEv2.

This commit is contained in:
Clavister OpenSource
2012-03-20 17:30:49 +01:00
parent d50152a70b
commit 9769b76cab
2 changed files with 25 additions and 14 deletions
+15 -9
View File
@@ -86,6 +86,11 @@ struct private_cert_payload_t {
* TRUE if the "Hash and URL" data is invalid * TRUE if the "Hash and URL" data is invalid
*/ */
bool invalid_hash_and_url; bool invalid_hash_and_url;
/**
* The payload type.
*/
payload_type_t type;
}; };
/** /**
@@ -182,7 +187,7 @@ METHOD(payload_t, get_header_length, int,
METHOD(payload_t, get_type, payload_type_t, METHOD(payload_t, get_type, payload_type_t,
private_cert_payload_t *this) private_cert_payload_t *this)
{ {
return CERTIFICATE; return this->type;
} }
METHOD(payload_t, get_next_type, payload_type_t, METHOD(payload_t, get_next_type, payload_type_t,
@@ -267,7 +272,7 @@ METHOD2(payload_t, cert_payload_t, destroy, void,
/* /*
* Described in header * Described in header
*/ */
cert_payload_t *cert_payload_create() cert_payload_t *cert_payload_create(payload_type_t type)
{ {
private_cert_payload_t *this; private_cert_payload_t *this;
@@ -291,6 +296,7 @@ cert_payload_t *cert_payload_create()
}, },
.next_payload = NO_PAYLOAD, .next_payload = NO_PAYLOAD,
.payload_length = get_header_length(this), .payload_length = get_header_length(this),
.type = type,
); );
return &this->public; return &this->public;
} }
@@ -298,9 +304,9 @@ cert_payload_t *cert_payload_create()
/* /*
* Described in header * Described in header
*/ */
cert_payload_t *cert_payload_create_from_cert(certificate_t *cert) cert_payload_t *cert_payload_create_from_cert(certificate_t *cert, payload_type_t type)
{ {
private_cert_payload_t *this = (private_cert_payload_t*)cert_payload_create(); private_cert_payload_t *this = (private_cert_payload_t*)cert_payload_create(type);
switch (cert->get_type(cert)) switch (cert->get_type(cert))
{ {
@@ -326,9 +332,9 @@ cert_payload_t *cert_payload_create_from_cert(certificate_t *cert)
/* /*
* Described in header * Described in header
*/ */
cert_payload_t *cert_payload_create_from_hash_and_url(chunk_t hash, char *url) cert_payload_t *cert_payload_create_from_hash_and_url(chunk_t hash, char *url, payload_type_t type)
{ {
private_cert_payload_t *this = (private_cert_payload_t*)cert_payload_create(); private_cert_payload_t *this = (private_cert_payload_t*)cert_payload_create(type);
this->encoding = ENC_X509_HASH_AND_URL; this->encoding = ENC_X509_HASH_AND_URL;
this->data = chunk_cat("cc", hash, chunk_create(url, strlen(url))); this->data = chunk_cat("cc", hash, chunk_create(url, strlen(url)));
@@ -339,11 +345,11 @@ cert_payload_t *cert_payload_create_from_hash_and_url(chunk_t hash, char *url)
/* /*
* Described in header * Described in header
*/ */
cert_payload_t *cert_payload_create_custom(cert_encoding_t type, chunk_t data) cert_payload_t *cert_payload_create_custom(cert_encoding_t encoding, chunk_t data, payload_type_t type)
{ {
private_cert_payload_t *this = (private_cert_payload_t*)cert_payload_create(); private_cert_payload_t *this = (private_cert_payload_t*)cert_payload_create(type);
this->encoding = type; this->encoding = encoding;
this->data = data; this->data = data;
this->payload_length = get_header_length(this) + this->data.len; this->payload_length = get_header_length(this) + this->data.len;
return &this->public; return &this->public;
+10 -5
View File
@@ -108,34 +108,39 @@ struct cert_payload_t {
/** /**
* Creates an empty certificate payload. * Creates an empty certificate payload.
* *
* @param type payload type (for IKEv1 or IKEv2)
* @param cert certificate to embed
* @return cert_payload_t object * @return cert_payload_t object
*/ */
cert_payload_t *cert_payload_create(void); cert_payload_t *cert_payload_create(payload_type_t type);
/** /**
* Creates a certificate payload with an embedded certificate. * Creates a certificate payload with an embedded certificate.
* *
* @param type payload type (for IKEv1 or IKEv2)
* @param cert certificate to embed * @param cert certificate to embed
* @return cert_payload_t object * @return cert_payload_t object
*/ */
cert_payload_t *cert_payload_create_from_cert(certificate_t *cert); cert_payload_t *cert_payload_create_from_cert(certificate_t *cert, payload_type_t type);
/** /**
* Creates a certificate payload with hash and URL encoding of a certificate. * Creates a certificate payload with hash and URL encoding of a certificate.
* *
* @param type payload type (for IKEv1 or IKEv2)
* @param hash hash of the DER encoded certificate (get's cloned) * @param hash hash of the DER encoded certificate (get's cloned)
* @param url the URL to locate the certificate (get's cloned) * @param url the URL to locate the certificate (get's cloned)
* @return cert_payload_t object * @return cert_payload_t object
*/ */
cert_payload_t *cert_payload_create_from_hash_and_url(chunk_t hash, char *url); cert_payload_t *cert_payload_create_from_hash_and_url(chunk_t hash, char *url, payload_type_t type);
/** /**
* Creates a custom certificate payload using type and associated data. * Creates a custom certificate payload using type and associated data.
* *
* @param type encoding type of certificate * @param type payload type (for IKEv1 or IKEv2)
* @param encoding encoding type of certificate
* @param data associated data (gets owned) * @param data associated data (gets owned)
* @return cert_payload_t object * @return cert_payload_t object
*/ */
cert_payload_t *cert_payload_create_custom(cert_encoding_t type, chunk_t data); cert_payload_t *cert_payload_create_custom(cert_encoding_t encoding, chunk_t data, payload_type_t type);
#endif /** CERT_PAYLOAD_H_ @}*/ #endif /** CERT_PAYLOAD_H_ @}*/