Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 2003 - 2005 Pekka Riikonen
+ Copyright (C) 2003 - 2006 Pekka Riikonen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
SILC_LOG_DEBUG(("Error decoding underlaying node for ANY"));
goto fail;
}
- assert(enc == SILC_BER_ENC_CONSTRUCTED);
+ if (enc != SILC_BER_ENC_CONSTRUCTED) {
+ SILC_LOG_DEBUG(("ANY was not constructed type"));
+ goto fail;
+ }
/* Now encode with implicit tagging */
len = silc_ber_encoded_len(tag, d_len, FALSE);
/* Object identifier */
char *cp, *oidstr = va_arg(asn1->ap, char *);
SilcUInt32 words[24], oid, mask;
- int i, c = -1;
+ int i, k, c = 0;
if (!oidstr)
break;
/* Get OID words from the string */
cp = strchr(oidstr, '.');
while (cp) {
- c = sscanf(oidstr, "%lu", (unsigned long *)&oid);
- if (c < 1) {
+ if (sscanf(oidstr, "%lu", (unsigned long *)&oid) != 1) {
SILC_LOG_DEBUG(("Malformed OID string"));
goto fail;
}
words[c++] = oid;
oidstr = cp + 1;
cp = strchr(oidstr, '.');
+
+ if (!cp) {
+ if (sscanf(oidstr, "%lu", (unsigned long *)&oid) != 1) {
+ SILC_LOG_DEBUG(("Malformed OID string"));
+ goto fail;
+ }
+ if (c + 1 > sizeof(words) / sizeof(words[0]))
+ goto fail;
+ words[c++] = oid;
+ break;
+ }
}
if (c < 2) {
SILC_LOG_DEBUG(("Malfromed OID string"));
for (i = 2, len = 1; i < c; i++) {
oid = words[i];
if (oid) {
- c = len;
+ k = len;
mask = 0;
while (oid) {
buf.data[len++] = (oid & 0x7f) | mask;
mask |= 0x80;
}
mask = len - 1;
- while (c < mask) {
- oid = buf.data[c];
- buf.data[c] = buf.data[mask];
+ while (k < mask) {
+ oid = buf.data[k];
+ buf.data[k] = buf.data[mask];
buf.data[mask] = oid;
- c++;
+ k++;
mask--;
}
buf.data[len++] = 0x00;
}
- len = silc_ber_encoded_len(tag, len, indef);
+ len = silc_ber_encoded_len(tag, silc_buffer_len(&buf), indef);
dest = silc_buffer_srealloc_size(stack1, dest,
silc_buffer_truelen(dest) + len);
ret = silc_ber_encode(dest, ber_class, SILC_BER_ENC_PRIMITIVE,
}
SILC_LOG_DEBUG(("Encoding success"));
SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
- SILC_LOG_DEBUG(("Decoding ASN.1 tree 9"));
+ SILC_LOG_DEBUG(("Decoding ASN.1 tree 10 (INTEGER)"));
success =
silc_asn1_decode(asn1, &node,
SILC_ASN1_INT(&mpint2),
SILC_LOG_DEBUG(("Decoding success"));
printf("\n");
+
+ memset(&node, 0, sizeof(node));
+ SILC_LOG_DEBUG(("Encoding ASN.1 tree 11 (OID)"));
+ success =
+ silc_asn1_encode(asn1, &node,
+ SILC_ASN1_OPTS(SILC_ASN1_ACCUMUL),
+ SILC_ASN1_OID("1.2.840.113549"),
+ SILC_ASN1_END);
+ if (!success) {
+ SILC_LOG_DEBUG(("Encoding failed"));
+ goto out;
+ }
+ SILC_LOG_DEBUG(("Encoding success"));
+ SILC_LOG_HEXDUMP(("ASN.1 tree"), node.data, silc_buffer_len(&node));
+ SILC_LOG_DEBUG(("Decoding ASN.1 tree 11 (OID)"));
+ success =
+ silc_asn1_decode(asn1, &node,
+ SILC_ASN1_OPTS(SILC_ASN1_ACCUMUL),
+ SILC_ASN1_OID(&str),
+ SILC_ASN1_END);
+ if (!success) {
+ SILC_LOG_DEBUG(("Decoding failed"));
+ goto out;
+ }
+ SILC_LOG_DEBUG(("Decoding success"));
+ SILC_LOG_DEBUG(("OID %s", str));
+ printf("\n");
+
+
#endif
silc_asn1_free(asn1);
@LINK=silcrng.html:SILC RNG Interface
@LINK=silccipher.html:SILC Cipher API
@LINK=silcpkcs.html:SILC PKCS API
-@LINK=silcpkcs1.html:SILC PKCS#1 API
+@LINK=silcpk.html:SILC Public Key API
+@LINK=silcpkcs1.html:SILC PKCS #1 API
@LINK=silchash.html:SILC Hash Interface
@LINK=silchmac.html:SILC HMAC Interface
-->
if (public_key->pkcs->import_public_key_file(data, data_len,
SILC_PKCS_FILE_BASE64,
- &public_key->public_key))
+ &public_key->public_key)) {
+ silc_free(data);
return TRUE;
+ }
if (public_key->pkcs->import_public_key_file(data, data_len,
SILC_PKCS_FILE_BIN,
- &public_key->public_key))
+ &public_key->public_key)) {
+ silc_free(data);
return TRUE;
+ }
}
silc_free(data);
if (!private_key->pkcs)
continue;
- if (private_key->pkcs->import_private_key_file(data, data_len,
- passphrase,
- passphrase_len,
- SILC_PKCS_FILE_BIN,
- &private_key->private_key))
+ if (private_key->pkcs->import_private_key_file(
+ data, data_len,
+ passphrase,
+ passphrase_len,
+ SILC_PKCS_FILE_BIN,
+ &private_key->private_key)) {
+ silc_free(data);
return TRUE;
+ }
- if (private_key->pkcs->import_private_key_file(data, data_len,
- passphrase,
- passphrase_len,
- SILC_PKCS_FILE_BASE64,
- &private_key->private_key))
+ if (private_key->pkcs->import_private_key_file(
+ data, data_len,
+ passphrase,
+ passphrase_len,
+ SILC_PKCS_FILE_BASE64,
+ &private_key->private_key)) {
+ silc_free(data);
return TRUE;
+ }
}
silc_free(data);
if (!silc_asn1_decode(asn1, &alg_key,
SILC_ASN1_OPTS(SILC_ASN1_ALLOC),
SILC_ASN1_SEQUENCE,
- SILC_ASN1_INT(&pubkey->n),
- SILC_ASN1_INT(&pubkey->e),
+ SILC_ASN1_INT(&pubkey->n),
+ SILC_ASN1_INT(&pubkey->e),
SILC_ASN1_END, SILC_ASN1_END))
goto err;
if (!silc_asn1_encode(asn1, &alg_key,
SILC_ASN1_OPTS(SILC_ASN1_ALLOC),
SILC_ASN1_SEQUENCE,
- SILC_ASN1_INT(&key->n),
- SILC_ASN1_INT(&key->e),
+ SILC_ASN1_INT(&key->n),
+ SILC_ASN1_INT(&key->e),
SILC_ASN1_END, SILC_ASN1_END))
goto err;
if (!silc_asn1_decode(asn1, &alg_key,
SILC_ASN1_OPTS(SILC_ASN1_ALLOC),
SILC_ASN1_SEQUENCE,
- SILC_ASN1_INT(NULL),
- SILC_ASN1_INT(&privkey->n),
- SILC_ASN1_INT(&privkey->e),
- SILC_ASN1_INT(&privkey->d),
- SILC_ASN1_INT(&privkey->p),
- SILC_ASN1_INT(&privkey->q),
- SILC_ASN1_INT(&privkey->dP),
- SILC_ASN1_INT(&privkey->dQ),
- SILC_ASN1_INT(&privkey->qP),
+ SILC_ASN1_INT(NULL),
+ SILC_ASN1_INT(&privkey->n),
+ SILC_ASN1_INT(&privkey->e),
+ SILC_ASN1_INT(&privkey->d),
+ SILC_ASN1_INT(&privkey->p),
+ SILC_ASN1_INT(&privkey->q),
+ SILC_ASN1_INT(&privkey->dP),
+ SILC_ASN1_INT(&privkey->dQ),
+ SILC_ASN1_INT(&privkey->qP),
SILC_ASN1_END, SILC_ASN1_END))
goto err;
if (!silc_asn1_encode(asn1, &alg_key,
SILC_ASN1_OPTS(SILC_ASN1_ALLOC),
SILC_ASN1_SEQUENCE,
- SILC_ASN1_INT(&version),
- SILC_ASN1_INT(&key->n),
- SILC_ASN1_INT(&key->e),
- SILC_ASN1_INT(&key->d),
- SILC_ASN1_INT(&key->p),
- SILC_ASN1_INT(&key->q),
- SILC_ASN1_INT(&key->dP),
- SILC_ASN1_INT(&key->dQ),
- SILC_ASN1_INT(&key->qP),
+ SILC_ASN1_INT(&version),
+ SILC_ASN1_INT(&key->n),
+ SILC_ASN1_INT(&key->e),
+ SILC_ASN1_INT(&key->d),
+ SILC_ASN1_INT(&key->p),
+ SILC_ASN1_INT(&key->q),
+ SILC_ASN1_INT(&key->dP),
+ SILC_ASN1_INT(&key->dQ),
+ SILC_ASN1_INT(&key->qP),
SILC_ASN1_END, SILC_ASN1_END))
goto err;
silc_mp_uninit(&version);
Author: Pekka Riikonen <priikone@silcnet.org>
- Copyright (C) 1997 - 2005 Pekka Riikonen
+ Copyright (C) 1997 - 2006 Pekka Riikonen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
goto ok;
slen = strlen(string);
- d = silc_srealloc_ua(stack, len, dst->head,
+ d = silc_srealloc_ua(stack, len + 1, dst->head,
sizeof(*dst->head) * (slen + len + 1));
if (!d)
return -1;