mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-10 13:04:23 +01:00
scd:p15: Prepare AODF parsing for other authentication types.
* scd/app-p15.c (auth_type_t): New. (struct aodf_object_s): Add field auth_type. (read_ef_aodf): Distinguish between pin and authkey types. Include the authtype in the verbose mode diags. -- Note that the bulk of changes are just indentation changes. There should be no functional change. Signed-off-by: Werner Koch <wk@gnupg.org> (cherry picked from commit e387cc97c82313457e4f79729a137e5871891bc1)
This commit is contained in:
parent
80cf64c651
commit
29fd805818
131
scd/app-p15.c
131
scd/app-p15.c
@ -156,6 +156,14 @@ typedef enum
|
||||
PIN_TYPE_ISO9564_1 = 4
|
||||
} pin_type_t;
|
||||
|
||||
/* The AuthenticationTypes as defined in pkcs#15 v1.1 (6.8.1) */
|
||||
typedef enum
|
||||
{
|
||||
AUTH_TYPE_PIN = -1,
|
||||
AUTH_TYPE_BIOMETRIC = 0,
|
||||
AUTH_TYPE_AUTHKEY = 1,
|
||||
AUTH_TYPE_EXTERNAL = 2,
|
||||
} auth_type_t;
|
||||
|
||||
/* A bit array with for the key usage flags from the
|
||||
commonKeyAttributes. */
|
||||
@ -376,6 +384,11 @@ struct aodf_object_s
|
||||
/* The file ID of this AODF. */
|
||||
unsigned short fid;
|
||||
|
||||
/* The type of this authentication object. */
|
||||
auth_type_t auth_type;
|
||||
|
||||
/* Info used for AUTH_TYPE_PIN: */
|
||||
|
||||
/* The PIN Flags. */
|
||||
struct
|
||||
{
|
||||
@ -423,6 +436,9 @@ struct aodf_object_s
|
||||
may be NULL. Malloced.*/
|
||||
size_t pathlen;
|
||||
unsigned short *path;
|
||||
|
||||
/* Info used for AUTH_TYPE_AUTHKEY: */
|
||||
|
||||
};
|
||||
typedef struct aodf_object_s *aodf_object_t;
|
||||
|
||||
@ -2638,37 +2654,46 @@ read_ef_cdf (app_t app, unsigned short fid, int cdftype, cdf_object_t *result)
|
||||
|
||||
|
||||
/*
|
||||
SEQUENCE {
|
||||
SEQUENCE { -- CommonObjectAttributes
|
||||
UTF8String 'specific PIN for DS'
|
||||
BIT STRING 0 unused bits
|
||||
'00000011'B
|
||||
}
|
||||
SEQUENCE { -- CommonAuthenticationObjectAttributes
|
||||
OCTET STRING
|
||||
07 -- iD
|
||||
}
|
||||
|
||||
[1] { -- typeAttributes
|
||||
SEQUENCE { -- PinAttributes
|
||||
BIT STRING 0 unused bits
|
||||
'0000100000110010'B -- local,initialized,needs-padding
|
||||
-- exchangeRefData
|
||||
ENUMERATED 1 -- ascii-numeric
|
||||
INTEGER 6 -- minLength
|
||||
INTEGER 6 -- storedLength
|
||||
INTEGER 8 -- maxLength
|
||||
[0]
|
||||
02 -- pinReference
|
||||
GeneralizedTime 19/04/2002 12:12 GMT -- lastPinChange
|
||||
SEQUENCE {
|
||||
OCTET STRING
|
||||
3F 00 40 16 -- path to DF of PIN
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
* SEQUENCE {
|
||||
* SEQUENCE { -- CommonObjectAttributes
|
||||
* UTF8String 'specific PIN for DS'
|
||||
* BIT STRING 0 unused bits
|
||||
* '00000011'B
|
||||
* }
|
||||
* SEQUENCE { -- CommonAuthenticationObjectAttributes
|
||||
* OCTET STRING
|
||||
* 07 -- iD
|
||||
* }
|
||||
*
|
||||
* [1] { -- typeAttributes
|
||||
* SEQUENCE { -- PinAttributes
|
||||
* BIT STRING 0 unused bits
|
||||
* '0000100000110010'B -- local,initialized,needs-padding
|
||||
* -- exchangeRefData
|
||||
* ENUMERATED 1 -- ascii-numeric
|
||||
* INTEGER 6 -- minLength
|
||||
* INTEGER 6 -- storedLength
|
||||
* INTEGER 8 -- maxLength
|
||||
* [0]
|
||||
* 02 -- pinReference
|
||||
* GeneralizedTime 19/04/2002 12:12 GMT -- lastPinChange
|
||||
* SEQUENCE {
|
||||
* OCTET STRING
|
||||
* 3F 00 40 16 -- path to DF of PIN
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*
|
||||
* Or for an authKey:
|
||||
*
|
||||
* [1] { -- typeAttributes
|
||||
* SEQUENCE { -- AuthKeyAttributes
|
||||
* BOOLEAN TRUE -- derivedKey
|
||||
* OCTET STRING 02 -- authKeyId
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
/* Read and parse an Authentication Object Directory File identified
|
||||
by FID. On success a newlist of AODF objects gets stored at RESULT
|
||||
@ -2705,6 +2730,7 @@ read_ef_aodf (app_t app, unsigned short fid, aodf_object_t *result)
|
||||
size_t nn;
|
||||
int where;
|
||||
const char *errstr = NULL;
|
||||
auth_type_t auth_type;
|
||||
aodf_object_t aodf = NULL;
|
||||
unsigned long ul;
|
||||
const char *s;
|
||||
@ -2717,13 +2743,14 @@ read_ef_aodf (app_t app, unsigned short fid, aodf_object_t *result)
|
||||
else if (objlen > n)
|
||||
err = gpg_error (GPG_ERR_INV_OBJ);
|
||||
else if (class == CLASS_UNIVERSAL && tag == TAG_SEQUENCE)
|
||||
; /* PinAttributes */
|
||||
auth_type = AUTH_TYPE_PIN; /* PinAttributes */
|
||||
else if (class == CLASS_CONTEXT && tag == 1 )
|
||||
auth_type = AUTH_TYPE_AUTHKEY; /* AuthKeyAttributes */
|
||||
else if (class == CLASS_CONTEXT)
|
||||
{
|
||||
switch (tag)
|
||||
{
|
||||
case 0: errstr = "biometric auth types are not supported"; break;
|
||||
case 1: errstr = "authKey auth types are not supported"; break;
|
||||
case 2: errstr = "external auth type are not supported"; break;
|
||||
default: errstr = "unknown privateKeyObject"; break;
|
||||
}
|
||||
@ -2735,7 +2762,6 @@ read_ef_aodf (app_t app, unsigned short fid, aodf_object_t *result)
|
||||
goto parse_error;
|
||||
}
|
||||
|
||||
|
||||
if (err)
|
||||
{
|
||||
log_error ("p15: error parsing AODF record: %s\n",
|
||||
@ -2752,6 +2778,7 @@ read_ef_aodf (app_t app, unsigned short fid, aodf_object_t *result)
|
||||
if (!aodf)
|
||||
goto no_core;
|
||||
aodf->fid = fid;
|
||||
aodf->auth_type = auth_type;
|
||||
|
||||
/* Parse the commonObjectAttributes. */
|
||||
where = __LINE__;
|
||||
@ -2810,7 +2837,7 @@ read_ef_aodf (app_t app, unsigned short fid, aodf_object_t *result)
|
||||
else if (!err && objlen > nn)
|
||||
err = gpg_error (GPG_ERR_INV_OBJ);
|
||||
else if (class == CLASS_UNIVERSAL && tag == TAG_SEQUENCE)
|
||||
; /* A typeAttribute always starts with a sequence */
|
||||
; /* Okay */
|
||||
else
|
||||
err = gpg_error (GPG_ERR_INV_OBJ);
|
||||
if (err)
|
||||
@ -2818,6 +2845,8 @@ read_ef_aodf (app_t app, unsigned short fid, aodf_object_t *result)
|
||||
|
||||
nn = objlen;
|
||||
|
||||
if (auth_type == AUTH_TYPE_PIN)
|
||||
{
|
||||
/* PinFlags */
|
||||
where = __LINE__;
|
||||
err = parse_ber_header (&pp, &nn, &class, &tag, &constructed,
|
||||
@ -2898,7 +2927,6 @@ read_ef_aodf (app_t app, unsigned short fid, aodf_object_t *result)
|
||||
nn -= objlen;
|
||||
}
|
||||
|
||||
|
||||
/* PinType */
|
||||
where = __LINE__;
|
||||
err = parse_ber_header (&pp, &nn, &class, &tag, &constructed,
|
||||
@ -2919,7 +2947,6 @@ read_ef_aodf (app_t app, unsigned short fid, aodf_object_t *result)
|
||||
}
|
||||
aodf->pintype = ul;
|
||||
|
||||
|
||||
/* minLength */
|
||||
where = __LINE__;
|
||||
err = parse_ber_header (&pp, &nn, &class, &tag, &constructed,
|
||||
@ -2939,7 +2966,6 @@ read_ef_aodf (app_t app, unsigned short fid, aodf_object_t *result)
|
||||
}
|
||||
aodf->min_length = ul;
|
||||
|
||||
|
||||
/* storedLength */
|
||||
where = __LINE__;
|
||||
err = parse_ber_header (&pp, &nn, &class, &tag, &constructed,
|
||||
@ -3080,10 +3106,10 @@ read_ef_aodf (app_t app, unsigned short fid, aodf_object_t *result)
|
||||
if (err)
|
||||
goto parse_error;
|
||||
|
||||
/* Make sure that the next element is a non zero FID and of
|
||||
even length (FID are two bytes each). */
|
||||
/* Make sure that the next element has a path of even
|
||||
* length (FIDs are two bytes each). */
|
||||
if (class != CLASS_UNIVERSAL || tag != TAG_OCTET_STRING
|
||||
|| !objlen || (objlen & 1) )
|
||||
|| (objlen & 1) )
|
||||
{
|
||||
errstr = "invalid path reference";
|
||||
goto parse_error;
|
||||
@ -3101,10 +3127,12 @@ read_ef_aodf (app_t app, unsigned short fid, aodf_object_t *result)
|
||||
/* An index and length follows. */
|
||||
aodf->have_off = 1;
|
||||
where = __LINE__;
|
||||
err = parse_ber_header (&ppp, &nnn, &class, &tag, &constructed,
|
||||
err = parse_ber_header (&ppp, &nnn, &class, &tag,
|
||||
&constructed,
|
||||
&ndef, &objlen, &hdrlen);
|
||||
if (!err && (objlen > nnn
|
||||
|| class != CLASS_UNIVERSAL || tag != TAG_INTEGER))
|
||||
|| class != CLASS_UNIVERSAL
|
||||
|| tag != TAG_INTEGER))
|
||||
err = gpg_error (GPG_ERR_INV_OBJ);
|
||||
if (err)
|
||||
goto parse_error;
|
||||
@ -3118,7 +3146,8 @@ read_ef_aodf (app_t app, unsigned short fid, aodf_object_t *result)
|
||||
aodf->off = ul;
|
||||
|
||||
where = __LINE__;
|
||||
err = parse_ber_header (&ppp, &nnn, &class, &tag, &constructed,
|
||||
err = parse_ber_header (&ppp, &nnn, &class, &tag,
|
||||
&constructed,
|
||||
&ndef, &objlen, &hdrlen);
|
||||
if (!err && (objlen > nnn
|
||||
|| class != CLASS_CONTEXT || tag != 0))
|
||||
@ -3135,6 +3164,11 @@ read_ef_aodf (app_t app, unsigned short fid, aodf_object_t *result)
|
||||
aodf->len = ul;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (auth_type == AUTH_TYPE_AUTHKEY)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/* Ignore further objects which might be there due to future
|
||||
extensions of pkcs#15. */
|
||||
@ -3150,6 +3184,9 @@ read_ef_aodf (app_t app, unsigned short fid, aodf_object_t *result)
|
||||
if (aodf->label)
|
||||
log_printf (" (%s)", aodf->label);
|
||||
log_info ("p15: ");
|
||||
log_printf (" %s",
|
||||
aodf->auth_type == AUTH_TYPE_PIN? "pin" :
|
||||
aodf->auth_type == AUTH_TYPE_AUTHKEY? "authkey" : "?");
|
||||
if (aodf->pathlen)
|
||||
{
|
||||
log_printf (" path=");
|
||||
@ -3164,6 +3201,8 @@ read_ef_aodf (app_t app, unsigned short fid, aodf_object_t *result)
|
||||
for (i=0; i < aodf->authidlen; i++)
|
||||
log_printf ("%02X", aodf->authid[i]);
|
||||
}
|
||||
if (aodf->auth_type == AUTH_TYPE_PIN)
|
||||
{
|
||||
if (aodf->pin_reference_valid)
|
||||
log_printf (" pinref=0x%02lX", aodf->pin_reference);
|
||||
log_printf (" min=%lu", aodf->min_length);
|
||||
@ -3216,6 +3255,10 @@ read_ef_aodf (app_t app, unsigned short fid, aodf_object_t *result)
|
||||
}
|
||||
log_printf ("%stype=%s", s, s2); s = ",";
|
||||
}
|
||||
}
|
||||
else if (aodf->auth_type == AUTH_TYPE_AUTHKEY)
|
||||
{
|
||||
}
|
||||
log_printf ("\n");
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user