Sprinkle more hx509_context so we can return propper errors.

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@18861 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Love Hörnquist Åstrand
2006-10-24 13:34:21 +00:00
parent 7f316a5b1e
commit f58f609484
2 changed files with 35 additions and 14 deletions

View File

@@ -107,7 +107,8 @@ free_private_key(struct private_key *key)
} }
int int
_hx509_collector_private_key_add(struct hx509_collector *c, _hx509_collector_private_key_add(hx509_context context,
struct hx509_collector *c,
const AlgorithmIdentifier *alg, const AlgorithmIdentifier *alg,
hx509_private_key private_key, hx509_private_key private_key,
const heim_octet_string *key_data, const heim_octet_string *key_data,
@@ -124,17 +125,21 @@ _hx509_collector_private_key_add(struct hx509_collector *c,
d = realloc(c->val.data, (c->val.len + 1) * sizeof(c->val.data[0])); d = realloc(c->val.data, (c->val.len + 1) * sizeof(c->val.data[0]));
if (d == NULL) { if (d == NULL) {
free(key); free(key);
hx509_set_error_string(context, 0, ENOMEM, "Out of memory");
return ENOMEM; return ENOMEM;
} }
c->val.data = d; c->val.data = d;
ret = copy_AlgorithmIdentifier(alg, &key->alg); ret = copy_AlgorithmIdentifier(alg, &key->alg);
if (ret) if (ret) {
hx509_set_error_string(context, 0, ret, "Failed to copy "
"AlgorithmIdentifier");
goto out; goto out;
}
if (private_key) { if (private_key) {
key->private_key = private_key; key->private_key = private_key;
} else { } else {
ret = _hx509_parse_private_key(&alg->algorithm, ret = _hx509_parse_private_key(context, &alg->algorithm,
key_data->data, key_data->length, key_data->data, key_data->length,
&key->private_key); &key->private_key);
if (ret) if (ret)
@@ -142,8 +147,11 @@ _hx509_collector_private_key_add(struct hx509_collector *c,
} }
if (localKeyId) { if (localKeyId) {
ret = der_copy_octet_string(localKeyId, &key->localKeyId); ret = der_copy_octet_string(localKeyId, &key->localKeyId);
if (ret) if (ret) {
hx509_set_error_string(context, 0, ret,
"Failed to copy localKeyId");
goto out; goto out;
}
} else } else
memset(&key->localKeyId, 0, sizeof(key->localKeyId)); memset(&key->localKeyId, 0, sizeof(key->localKeyId));

View File

@@ -98,7 +98,8 @@ struct signature_alg {
const heim_octet_string *, const heim_octet_string *,
AlgorithmIdentifier *, AlgorithmIdentifier *,
heim_octet_string *); heim_octet_string *);
int (*parse_private_key)(const struct signature_alg *, int (*parse_private_key)(hx509_context,
const struct signature_alg *,
const void *data, const void *data,
size_t len, size_t len,
hx509_private_key private_key); hx509_private_key private_key);
@@ -349,7 +350,8 @@ create_signature(const struct signature_alg *sig_alg,
#endif #endif
static int static int
rsa_parse_private_key(const struct signature_alg *sig_alg, rsa_parse_private_key(hx509_context context,
const struct signature_alg *sig_alg,
const void *data, const void *data,
size_t len, size_t len,
hx509_private_key private_key) hx509_private_key private_key)
@@ -358,8 +360,11 @@ rsa_parse_private_key(const struct signature_alg *sig_alg,
private_key->private_key.rsa = private_key->private_key.rsa =
d2i_RSAPrivateKey(NULL, &p, len); d2i_RSAPrivateKey(NULL, &p, len);
if (private_key->private_key.rsa == NULL) if (private_key->private_key.rsa == NULL) {
return EINVAL; hx509_set_error_string(context, 0, HX509_PARSING_KEY_FAILED,
"Failed to parse RSA key");
return HX509_PARSING_KEY_FAILED;
}
private_key->signature_alg = oid_id_pkcs1_sha1WithRSAEncryption(); private_key->signature_alg = oid_id_pkcs1_sha1WithRSAEncryption();
return 0; return 0;
@@ -478,7 +483,8 @@ dsa_verify_signature(const struct signature_alg *sig_alg,
} }
static int static int
dsa_parse_private_key(const struct signature_alg *sig_alg, dsa_parse_private_key(hx509_context context,
const struct signature_alg *sig_alg,
const void *data, const void *data,
size_t len, size_t len,
hx509_private_key private_key) hx509_private_key private_key)
@@ -494,7 +500,9 @@ dsa_parse_private_key(const struct signature_alg *sig_alg,
return 0; return 0;
#else #else
return EINVAL; hx509_set_error_string(context, 0, HX509_PARSING_KEY_FAILED,
"No support to parse DSA keys");
return HX509_PARSING_KEY_FAILED;
#endif #endif
} }
@@ -993,7 +1001,8 @@ _hx509_private_key_private_decrypt(const heim_octet_string *ciphertext,
int int
_hx509_parse_private_key(const heim_oid *key_oid, _hx509_parse_private_key(hx509_context context,
const heim_oid *key_oid,
const void *data, const void *data,
size_t len, size_t len,
hx509_private_key *private_key) hx509_private_key *private_key)
@@ -1004,14 +1013,18 @@ _hx509_parse_private_key(const heim_oid *key_oid,
*private_key = NULL; *private_key = NULL;
md = find_key_alg(key_oid); md = find_key_alg(key_oid);
if (md == NULL) if (md == NULL) {
hx509_clear_error_string(context);
return HX509_SIG_ALG_NO_SUPPORTED; return HX509_SIG_ALG_NO_SUPPORTED;
}
ret = _hx509_new_private_key(private_key); ret = _hx509_new_private_key(private_key);
if (ret) if (ret) {
hx509_set_error_string(context, 0, ret, "out of memory");
return ret; return ret;
}
ret = (*md->parse_private_key)(md, data, len, *private_key); ret = (*md->parse_private_key)(context, md, data, len, *private_key);
if (ret) if (ret)
_hx509_free_private_key(private_key); _hx509_free_private_key(private_key);
else else