properly initialize sc_asn1_entry elements + some cleanup

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@2463 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
nils 2005-08-05 07:24:43 +00:00
parent b12711e6b3
commit 23802d825e
8 changed files with 188 additions and 189 deletions

View File

@ -60,16 +60,16 @@ const sc_app_info_t * sc_find_pkcs15_app(sc_card_t *card)
} }
static const struct sc_asn1_entry c_asn1_dirrecord[] = { static const struct sc_asn1_entry c_asn1_dirrecord[] = {
{ "aid", SC_ASN1_OCTET_STRING, SC_ASN1_APP | 15, 0, NULL }, { "aid", SC_ASN1_OCTET_STRING, SC_ASN1_APP | 15, 0, NULL, NULL },
{ "label", SC_ASN1_UTF8STRING, SC_ASN1_APP | 16, SC_ASN1_OPTIONAL, NULL }, { "label", SC_ASN1_UTF8STRING, SC_ASN1_APP | 16, SC_ASN1_OPTIONAL, NULL, NULL },
{ "path", SC_ASN1_OCTET_STRING, SC_ASN1_APP | 17, SC_ASN1_OPTIONAL, NULL }, { "path", SC_ASN1_OCTET_STRING, SC_ASN1_APP | 17, SC_ASN1_OPTIONAL, NULL, NULL },
{ "ddo", SC_ASN1_OCTET_STRING, SC_ASN1_APP | 19 | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL }, { "ddo", SC_ASN1_OCTET_STRING, SC_ASN1_APP | 19 | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static const struct sc_asn1_entry c_asn1_dir[] = { static const struct sc_asn1_entry c_asn1_dir[] = {
{ "dirRecord", SC_ASN1_STRUCT, SC_ASN1_APP | 1 | SC_ASN1_CONS, 0, NULL }, { "dirRecord", SC_ASN1_STRUCT, SC_ASN1_APP | 1 | SC_ASN1_CONS, 0, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static int parse_dir_record(sc_card_t *card, u8 ** buf, size_t *buflen, static int parse_dir_record(sc_card_t *card, u8 ** buf, size_t *buflen,

View File

@ -30,8 +30,8 @@
* AlgorithmIdentifier handling * AlgorithmIdentifier handling
*/ */
static struct sc_asn1_entry c_asn1_des_iv[] = { static struct sc_asn1_entry c_asn1_des_iv[] = {
{ "iv", SC_ASN1_OCTET_STRING, ASN1_OCTET_STRING, 0 }, { "iv", SC_ASN1_OCTET_STRING, ASN1_OCTET_STRING, 0, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static int static int
@ -69,11 +69,11 @@ asn1_encode_des_params(sc_context_t *ctx, void *params,
} }
static const struct sc_asn1_entry c_asn1_pbkdf2_params[] = { static const struct sc_asn1_entry c_asn1_pbkdf2_params[] = {
{ "salt", SC_ASN1_OCTET_STRING, ASN1_OCTET_STRING, 0 }, { "salt", SC_ASN1_OCTET_STRING, ASN1_OCTET_STRING, 0, NULL, NULL },
{ "count", SC_ASN1_INTEGER, ASN1_INTEGER, 0 }, { "count", SC_ASN1_INTEGER, ASN1_INTEGER, 0, NULL, NULL },
{ "keyLength", SC_ASN1_INTEGER, ASN1_INTEGER, SC_ASN1_OPTIONAL }, { "keyLength", SC_ASN1_INTEGER, ASN1_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
{ "prf", SC_ASN1_ALGORITHM_ID, ASN1_SEQUENCE, SC_ASN1_OPTIONAL }, { "prf", SC_ASN1_ALGORITHM_ID, ASN1_SEQUENCE, SC_ASN1_OPTIONAL, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static int static int
@ -134,9 +134,9 @@ asn1_encode_pbkdf2_params(sc_context_t *ctx, void *params,
} }
static const struct sc_asn1_entry c_asn1_pbes2_params[] = { static const struct sc_asn1_entry c_asn1_pbes2_params[] = {
{ "keyDerivationAlg", SC_ASN1_ALGORITHM_ID, ASN1_SEQUENCE, 0 }, { "keyDerivationAlg", SC_ASN1_ALGORITHM_ID, ASN1_SEQUENCE, 0, NULL, NULL },
{ "keyEcnryptionAlg", SC_ASN1_ALGORITHM_ID, ASN1_SEQUENCE, 0 }, { "keyEcnryptionAlg", SC_ASN1_ALGORITHM_ID, ASN1_SEQUENCE, 0, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static int static int
@ -193,25 +193,25 @@ asn1_free_pbes2_params(void *ptr)
static struct sc_asn1_pkcs15_algorithm_info algorithm_table[] = { static struct sc_asn1_pkcs15_algorithm_info algorithm_table[] = {
#ifdef SC_ALGORITHM_SHA1 #ifdef SC_ALGORITHM_SHA1
/* hmacWithSHA1 */ /* hmacWithSHA1 */
{ SC_ALGORITHM_SHA1, {{ 1, 2, 840, 113549, 2, 7 }} }, { SC_ALGORITHM_SHA1, {{ 1, 2, 840, 113549, 2, 7 }}, NULL, NULL, NULL },
{ SC_ALGORITHM_SHA1, {{ 1, 3, 6, 1, 5, 5, 8, 1, 2 }} }, { SC_ALGORITHM_SHA1, {{ 1, 3, 6, 1, 5, 5, 8, 1, 2 }}, NULL, NULL, NULL },
/* SHA1 */ /* SHA1 */
{ SC_ALGORITHM_SHA1, {{ 1, 3, 14, 3, 2, 26, }} }, { SC_ALGORITHM_SHA1, {{ 1, 3, 14, 3, 2, 26, }}, NULL, NULL, NULL },
#endif #endif
#ifdef SC_ALGORITHM_MD5 #ifdef SC_ALGORITHM_MD5
{ SC_ALGORITHM_MD5, {{ 1, 2, 840, 113549, 2, 5, }} }, { SC_ALGORITHM_MD5, {{ 1, 2, 840, 113549, 2, 5, }}, NULL, NULL, NULL },
#endif #endif
#ifdef SC_ALGORITHM_DSA #ifdef SC_ALGORITHM_DSA
{ SC_ALGORITHM_DSA, {{ 1, 2, 840, 10040, 4, 3 }} }, { SC_ALGORITHM_DSA, {{ 1, 2, 840, 10040, 4, 3 }}, NULL, NULL, NULL },
#endif #endif
#ifdef SC_ALGORITHM_RSA /* really rsaEncryption */ #ifdef SC_ALGORITHM_RSA /* really rsaEncryption */
{ SC_ALGORITHM_RSA, {{ 1, 2, 840, 113549, 1, 1, 1 }} }, { SC_ALGORITHM_RSA, {{ 1, 2, 840, 113549, 1, 1, 1 }}, NULL, NULL, NULL },
#endif #endif
#ifdef SC_ALGORITHM_DH #ifdef SC_ALGORITHM_DH
{ SC_ALGORITHM_DH, {{ 1, 2, 840, 10046, 2, 1 }} }, { SC_ALGORITHM_DH, {{ 1, 2, 840, 10046, 2, 1 }}, NULL, NULL, NULL },
#endif #endif
#ifdef SC_ALGORITHM_RC2_WRAP /* from CMS */ #ifdef SC_ALGORITHM_RC2_WRAP /* from CMS */
{ SC_ALGORITHM_RC2_WRAP, {{ 1, 2, 840, 113549, 1, 9, 16, 3, 7 }} }, { SC_ALGORITHM_RC2_WRAP, {{ 1, 2, 840, 113549, 1, 9, 16, 3, 7 }}, NULL, NULL, NULL },
#endif #endif
#ifdef SC_ALGORITHM_RC2 /* CBC mode */ #ifdef SC_ALGORITHM_RC2 /* CBC mode */
{ SC_ALGORITHM_RC2, {{ 1, 2, 840, 113549, 3, 2 }}, { SC_ALGORITHM_RC2, {{ 1, 2, 840, 113549, 3, 2 }},
@ -225,7 +225,7 @@ static struct sc_asn1_pkcs15_algorithm_info algorithm_table[] = {
free }, free },
#endif #endif
#ifdef SC_ALGORITHM_3DES_WRAP /* from CMS */ #ifdef SC_ALGORITHM_3DES_WRAP /* from CMS */
{ SC_ALGORITHM_3DES_WRAP, {{ 1, 2, 840, 113549, 1, 9, 16, 3, 6 }} }, { SC_ALGORITHM_3DES_WRAP, {{ 1, 2, 840, 113549, 1, 9, 16, 3, 6 }}, NULL, NULL, NULL },
#endif #endif
#ifdef SC_ALGORITHM_3DES /* EDE CBC mode */ #ifdef SC_ALGORITHM_3DES /* EDE CBC mode */
{ SC_ALGORITHM_3DES, {{ 1, 2, 840, 113549, 3, 7 }}, { SC_ALGORITHM_3DES, {{ 1, 2, 840, 113549, 3, 7 }},
@ -245,7 +245,7 @@ static struct sc_asn1_pkcs15_algorithm_info algorithm_table[] = {
asn1_decode_pbes2_params, asn1_decode_pbes2_params,
asn1_encode_pbes2_params, asn1_encode_pbes2_params,
asn1_free_pbes2_params }, asn1_free_pbes2_params },
{ -1 } { -1, {{ -1 }}, NULL, NULL, NULL }
#endif #endif
}; };
@ -283,9 +283,9 @@ sc_asn1_get_algorithm_info(const struct sc_algorithm_id *id)
} }
static const struct sc_asn1_entry c_asn1_alg_id[6] = { static const struct sc_asn1_entry c_asn1_alg_id[6] = {
{ "algorithm", SC_ASN1_OBJECT, ASN1_OBJECT, 0, NULL }, { "algorithm", SC_ASN1_OBJECT, ASN1_OBJECT, 0, NULL, NULL },
{ "nullParam", SC_ASN1_NULL, ASN1_NULL, SC_ASN1_OPTIONAL, NULL }, { "nullParam", SC_ASN1_NULL, ASN1_NULL, SC_ASN1_OPTIONAL, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
int int

View File

@ -30,48 +30,48 @@
#endif #endif
#include <assert.h> #include <assert.h>
int parse_x509_cert(sc_context_t *ctx, const u8 *buf, size_t buflen, struct sc_pkcs15_cert *cert) static int parse_x509_cert(sc_context_t *ctx, const u8 *buf, size_t buflen, struct sc_pkcs15_cert *cert)
{ {
int r; int r;
struct sc_algorithm_id pk_alg, sig_alg; struct sc_algorithm_id pk_alg, sig_alg;
sc_pkcs15_der_t pk = { NULL, 0 }; sc_pkcs15_der_t pk = { NULL, 0 };
struct sc_asn1_entry asn1_version[] = { struct sc_asn1_entry asn1_version[] = {
{ "version", SC_ASN1_INTEGER, ASN1_INTEGER, 0, &cert->version }, { "version", SC_ASN1_INTEGER, ASN1_INTEGER, 0, &cert->version, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
struct sc_asn1_entry asn1_pkinfo[] = { struct sc_asn1_entry asn1_pkinfo[] = {
{ "algorithm", SC_ASN1_ALGORITHM_ID, ASN1_SEQUENCE | SC_ASN1_CONS, 0, &pk_alg }, { "algorithm", SC_ASN1_ALGORITHM_ID, ASN1_SEQUENCE | SC_ASN1_CONS, 0, &pk_alg, NULL },
{ "subjectPublicKey", SC_ASN1_BIT_STRING_NI, ASN1_BIT_STRING, SC_ASN1_ALLOC, &pk.value, &pk.len }, { "subjectPublicKey", SC_ASN1_BIT_STRING_NI, ASN1_BIT_STRING, SC_ASN1_ALLOC, &pk.value, &pk.len },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
struct sc_asn1_entry asn1_x509v3[] = { struct sc_asn1_entry asn1_x509v3[] = {
{ "certificatePolicies", SC_ASN1_OCTET_STRING, SC_ASN1_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL }, { "certificatePolicies", SC_ASN1_OCTET_STRING, SC_ASN1_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL },
{ "subjectKeyIdentifier", SC_ASN1_OCTET_STRING, SC_ASN1_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL }, { "subjectKeyIdentifier", SC_ASN1_OCTET_STRING, SC_ASN1_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL },
{ "crlDistributionPoints", SC_ASN1_OCTET_STRING, SC_ASN1_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL | SC_ASN1_ALLOC, &cert->crl, &cert->crl_len }, { "crlDistributionPoints", SC_ASN1_OCTET_STRING, SC_ASN1_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL | SC_ASN1_ALLOC, &cert->crl, &cert->crl_len },
{ "authorityKeyIdentifier", SC_ASN1_OCTET_STRING, SC_ASN1_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL }, { "authorityKeyIdentifier", SC_ASN1_OCTET_STRING, SC_ASN1_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL },
{ "keyUsage", SC_ASN1_BOOLEAN, SC_ASN1_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL }, { "keyUsage", SC_ASN1_BOOLEAN, SC_ASN1_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
struct sc_asn1_entry asn1_extensions[] = { struct sc_asn1_entry asn1_extensions[] = {
{ "x509v3", SC_ASN1_STRUCT, ASN1_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, asn1_x509v3 }, { "x509v3", SC_ASN1_STRUCT, ASN1_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, asn1_x509v3, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
struct sc_asn1_entry asn1_tbscert[] = { struct sc_asn1_entry asn1_tbscert[] = {
{ "version", SC_ASN1_STRUCT, SC_ASN1_CTX | 0 | SC_ASN1_CONS, SC_ASN1_OPTIONAL, asn1_version }, { "version", SC_ASN1_STRUCT, SC_ASN1_CTX | 0 | SC_ASN1_CONS, SC_ASN1_OPTIONAL, asn1_version, NULL },
{ "serialNumber", SC_ASN1_OCTET_STRING, ASN1_INTEGER, SC_ASN1_ALLOC, &cert->serial, &cert->serial_len }, { "serialNumber", SC_ASN1_OCTET_STRING, ASN1_INTEGER, SC_ASN1_ALLOC, &cert->serial, &cert->serial_len },
{ "signature", SC_ASN1_STRUCT, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL }, { "signature", SC_ASN1_STRUCT, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
{ "issuer", SC_ASN1_OCTET_STRING, ASN1_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, &cert->issuer, &cert->issuer_len }, { "issuer", SC_ASN1_OCTET_STRING, ASN1_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, &cert->issuer, &cert->issuer_len },
{ "validity", SC_ASN1_STRUCT, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL }, { "validity", SC_ASN1_STRUCT, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
{ "subject", SC_ASN1_OCTET_STRING, ASN1_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, &cert->subject, &cert->subject_len }, { "subject", SC_ASN1_OCTET_STRING, ASN1_SEQUENCE | SC_ASN1_CONS, SC_ASN1_ALLOC, &cert->subject, &cert->subject_len },
{ "subjectPublicKeyInfo",SC_ASN1_STRUCT, ASN1_SEQUENCE | SC_ASN1_CONS, 0, asn1_pkinfo }, { "subjectPublicKeyInfo",SC_ASN1_STRUCT, ASN1_SEQUENCE | SC_ASN1_CONS, 0, asn1_pkinfo, NULL },
{ "extensions", SC_ASN1_STRUCT, SC_ASN1_CTX | 3 | SC_ASN1_CONS, SC_ASN1_OPTIONAL, asn1_extensions }, { "extensions", SC_ASN1_STRUCT, SC_ASN1_CTX | 3 | SC_ASN1_CONS, SC_ASN1_OPTIONAL, asn1_extensions, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
struct sc_asn1_entry asn1_cert[] = { struct sc_asn1_entry asn1_cert[] = {
{ "tbsCertificate", SC_ASN1_STRUCT, ASN1_SEQUENCE | SC_ASN1_CONS, 0, asn1_tbscert }, { "tbsCertificate", SC_ASN1_STRUCT, ASN1_SEQUENCE | SC_ASN1_CONS, 0, asn1_tbscert, NULL },
{ "signatureAlgorithm", SC_ASN1_ALGORITHM_ID, ASN1_SEQUENCE | SC_ASN1_CONS, 0, &sig_alg }, { "signatureAlgorithm", SC_ASN1_ALGORITHM_ID, ASN1_SEQUENCE | SC_ASN1_CONS, 0, &sig_alg, NULL },
{ "signatureValue", SC_ASN1_BIT_STRING,ASN1_BIT_STRING, 0, NULL, 0 }, { "signatureValue", SC_ASN1_BIT_STRING, ASN1_BIT_STRING, 0, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
const u8 *obj; const u8 *obj;
size_t objlen; size_t objlen;
@ -143,33 +143,33 @@ int sc_pkcs15_read_certificate(struct sc_pkcs15_card *p15card,
} }
static const struct sc_asn1_entry c_asn1_cred_ident[] = { static const struct sc_asn1_entry c_asn1_cred_ident[] = {
{ "idType", SC_ASN1_INTEGER, ASN1_INTEGER, 0, NULL }, { "idType", SC_ASN1_INTEGER, ASN1_INTEGER, 0, NULL, NULL },
{ "idValue", SC_ASN1_OCTET_STRING, ASN1_OCTET_STRING, 0, NULL }, { "idValue", SC_ASN1_OCTET_STRING, ASN1_OCTET_STRING, 0, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static const struct sc_asn1_entry c_asn1_com_cert_attr[] = { static const struct sc_asn1_entry c_asn1_com_cert_attr[] = {
{ "iD", SC_ASN1_PKCS15_ID, ASN1_OCTET_STRING, 0, NULL }, { "iD", SC_ASN1_PKCS15_ID, ASN1_OCTET_STRING, 0, NULL, NULL },
{ "authority", SC_ASN1_BOOLEAN, ASN1_BOOLEAN, SC_ASN1_OPTIONAL, NULL }, { "authority", SC_ASN1_BOOLEAN, ASN1_BOOLEAN, SC_ASN1_OPTIONAL, NULL, NULL },
{ "identifier", SC_ASN1_STRUCT, ASN1_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL }, { "identifier", SC_ASN1_STRUCT, ASN1_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL },
/* FIXME: Add rest of the optional fields */ /* FIXME: Add rest of the optional fields */
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static const struct sc_asn1_entry c_asn1_x509_cert_value_choice[] = { static const struct sc_asn1_entry c_asn1_x509_cert_value_choice[] = {
{ "path", SC_ASN1_PATH, ASN1_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL }, { "path", SC_ASN1_PATH, ASN1_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL },
{ "direct", SC_ASN1_OCTET_STRING, SC_ASN1_CTX | 0 | SC_ASN1_CONS, SC_ASN1_OPTIONAL | SC_ASN1_ALLOC, NULL }, { "direct", SC_ASN1_OCTET_STRING, SC_ASN1_CTX | 0 | SC_ASN1_CONS, SC_ASN1_OPTIONAL | SC_ASN1_ALLOC, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static const struct sc_asn1_entry c_asn1_x509_cert_attr[] = { static const struct sc_asn1_entry c_asn1_x509_cert_attr[] = {
{ "value", SC_ASN1_CHOICE, 0, 0, NULL }, { "value", SC_ASN1_CHOICE, 0, 0, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static const struct sc_asn1_entry c_asn1_type_cert_attr[] = { static const struct sc_asn1_entry c_asn1_type_cert_attr[] = {
{ "x509CertificateAttributes", SC_ASN1_STRUCT, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL }, { "x509CertificateAttributes", SC_ASN1_STRUCT, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static const struct sc_asn1_entry c_asn1_cert[] = { static const struct sc_asn1_entry c_asn1_cert[] = {
{ "x509Certificate", SC_ASN1_PKCS15_OBJECT, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL }, { "x509Certificate", SC_ASN1_PKCS15_OBJECT, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
int sc_pkcs15_decode_cdf_entry(struct sc_pkcs15_card *p15card, int sc_pkcs15_decode_cdf_entry(struct sc_pkcs15_card *p15card,

View File

@ -30,11 +30,10 @@
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif #endif
#include <assert.h>
static const struct sc_asn1_entry c_asn1_data_object[] = { static const struct sc_asn1_entry c_asn1_data_object[] = {
{ "dataObject", SC_ASN1_OCTET_STRING, ASN1_OCTET_STRING, 0 }, { "dataObject", SC_ASN1_OCTET_STRING, ASN1_OCTET_STRING, 0, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
int sc_pkcs15_read_data_object(struct sc_pkcs15_card *p15card, int sc_pkcs15_read_data_object(struct sc_pkcs15_card *p15card,
@ -46,7 +45,8 @@ int sc_pkcs15_read_data_object(struct sc_pkcs15_card *p15card,
u8 *data = NULL; u8 *data = NULL;
size_t len; size_t len;
assert(p15card != NULL && info != NULL && data_object_out != NULL); if (p15card == NULL || info == NULL || data_object_out == NULL)
return SC_ERROR_INVALID_ARGUMENTS;
SC_FUNC_CALLED(p15card->card->ctx, 1); SC_FUNC_CALLED(p15card->card->ctx, 1);
r = sc_pkcs15_read_file(p15card, &info->path, &data, &len, NULL); r = sc_pkcs15_read_file(p15card, &info->path, &data, &len, NULL);
@ -66,17 +66,17 @@ int sc_pkcs15_read_data_object(struct sc_pkcs15_card *p15card,
} }
static const struct sc_asn1_entry c_asn1_data[] = { static const struct sc_asn1_entry c_asn1_data[] = {
{ "data", SC_ASN1_PKCS15_OBJECT, ASN1_SEQUENCE | SC_ASN1_CONS }, { "data", SC_ASN1_PKCS15_OBJECT, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static const struct sc_asn1_entry c_asn1_com_data_attr[] = { static const struct sc_asn1_entry c_asn1_com_data_attr[] = {
{ "appName", SC_ASN1_UTF8STRING, ASN1_UTF8STRING, SC_ASN1_OPTIONAL }, { "appName", SC_ASN1_UTF8STRING, ASN1_UTF8STRING, SC_ASN1_OPTIONAL, NULL, NULL },
{ "appOID", SC_ASN1_OBJECT, ASN1_OBJECT, SC_ASN1_OPTIONAL }, { "appOID", SC_ASN1_OBJECT, ASN1_OBJECT, SC_ASN1_OPTIONAL, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static const struct sc_asn1_entry c_asn1_type_data_attr[] = { static const struct sc_asn1_entry c_asn1_type_data_attr[] = {
{ "path", SC_ASN1_PATH, ASN1_SEQUENCE | SC_ASN1_CONS }, { "path", SC_ASN1_PATH, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
int sc_pkcs15_decode_dodf_entry(struct sc_pkcs15_card *p15card, int sc_pkcs15_decode_dodf_entry(struct sc_pkcs15_card *p15card,
@ -156,7 +156,8 @@ int sc_pkcs15_encode_dodf_entry(sc_context_t *ctx,
void sc_pkcs15_free_data_object(struct sc_pkcs15_data *data_object) void sc_pkcs15_free_data_object(struct sc_pkcs15_data *data_object)
{ {
assert(data_object != NULL); if (data_object == NULL)
return;
free(data_object->data); free(data_object->data);
free(data_object); free(data_object);

View File

@ -27,28 +27,28 @@
#include <stdio.h> #include <stdio.h>
static const struct sc_asn1_entry c_asn1_com_ao_attr[] = { static const struct sc_asn1_entry c_asn1_com_ao_attr[] = {
{ "authId", SC_ASN1_PKCS15_ID, ASN1_OCTET_STRING, 0, NULL }, { "authId", SC_ASN1_PKCS15_ID, ASN1_OCTET_STRING, 0, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static const struct sc_asn1_entry c_asn1_pin_attr[] = { static const struct sc_asn1_entry c_asn1_pin_attr[] = {
{ "pinFlags", SC_ASN1_BIT_FIELD, ASN1_BIT_STRING, 0, NULL }, { "pinFlags", SC_ASN1_BIT_FIELD, ASN1_BIT_STRING, 0, NULL, NULL },
{ "pinType", SC_ASN1_ENUMERATED, ASN1_ENUMERATED, 0, NULL }, { "pinType", SC_ASN1_ENUMERATED, ASN1_ENUMERATED, 0, NULL, NULL },
{ "minLength", SC_ASN1_INTEGER, ASN1_INTEGER, 0, NULL }, { "minLength", SC_ASN1_INTEGER, ASN1_INTEGER, 0, NULL, NULL },
{ "storedLength", SC_ASN1_INTEGER, ASN1_INTEGER, 0, NULL }, { "storedLength", SC_ASN1_INTEGER, ASN1_INTEGER, 0, NULL, NULL },
{ "maxLength", SC_ASN1_INTEGER, ASN1_INTEGER, SC_ASN1_OPTIONAL, NULL }, { "maxLength", SC_ASN1_INTEGER, ASN1_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
{ "pinReference", SC_ASN1_INTEGER, SC_ASN1_CTX | 0, SC_ASN1_OPTIONAL, NULL }, { "pinReference", SC_ASN1_INTEGER, SC_ASN1_CTX | 0, SC_ASN1_OPTIONAL, NULL, NULL },
{ "padChar", SC_ASN1_OCTET_STRING, ASN1_OCTET_STRING, SC_ASN1_OPTIONAL, NULL }, { "padChar", SC_ASN1_OCTET_STRING, ASN1_OCTET_STRING, SC_ASN1_OPTIONAL, NULL, NULL },
{ "lastPinChange",SC_ASN1_GENERALIZEDTIME, ASN1_GENERALIZEDTIME, SC_ASN1_OPTIONAL, NULL }, { "lastPinChange",SC_ASN1_GENERALIZEDTIME, ASN1_GENERALIZEDTIME, SC_ASN1_OPTIONAL, NULL, NULL },
{ "path", SC_ASN1_PATH, ASN1_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL }, { "path", SC_ASN1_PATH, ASN1_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static const struct sc_asn1_entry c_asn1_type_pin_attr[] = { static const struct sc_asn1_entry c_asn1_type_pin_attr[] = {
{ "pinAttributes", SC_ASN1_STRUCT, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL }, { "pinAttributes", SC_ASN1_STRUCT, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static const struct sc_asn1_entry c_asn1_pin[] = { static const struct sc_asn1_entry c_asn1_pin[] = {
{ "pin", SC_ASN1_PKCS15_OBJECT, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL }, { "pin", SC_ASN1_PKCS15_OBJECT, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
int sc_pkcs15_decode_aodf_entry(struct sc_pkcs15_card *p15card, int sc_pkcs15_decode_aodf_entry(struct sc_pkcs15_card *p15card,
@ -157,7 +157,7 @@ int sc_pkcs15_encode_aodf_entry(sc_context_t *ctx,
static int _validate_pin(struct sc_pkcs15_card *p15card, static int _validate_pin(struct sc_pkcs15_card *p15card,
struct sc_pkcs15_pin_info *pin, struct sc_pkcs15_pin_info *pin,
const u8 *pincode, size_t pinlen) size_t pinlen)
{ {
size_t max_length; size_t max_length;
assert(p15card != NULL); assert(p15card != NULL);
@ -196,7 +196,7 @@ int sc_pkcs15_verify_pin(struct sc_pkcs15_card *p15card,
sc_card_t *card; sc_card_t *card;
struct sc_pin_cmd_data data; struct sc_pin_cmd_data data;
if ((r = _validate_pin(p15card, pin, pincode, pinlen)) != SC_SUCCESS) if ((r = _validate_pin(p15card, pin, pinlen)) != SC_SUCCESS)
return r; return r;
card = p15card->card; card = p15card->card;
@ -269,9 +269,9 @@ int sc_pkcs15_change_pin(struct sc_pkcs15_card *p15card,
struct sc_pin_cmd_data data; struct sc_pin_cmd_data data;
/* make sure the pins are in valid range */ /* make sure the pins are in valid range */
if ((r = _validate_pin(p15card, pin, oldpin, oldpinlen)) != SC_SUCCESS) if ((r = _validate_pin(p15card, pin, oldpinlen)) != SC_SUCCESS)
return r; return r;
if ((r = _validate_pin(p15card, pin, newpin, newpinlen)) != SC_SUCCESS) if ((r = _validate_pin(p15card, pin, newpinlen)) != SC_SUCCESS)
return r; return r;
/* pin change with pin pad reader not yet supported */ /* pin change with pin pad reader not yet supported */
@ -355,7 +355,7 @@ int sc_pkcs15_unblock_pin(struct sc_pkcs15_card *p15card,
struct sc_pkcs15_pin_info *puk_info = NULL; struct sc_pkcs15_pin_info *puk_info = NULL;
/* make sure the pins are in valid range */ /* make sure the pins are in valid range */
if ((r = _validate_pin(p15card, pin, newpin, newpinlen)) != SC_SUCCESS) if ((r = _validate_pin(p15card, pin, newpinlen)) != SC_SUCCESS)
return r; return r;
/* pin change with pin pad reader not yet supported */ /* pin change with pin pad reader not yet supported */
@ -384,7 +384,7 @@ int sc_pkcs15_unblock_pin(struct sc_pkcs15_card *p15card,
} }
/* make sure the puk is in valid range */ /* make sure the puk is in valid range */
if ((r = _validate_pin(p15card, puk_info, puk, puklen)) != SC_SUCCESS) if ((r = _validate_pin(p15card, puk_info, puklen)) != SC_SUCCESS)
return r; return r;
r = sc_lock(card); r = sc_lock(card);

View File

@ -27,56 +27,56 @@
#include <assert.h> #include <assert.h>
static const struct sc_asn1_entry c_asn1_com_key_attr[] = { static const struct sc_asn1_entry c_asn1_com_key_attr[] = {
{ "iD", SC_ASN1_PKCS15_ID, ASN1_OCTET_STRING, 0, NULL }, { "iD", SC_ASN1_PKCS15_ID, ASN1_OCTET_STRING, 0, NULL, NULL },
{ "usage", SC_ASN1_BIT_FIELD, ASN1_BIT_STRING, 0, NULL }, { "usage", SC_ASN1_BIT_FIELD, ASN1_BIT_STRING, 0, NULL, NULL },
{ "native", SC_ASN1_BOOLEAN, ASN1_BOOLEAN, SC_ASN1_OPTIONAL, NULL }, { "native", SC_ASN1_BOOLEAN, ASN1_BOOLEAN, SC_ASN1_OPTIONAL, NULL, NULL },
{ "accessFlags", SC_ASN1_BIT_FIELD, ASN1_BIT_STRING, SC_ASN1_OPTIONAL, NULL }, { "accessFlags", SC_ASN1_BIT_FIELD, ASN1_BIT_STRING, SC_ASN1_OPTIONAL, NULL, NULL },
{ "keyReference",SC_ASN1_INTEGER, ASN1_INTEGER, SC_ASN1_OPTIONAL, NULL }, { "keyReference",SC_ASN1_INTEGER, ASN1_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static const struct sc_asn1_entry c_asn1_com_prkey_attr[] = { static const struct sc_asn1_entry c_asn1_com_prkey_attr[] = {
/* FIXME */ /* FIXME */
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static const struct sc_asn1_entry c_asn1_rsakey_attr[] = { static const struct sc_asn1_entry c_asn1_rsakey_attr[] = {
{ "value", SC_ASN1_PATH, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL }, { "value", SC_ASN1_PATH, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
{ "modulusLength", SC_ASN1_INTEGER, ASN1_INTEGER, 0, NULL }, { "modulusLength", SC_ASN1_INTEGER, ASN1_INTEGER, 0, NULL, NULL },
{ "keyInfo", SC_ASN1_INTEGER, ASN1_INTEGER, SC_ASN1_OPTIONAL, NULL }, { "keyInfo", SC_ASN1_INTEGER, ASN1_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static const struct sc_asn1_entry c_asn1_prk_rsa_attr[] = { static const struct sc_asn1_entry c_asn1_prk_rsa_attr[] = {
{ "privateRSAKeyAttributes", SC_ASN1_STRUCT, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL }, { "privateRSAKeyAttributes", SC_ASN1_STRUCT, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static const struct sc_asn1_entry c_asn1_dsakey_i_p_attr[] = { static const struct sc_asn1_entry c_asn1_dsakey_i_p_attr[] = {
{ "path", SC_ASN1_PATH, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL }, { "path", SC_ASN1_PATH, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static const struct sc_asn1_entry c_asn1_dsakey_value_attr[] = { static const struct sc_asn1_entry c_asn1_dsakey_value_attr[] = {
{ "path", SC_ASN1_PATH, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL }, { "path", SC_ASN1_PATH, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
{ "pathProtected",SC_ASN1_STRUCT, SC_ASN1_CTX | 1 | SC_ASN1_CONS, }, { "pathProtected",SC_ASN1_STRUCT, SC_ASN1_CTX | 1 | SC_ASN1_CONS, 0, NULL, NULL},
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static const struct sc_asn1_entry c_asn1_dsakey_attr[] = { static const struct sc_asn1_entry c_asn1_dsakey_attr[] = {
{ "value", SC_ASN1_CHOICE, 0, 0, NULL }, { "value", SC_ASN1_CHOICE, 0, 0, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static const struct sc_asn1_entry c_asn1_prk_dsa_attr[] = { static const struct sc_asn1_entry c_asn1_prk_dsa_attr[] = {
{ "privateDSAKeyAttributes", SC_ASN1_STRUCT, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL }, { "privateDSAKeyAttributes", SC_ASN1_STRUCT, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static const struct sc_asn1_entry c_asn1_prkey[] = { static const struct sc_asn1_entry c_asn1_prkey[] = {
{ "privateRSAKey", SC_ASN1_PKCS15_OBJECT, ASN1_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL }, { "privateRSAKey", SC_ASN1_PKCS15_OBJECT, ASN1_SEQUENCE | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL },
{ "privateDSAKey", SC_ASN1_PKCS15_OBJECT, 2 | SC_ASN1_CTX | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL }, { "privateDSAKey", SC_ASN1_PKCS15_OBJECT, 2 | SC_ASN1_CTX | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
int sc_pkcs15_decode_prkdf_entry(struct sc_pkcs15_card *p15card, int sc_pkcs15_decode_prkdf_entry(struct sc_pkcs15_card *p15card,
@ -239,8 +239,8 @@ int sc_pkcs15_encode_prkdf_entry(sc_context_t *ctx,
* Store private keys on the card, encrypted * Store private keys on the card, encrypted
*/ */
static const struct sc_asn1_entry c_asn1_dsa_prkey_obj[] = { static const struct sc_asn1_entry c_asn1_dsa_prkey_obj[] = {
{ "privateKey", SC_ASN1_OCTET_STRING, ASN1_INTEGER, SC_ASN1_ALLOC }, { "privateKey", SC_ASN1_OCTET_STRING, ASN1_INTEGER, SC_ASN1_ALLOC, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static int static int

View File

@ -27,50 +27,50 @@
#include <assert.h> #include <assert.h>
static const struct sc_asn1_entry c_asn1_com_key_attr[] = { static const struct sc_asn1_entry c_asn1_com_key_attr[] = {
{ "iD", SC_ASN1_PKCS15_ID, ASN1_OCTET_STRING, 0, NULL }, { "iD", SC_ASN1_PKCS15_ID, ASN1_OCTET_STRING, 0, NULL, NULL },
{ "usage", SC_ASN1_BIT_FIELD, ASN1_BIT_STRING, 0, NULL }, { "usage", SC_ASN1_BIT_FIELD, ASN1_BIT_STRING, 0, NULL, NULL },
{ "native", SC_ASN1_BOOLEAN, ASN1_BOOLEAN, SC_ASN1_OPTIONAL, NULL }, { "native", SC_ASN1_BOOLEAN, ASN1_BOOLEAN, SC_ASN1_OPTIONAL, NULL, NULL },
{ "accessFlags", SC_ASN1_BIT_FIELD, ASN1_BIT_STRING, SC_ASN1_OPTIONAL, NULL }, { "accessFlags", SC_ASN1_BIT_FIELD, ASN1_BIT_STRING, SC_ASN1_OPTIONAL, NULL, NULL },
{ "keyReference",SC_ASN1_INTEGER, ASN1_INTEGER, SC_ASN1_OPTIONAL, NULL }, { "keyReference",SC_ASN1_INTEGER, ASN1_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static const struct sc_asn1_entry c_asn1_com_pubkey_attr[] = { static const struct sc_asn1_entry c_asn1_com_pubkey_attr[] = {
/* FIXME */ /* FIXME */
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static const struct sc_asn1_entry c_asn1_rsakey_attr[] = { static const struct sc_asn1_entry c_asn1_rsakey_attr[] = {
{ "value", SC_ASN1_PATH, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL }, { "value", SC_ASN1_PATH, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
{ "modulusLength", SC_ASN1_INTEGER, ASN1_INTEGER, 0, NULL }, { "modulusLength", SC_ASN1_INTEGER, ASN1_INTEGER, 0, NULL, NULL },
{ "keyInfo", SC_ASN1_INTEGER, ASN1_INTEGER, SC_ASN1_OPTIONAL, NULL }, { "keyInfo", SC_ASN1_INTEGER, ASN1_INTEGER, SC_ASN1_OPTIONAL, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static const struct sc_asn1_entry c_asn1_rsa_type_attr[] = { static const struct sc_asn1_entry c_asn1_rsa_type_attr[] = {
{ "publicRSAKeyAttributes", SC_ASN1_STRUCT, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL }, { "publicRSAKeyAttributes", SC_ASN1_STRUCT, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static const struct sc_asn1_entry c_asn1_dsakey_attr[] = { static const struct sc_asn1_entry c_asn1_dsakey_attr[] = {
{ "value", SC_ASN1_PATH, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL }, { "value", SC_ASN1_PATH, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static const struct sc_asn1_entry c_asn1_dsa_type_attr[] = { static const struct sc_asn1_entry c_asn1_dsa_type_attr[] = {
{ "publicDSAKeyAttributes", SC_ASN1_STRUCT, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL }, { "publicDSAKeyAttributes", SC_ASN1_STRUCT, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static const struct sc_asn1_entry c_asn1_pubkey_choice[] = { static const struct sc_asn1_entry c_asn1_pubkey_choice[] = {
{ "publicRSAKey", SC_ASN1_PKCS15_OBJECT, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL }, { "publicRSAKey", SC_ASN1_PKCS15_OBJECT, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
{ "publicDSAKey", SC_ASN1_PKCS15_OBJECT, 2 | SC_ASN1_CTX | SC_ASN1_CONS, 0, NULL }, { "publicDSAKey", SC_ASN1_PKCS15_OBJECT, 2 | SC_ASN1_CTX | SC_ASN1_CONS, 0, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static const struct sc_asn1_entry c_asn1_pubkey[] = { static const struct sc_asn1_entry c_asn1_pubkey[] = {
{ "publicKey", SC_ASN1_CHOICE, }, { "publicKey", SC_ASN1_CHOICE, 0, 0, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
int sc_pkcs15_decode_pukdf_entry(struct sc_pkcs15_card *p15card, int sc_pkcs15_decode_pukdf_entry(struct sc_pkcs15_card *p15card,
@ -213,22 +213,22 @@ int sc_pkcs15_encode_pukdf_entry(sc_context_t *ctx,
} }
static struct sc_asn1_entry c_asn1_public_key[2] = { static struct sc_asn1_entry c_asn1_public_key[2] = {
{ "publicKeyCoefficients", SC_ASN1_STRUCT, ASN1_SEQUENCE | SC_ASN1_CONS, }, { "publicKeyCoefficients", SC_ASN1_STRUCT, ASN1_SEQUENCE | SC_ASN1_CONS, 0, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static struct sc_asn1_entry c_asn1_rsa_pub_coefficients[3] = { static struct sc_asn1_entry c_asn1_rsa_pub_coefficients[3] = {
{ "modulus", SC_ASN1_OCTET_STRING, ASN1_INTEGER, SC_ASN1_ALLOC|SC_ASN1_UNSIGNED, }, { "modulus", SC_ASN1_OCTET_STRING, ASN1_INTEGER, SC_ASN1_ALLOC|SC_ASN1_UNSIGNED, NULL, NULL },
{ "exponent", SC_ASN1_OCTET_STRING, ASN1_INTEGER, SC_ASN1_ALLOC|SC_ASN1_UNSIGNED, }, { "exponent", SC_ASN1_OCTET_STRING, ASN1_INTEGER, SC_ASN1_ALLOC|SC_ASN1_UNSIGNED, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static struct sc_asn1_entry c_asn1_dsa_pub_coefficients[5] = { static struct sc_asn1_entry c_asn1_dsa_pub_coefficients[5] = {
{ "publicKey",SC_ASN1_OCTET_STRING, ASN1_INTEGER, SC_ASN1_ALLOC|SC_ASN1_UNSIGNED, }, { "publicKey",SC_ASN1_OCTET_STRING, ASN1_INTEGER, SC_ASN1_ALLOC|SC_ASN1_UNSIGNED, NULL, NULL },
{ "paramP", SC_ASN1_OCTET_STRING, ASN1_INTEGER, SC_ASN1_ALLOC|SC_ASN1_UNSIGNED, }, { "paramP", SC_ASN1_OCTET_STRING, ASN1_INTEGER, SC_ASN1_ALLOC|SC_ASN1_UNSIGNED, NULL, NULL },
{ "paramQ", SC_ASN1_OCTET_STRING, ASN1_INTEGER, SC_ASN1_ALLOC|SC_ASN1_UNSIGNED, }, { "paramQ", SC_ASN1_OCTET_STRING, ASN1_INTEGER, SC_ASN1_ALLOC|SC_ASN1_UNSIGNED, NULL, NULL },
{ "paramG", SC_ASN1_OCTET_STRING, ASN1_INTEGER, SC_ASN1_ALLOC|SC_ASN1_UNSIGNED, }, { "paramG", SC_ASN1_OCTET_STRING, ASN1_INTEGER, SC_ASN1_ALLOC|SC_ASN1_UNSIGNED, NULL, NULL },
{ NULL }, { NULL, 0, 0, 0, NULL, NULL },
}; };
int int

View File

@ -27,7 +27,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <assert.h>
/* /*
* The asn.1 stuff from openssl and the one from opensc don't * The asn.1 stuff from openssl and the one from opensc don't
@ -120,8 +119,7 @@ sc_pkcs15_derive_key(sc_context_t *ctx,
} }
static int static int
do_cipher(sc_context_t *ctx, EVP_CIPHER_CTX *cipher_ctx, do_cipher(EVP_CIPHER_CTX *cipher_ctx, const u8 *in, size_t in_len,
const u8 *in, size_t in_len,
u8 **out, size_t *out_len) u8 **out, size_t *out_len)
{ {
const u8 *end; const u8 *end;
@ -138,7 +136,7 @@ do_cipher(sc_context_t *ctx, EVP_CIPHER_CTX *cipher_ctx,
left = bl; left = bl;
if (!EVP_CipherUpdate(cipher_ctx, if (!EVP_CipherUpdate(cipher_ctx,
p + total, (int *) &done, p + total, (int *) &done,
(u8 *) in, left)) (u8 *) in, (int)left))
goto fail; goto fail;
total += done; total += done;
in += left; in += left;
@ -187,7 +185,7 @@ sc_pkcs15_wrap_data(sc_context_t *ctx,
return r; return r;
/* Now encrypt the data using the derived key */ /* Now encrypt the data using the derived key */
r = do_cipher(ctx, &cipher_ctx, in, in_len, r = do_cipher(&cipher_ctx, in, in_len,
&envdata.content, &envdata.content_len); &envdata.content, &envdata.content_len);
if (r < 0) if (r < 0)
return r; return r;
@ -224,7 +222,7 @@ sc_pkcs15_unwrap_data(sc_context_t *ctx,
return r; return r;
/* Now decrypt the data using the derived key */ /* Now decrypt the data using the derived key */
r = do_cipher(ctx, &cipher_ctx, envdata.content, envdata.content_len, r = do_cipher(&cipher_ctx, envdata.content, envdata.content_len,
out, out_len); out, out_len);
if (r < 0) if (r < 0)
return r; return r;
@ -244,44 +242,44 @@ sc_pkcs15_unwrap_data(sc_context_t *ctx,
* we treat it as if there's always just one element in the set. * we treat it as if there's always just one element in the set.
*/ */
static const struct sc_asn1_entry c_asn1_enveloped_data_attr[] = { static const struct sc_asn1_entry c_asn1_enveloped_data_attr[] = {
{ "version", SC_ASN1_INTEGER, ASN1_INTEGER, 0, NULL, 0 }, { "version", SC_ASN1_INTEGER, ASN1_INTEGER, 0, NULL, NULL },
{ "originator", SC_ASN1_STRUCT, SC_ASN1_CONS|ASN1_SEQUENCE, SC_ASN1_OPTIONAL }, { "originator", SC_ASN1_STRUCT, SC_ASN1_CONS|ASN1_SEQUENCE, SC_ASN1_OPTIONAL, NULL, NULL },
{ "recipients", SC_ASN1_STRUCT, SC_ASN1_CONS|ASN1_SET, 0 }, { "recipients", SC_ASN1_STRUCT, SC_ASN1_CONS|ASN1_SET, 0, NULL, NULL },
{ "contentInfo",SC_ASN1_STRUCT, SC_ASN1_CONS|ASN1_SEQUENCE, 0 }, { "contentInfo",SC_ASN1_STRUCT, SC_ASN1_CONS|ASN1_SEQUENCE, 0, NULL, NULL },
/* some more optional foo we ignore for now */ /* some more optional foo we ignore for now */
{ NULL} { NULL, 0, 0, 0, NULL, NULL}
}; };
static const struct sc_asn1_entry c_asn1_content_attr[] = { static const struct sc_asn1_entry c_asn1_content_attr[] = {
{ "contentType",SC_ASN1_OBJECT, ASN1_OBJECT, 0 }, { "contentType",SC_ASN1_OBJECT, ASN1_OBJECT, 0, NULL, NULL },
{ "contentEncrAlg", SC_ASN1_ALGORITHM_ID, SC_ASN1_CONS|ASN1_SEQUENCE, 0 }, { "contentEncrAlg", SC_ASN1_ALGORITHM_ID, SC_ASN1_CONS|ASN1_SEQUENCE, 0, NULL, NULL },
{ "encrContent",SC_ASN1_STRUCT, SC_ASN1_CTX | 0 | SC_ASN1_CONS, SC_ASN1_OPTIONAL }, { "encrContent",SC_ASN1_STRUCT, SC_ASN1_CTX | 0 | SC_ASN1_CONS, SC_ASN1_OPTIONAL, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static const struct sc_asn1_entry c_asn1_encr_content[] = { static const struct sc_asn1_entry c_asn1_encr_content[] = {
{ "data", SC_ASN1_OCTET_STRING, ASN1_OCTET_STRING, SC_ASN1_ALLOC }, { "data", SC_ASN1_OCTET_STRING, ASN1_OCTET_STRING, SC_ASN1_ALLOC, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static const struct sc_asn1_entry c_asn1_recipients_attr[] = { static const struct sc_asn1_entry c_asn1_recipients_attr[] = {
{ "kekri", SC_ASN1_STRUCT, SC_ASN1_CTX | 2 | SC_ASN1_CONS }, { "kekri", SC_ASN1_STRUCT, SC_ASN1_CTX | 2 | SC_ASN1_CONS , 0, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static const struct sc_asn1_entry c_asn1_kekri_attr[] = { static const struct sc_asn1_entry c_asn1_kekri_attr[] = {
{ "version", SC_ASN1_INTEGER, ASN1_INTEGER, 0 }, { "version", SC_ASN1_INTEGER, ASN1_INTEGER, 0, NULL, NULL },
{ "id", SC_ASN1_STRUCT, SC_ASN1_CONS|ASN1_SEQUENCE, 0 }, { "id", SC_ASN1_STRUCT, SC_ASN1_CONS|ASN1_SEQUENCE, 0, NULL, NULL },
{ "keyEncrAlg", SC_ASN1_ALGORITHM_ID, SC_ASN1_CONS|ASN1_SEQUENCE, 0 }, { "keyEncrAlg", SC_ASN1_ALGORITHM_ID, SC_ASN1_CONS|ASN1_SEQUENCE, 0, NULL, NULL },
{ "keyEncrKey", SC_ASN1_OCTET_STRING, ASN1_OCTET_STRING, SC_ASN1_ALLOC }, { "keyEncrKey", SC_ASN1_OCTET_STRING, ASN1_OCTET_STRING, SC_ASN1_ALLOC, NULL, NULL },
{ NULL } { NULL, 0, 0, 0, NULL, NULL }
}; };
static const struct sc_asn1_entry c_asn1_kek_attr[] = { static const struct sc_asn1_entry c_asn1_kek_attr[] = {
{ "id", SC_ASN1_OCTET_STRING, ASN1_OCTET_STRING, 0 }, { "id", SC_ASN1_OCTET_STRING, ASN1_OCTET_STRING, 0, NULL, NULL },
{ "date", SC_ASN1_OCTET_STRING, ASN1_GENERALIZEDTIME, SC_ASN1_OPTIONAL }, { "date", SC_ASN1_OCTET_STRING, ASN1_GENERALIZEDTIME, SC_ASN1_OPTIONAL, NULL, NULL },
{ "other", SC_ASN1_STRUCT, SC_ASN1_CONS|ASN1_SEQUENCE, SC_ASN1_OPTIONAL }, { "other", SC_ASN1_STRUCT, SC_ASN1_CONS|ASN1_SEQUENCE, SC_ASN1_OPTIONAL, NULL, NULL },
{ NULL} { NULL, 0, 0, 0, NULL, NULL }
}; };
int int