int len;
/* Protocol says that at least UN and HN must be provided as identifier */
- if (!strstr(identifier, "UN=") && !strstr(identifier, "HN=")) {
+ if (!strstr(identifier, "UN=") || !strstr(identifier, "HN=")) {
SILC_LOG_DEBUG(("The public does not have the required UN= and HN= "
"identifiers"));
return FALSE;
if (!username || !host)
return NULL;
- if (strlen(username) < 3 || strlen(host) < 3)
+ if (strlen(username) < 1 || strlen(host) < 1)
return NULL;
memset(&buf, 0, sizeof(buf));
/* 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) +
/* 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;
}
/* 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;
}