"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/keyinfo.c" between
libksba-1.5.1.tar.bz2 and libksba-1.6.0.tar.bz2

About: KSBA is a library to make the tasks of working with X.509 certificates, CMS data and related objects more easy.

keyinfo.c  (libksba-1.5.1.tar.bz2):keyinfo.c  (libksba-1.6.0.tar.bz2)
skipping to change at line 531 skipping to change at line 531
/* Return the OFF and the LEN of algorithm within DER. Do some checks /* Return the OFF and the LEN of algorithm within DER. Do some checks
and return the number of bytes read in r_nread, adding this to der and return the number of bytes read in r_nread, adding this to der
does point into the BIT STRING. does point into the BIT STRING.
mode 0: just get the algorithm identifier. FIXME: should be able to mode 0: just get the algorithm identifier. FIXME: should be able to
handle BER Encoding. handle BER Encoding.
mode 1: as described. mode 1: as described.
*/ */
static gpg_error_t static gpg_error_t
get_algorithm (int mode, const unsigned char *der, size_t derlen, get_algorithm (int mode, const unsigned char *der, size_t derlen, int firsttag,
size_t *r_nread, size_t *r_pos, size_t *r_len, int *r_bitstr, size_t *r_nread, size_t *r_pos, size_t *r_len, int *r_bitstr,
size_t *r_parm_pos, size_t *r_parm_len, int *r_parm_type) size_t *r_parm_pos, size_t *r_parm_len, int *r_parm_type)
{ {
int c; int c;
const unsigned char *start = der; const unsigned char *start = der;
const unsigned char *startseq; const unsigned char *startseq;
unsigned long seqlen, len; unsigned long seqlen, len;
*r_bitstr = 0; *r_bitstr = 0;
if (r_parm_pos) if (r_parm_pos)
*r_parm_pos = 0; *r_parm_pos = 0;
if (r_parm_len) if (r_parm_len)
*r_parm_len = 0; *r_parm_len = 0;
if (r_parm_type) if (r_parm_type)
*r_parm_type = 0; *r_parm_type = 0;
/* get the inner sequence */ /* get the inner sequence */
if (!derlen) if (!derlen)
return gpg_error (GPG_ERR_INV_KEYINFO); return gpg_error (GPG_ERR_INV_KEYINFO);
c = *der++; derlen--; c = *der++; derlen--;
if ( c != 0x30 ) if ( c != firsttag )
return gpg_error (GPG_ERR_UNEXPECTED_TAG); /* not a SEQUENCE */ return gpg_error (GPG_ERR_UNEXPECTED_TAG); /* not a SEQUENCE or whatever */
TLV_LENGTH(der); TLV_LENGTH(der);
seqlen = len; seqlen = len;
startseq = der; startseq = der;
/* get the object identifier */ /* get the object identifier */
if (!derlen) if (!derlen)
return gpg_error (GPG_ERR_INV_KEYINFO); return gpg_error (GPG_ERR_INV_KEYINFO);
c = *der++; derlen--; c = *der++; derlen--;
if ( c != 0x06 ) if ( c != 0x06 )
return gpg_error (GPG_ERR_UNEXPECTED_TAG); /* not an OBJECT IDENTIFIER */ return gpg_error (GPG_ERR_UNEXPECTED_TAG); /* not an OBJECT IDENTIFIER */
skipping to change at line 669 skipping to change at line 669
} }
*r_nread = der - start; *r_nread = der - start;
return 0; return 0;
} }
gpg_error_t gpg_error_t
_ksba_parse_algorithm_identifier (const unsigned char *der, size_t derlen, _ksba_parse_algorithm_identifier (const unsigned char *der, size_t derlen,
size_t *r_nread, char **r_oid) size_t *r_nread, char **r_oid)
{ {
return _ksba_parse_algorithm_identifier2 (der, derlen, return _ksba_parse_algorithm_identifier3 (der, derlen, 0x30,
r_nread, r_oid, NULL, NULL); r_nread, r_oid, NULL, NULL, NULL);
} }
/* Note that R_NREAD, R_PARM, and R_PARMLEN are optional. */
gpg_error_t gpg_error_t
_ksba_parse_algorithm_identifier2 (const unsigned char *der, size_t derlen, _ksba_parse_algorithm_identifier2 (const unsigned char *der, size_t derlen,
size_t *r_nread, char **r_oid, size_t *r_nread, char **r_oid,
char **r_parm, size_t *r_parmlen) char **r_parm, size_t *r_parmlen)
{ {
return _ksba_parse_algorithm_identifier3 (der, derlen, 0x30,
r_nread, r_oid,
r_parm, r_parmlen, NULL);
}
/* Note that R_NREAD, R_PARM, and R_PARMLEN are optional. */
gpg_error_t
_ksba_parse_algorithm_identifier3 (const unsigned char *der, size_t derlen,
int firsttag,
size_t *r_nread, char **r_oid,
char **r_parm, size_t *r_parmlen,
int *r_parmtype)
{
gpg_error_t err; gpg_error_t err;
int is_bitstr; int is_bitstr;
size_t nread, off, len, off2, len2; size_t nread, off, len, off2, len2;
int parm_type; int parm_type;
/* fixme: get_algorithm might return the error invalid keyinfo - /* fixme: get_algorithm might return the error invalid keyinfo -
this should be invalid algorithm identifier */ this should be invalid algorithm identifier */
*r_oid = NULL; *r_oid = NULL;
if (r_nread) if (r_nread)
*r_nread = 0; *r_nread = 0;
off2 = len2 = 0; off2 = len2 = 0;
err = get_algorithm (0, der, derlen, &nread, &off, &len, &is_bitstr, err = get_algorithm (0, der, derlen, firsttag,
&nread, &off, &len, &is_bitstr,
&off2, &len2, &parm_type); &off2, &len2, &parm_type);
if (err) if (err)
return err; return err;
if (r_nread) if (r_nread)
*r_nread = nread; *r_nread = nread;
*r_oid = ksba_oid_to_str (der+off, len); *r_oid = ksba_oid_to_str (der+off, len);
if (!*r_oid) if (!*r_oid)
return gpg_error (GPG_ERR_ENOMEM); return gpg_error (GPG_ERR_ENOMEM);
/* Special hack for ecdsaWithSpecified. We replace the returned OID /* Special hack for ecdsaWithSpecified. We replace the returned OID
by the one in the parameter. */ by the one in the parameter. */
if (off2 && len2 && parm_type == TYPE_SEQUENCE if (off2 && len2 && parm_type == TYPE_SEQUENCE && firsttag == 0x30
&& !strcmp (*r_oid, "1.2.840.10045.4.3")) && !strcmp (*r_oid, "1.2.840.10045.4.3"))
{ {
xfree (*r_oid); xfree (*r_oid);
*r_oid = NULL; *r_oid = NULL;
err = get_algorithm (0, der+off2, len2, &nread, &off, &len, &is_bitstr, err = get_algorithm (0, der+off2, len2, 0x30,
&nread, &off, &len, &is_bitstr,
NULL, NULL, NULL); NULL, NULL, NULL);
if (err) if (err)
{ {
if (r_nread) if (r_nread)
*r_nread = 0; *r_nread = 0;
return err; return err;
} }
*r_oid = ksba_oid_to_str (der+off2+off, len); *r_oid = ksba_oid_to_str (der+off2+off, len);
if (!*r_oid) if (!*r_oid)
{ {
skipping to change at line 746 skipping to change at line 760
} }
memcpy (*r_parm, der+off2, len2); memcpy (*r_parm, der+off2, len2);
*r_parmlen = len2; *r_parmlen = len2;
} }
else else
{ {
*r_parm = NULL; *r_parm = NULL;
*r_parmlen = 0; *r_parmlen = 0;
} }
} }
if (r_parmtype)
*r_parmtype = parm_type;
return 0; return 0;
} }
/* Assume that DER is a buffer of length DERLEN with a DER encoded /* Assume that DER is a buffer of length DERLEN with a DER encoded
ASN.1 structure like this: ASN.1 structure like this:
keyInfo ::= SEQUENCE { keyInfo ::= SEQUENCE {
SEQUENCE { SEQUENCE {
algorithm OBJECT IDENTIFIER, algorithm OBJECT IDENTIFIER,
parameters ANY DEFINED BY algorithm OPTIONAL } parameters ANY DEFINED BY algorithm OPTIONAL }
skipping to change at line 792 skipping to change at line 809
*r_string = NULL; *r_string = NULL;
/* check the outer sequence */ /* check the outer sequence */
if (!derlen) if (!derlen)
return gpg_error (GPG_ERR_INV_KEYINFO); return gpg_error (GPG_ERR_INV_KEYINFO);
c = *der++; derlen--; c = *der++; derlen--;
if ( c != 0x30 ) if ( c != 0x30 )
return gpg_error (GPG_ERR_UNEXPECTED_TAG); /* not a SEQUENCE */ return gpg_error (GPG_ERR_UNEXPECTED_TAG); /* not a SEQUENCE */
TLV_LENGTH(der); TLV_LENGTH(der);
/* and now the inner part */ /* and now the inner part */
err = get_algorithm (1, der, derlen, &nread, &off, &len, &is_bitstr, err = get_algorithm (1, der, derlen, 0x30,
&nread, &off, &len, &is_bitstr,
&parm_off, &parm_len, &parm_type); &parm_off, &parm_len, &parm_type);
if (err) if (err)
return err; return err;
/* look into our table of supported algorithms */ /* look into our table of supported algorithms */
for (algoidx=0; pk_algo_table[algoidx].oid; algoidx++) for (algoidx=0; pk_algo_table[algoidx].oid; algoidx++)
{ {
if ( len == pk_algo_table[algoidx].oidlen if ( len == pk_algo_table[algoidx].oidlen
&& !memcmp (der+off, pk_algo_table[algoidx].oid, len)) && !memcmp (der+off, pk_algo_table[algoidx].oid, len))
break; break;
skipping to change at line 1486 skipping to change at line 1504
unsigned int salt_length = 0; unsigned int salt_length = 0;
/* FIXME: The entire function is very similar to keyinfo_to_sexp */ /* FIXME: The entire function is very similar to keyinfo_to_sexp */
*r_string = NULL; *r_string = NULL;
if (!mode) if (!mode)
algo_table = sig_algo_table; algo_table = sig_algo_table;
else else
algo_table = enc_algo_table; algo_table = enc_algo_table;
err = get_algorithm (1, der, derlen, &nread, &off, &len, &is_bitstr, err = get_algorithm (1, der, derlen, 0x30,
&nread, &off, &len, &is_bitstr,
&parm_off, &parm_len, &parm_type); &parm_off, &parm_len, &parm_type);
if (err) if (err)
return err; return err;
/* look into our table of supported algorithms */ /* look into our table of supported algorithms */
for (algoidx=0; algo_table[algoidx].oid; algoidx++) for (algoidx=0; algo_table[algoidx].oid; algoidx++)
{ {
if ( len == algo_table[algoidx].oidlen if ( len == algo_table[algoidx].oidlen
&& !memcmp (der+off, algo_table[algoidx].oid, len)) && !memcmp (der+off, algo_table[algoidx].oid, len))
break; break;
 End of changes. 11 change blocks. 
11 lines changed or deleted 30 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)