Removed chunk_from_buf() in favor of a simpler chunk_from_chars() macro
This commit is contained in:
@@ -28,15 +28,11 @@
|
||||
#include "asn1_parser.h"
|
||||
|
||||
/**
|
||||
* some common prefabricated ASN.1 constants
|
||||
* Commonly used ASN1 values.
|
||||
*/
|
||||
static u_char ASN1_INTEGER_0_str[] = { 0x02, 0x00 };
|
||||
static u_char ASN1_INTEGER_1_str[] = { 0x02, 0x01, 0x01 };
|
||||
static u_char ASN1_INTEGER_2_str[] = { 0x02, 0x01, 0x02 };
|
||||
|
||||
const chunk_t ASN1_INTEGER_0 = chunk_from_buf(ASN1_INTEGER_0_str);
|
||||
const chunk_t ASN1_INTEGER_1 = chunk_from_buf(ASN1_INTEGER_1_str);
|
||||
const chunk_t ASN1_INTEGER_2 = chunk_from_buf(ASN1_INTEGER_2_str);
|
||||
const chunk_t ASN1_INTEGER_0 = chunk_from_chars(0x02, 0x00);
|
||||
const chunk_t ASN1_INTEGER_1 = chunk_from_chars(0x02, 0x01, 0x01);
|
||||
const chunk_t ASN1_INTEGER_2 = chunk_from_chars(0x02, 0x01, 0x02);
|
||||
|
||||
/*
|
||||
* Defined in header.
|
||||
|
||||
@@ -169,9 +169,9 @@ static inline void chunk_clear(chunk_t *chunk)
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize a chunk to point to buffer inspectable by sizeof()
|
||||
* Initialize a chunk using a char array
|
||||
*/
|
||||
#define chunk_from_buf(str) { str, sizeof(str) }
|
||||
#define chunk_from_chars(...) ((chunk_t){(char[]){__VA_ARGS__}, sizeof((char[]){__VA_ARGS__})})
|
||||
|
||||
/**
|
||||
* Initialize a chunk to point to a thing
|
||||
|
||||
@@ -84,66 +84,42 @@ struct private_pkcs7_t {
|
||||
/**
|
||||
* PKCS7 contentInfo OIDs
|
||||
*/
|
||||
static u_char ASN1_pkcs7_data_oid_str[] = {
|
||||
static chunk_t ASN1_pkcs7_data_oid = chunk_from_chars(
|
||||
0x06, 0x09,
|
||||
0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x01
|
||||
};
|
||||
|
||||
static u_char ASN1_pkcs7_signed_data_oid_str[] = {
|
||||
);
|
||||
static chunk_t ASN1_pkcs7_signed_data_oid = chunk_from_chars(
|
||||
0x06, 0x09,
|
||||
0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x02
|
||||
};
|
||||
|
||||
static u_char ASN1_pkcs7_enveloped_data_oid_str[] = {
|
||||
);
|
||||
static chunk_t ASN1_pkcs7_enveloped_data_oid = chunk_from_chars(
|
||||
0x06, 0x09,
|
||||
0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x03
|
||||
};
|
||||
|
||||
static u_char ASN1_pkcs7_signed_enveloped_data_oid_str[] = {
|
||||
);
|
||||
static chunk_t ASN1_pkcs7_signed_enveloped_data_oid = chunk_from_chars(
|
||||
0x06, 0x09,
|
||||
0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x04
|
||||
};
|
||||
|
||||
static u_char ASN1_pkcs7_digested_data_oid_str[] = {
|
||||
);
|
||||
static chunk_t ASN1_pkcs7_digested_data_oid = chunk_from_chars(
|
||||
0x06, 0x09,
|
||||
0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x05
|
||||
};
|
||||
|
||||
static char ASN1_pkcs7_encrypted_data_oid_str[] = {
|
||||
);
|
||||
static chunk_t ASN1_pkcs7_encrypted_data_oid = chunk_from_chars(
|
||||
0x06, 0x09,
|
||||
0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x07, 0x06
|
||||
};
|
||||
|
||||
static const chunk_t ASN1_pkcs7_data_oid =
|
||||
chunk_from_buf(ASN1_pkcs7_data_oid_str);
|
||||
static const chunk_t ASN1_pkcs7_signed_data_oid =
|
||||
chunk_from_buf(ASN1_pkcs7_signed_data_oid_str);
|
||||
static const chunk_t ASN1_pkcs7_enveloped_data_oid =
|
||||
chunk_from_buf(ASN1_pkcs7_enveloped_data_oid_str);
|
||||
static const chunk_t ASN1_pkcs7_signed_enveloped_data_oid =
|
||||
chunk_from_buf(ASN1_pkcs7_signed_enveloped_data_oid_str);
|
||||
static const chunk_t ASN1_pkcs7_digested_data_oid =
|
||||
chunk_from_buf(ASN1_pkcs7_digested_data_oid_str);
|
||||
static const chunk_t ASN1_pkcs7_encrypted_data_oid =
|
||||
chunk_from_buf(ASN1_pkcs7_encrypted_data_oid_str);
|
||||
);
|
||||
|
||||
/**
|
||||
* 3DES and DES encryption OIDs
|
||||
*/
|
||||
static u_char ASN1_3des_ede_cbc_oid_str[] = {
|
||||
static const chunk_t ASN1_3des_ede_cbc_oid = chunk_from_chars(
|
||||
0x06, 0x08,
|
||||
0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x03, 0x07
|
||||
};
|
||||
|
||||
static u_char ASN1_des_cbc_oid_str[] = {
|
||||
);
|
||||
static const chunk_t ASN1_des_cbc_oid = chunk_from_chars(
|
||||
0x06, 0x05,
|
||||
0x2B, 0x0E, 0x03, 0x02, 0x07
|
||||
};
|
||||
|
||||
static const chunk_t ASN1_3des_ede_cbc_oid =
|
||||
chunk_from_buf(ASN1_3des_ede_cbc_oid_str);
|
||||
static const chunk_t ASN1_des_cbc_oid =
|
||||
chunk_from_buf(ASN1_des_cbc_oid_str);
|
||||
);
|
||||
|
||||
/**
|
||||
* Implements pkcs7_t.is_data.
|
||||
|
||||
@@ -78,48 +78,30 @@ struct attribute_t {
|
||||
/**
|
||||
* PKCS#9 attribute type OIDs
|
||||
*/
|
||||
static u_char ASN1_contentType_oid_str[] = {
|
||||
static chunk_t ASN1_contentType_oid = chunk_from_chars(
|
||||
0x06, 0x09,
|
||||
0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x03
|
||||
};
|
||||
|
||||
static u_char ASN1_messageDigest_oid_str[] = {
|
||||
);
|
||||
static chunk_t ASN1_messageDigest_oid = chunk_from_chars(
|
||||
0x06, 0x09,
|
||||
0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x04
|
||||
};
|
||||
|
||||
static u_char ASN1_signingTime_oid_str[] = {
|
||||
);
|
||||
static chunk_t ASN1_signingTime_oid = chunk_from_chars(
|
||||
0x06, 0x09,
|
||||
0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x05
|
||||
};
|
||||
|
||||
static char ASN1_messageType_oid_str[] = {
|
||||
);
|
||||
static chunk_t ASN1_messageType_oid = chunk_from_chars(
|
||||
0x06, 0x0A,
|
||||
0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01, 0x09, 0x02
|
||||
};
|
||||
|
||||
static char ASN1_senderNonce_oid_str[] = {
|
||||
);
|
||||
static chunk_t ASN1_senderNonce_oid = chunk_from_chars(
|
||||
0x06, 0x0A,
|
||||
0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01, 0x09, 0x05
|
||||
};
|
||||
|
||||
static char ASN1_transId_oid_str[] = {
|
||||
);
|
||||
static chunk_t ASN1_transId_oid = chunk_from_chars(
|
||||
0x06, 0x0A,
|
||||
0x60, 0x86, 0x48, 0x01, 0x86, 0xF8, 0x45, 0x01, 0x09, 0x07
|
||||
};
|
||||
|
||||
static const chunk_t ASN1_contentType_oid =
|
||||
chunk_from_buf(ASN1_contentType_oid_str);
|
||||
static const chunk_t ASN1_messageDigest_oid =
|
||||
chunk_from_buf(ASN1_messageDigest_oid_str);
|
||||
static const chunk_t ASN1_signingTime_oid =
|
||||
chunk_from_buf(ASN1_signingTime_oid_str);
|
||||
static const chunk_t ASN1_messageType_oid =
|
||||
chunk_from_buf(ASN1_messageType_oid_str);
|
||||
static const chunk_t ASN1_senderNonce_oid =
|
||||
chunk_from_buf(ASN1_senderNonce_oid_str);
|
||||
static const chunk_t ASN1_transId_oid =
|
||||
chunk_from_buf(ASN1_transId_oid_str);
|
||||
);
|
||||
|
||||
/**
|
||||
* return the ASN.1 encoded OID of a PKCS#9 attribute
|
||||
|
||||
@@ -161,7 +161,7 @@ static bool read_key(private_agent_private_key_t *this, public_key_t *pubkey)
|
||||
{
|
||||
int len, count;
|
||||
char buf[2048];
|
||||
chunk_t blob = chunk_from_buf(buf), key, type, n;
|
||||
chunk_t blob, key, type, n;
|
||||
|
||||
len = htonl(1);
|
||||
buf[0] = SSH_AGENT_ID_REQUEST;
|
||||
@@ -172,6 +172,7 @@ static bool read_key(private_agent_private_key_t *this, public_key_t *pubkey)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
blob = chunk_create(buf, sizeof(buf));
|
||||
blob.len = read(this->socket, blob.ptr, blob.len);
|
||||
|
||||
if (blob.len < sizeof(u_int32_t) + sizeof(u_char) ||
|
||||
@@ -226,7 +227,7 @@ static bool sign(private_agent_private_key_t *this, signature_scheme_t scheme,
|
||||
{
|
||||
u_int32_t len, flags;
|
||||
char buf[2048];
|
||||
chunk_t blob = chunk_from_buf(buf);
|
||||
chunk_t blob;
|
||||
|
||||
if (scheme != SIGN_RSA_EMSA_PKCS1_SHA1)
|
||||
{
|
||||
@@ -267,6 +268,7 @@ static bool sign(private_agent_private_key_t *this, signature_scheme_t scheme,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
blob = chunk_create(buf, sizeof(buf));
|
||||
blob.len = read(this->socket, blob.ptr, blob.len);
|
||||
if (blob.len < sizeof(u_int32_t) + sizeof(u_char) ||
|
||||
read_uint32(&blob) != blob.len ||
|
||||
|
||||
@@ -114,7 +114,6 @@ static void get_bytes(private_fips_prf_t *this, chunk_t seed, u_int8_t w[])
|
||||
u_int8_t sum[this->b];
|
||||
u_int8_t *xkey = this->key;
|
||||
u_int8_t one[this->b];
|
||||
chunk_t xval_chunk = chunk_from_buf(xval);
|
||||
|
||||
memset(one, 0, this->b);
|
||||
one[this->b - 1] = 0x01;
|
||||
@@ -129,7 +128,7 @@ static void get_bytes(private_fips_prf_t *this, chunk_t seed, u_int8_t w[])
|
||||
add_mod(this->b, xkey, xseed, xval);
|
||||
DBG3("XVAL %b", xval, this->b);
|
||||
/* b. wi = G(t, XVAL ) */
|
||||
this->g(this, xval_chunk, &w[i * this->b]);
|
||||
this->g(this, chunk_create(xval, this->b), &w[i * this->b]);
|
||||
DBG3("w[%d] %b", i, &w[i * this->b], this->b);
|
||||
/* c. XKEY = (1 + XKEY + wi) mod 2b */
|
||||
add_mod(this->b, xkey, &w[i * this->b], sum);
|
||||
|
||||
@@ -153,30 +153,21 @@ struct private_x509_ac_t {
|
||||
refcount_t ref;
|
||||
};
|
||||
|
||||
static u_char ASN1_group_oid_str[] = {
|
||||
static chunk_t ASN1_group_oid = chunk_from_chars(
|
||||
0x06, 0x08,
|
||||
0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x0a ,0x04
|
||||
};
|
||||
|
||||
static const chunk_t ASN1_group_oid = chunk_from_buf(ASN1_group_oid_str);
|
||||
|
||||
static u_char ASN1_authorityKeyIdentifier_oid_str[] = {
|
||||
);
|
||||
static chunk_t ASN1_authorityKeyIdentifier_oid = chunk_from_chars(
|
||||
0x06, 0x03,
|
||||
0x55, 0x1d, 0x23
|
||||
};
|
||||
|
||||
static const chunk_t ASN1_authorityKeyIdentifier_oid =
|
||||
chunk_from_buf(ASN1_authorityKeyIdentifier_oid_str);
|
||||
|
||||
static u_char ASN1_noRevAvail_ext_str[] = {
|
||||
);
|
||||
static chunk_t ASN1_noRevAvail_ext = chunk_from_chars(
|
||||
0x30, 0x09,
|
||||
0x06, 0x03,
|
||||
0x55, 0x1d, 0x38,
|
||||
0x04, 0x02,
|
||||
0x05, 0x00
|
||||
};
|
||||
|
||||
static const chunk_t ASN1_noRevAvail_ext = chunk_from_buf(ASN1_noRevAvail_ext_str);
|
||||
);
|
||||
|
||||
/**
|
||||
* declaration of function implemented in x509_cert.c
|
||||
|
||||
@@ -171,10 +171,9 @@ struct private_x509_cert_t {
|
||||
refcount_t ref;
|
||||
};
|
||||
|
||||
static u_char ASN1_sAN_oid_buf[] = {
|
||||
static const chunk_t ASN1_subjectAltName_oid = chunk_from_chars(
|
||||
0x06, 0x03, 0x55, 0x1D, 0x11
|
||||
};
|
||||
static const chunk_t ASN1_subjectAltName_oid = chunk_from_buf(ASN1_sAN_oid_buf);
|
||||
);
|
||||
|
||||
/**
|
||||
* ASN.1 definition of a basicConstraints extension
|
||||
@@ -1341,16 +1340,16 @@ static bool generate(private_x509_cert_t *cert, certificate_t *sign_cert,
|
||||
|
||||
if (cert->flags & X509_CA)
|
||||
{
|
||||
chunk_t yes, keyid;
|
||||
chunk_t keyid;
|
||||
|
||||
yes = chunk_alloca(1);
|
||||
yes.ptr[0] = 0xFF;
|
||||
basicConstraints = asn1_wrap(ASN1_SEQUENCE, "mmm",
|
||||
asn1_build_known_oid(OID_BASIC_CONSTRAINTS),
|
||||
asn1_wrap(ASN1_BOOLEAN, "c", yes),
|
||||
asn1_wrap(ASN1_BOOLEAN, "c",
|
||||
chunk_from_chars(0xFF)),
|
||||
asn1_wrap(ASN1_OCTET_STRING, "m",
|
||||
asn1_wrap(ASN1_SEQUENCE, "m",
|
||||
asn1_wrap(ASN1_BOOLEAN, "c", yes))));
|
||||
asn1_wrap(ASN1_BOOLEAN, "c",
|
||||
chunk_from_chars(0xFF)))));
|
||||
/* add subjectKeyIdentifier to CA certificates */
|
||||
if (cert->public_key->get_fingerprint(cert->public_key,
|
||||
KEY_ID_PUBKEY_SHA1, &keyid))
|
||||
|
||||
@@ -81,29 +81,23 @@ struct private_x509_ocsp_request_t {
|
||||
refcount_t ref;
|
||||
};
|
||||
|
||||
static u_char ASN1_nonce_oid_str[] = {
|
||||
static const chunk_t ASN1_nonce_oid = chunk_from_chars(
|
||||
0x06, 0x09,
|
||||
0x2B, 0x06,
|
||||
0x01, 0x05, 0x05, 0x07, 0x30, 0x01, 0x02
|
||||
};
|
||||
|
||||
static u_char ASN1_response_oid_str[] = {
|
||||
);
|
||||
static const chunk_t ASN1_response_oid = chunk_from_chars(
|
||||
0x06, 0x09,
|
||||
0x2B, 0x06,
|
||||
0x01, 0x05, 0x05, 0x07, 0x30, 0x01, 0x04
|
||||
};
|
||||
|
||||
static u_char ASN1_response_content_str[] = {
|
||||
);
|
||||
static const chunk_t ASN1_response_content = chunk_from_chars(
|
||||
0x04, 0x0D,
|
||||
0x30, 0x0B,
|
||||
0x06, 0x09,
|
||||
0x2B, 0x06,
|
||||
0x01, 0x05, 0x05, 0x07, 0x30, 0x01, 0x01
|
||||
};
|
||||
|
||||
static const chunk_t ASN1_nonce_oid = chunk_from_buf(ASN1_nonce_oid_str);
|
||||
static const chunk_t ASN1_response_oid = chunk_from_buf(ASN1_response_oid_str);
|
||||
static const chunk_t ASN1_response_content = chunk_from_buf(ASN1_response_content_str);
|
||||
);
|
||||
|
||||
/**
|
||||
* build requestorName
|
||||
|
||||
@@ -130,29 +130,23 @@ typedef struct {
|
||||
#define OCSP_BASIC_RESPONSE_VERSION 1
|
||||
|
||||
/* some OCSP specific prefabricated ASN.1 constants */
|
||||
static u_char ASN1_nonce_oid_str[] = {
|
||||
static const chunk_t ASN1_nonce_oid = chunk_from_chars(
|
||||
0x06, 0x09,
|
||||
0x2B, 0x06,
|
||||
0x01, 0x05, 0x05, 0x07, 0x30, 0x01, 0x02
|
||||
};
|
||||
|
||||
static u_char ASN1_response_oid_str[] = {
|
||||
);
|
||||
static const chunk_t ASN1_response_oid = chunk_from_chars(
|
||||
0x06, 0x09,
|
||||
0x2B, 0x06,
|
||||
0x01, 0x05, 0x05, 0x07, 0x30, 0x01, 0x04
|
||||
};
|
||||
|
||||
static u_char ASN1_response_content_str[] = {
|
||||
);
|
||||
static const chunk_t ASN1_response_content = chunk_from_chars(
|
||||
0x04, 0x0D,
|
||||
0x30, 0x0B,
|
||||
0x06, 0x09,
|
||||
0x2B, 0x06,
|
||||
0x01, 0x05, 0x05, 0x07, 0x30, 0x01, 0x01
|
||||
};
|
||||
|
||||
static const chunk_t ASN1_nonce_oid = chunk_from_buf(ASN1_nonce_oid_str);
|
||||
static const chunk_t ASN1_response_oid = chunk_from_buf(ASN1_response_oid_str);
|
||||
static const chunk_t ASN1_response_content = chunk_from_buf(ASN1_response_content_str);
|
||||
);
|
||||
|
||||
/**
|
||||
* Implementaiton of ocsp_response_t.get_status
|
||||
|
||||
Reference in New Issue
Block a user