/* Check start of file and remove header from the data. */
len = strlen(SILC_PKCS_PUBLIC_KEYFILE_BEGIN);
- if (filedata_len < len + strlen(SILC_PKCS_PUBLIC_KEYFILE_END))
+ if (filedata_len < len + strlen(SILC_PKCS_PUBLIC_KEYFILE_END)) {
+ SILC_LOG_ERROR(("Malformed SILC public key header"));
return FALSE;
+ }
for (i = 0; i < len; i++) {
- if (*filedata != SILC_PKCS_PUBLIC_KEYFILE_BEGIN[i])
+ if (*filedata != SILC_PKCS_PUBLIC_KEYFILE_BEGIN[i]) {
+ SILC_LOG_ERROR(("Malformed SILC public key header"));
return FALSE;
+ }
filedata++;
}
filedata_len -= (strlen(SILC_PKCS_PUBLIC_KEYFILE_BEGIN) +
goto err;
SILC_LOG_DEBUG(("Public key version %s",
- (!silc_pubkey->identifier.version ? " 1" :
+ (!silc_pubkey->identifier.version ? "1" :
silc_pubkey->identifier.version)));
if (!strcmp(pkcs_name, "rsa")) {
pkcs = silc_pkcs_find_algorithm(pkcs_name, "pkcs1");
}
if (!pkcs) {
- SILC_LOG_DEBUG(("Unsupported PKCS algorithm"));
+ SILC_LOG_DEBUG(("Unsupported PKCS algorithm: rsa"));
goto err;
}
silc_pubkey->pkcs = pkcs;
/* Export PKCS algorithm public key */
if (pkcs->export_public_key)
pk = pkcs->export_public_key(silc_pubkey->public_key, &pk_len);
- if (!pk)
+ if (!pk) {
+ SILC_LOG_ERROR(("Error exporting PKCS algorithm key"));
return NULL;
+ }
silc_buffer_set(&alg_key, pk, pk_len);
/* Encode identifier */
silc_pubkey->identifier.org,
silc_pubkey->identifier.country,
silc_pubkey->identifier.version);
- if (!identifier)
+ if (!identifier) {
+ SILC_LOG_ERROR(("Error encoding SILC public key identifier"));
goto err;
+ }
asn1 = silc_asn1_alloc();
if (!asn1)
goto err;
} else {
- SILC_LOG_DEBUG(("Unsupported PKCS algorithm"));
+ SILC_LOG_ERROR(("Unsupported PKCS algorithm: %s", pkcs->name));
goto err;
}
silc_buffer_free(buf);
silc_free(key);
silc_free(identifier);
+ silc_buffer_purge(&alg_key);
silc_asn1_free(asn1);
return ret;
void *silc_pkcs_silc_public_key_copy(void *public_key)
{
SilcSILCPublicKey silc_pubkey = public_key, new_pubkey;
+ SilcPublicKeyIdentifier ident = &silc_pubkey->identifier;
new_pubkey = silc_calloc(1, sizeof(*new_pubkey));
if (!new_pubkey)
return NULL;
}
+ if (ident->username)
+ new_pubkey->identifier.username =
+ silc_memdup(ident->username, strlen(ident->username));
+ if (ident->host)
+ new_pubkey->identifier.host =
+ silc_memdup(ident->host, strlen(ident->host));
+ if (ident->realname)
+ new_pubkey->identifier.realname =
+ silc_memdup(ident->realname, strlen(ident->realname));
+ if (ident->email)
+ new_pubkey->identifier.email =
+ silc_memdup(ident->email, strlen(ident->email));
+ if (ident->org)
+ new_pubkey->identifier.org =
+ silc_memdup(ident->org, strlen(ident->org));
+ if (ident->country)
+ new_pubkey->identifier.country =
+ silc_memdup(ident->country, strlen(ident->country));
+ if (ident->version)
+ new_pubkey->identifier.version =
+ silc_memdup(ident->version, strlen(ident->version));
+
return new_pubkey;
}
/* Check start of file and remove header from the data. */
len = strlen(SILC_PKCS_PRIVATE_KEYFILE_BEGIN);
- if (filedata_len < len + strlen(SILC_PKCS_PRIVATE_KEYFILE_END))
+ if (filedata_len < len + strlen(SILC_PKCS_PRIVATE_KEYFILE_END)) {
+ SILC_LOG_ERROR(("Malformed SILC private key header"));
return FALSE;
+ }
for (i = 0; i < len; i++) {
- if (*filedata != SILC_PKCS_PRIVATE_KEYFILE_BEGIN[i])
+ if (*filedata != SILC_PKCS_PRIVATE_KEYFILE_BEGIN[i]) {
+ SILC_LOG_ERROR(("Malformed SILC private key header"));
return FALSE;
+ }
filedata++;
}
silc_free(silc_privkey);
if (asn1)
silc_asn1_free(asn1);
+ SILC_LOG_ERROR(("Malformed SILC private key "));
return 0;
}