const struct pbkdf2_params *kdf_params,
const struct pbe_enc_params *enc_params,
gnutls_datum * decrypted_data);
-static ASN1_TYPE decode_private_key_info(const gnutls_datum * der,
- gnutls_x509_privkey pkey);
+static int decode_private_key_info(const gnutls_datum * der,
+ gnutls_x509_privkey pkey, ASN1_TYPE* out);
static int write_schema_params(schema_id schema, ASN1_TYPE pkcs8_asn, const char* where,
const struct pbkdf2_params *kdf_params,
const struct pbe_enc_params *enc_params);
/* Converts a PKCS #8 private key info to
* a PKCS #8 EncryptedPrivateKeyInfo.
*/
-static ASN1_TYPE encode_to_pkcs8_key( schema_id schema, const gnutls_datum * der_key,
- const char *password)
+static
+int encode_to_pkcs8_key( schema_id schema, const gnutls_datum * der_key,
+ const char *password, ASN1_TYPE* out)
{
int result;
gnutls_datum key = { NULL, 0 };
"PKIX1.pkcs-8-EncryptedPrivateKeyInfo",
&pkcs8_asn)) != ASN1_SUCCESS) {
gnutls_assert();
+ result = _gnutls_asn2err(result);
goto error;
}
if (result != ASN1_SUCCESS) {
gnutls_assert();
+ result = _gnutls_asn2err(result);
goto error;
}
tmp.size);
if (result != ASN1_SUCCESS) {
gnutls_assert();
+ result = _gnutls_asn2err(result);
goto error;
}
_gnutls_free_datum(&tmp);
_gnutls_free_datum(&key);
- return pkcs8_asn;
+ *out = pkcs8_asn;
+
+ return 0;
error:
_gnutls_free_datum(&key);
_gnutls_free_datum(&tmp);
asn1_delete_structure(&pkcs8_asn);
- return NULL;
+ return result;
}
asn1_delete_structure(&pkey_info); /* we don't need it */
- pkcs8_asn = encode_to_pkcs8_key(schema, &tmp, password);
+ ret = encode_to_pkcs8_key(schema, &tmp, password, &pkcs8_asn);
_gnutls_free_datum(&tmp);
- if (pkcs8_asn == NULL) {
+ if (ret < 0) {
gnutls_assert();
- return GNUTLS_E_ASN1_GENERIC_ERROR;
+ return ret;
}
ret =
* an internal structure (gnutls_private_key)
* (normally a PKCS #1 encoded RSA key)
*/
-static ASN1_TYPE decode_pkcs8_key(const gnutls_datum * raw_key,
+static
+int decode_pkcs8_key(const gnutls_datum * raw_key,
const char *password,
- gnutls_x509_privkey pkey)
+ gnutls_x509_privkey pkey, ASN1_TYPE* out)
{
int result, len;
opaque enc_oid[64];
"PKIX1.pkcs-8-EncryptedPrivateKeyInfo",
&pkcs8_asn)) != ASN1_SUCCESS) {
gnutls_assert();
+ result = _gnutls_asn2err(result);
goto error;
}
NULL);
if (result != ASN1_SUCCESS) {
gnutls_assert();
+ result = _gnutls_asn2err(result);
goto error;
}
¶ms_start, ¶ms_end);
if (result != ASN1_SUCCESS) {
gnutls_assert();
+ result = _gnutls_asn2err(result);
goto error;
}
params_len = params_end - params_start + 1;
asn1_delete_structure(&pkcs8_asn);
- ret_asn = decode_private_key_info(&tmp, pkey);
+ result = decode_private_key_info(&tmp, pkey, &ret_asn);
_gnutls_free_datum(&tmp);
- return ret_asn;
+ if (result < 0) {
+ gnutls_assert();
+ goto error;
+ }
+
+ *out = ret_asn;
+
+ return 0;
error:
asn1_delete_structure(&pbes2_asn);
asn1_delete_structure(&pkcs8_asn);
- return NULL;
+ return result;
}
-static ASN1_TYPE decode_private_key_info(const gnutls_datum * der,
- gnutls_x509_privkey pkey)
+static
+int decode_private_key_info(const gnutls_datum * der,
+ gnutls_x509_privkey pkey, ASN1_TYPE* out)
{
int result, len;
opaque oid[64], *data = NULL;
"PKIX1.pkcs-8-PrivateKeyInfo",
&pkcs8_asn)) != ASN1_SUCCESS) {
gnutls_assert();
+ result = _gnutls_asn2err(result);
goto error;
}
oid, &len);
if (result != ASN1_SUCCESS) {
gnutls_assert();
+ result = _gnutls_asn2err(result);
goto error;
}
_gnutls_x509_log
("PKCS #8 private key OID '%s' is unsupported.\n",
oid);
+ result = GNUTLS_E_UNKNOWN_PK_ALGORITHM;
goto error;
}
gnutls_assert();
}
- return ret_asn;
+ *out = ret_asn;
+
+ return 0;
error:
asn1_delete_structure(&pkcs8_asn);
if (data != NULL) {
gnutls_afree(data);
}
- return NULL;
+ return result;
}
}
if (flags & GNUTLS_PKCS8_PLAIN || password == NULL) {
- key->key = decode_private_key_info(&_data, key);
+ result = decode_private_key_info(&_data, key, &key->key);
} else { /* encrypted. */
- key->key = decode_pkcs8_key(&_data, password, key);
+ result = decode_pkcs8_key(&_data, password, key, &key->key);
}
- if (key->key == NULL) {
+ if (result < 0) {
gnutls_assert();
- result = GNUTLS_E_DECRYPTION_FAILED;
goto cleanup;
}
static int read_pkcs12_kdf_params(ASN1_TYPE pbes2_asn,
struct pbkdf2_params *params)
{
- int len, result;
- char oid[64];
+ int result;
memset(params, 0, sizeof(params));