Sprinkle error string and hx509_contexts.

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@19128 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Love Hörnquist Åstrand
2006-11-26 17:53:25 +00:00
parent 95730a19d6
commit e37704f850

View File

@@ -1034,7 +1034,8 @@ _hx509_public_encrypt(const heim_octet_string *cleartext,
} }
int int
_hx509_private_key_private_decrypt(const heim_octet_string *ciphertext, _hx509_private_key_private_decrypt(hx509_context context,
const heim_octet_string *ciphertext,
const heim_oid *encryption_oid, const heim_oid *encryption_oid,
hx509_private_key p, hx509_private_key p,
heim_octet_string *cleartext) heim_octet_string *cleartext)
@@ -1044,21 +1045,27 @@ _hx509_private_key_private_decrypt(const heim_octet_string *ciphertext,
cleartext->data = NULL; cleartext->data = NULL;
cleartext->length = 0; cleartext->length = 0;
if (p->private_key.rsa == NULL) if (p->private_key.rsa == NULL) {
hx509_set_error_string(context, 0, HX509_PRIVATE_KEY_MISSING,
"Private RSA key missing");
return HX509_PRIVATE_KEY_MISSING; return HX509_PRIVATE_KEY_MISSING;
}
cleartext->length = RSA_size(p->private_key.rsa); cleartext->length = RSA_size(p->private_key.rsa);
cleartext->data = malloc(cleartext->length); cleartext->data = malloc(cleartext->length);
if (cleartext->data == NULL) if (cleartext->data == NULL) {
hx509_set_error_string(context, 0, ENOMEM, "out of memory");
return ENOMEM; return ENOMEM;
}
ret = RSA_private_decrypt(ciphertext->length, ciphertext->data, ret = RSA_private_decrypt(ciphertext->length, ciphertext->data,
cleartext->data, cleartext->data,
p->private_key.rsa, p->private_key.rsa,
RSA_PKCS1_PADDING); RSA_PKCS1_PADDING);
if (ret <= 0) { if (ret <= 0) {
der_free_octet_string(cleartext); der_free_octet_string(cleartext);
return ENOMEM; hx509_set_error_string(context, 0, HX509_CRYPTO_RSA_PRIVATE_DECRYPT,
"Failed to decrypt using private key");
return HX509_CRYPTO_RSA_PRIVATE_DECRYPT;
} }
if (cleartext->length < ret) if (cleartext->length < ret)
_hx509_abort("internal rsa decryption failure: ret > tosize"); _hx509_abort("internal rsa decryption failure: ret > tosize");