pkcs15: new procedure to find an Auth PKCS#15 object (PIN) by flags
This commit is contained in:
parent
343fa20a00
commit
bf752f3c61
|
@ -166,6 +166,7 @@ sc_pkcs15_find_data_object_by_id
|
|||
sc_pkcs15_find_data_object_by_name
|
||||
sc_pkcs15_find_object_by_id
|
||||
sc_pkcs15_find_pin_by_auth_id
|
||||
sc_pkcs15_find_pin_by_flags
|
||||
sc_pkcs15_find_pin_by_reference
|
||||
sc_pkcs15_find_prkey_by_id
|
||||
sc_pkcs15_find_prkey_by_id_usage
|
||||
|
|
|
@ -1389,9 +1389,50 @@ int sc_pkcs15_find_pin_by_type_and_reference(struct sc_pkcs15_card *p15card,
|
|||
return SC_ERROR_OBJECT_NOT_FOUND;
|
||||
}
|
||||
|
||||
int sc_pkcs15_find_data_object_by_id(struct sc_pkcs15_card *p15card,
|
||||
const struct sc_pkcs15_id *id,
|
||||
struct sc_pkcs15_object **out)
|
||||
|
||||
int
|
||||
sc_pkcs15_find_pin_by_flags(struct sc_pkcs15_card *p15card,
|
||||
unsigned flags, unsigned mask, int *index,
|
||||
struct sc_pkcs15_object **out)
|
||||
{
|
||||
sc_context_t *ctx = p15card->card->ctx;
|
||||
struct sc_pkcs15_object *auths[SC_PKCS15_MAX_PINS];
|
||||
int r, i, num, idx = 0;
|
||||
|
||||
LOG_FUNC_CALLED(ctx);
|
||||
sc_log(ctx, "Find PIN flags:0x%X, mask:0x%X, index:%i", flags, mask, index ? *index : -1);
|
||||
if (index)
|
||||
idx = *index;
|
||||
/* Get authentication PKCS#15 objects that are present in the given application */
|
||||
r = sc_pkcs15_get_objects(p15card, SC_PKCS15_TYPE_AUTH_PIN, auths, SC_PKCS15_MAX_PINS);
|
||||
if (r < 0)
|
||||
return r;
|
||||
num = r;
|
||||
|
||||
for (i=idx; i<num; i++) {
|
||||
struct sc_pkcs15_auth_info *pin_info = (struct sc_pkcs15_auth_info *)(*(auths + i))->data;
|
||||
|
||||
if (!pin_info || pin_info->auth_type != SC_PKCS15_PIN_AUTH_TYPE_PIN)
|
||||
continue;
|
||||
|
||||
if ((pin_info->attrs.pin.flags & mask) != flags)
|
||||
continue;
|
||||
|
||||
if (out)
|
||||
*out = *(auths + i);
|
||||
if (index)
|
||||
*index = i;
|
||||
|
||||
LOG_FUNC_RETURN(ctx, SC_SUCCESS);
|
||||
}
|
||||
|
||||
LOG_FUNC_RETURN(ctx, SC_ERROR_OBJECT_NOT_FOUND);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
sc_pkcs15_find_data_object_by_id(struct sc_pkcs15_card *p15card,
|
||||
const struct sc_pkcs15_id *id, struct sc_pkcs15_object **out)
|
||||
{
|
||||
return sc_pkcs15_find_object_by_id(p15card, SC_PKCS15_TYPE_DATA_OBJECT, id, out);
|
||||
}
|
||||
|
|
|
@ -63,6 +63,27 @@ typedef struct sc_pkcs15_id sc_pkcs15_id_t;
|
|||
#define SC_PKCS15_PIN_FLAG_CONFIDENTIALITY_PROTECTED 0x0400
|
||||
#define SC_PKCS15_PIN_FLAG_EXCHANGE_REF_DATA 0x0800
|
||||
|
||||
#define SC_PKCS15_PIN_TYPE_FLAGS_MASK \
|
||||
( SC_PKCS15_PIN_FLAG_LOCAL | SC_PKCS15_PIN_FLAG_INITIALIZED \
|
||||
| SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN | SC_PKCS15_PIN_FLAG_SO_PIN )
|
||||
|
||||
#define SC_PKCS15_PIN_TYPE_FLAGS_SOPIN \
|
||||
( SC_PKCS15_PIN_FLAG_SO_PIN | SC_PKCS15_PIN_FLAG_INITIALIZED )
|
||||
|
||||
#define SC_PKCS15_PIN_TYPE_FLAGS_PIN_GLOBAL \
|
||||
( SC_PKCS15_PIN_FLAG_INITIALIZED )
|
||||
|
||||
#define SC_PKCS15_PIN_TYPE_FLAGS_PIN_LOCAL \
|
||||
( SC_PKCS15_PIN_FLAG_INITIALIZED | SC_PKCS15_PIN_FLAG_LOCAL)
|
||||
|
||||
#define SC_PKCS15_PIN_TYPE_FLAGS_PUK_GLOBAL \
|
||||
( SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN \
|
||||
| SC_PKCS15_PIN_FLAG_INITIALIZED )
|
||||
|
||||
#define SC_PKCS15_PIN_TYPE_FLAGS_PUK_LOCAL \
|
||||
( SC_PKCS15_PIN_FLAG_UNBLOCKING_PIN \
|
||||
| SC_PKCS15_PIN_FLAG_INITIALIZED | SC_PKCS15_PIN_FLAG_LOCAL)
|
||||
|
||||
#define SC_PKCS15_PIN_TYPE_BCD 0
|
||||
#define SC_PKCS15_PIN_TYPE_ASCII_NUMERIC 1
|
||||
#define SC_PKCS15_PIN_TYPE_UTF8 2
|
||||
|
@ -683,15 +704,18 @@ int sc_pkcs15_find_pin_by_reference(struct sc_pkcs15_card *card,
|
|||
const sc_path_t *path, int reference,
|
||||
struct sc_pkcs15_object **out);
|
||||
int sc_pkcs15_find_pin_by_type_and_reference(struct sc_pkcs15_card *card,
|
||||
const sc_path_t *path, unsigned auth_method,
|
||||
const sc_path_t *path, unsigned auth_method,
|
||||
int reference,
|
||||
struct sc_pkcs15_object **out);
|
||||
int sc_pkcs15_find_so_pin(struct sc_pkcs15_card *card,
|
||||
struct sc_pkcs15_object **out);
|
||||
int sc_pkcs15_find_pin_by_flags(struct sc_pkcs15_card *p15card,
|
||||
unsigned flags, unsigned mask, int *index,
|
||||
struct sc_pkcs15_object **out);
|
||||
|
||||
void sc_pkcs15_pincache_add(struct sc_pkcs15_card *, struct sc_pkcs15_object *,
|
||||
void sc_pkcs15_pincache_add(struct sc_pkcs15_card *, struct sc_pkcs15_object *,
|
||||
const u8 *, size_t);
|
||||
int sc_pkcs15_pincache_revalidate(struct sc_pkcs15_card *p15card,
|
||||
int sc_pkcs15_pincache_revalidate(struct sc_pkcs15_card *p15card,
|
||||
const sc_pkcs15_object_t *obj);
|
||||
void sc_pkcs15_pincache_clear(struct sc_pkcs15_card *p15card);
|
||||
|
||||
|
|
Loading…
Reference in New Issue