added documentation
git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@289 96b47cad-a561-4643-ad3b-153ac7d7599c
This commit is contained in:
@@ -16,6 +16,9 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* ccid. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
#ifndef _CCID_H
|
||||
#define _CCID_H
|
||||
|
||||
@@ -32,36 +35,36 @@ extern "C" {
|
||||
#define CCID_CONTROL_GET_CLOCK_FREQUENCIES 0x02
|
||||
#define CCID_CONTROL_GET_DATA_RATES 0x03
|
||||
|
||||
#define CCID_BERROR_CMD_ABORTED 0xff /* Host aborted the current activity */
|
||||
#define CCID_BERROR_ICC_MUTE 0xfe /* CCID timed out while talking to the ICC */
|
||||
#define CCID_BERROR_XFR_PARITY_ERROR 0xfd /* Parity error while talking to the ICC */
|
||||
#define CCID_BERROR_XFR_OVERRUN 0xfc /* Overrun error while talking to the ICC */
|
||||
#define CCID_BERROR_HW_ERROR 0xfb /* An all inclusive hardware error occurred */
|
||||
#define CCID_BERROR_CMD_ABORTED 0xff /** Host aborted the current activity */
|
||||
#define CCID_BERROR_ICC_MUTE 0xfe /** CCID timed out while talking to the ICC */
|
||||
#define CCID_BERROR_XFR_PARITY_ERROR 0xfd /** Parity error while talking to the ICC */
|
||||
#define CCID_BERROR_XFR_OVERRUN 0xfc /** Overrun error while talking to the ICC */
|
||||
#define CCID_BERROR_HW_ERROR 0xfb /** An all inclusive hardware error occurred */
|
||||
#define CCID_BERROR_BAD_ATR_TS 0xf
|
||||
#define CCID_BERROR_BAD_ATR_TCK 0xf
|
||||
#define CCID_BERROR_ICC_PROTOCOL_NOT_SUPPORTED 0xf6
|
||||
#define CCID_BERROR_ICC_CLASS_NOT_SUPPORTED 0xf5
|
||||
#define CCID_BERROR_PROCEDURE_BYTE_CONFLICT 0xf4
|
||||
#define CCID_BERROR_DEACTIVATED_PROTOCOL 0xf3
|
||||
#define CCID_BERROR_BUSY_WITH_AUTO_SEQUENCE 0xf2 /* Automatic Sequence Ongoing */
|
||||
#define CCID_BERROR_BUSY_WITH_AUTO_SEQUENCE 0xf2 /** Automatic Sequence Ongoing */
|
||||
#define CCID_BERROR_PIN_TIMEOUT 0xf0
|
||||
#define CCID_BERROR_PIN_CANCELLED 0xef
|
||||
#define CCID_BERROR_CMD_SLOT_BUSY 0xe0 /* A second command was sent to a slot which was already processing a command. */
|
||||
#define CCID_BERROR_CMD_SLOT_BUSY 0xe0 /** A second command was sent to a slot which was already processing a command. */
|
||||
#define CCID_BERROR_CMD_NOT_SUPPORTED 0x00
|
||||
#define CCID_BERROR_OK 0x00
|
||||
|
||||
#define CCID_BSTATUS_OK_ACTIVE 0x00 /* No error. An ICC is present and active */
|
||||
#define CCID_BSTATUS_OK_INACTIVE 0x01 /* No error. ICC is present and inactive */
|
||||
#define CCID_BSTATUS_OK_NOICC 0x02 /* No error. No ICC is present */
|
||||
#define CCID_BSTATUS_ERROR_ACTIVE 0x40 /* Failed. An ICC is present and active */
|
||||
#define CCID_BSTATUS_ERROR_INACTIVE 0x41 /* Failed. ICC is present and inactive */
|
||||
#define CCID_BSTATUS_ERROR_NOICC 0x42 /* Failed. No ICC is present */
|
||||
#define CCID_BSTATUS_OK_ACTIVE 0x00 /** No error. An ICC is present and active */
|
||||
#define CCID_BSTATUS_OK_INACTIVE 0x01 /** No error. ICC is present and inactive */
|
||||
#define CCID_BSTATUS_OK_NOICC 0x02 /** No error. No ICC is present */
|
||||
#define CCID_BSTATUS_ERROR_ACTIVE 0x40 /** Failed. An ICC is present and active */
|
||||
#define CCID_BSTATUS_ERROR_INACTIVE 0x41 /** Failed. ICC is present and inactive */
|
||||
#define CCID_BSTATUS_ERROR_NOICC 0x42 /** Failed. No ICC is present */
|
||||
|
||||
#define CCID_WLEVEL_DIRECT __constant_cpu_to_le16(0) /* APDU begins and ends with this command */
|
||||
#define CCID_WLEVEL_CHAIN_NEXT_XFRBLOCK __constant_cpu_to_le16(1) /* APDU begins with this command, and continue in the next PC_to_RDR_XfrBlock */
|
||||
#define CCID_WLEVEL_CHAIN_END __constant_cpu_to_le16(2) /* abData field continues a command APDU and ends the APDU command */
|
||||
#define CCID_WLEVEL_CHAIN_CONTINUE __constant_cpu_to_le16(3) /* abData field continues a command APDU and another block is to follow */
|
||||
#define CCID_WLEVEL_RESPONSE_IN_DATABLOCK __constant_cpu_to_le16(0x10) /* empty abData field, continuation of response APDU is expected in the next RDR_to_PC_DataBlock */
|
||||
#define CCID_WLEVEL_DIRECT __constant_cpu_to_le16(0) /** APDU begins and ends with this command */
|
||||
#define CCID_WLEVEL_CHAIN_NEXT_XFRBLOCK __constant_cpu_to_le16(1) /** APDU begins with this command, and continue in the next PC_to_RDR_XfrBlock */
|
||||
#define CCID_WLEVEL_CHAIN_END __constant_cpu_to_le16(2) /** abData field continues a command APDU and ends the APDU command */
|
||||
#define CCID_WLEVEL_CHAIN_CONTINUE __constant_cpu_to_le16(3) /** abData field continues a command APDU and another block is to follow */
|
||||
#define CCID_WLEVEL_RESPONSE_IN_DATABLOCK __constant_cpu_to_le16(0x10) /** empty abData field, continuation of response APDU is expected in the next RDR_to_PC_DataBlock */
|
||||
|
||||
#define CCID_PIN_ENCODING_BIN 0x00
|
||||
#define CCID_PIN_ENCODING_BCD 0x01
|
||||
@@ -275,7 +278,7 @@ struct hid_class_descriptor {
|
||||
* @param[in] cdriver Card driver to be used (optional)
|
||||
* @param[in] verbose Verbosity level passed to \c sc_context_t
|
||||
*
|
||||
* @return \c SC_SUCCESS or error code if an error occurred
|
||||
* @return \c SC_SUCCESS or error code if an error occurred
|
||||
*/
|
||||
int ccid_initialize(int reader_id, const char *cdriver, int verbose);
|
||||
|
||||
@@ -293,7 +296,7 @@ void ccid_shutdown();
|
||||
*
|
||||
* @param[in] inbuf input buffer (command pipe bulk-OUT message)
|
||||
* @param[in] inlen length of \a inbuf
|
||||
* @param[in,out] outbuf where to save the output buffer (resoponse pipe bulk-IN message), memory is reused via realloc()
|
||||
* @param[in,out] outbuf where to save the output buffer (resoponse pipe bulk-IN message), memory is reused via \c realloc()
|
||||
*
|
||||
* @return length of \a outbuf or -1 if an error occurred
|
||||
*/
|
||||
@@ -305,7 +308,7 @@ int ccid_parse_bulkout(const __u8* inbuf, size_t inlen, __u8** outbuf);
|
||||
* Parses CCID class-specific requests according to CCID Rev 1.1 section 5.3
|
||||
*
|
||||
* @param[in] setup input from control pipe
|
||||
* @param[in,out] outbuf where to save the output buffer, memory is reused via realloc()
|
||||
* @param[in,out] outbuf where to save the output buffer, memory is reused via \c realloc()
|
||||
*
|
||||
* @return length of \a outbuf or -1 if an error occurred
|
||||
*/
|
||||
@@ -316,7 +319,7 @@ int ccid_parse_control(struct usb_ctrlrequest *setup, __u8 **outbuf);
|
||||
*
|
||||
* @param[in,out] slotchange where to save the output
|
||||
* @param[in] timeout currently not used
|
||||
* @note ccid_state_changed() must be called periodically. Because the OpenSC implementation of sc_wait_for_event() blocks all other operations with the reader, it can't be used for slot state detection.
|
||||
* @note ccid_state_changed() must be called periodically. Because the OpenSC implementation of \c sc_wait_for_event() blocks all other operations with the reader, it can't be used for slot state detection.
|
||||
*
|
||||
* @return 1 if a card is present and/or the state is changed or 0
|
||||
*/
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* ccid. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
#ifndef _CCID_PACE_H
|
||||
#define _CCID_PACE_H
|
||||
|
||||
@@ -67,19 +70,32 @@ extern "C" {
|
||||
const char *pace_secret_name(enum s_type pin_id);
|
||||
|
||||
|
||||
/**
|
||||
* Input data for EstablishPACEChannel()
|
||||
*/
|
||||
struct establish_pace_channel_input {
|
||||
/** Type of secret. You may use <tt>enum s_type</tt> from \c <openssl/pace.h> */
|
||||
unsigned char pin_id;
|
||||
|
||||
/** Length of card holder authorization template */
|
||||
size_t chat_length;
|
||||
/** Card holder authorization template */
|
||||
const unsigned char *chat;
|
||||
|
||||
/** Length of secret */
|
||||
size_t pin_length;
|
||||
/** Secret */
|
||||
const unsigned char *pin;
|
||||
|
||||
/** Length of certificate description */
|
||||
size_t certificate_description_length;
|
||||
/** Certificate description */
|
||||
const unsigned char *certificate_description;
|
||||
};
|
||||
|
||||
/**
|
||||
* Output data for EstablishPACEChannel()
|
||||
*/
|
||||
struct establish_pace_channel_output {
|
||||
unsigned int result;
|
||||
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* ccid. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
#ifndef _CCID_PACE_LIB_H
|
||||
#define _CCID_PACE_LIB_H
|
||||
|
||||
@@ -25,17 +28,47 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** PACE secure messaging context */
|
||||
struct pace_sm_ctx {
|
||||
/** Send sequence counter */
|
||||
BIGNUM *ssc;
|
||||
/** Key for message authentication code */
|
||||
const BUF_MEM *key_mac;
|
||||
/** Key for encryption and decryption */
|
||||
const BUF_MEM *key_enc;
|
||||
/** PACE context */
|
||||
PACE_CTX *ctx;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Creates a PACE SM object
|
||||
*
|
||||
* @param[in] key_mac Key for message authentication code
|
||||
* @param[in] key_enc Key for encryption and decryption
|
||||
* @param[in] ctx PACE context
|
||||
*
|
||||
* @return Initialized PACE SM object or NULL, if an error occurred
|
||||
*/
|
||||
struct pace_sm_ctx * pace_sm_ctx_create(const BUF_MEM *key_mac,
|
||||
const BUF_MEM *key_enc, PACE_CTX *ctx);
|
||||
|
||||
/**
|
||||
* @brief Frees a PACE SM object
|
||||
*
|
||||
* Frees memory allocated for \a ctx and its send sequence counter
|
||||
*
|
||||
* @param[in] ctx object to be freed
|
||||
*/
|
||||
void pace_sm_ctx_free(struct pace_sm_ctx *ctx);
|
||||
|
||||
/**
|
||||
* @brief Frees a PACE SM object and all its components
|
||||
*
|
||||
* Frees memory allocated for \a ctx and its send sequence counter, keys and PACE context
|
||||
*
|
||||
* @param[in] ctx object to be freed
|
||||
*/
|
||||
void pace_sm_ctx_clear_free(struct pace_sm_ctx *ctx);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -16,23 +16,77 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* ccid. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
#ifndef _CCID_SCUTIL_H
|
||||
#define _CCID_SCUTIL_H
|
||||
|
||||
#include <opensc/opensc.h>
|
||||
|
||||
/**
|
||||
* @brief Initializes smart card context and reader
|
||||
*
|
||||
* @param[in] reader_id Index to the reader to be used (optional). Set to -1 to use a reader with a inserted card.
|
||||
* @param[in] cdriver Card driver to be used (optional)
|
||||
* @param[in] verbose verbosity level passed to \c sc_context_t
|
||||
* @param[in,out] ctx Where to write the sc context
|
||||
* @param[in,out] reader Where to write the reader context
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
int initialize(int reader_id, const char *cdriver, int verbose,
|
||||
sc_context_t **ctx, sc_reader_t **reader);
|
||||
|
||||
/**
|
||||
* @brief Parse an APDU buffer
|
||||
*
|
||||
* @param[in] ctx sc context
|
||||
* @param[in] buf Buffer of APDU
|
||||
* @param[in] len Length of \a buf
|
||||
* @param [in,out] apdu Where to write the initialized APDU
|
||||
*
|
||||
* @return \c SC_SUCCESS or error code if an error occurred
|
||||
*/
|
||||
int build_apdu(sc_context_t *ctx, const u8 *buf, size_t len, sc_apdu_t *apdu);
|
||||
|
||||
/**
|
||||
* @brief Print binary data to a file stream
|
||||
*
|
||||
* @param[in] file File for printing
|
||||
* @param[in] label Label to prepend to the buffer
|
||||
* @param[in] data Binary data
|
||||
* @param[in] len Length of \a data
|
||||
*/
|
||||
#define bin_print(file, label, data, len) \
|
||||
_bin_log(NULL, 0, NULL, 0, NULL, label, data, len, file)
|
||||
/**
|
||||
* @brief Log binary data to a sc context
|
||||
*
|
||||
* @param[in] ctx Context for logging
|
||||
* @param[in] label Label to prepend to the buffer
|
||||
* @param[in] data Binary data
|
||||
* @param[in] len Length of \a data
|
||||
*/
|
||||
#define bin_log(ctx, label, data, len) \
|
||||
_bin_log(ctx, SC_LOG_TYPE_DEBUG, __FILE__, __LINE__, __FUNCTION__, label, data, len, NULL)
|
||||
/**
|
||||
* @brief Log binary data
|
||||
*
|
||||
* Either choose \a ctx or \a file for logging
|
||||
*
|
||||
* @param[in] ctx (optional) Context for logging
|
||||
* @param[in] type Debug level
|
||||
* @param[in] file File name to be prepended
|
||||
* @param[in] line Line to be prepended
|
||||
* @param[in] func Function to be prepended
|
||||
* @param[in] label label to prepend to the buffer
|
||||
* @param[in] data binary data
|
||||
* @param[in] len length of \a data
|
||||
* @param[in] f (optional) File for printing
|
||||
*/
|
||||
void _bin_log(sc_context_t *ctx, int type, const char *file, int line,
|
||||
const char *func, const char *label, const u8 *data, size_t len,
|
||||
FILE *f);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -16,6 +16,9 @@
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* ccid. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
/**
|
||||
* @file
|
||||
*/
|
||||
#ifndef _CCID_SM_H
|
||||
#define _CCID_SM_H
|
||||
|
||||
@@ -40,25 +43,52 @@ struct sm_ctx {
|
||||
/** Pad to this block length */
|
||||
size_t block_length;
|
||||
|
||||
/** Authentication context for the specific authentication implementation */
|
||||
void *authentication_ctx;
|
||||
/** Call back function for authentication of data */
|
||||
int (*authenticate)(sc_card_t *card, const struct sm_ctx *ctx,
|
||||
const u8 *data, size_t datalen, u8 **outdata);
|
||||
/** Call back function for verifying authentication data */
|
||||
int (*verify_authentication)(sc_card_t *card, const struct sm_ctx *ctx,
|
||||
const u8 *mac, size_t maclen,
|
||||
const u8 *macdata, size_t macdatalen);
|
||||
|
||||
/** Cipher context for the specific cipher implementation */
|
||||
void *cipher_ctx;
|
||||
/** Call back function for encryption of data */
|
||||
int (*encrypt)(sc_card_t *card, const struct sm_ctx *ctx,
|
||||
const u8 *data, size_t datalen, u8 **enc);
|
||||
/** Call back function for decryption of data */
|
||||
int (*decrypt)(sc_card_t *card, const struct sm_ctx *ctx,
|
||||
const u8 *enc, size_t enclen, u8 **data);
|
||||
|
||||
/** Call back function for actions before encoding and encryption of \a apdu */
|
||||
int (*pre_transmit)(sc_card_t *card, const struct sm_ctx *ctx,
|
||||
sc_apdu_t *apdu);
|
||||
/** Call back function for actions before decryption and decoding of \a sm_apdu */
|
||||
int (*post_transmit)(sc_card_t *card, const struct sm_ctx *ctx,
|
||||
sc_apdu_t *sm_apdu);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Secure messaging wrapper for sc_transmit_apdu()
|
||||
*
|
||||
* If secure messaging (SM) is activated in \a sctx and \a apdu is not already
|
||||
* SM protected, \a apdu is processed with the following steps:
|
||||
* \li call to \a sctx->pre_transmit
|
||||
* \li encrypt \a apdu calling \a sctx->encrypt
|
||||
* \li authenticate \a apdu calling \a sctx->authenticate
|
||||
* \li transmit SM protected \a apdu
|
||||
* \li verify SM protected \a apdu calling \a sctx->verify_authentication
|
||||
* \li decrypt SM protected \a apdu calling \a sctx->decrypt
|
||||
* \li copy decrypted/authenticated data and status bytes to \a apdu
|
||||
*
|
||||
* @param[in] sctx
|
||||
* @param[in] card
|
||||
* @param[in,out] apdu
|
||||
*
|
||||
* @return \c SC_SUCCESS or error code if an error occurred
|
||||
*/
|
||||
int sm_transmit_apdu(struct sm_ctx *sctx, sc_card_t *card,
|
||||
sc_apdu_t *apdu);
|
||||
|
||||
|
||||
@@ -564,8 +564,6 @@ static int sm_decrypt(const struct sm_ctx *ctx, sc_card_t *card,
|
||||
apdu->resp, apdu->resplen);
|
||||
}
|
||||
|
||||
/* XXX verify mac */
|
||||
|
||||
r = SC_SUCCESS;
|
||||
|
||||
err:
|
||||
|
||||
Reference in New Issue
Block a user