eac.h
Go to the documentation of this file.
/*
* Copyright (c) 2010-2012 Frank Morgner and Dominik Oepen
*
* This file is part of OpenPACE.
*
* OpenPACE is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* OpenPACE is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* OpenPACE. If not, see <http://www.gnu.org/licenses/>.
*
* Additional permission under GNU GPL version 3 section 7
*
* If you modify this Program, or any covered work, by linking or combining it
* with OpenSSL (or a modified version of that library), containing
* parts covered by the terms of OpenSSL's license, the licensors of
* this Program grant you additional permission to convey the resulting work.
* Corresponding Source for a non-source form of such a combination shall include
* the source code for the parts of OpenSSL used as well as that of the
* covered work.
*
* If you modify this Program, or any covered work, by linking or combining it
* with OpenSC (or a modified version of that library), containing
* parts covered by the terms of OpenSC's license, the licensors of
* this Program grant you additional permission to convey the resulting work.
* Corresponding Source for a non-source form of such a combination shall include
* the source code for the parts of OpenSC used as well as that of the
* covered work.
*/
#ifndef EAC_H_
#define EAC_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <eac/cv_cert.h>
#include <eac/objects.h>
#include <openssl/asn1.h>
#include <openssl/buffer.h>
#include <openssl/cmac.h>
#include <openssl/ec.h>
#include <openssl/evp.h>
enum eac_tr_version {
EAC_TR_VERSION = 0,
EAC_TR_VERSION_2_01,
EAC_TR_VERSION_2_02,
};
typedef struct ka_ctx {
const EVP_MD * md;
ENGINE * md_engine;
CMAC_CTX * cmac_ctx;
const EVP_CIPHER * cipher;
ENGINE * cipher_engine;
unsigned char * iv;
int mac_keylen;
int enc_keylen;
BUF_MEM * (*generate_key)(EVP_PKEY *key, BN_CTX *bn_ctx);
BUF_MEM * (*compute_key)(EVP_PKEY *key, const BUF_MEM *in, BN_CTX *bn_ctx);
EVP_PKEY *key;
BUF_MEM *shared_secret;
BUF_MEM *k_enc;
BUF_MEM *k_mac;
} KA_CTX;
typedef struct pace_ctx {
int protocol;
unsigned char version;
int id;
BUF_MEM * (*map_generate_key)(const struct pace_ctx *ctx, BN_CTX *bn_ctx);
int (*map_compute_key)(struct pace_ctx * ctx, const BUF_MEM * s,
const BUF_MEM * in, BN_CTX *bn_ctx);
EVP_PKEY *static_key;
KA_CTX *ka_ctx;
BUF_MEM *nonce;
BUF_MEM *my_eph_pubkey;
} PACE_CTX;
typedef struct ri_ctx {
int protocol;
int id;
const EVP_MD * md;
BUF_MEM * (*generate_key)(EVP_PKEY *key, BN_CTX *bn_ctx);
BUF_MEM * (*compute_key)(EVP_PKEY *key, const BUF_MEM *in, BN_CTX *bn_ctx);
EVP_PKEY *static_key;
} RI_CTX;
typedef CVC_CERT * (*CVC_lookup_cvca_cert) (const unsigned char *chr, size_t car_len);
typedef struct ta_ctx {
unsigned char version;
int protocol;
ENGINE *key_engine;
EVP_PKEY *priv_key;
EVP_PKEY *pub_key;
BUF_MEM *pk_pcd;
BUF_MEM *nonce;
CVC_CERT *trust_anchor;
CVC_CERT *current_cert;
CVC_CERT *new_trust_anchor;
int flags;
CVC_lookup_cvca_cert lookup_cvca_cert;
} TA_CTX;
typedef X509_STORE * (*X509_lookup_csca_cert) (unsigned long issuer_name_hash);
typedef struct ca_ctx {
unsigned char version;
int protocol;
int id;
int flags;
KA_CTX *ka_ctx;
X509_lookup_csca_cert lookup_csca_cert;
} CA_CTX;
typedef struct eac_ctx {
enum eac_tr_version tr_version;
BN_CTX * bn_ctx;
EVP_MD_CTX * md_ctx;
EVP_CIPHER_CTX * cipher_ctx;
PACE_CTX *pace_ctx;
STACK_OF(PACE_CTX *) pace_ctxs;
RI_CTX *ri_ctx;
STACK_OF(RI_CTX *) ri_ctxs;
TA_CTX *ta_ctx;
CA_CTX *ca_ctx;
STACK_OF(CA_CTX *) ca_ctxs;
KA_CTX *key_ctx;
BIGNUM *ssc;
} EAC_CTX;
#define EAC_AES_MAC_LENGTH 8
void EAC_init(void);
void EAC_cleanup(void);
EAC_CTX *
EAC_CTX_new(void);
void EAC_CTX_clear_free(EAC_CTX *ctx);
int
EAC_CTX_init_pace(EAC_CTX *ctx, int protocol, int curve);
int
EAC_CTX_init_ta(const EAC_CTX *ctx,
const unsigned char *privkey, size_t privkey_len,
const unsigned char *cvca, size_t cvca_len);
int EAC_CTX_init_ca(EAC_CTX *ctx, int protocol, int curve);
int
EAC_CTX_init_ri(EAC_CTX *ctx, int protocol, int stnd_dp);
int EAC_CTX_init_ef_cardaccess(unsigned const char * in, size_t in_len,
EAC_CTX *ctx);
int EAC_CTX_init_ef_cardsecurity(
const unsigned char *ef_cardsecurity, size_t ef_cardsecurity_len,
EAC_CTX *ctx);
int EAC_CTX_get_cvca_lookup(const EAC_CTX *ctx, CVC_lookup_cvca_cert *lookup_cvca_cert);
int EAC_CTX_set_cvca_lookup(EAC_CTX *ctx, CVC_lookup_cvca_cert lookup_cvca_cert);
CVC_lookup_cvca_cert EAC_get_default_cvca_lookup(void);
void EAC_set_cvc_default_dir(const char *default_dir);
int EAC_CTX_get_csca_lookup_cert(const EAC_CTX *ctx, X509_lookup_csca_cert *lookup_cvca_cert);
int EAC_CTX_set_csca_lookup_cert(EAC_CTX *ctx, X509_lookup_csca_cert lookup_cvca_cert);
X509_lookup_csca_cert EAC_get_default_csca_lookup(void);
void EAC_set_x509_default_dir(const char *default_dir);
BUF_MEM *
EAC_add_iso_pad(const EAC_CTX *ctx, const BUF_MEM * unpadded);
BUF_MEM *
EAC_remove_iso_pad(const BUF_MEM * padded);
int EAC_increment_ssc(const EAC_CTX *ctx);
int EAC_reset_ssc(const EAC_CTX *ctx);
int EAC_set_ssc(const EAC_CTX *ctx, unsigned long ssc);
BUF_MEM *
EAC_encrypt(const EAC_CTX *ctx, const BUF_MEM *data);
BUF_MEM *
EAC_decrypt(const EAC_CTX *ctx, const BUF_MEM *data);
BUF_MEM *
EAC_authenticate(const EAC_CTX *ctx, const BUF_MEM *data);
int
EAC_verify_authentication(const EAC_CTX *ctx, const BUF_MEM *data,
const BUF_MEM *mac);
BUF_MEM *
EAC_Comp(const EAC_CTX *ctx, int id, const BUF_MEM *pub);
BUF_MEM *
EAC_hash_certificate_description(const unsigned char *cert_desc,
size_t cert_desc_len);
#define EAC_ID_PACE 0
#define EAC_ID_CA 1
#define EAC_ID_TA 2
#define EAC_ID_EAC 3
int
EAC_CTX_set_encryption_ctx(EAC_CTX *ctx, int id);
int EAC_CTX_print_private(BIO *out, const EAC_CTX *ctx, int indent);
int BUF_MEM_print(BIO *out, const BUF_MEM *buf, int indent);
void
BUF_MEM_clear_free(BUF_MEM *b);
#ifdef __cplusplus
}
#endif
#endif
cv_cert.h
Interface for Card Verifiable Certificates.
eac_tr_version
eac_tr_version
Identification of the specifications to use.
Definition eac.h:81
EAC_TR_VERSION_2_01
@ EAC_TR_VERSION_2_01
Perform EAC according to TR-03110 v2.01.
Definition eac.h:85
EAC_TR_VERSION_2_02
@ EAC_TR_VERSION_2_02
Perform EAC according to TR-03110 v2.02 and later.
Definition eac.h:87
EAC_TR_VERSION
@ EAC_TR_VERSION
Undefined type, if nothing else matches.
Definition eac.h:83
TA_CTX
struct ta_ctx TA_CTX
Context for the Terminal Authentication protocol.
PACE_CTX
struct pace_ctx PACE_CTX
Context for the Password Authenticated Connection Establishment protocol.
EAC_CTX
struct eac_ctx EAC_CTX
Context for the Extended Access Control protocol.
CA_CTX
struct ca_ctx CA_CTX
Context for the Chip Authentication protocol.
RI_CTX
struct ri_ctx RI_CTX
Context for the Restricted Identification protocol.
X509_lookup_csca_cert
X509_STORE *(* X509_lookup_csca_cert)(unsigned long issuer_name_hash)
callback for finding the X.509 trust anchor
Definition eac.h:301
KA_CTX
struct ka_ctx KA_CTX
Context for a key agreement and subsequent derivation of session keys.
CVC_lookup_cvca_cert
CVC_CERT *(* CVC_lookup_cvca_cert)(const unsigned char *chr, size_t car_len)
callback for finding the CVCA trust anchor
Definition eac.h:244
EAC_CTX_set_cvca_lookup
int EAC_CTX_set_cvca_lookup(EAC_CTX *ctx, CVC_lookup_cvca_cert lookup_cvca_cert)
Set the CVCA lookup callback.
EAC_CTX_get_csca_lookup_cert
int EAC_CTX_get_csca_lookup_cert(const EAC_CTX *ctx, X509_lookup_csca_cert *lookup_cvca_cert)
Get the CSCA lookup callback.
EAC_CTX_init_ri
int EAC_CTX_init_ri(EAC_CTX *ctx, int protocol, int stnd_dp)
Initialize an EAC context for Restricted Identification.
EAC_get_default_csca_lookup
X509_lookup_csca_cert EAC_get_default_csca_lookup(void)
Return the default lookup of the country signing CA.
EAC_CTX_init_pace
int EAC_CTX_init_pace(EAC_CTX *ctx, int protocol, int curve)
Initialize an EAC context for PACE.
EAC_CTX_set_csca_lookup_cert
int EAC_CTX_set_csca_lookup_cert(EAC_CTX *ctx, X509_lookup_csca_cert lookup_cvca_cert)
Set the CSCA lookup callback.
EAC_init
void EAC_init(void)
Initializes OpenSSL and the EAC identifier.
EAC_set_x509_default_dir
void EAC_set_x509_default_dir(const char *default_dir)
Set directory for EAC_get_default_csca_lookup()
EAC_CTX_clear_free
void EAC_CTX_clear_free(EAC_CTX *ctx)
Free an EAC context.
EAC_cleanup
void EAC_cleanup(void)
Wrapper to EVP_cleanup()
EAC_set_cvc_default_dir
void EAC_set_cvc_default_dir(const char *default_dir)
Set directory for EAC_get_default_cvca_lookup()
EAC_CTX_init_ca
int EAC_CTX_init_ca(EAC_CTX *ctx, int protocol, int curve)
Initialize an EAC context for Chip Authentication.
EAC_get_default_cvca_lookup
CVC_lookup_cvca_cert EAC_get_default_cvca_lookup(void)
Return the default lookup of the country verifying CA.
EAC_CTX_init_ef_cardaccess
int EAC_CTX_init_ef_cardaccess(unsigned const char *in, size_t in_len, EAC_CTX *ctx)
Initialize an EAC context for PACE, TA and CA from the data given in an EF.CardAccess.
EAC_CTX_init_ta
int EAC_CTX_init_ta(const EAC_CTX *ctx, const unsigned char *privkey, size_t privkey_len, const unsigned char *cvca, size_t cvca_len)
Initialize an EAC context for TA with the terminal's PKI data. Use either a CV certificate or a known...
EAC_CTX_init_ef_cardsecurity
int EAC_CTX_init_ef_cardsecurity(const unsigned char *ef_cardsecurity, size_t ef_cardsecurity_len, EAC_CTX *ctx)
Initialize an EAC context for PACE, TA and CA from the data given in an EF.CardSecurity.
EAC_CTX_new
EAC_CTX * EAC_CTX_new(void)
Create a new EAC context.
EAC_CTX_get_cvca_lookup
int EAC_CTX_get_cvca_lookup(const EAC_CTX *ctx, CVC_lookup_cvca_cert *lookup_cvca_cert)
Return the EAC context's CVCA lookup callback.
BUF_MEM_clear_free
void BUF_MEM_clear_free(BUF_MEM *b)
Frees and wipes a buffer.
EAC_CTX_print_private
int EAC_CTX_print_private(BIO *out, const EAC_CTX *ctx, int indent)
Print EAC context including private data.
BUF_MEM_print
int BUF_MEM_print(BIO *out, const BUF_MEM *buf, int indent)
Prints buffer.
EAC_hash_certificate_description
BUF_MEM * EAC_hash_certificate_description(const unsigned char *cert_desc, size_t cert_desc_len)
Compute the hash of a CV certificate description.
EAC_verify_authentication
int EAC_verify_authentication(const EAC_CTX *ctx, const BUF_MEM *data, const BUF_MEM *mac)
Verify authenticated data according to TR-03110 F.2.
EAC_CTX_set_encryption_ctx
int EAC_CTX_set_encryption_ctx(EAC_CTX *ctx, int id)
Set the SM context for encryption, decryption and authentication.
EAC_encrypt
BUF_MEM * EAC_encrypt(const EAC_CTX *ctx, const BUF_MEM *data)
Encrypts data according to TR-03110 F.2.
EAC_add_iso_pad
BUF_MEM * EAC_add_iso_pad(const EAC_CTX *ctx, const BUF_MEM *unpadded)
Pad a buffer using ISO/IEC 9797-1 padding method 2.
EAC_reset_ssc
int EAC_reset_ssc(const EAC_CTX *ctx)
Reset the Send Sequence Counter.
EAC_decrypt
BUF_MEM * EAC_decrypt(const EAC_CTX *ctx, const BUF_MEM *data)
Decrypt data according to TR-03110 F.2.
EAC_authenticate
BUF_MEM * EAC_authenticate(const EAC_CTX *ctx, const BUF_MEM *data)
Authenticate data according to TR-03110 F.2.
EAC_set_ssc
int EAC_set_ssc(const EAC_CTX *ctx, unsigned long ssc)
Set the Send Sequence Counter.
EAC_Comp
BUF_MEM * EAC_Comp(const EAC_CTX *ctx, int id, const BUF_MEM *pub)
Compresse a public key according to TR-03110 Table A.2.
EAC_increment_ssc
int EAC_increment_ssc(const EAC_CTX *ctx)
Increment the Send Sequence Counter.
EAC_remove_iso_pad
BUF_MEM * EAC_remove_iso_pad(const BUF_MEM *padded)
Remove ISO/IEC 9797-1 padding method 2 from a message.
objects.h
Definitions of object identifiers.
ca_ctx
Context for the Chip Authentication protocol.
Definition eac.h:304
ca_ctx::version
unsigned char version
(currently unused) Version of the CA protocol, MUST be 1 or 2
Definition eac.h:306
ca_ctx::id
int id
identifier of this CA context
Definition eac.h:321
ca_ctx::flags
int flags
Flags to control some of the behaviour of the CA.
Definition eac.h:327
ca_ctx::protocol
int protocol
Identifier of the protocol's OID specifying the exact CA parameters to use.
Definition eac.h:319
ca_ctx::lookup_csca_cert
X509_lookup_csca_cert lookup_csca_cert
callback for finding the X.509 trust anchor
Definition eac.h:338
ca_ctx::ka_ctx
KA_CTX * ka_ctx
Key agreement object used with the PICC's private key.
Definition eac.h:329
cvc_cert_seq_st
The actual certifcate, consisting of the body and a signature.
Definition cv_cert.h:209
eac_ctx
Context for the Extended Access Control protocol.
Definition eac.h:342
eac_ctx::STACK_OF
STACK_OF(CA_CTX *) ca_ctxs
stack of available Chip Authentication configurations
eac_ctx::ta_ctx
TA_CTX * ta_ctx
Context for the currently selected Terminal Authentication protocol.
Definition eac.h:364
eac_ctx::ca_ctx
CA_CTX * ca_ctx
Context for the currently selected Chip Authentication protocol.
Definition eac.h:368
eac_ctx::md_ctx
EVP_MD_CTX * md_ctx
Context for various hashing operations.
Definition eac.h:348
eac_ctx::key_ctx
KA_CTX * key_ctx
Context for currently selected secure messaging established with PACE or CA.
Definition eac.h:372
eac_ctx::pace_ctx
PACE_CTX * pace_ctx
Context for the currently selected Password Authenticated Connection Establishment protocol.
Definition eac.h:354
eac_ctx::STACK_OF
STACK_OF(RI_CTX *) ri_ctxs
stack of available Restricted Identification configurations
eac_ctx::bn_ctx
BN_CTX * bn_ctx
Context for various operations with BIGNUM objects.
Definition eac.h:346
eac_ctx::STACK_OF
STACK_OF(PACE_CTX *) pace_ctxs
stack of available Password Authenticated Connection Establishment configurations
eac_ctx::ssc
BIGNUM * ssc
Send sequence counter.
Definition eac.h:374
eac_ctx::cipher_ctx
EVP_CIPHER_CTX * cipher_ctx
Context for various cipher operations.
Definition eac.h:350
eac_ctx::ri_ctx
RI_CTX * ri_ctx
Context for the currently selected Restricted Identification protocol.
Definition eac.h:360
eac_ctx::tr_version
enum eac_tr_version tr_version
Perform EAC conforming to this version of TR-03110.
Definition eac.h:344
ka_ctx
Context for a key agreement and subsequent derivation of session keys.
Definition eac.h:95
ka_ctx::cipher_engine
ENGINE * cipher_engine
Cipher's engine.
Definition eac.h:105
ka_ctx::k_mac
BUF_MEM * k_mac
Symmetric key used for integrity protection. Derived from KA_CTX.shared_secret.
Definition eac.h:141
ka_ctx::md_engine
ENGINE * md_engine
Digest's engine.
Definition eac.h:99
ka_ctx::enc_keylen
int enc_keylen
Length of the computed key for the encryption/decryption.
Definition eac.h:111
ka_ctx::k_enc
BUF_MEM * k_enc
Symmetric key used for encryption/decryption. Derived from KA_CTX.shared_secret.
Definition eac.h:139
ka_ctx::cipher
const EVP_CIPHER * cipher
Cipher to use for encryption/decryption.
Definition eac.h:103
ka_ctx::key
EVP_PKEY * key
Container for the key pair used for key agreement.
Definition eac.h:134
ka_ctx::md
const EVP_MD * md
Digest to use for key derivation.
Definition eac.h:97
ka_ctx::shared_secret
BUF_MEM * shared_secret
Shared secret computed during the key agreement protocol.
Definition eac.h:137
ka_ctx::cmac_ctx
CMAC_CTX * cmac_ctx
Context for CMAC.
Definition eac.h:101
ka_ctx::mac_keylen
int mac_keylen
Length of the computed key for the message authentication code.
Definition eac.h:109
ka_ctx::iv
unsigned char * iv
Initialisation vector for encryption/decryption.
Definition eac.h:107
pace_ctx
Context for the Password Authenticated Connection Establishment protocol.
Definition eac.h:146
pace_ctx::nonce
BUF_MEM * nonce
PICC's decrypted challenge generated in PACE step 1.
Definition eac.h:192
pace_ctx::ka_ctx
KA_CTX * ka_ctx
Key agreement object used with the ephemeral domain parameters.
Definition eac.h:190
pace_ctx::version
unsigned char version
(currently unused) Version of the PACE protocol, MUST be 1 or 2
Definition eac.h:174
pace_ctx::my_eph_pubkey
BUF_MEM * my_eph_pubkey
The own ephemeral public key generated in PACe step 3b.
Definition eac.h:194
pace_ctx::map_compute_key
int(* map_compute_key)(struct pace_ctx *ctx, const BUF_MEM *s, const BUF_MEM *in, BN_CTX *bn_ctx)
Points to the implementation of a specific mapping.
Definition eac.h:184
pace_ctx::static_key
EVP_PKEY * static_key
PICC's static domain parameters.
Definition eac.h:188
pace_ctx::id
int id
identifier of this PACE context
Definition eac.h:176
pace_ctx::protocol
int protocol
Identifier of the protocol's OID specifying the exact PACE parameters to use.
Definition eac.h:172
ri_ctx
Context for the Restricted Identification protocol.
Definition eac.h:199
ri_ctx::protocol
int protocol
Identifier of the hash function to use.
Definition eac.h:215
ri_ctx::static_key
EVP_PKEY * static_key
PICC's static domain parameters.
Definition eac.h:240
ri_ctx::id
int id
identifier of this RI context
Definition eac.h:217
ri_ctx::md
const EVP_MD * md
Digest to use for derivation of I^{sector}_{ID}.
Definition eac.h:219
ta_ctx
Context for the Terminal Authentication protocol.
Definition eac.h:247
ta_ctx::pub_key
EVP_PKEY * pub_key
TA public key used for signing the challenge.
Definition eac.h:272
ta_ctx::new_trust_anchor
CVC_CERT * new_trust_anchor
When a complete CV certificate chain has been verified, this will be the new trust anchor.
Definition eac.h:282
ta_ctx::nonce
BUF_MEM * nonce
PICC's challenge.
Definition eac.h:276
ta_ctx::key_engine
ENGINE * key_engine
(currently unused) engine for signing and signature verification
Definition eac.h:268
ta_ctx::priv_key
EVP_PKEY * priv_key
TA private key used for signing the challenge.
Definition eac.h:270
ta_ctx::lookup_cvca_cert
CVC_lookup_cvca_cert lookup_cvca_cert
Lookup the CVCA trust anchor.
Definition eac.h:297
ta_ctx::pk_pcd
BUF_MEM * pk_pcd
PCD's public key extracted from it's CV certificate.
Definition eac.h:274
ta_ctx::trust_anchor
CVC_CERT * trust_anchor
Trust anchor for CV certificate validation.
Definition eac.h:278
ta_ctx::current_cert
CVC_CERT * current_cert
Most recent verified CV certificate in a certificate chain.
Definition eac.h:280
ta_ctx::version
unsigned char version
(currently unused) Version of the TA protocol, MUST be 1 or 2
Definition eac.h:249
ta_ctx::flags
int flags
Flags to control some of the behaviour of the CA.
Definition eac.h:288
ta_ctx::protocol
int protocol
Identifier of the protocol's OID specifying the exact TA parameters to use.
Definition eac.h:266