提交 b03da688 编写于 作者: R Richard Levitte

Adapt everything else to the updated OSSL_ENCODER_CTX_new_by_EVP_PKEY()

Reviewed-by: NTim Hudson <tjh@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13545)
上级 cbcbac64
......@@ -325,7 +325,7 @@ int dhparam_main(int argc, char **argv)
OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS,
outformat == FORMAT_ASN1
? "DER" : "PEM",
NULL, NULL, NULL);
NULL, NULL);
if (ectx == NULL || !OSSL_ENCODER_to_bio(ectx, out)) {
OSSL_ENCODER_CTX_free(ectx);
......
......@@ -323,7 +323,7 @@ int rsa_main(int argc, char **argv)
/* Now, perform the encoding */
ectx = OSSL_ENCODER_CTX_new_by_EVP_PKEY(pkey, selection,
output_type, output_structure,
NULL, NULL);
NULL);
if (OSSL_ENCODER_CTX_get_num_encoders(ectx) == 0) {
BIO_printf(bio_err, "%s format not supported\n", output_type);
goto end;
......
......@@ -42,8 +42,7 @@ static int i2d_provided(const EVP_PKEY *a, int selection,
size_t len = INT_MAX;
ctx = OSSL_ENCODER_CTX_new_by_EVP_PKEY(a, selection, "DER",
*output_structures,
NULL, NULL);
*output_structures, NULL);
if (ctx == NULL)
return -1;
if (OSSL_ENCODER_to_data(ctx, pp, &len))
......
......@@ -81,15 +81,13 @@ PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8(const EVP_PKEY *pkey)
*/
if (evp_pkey_is_provided(pkey)) {
int selection = OSSL_KEYMGMT_SELECT_ALL;
const OSSL_PROVIDER *prov = EVP_KEYMGMT_provider(pkey->keymgmt);
OSSL_LIB_CTX *libctx = ossl_provider_libctx(prov);
unsigned char *der = NULL;
size_t derlen = 0;
const unsigned char *pp;
if ((ctx = OSSL_ENCODER_CTX_new_by_EVP_PKEY(pkey, selection,
"DER", "pkcs8",
libctx, NULL)) == NULL
NULL)) == NULL
|| !OSSL_ENCODER_to_data(ctx, &der, &derlen))
goto error;
......
......@@ -1140,7 +1140,6 @@ static int unsup_alg(BIO *out, const EVP_PKEY *pkey, int indent,
static int print_pkey(const EVP_PKEY *pkey, BIO *out, int indent,
int selection /* For provided encoding */,
OSSL_LIB_CTX *libctx /* For provided encoding */,
const char *propquery /* For provided encoding */,
int (*legacy_print)(BIO *out, const EVP_PKEY *pkey,
int indent, ASN1_PCTX *pctx),
......@@ -1155,7 +1154,7 @@ static int print_pkey(const EVP_PKEY *pkey, BIO *out, int indent,
return 0;
ctx = OSSL_ENCODER_CTX_new_by_EVP_PKEY(pkey, selection, "TEXT", NULL,
libctx, propquery);
propquery);
if (OSSL_ENCODER_CTX_get_num_encoders(ctx) != 0)
ret = OSSL_ENCODER_to_bio(ctx, out);
OSSL_ENCODER_CTX_free(ctx);
......@@ -1177,7 +1176,7 @@ static int print_pkey(const EVP_PKEY *pkey, BIO *out, int indent,
int EVP_PKEY_print_public(BIO *out, const EVP_PKEY *pkey,
int indent, ASN1_PCTX *pctx)
{
return print_pkey(pkey, out, indent, EVP_PKEY_PUBLIC_KEY, NULL, NULL,
return print_pkey(pkey, out, indent, EVP_PKEY_PUBLIC_KEY, NULL,
(pkey->ameth != NULL ? pkey->ameth->pub_print : NULL),
pctx);
}
......@@ -1185,7 +1184,7 @@ int EVP_PKEY_print_public(BIO *out, const EVP_PKEY *pkey,
int EVP_PKEY_print_private(BIO *out, const EVP_PKEY *pkey,
int indent, ASN1_PCTX *pctx)
{
return print_pkey(pkey, out, indent, EVP_PKEY_KEYPAIR, NULL, NULL,
return print_pkey(pkey, out, indent, EVP_PKEY_KEYPAIR, NULL,
(pkey->ameth != NULL ? pkey->ameth->priv_print : NULL),
pctx);
}
......@@ -1193,7 +1192,7 @@ int EVP_PKEY_print_private(BIO *out, const EVP_PKEY *pkey,
int EVP_PKEY_print_params(BIO *out, const EVP_PKEY *pkey,
int indent, ASN1_PCTX *pctx)
{
return print_pkey(pkey, out, indent, EVP_PKEY_KEY_PARAMETERS, NULL, NULL,
return print_pkey(pkey, out, indent, EVP_PKEY_KEY_PARAMETERS, NULL,
(pkey->ameth != NULL ? pkey->ameth->param_print : NULL),
pctx);
}
......
......@@ -49,7 +49,7 @@
OSSL_ENCODER_CTX *ctx = \
OSSL_ENCODER_CTX_new_by_##type(x, PEM_SELECTION_##asn1, \
"PEM", PEM_STRUCTURE_##asn1, \
NULL, NULL); \
NULL); \
\
if (OSSL_ENCODER_CTX_get_num_encoders(ctx) == 0) { \
OSSL_ENCODER_CTX_free(ctx); \
......
......@@ -22,14 +22,14 @@ static int do_pk8pkey(BIO *bp, const EVP_PKEY *x, int isder,
int nid, const EVP_CIPHER *enc,
const char *kstr, int klen,
pem_password_cb *cb, void *u,
OSSL_LIB_CTX *libctx, const char *propq);
const char *propq);
#ifndef OPENSSL_NO_STDIO
static int do_pk8pkey_fp(FILE *bp, const EVP_PKEY *x, int isder,
int nid, const EVP_CIPHER *enc,
const char *kstr, int klen,
pem_password_cb *cb, void *u,
OSSL_LIB_CTX *libctx, const char *propq);
const char *propq);
#endif
/*
* These functions write a private key in PKCS#8 format: it is a "drop in"
......@@ -42,40 +42,39 @@ int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, const EVP_PKEY *x, int nid,
const char *kstr, int klen,
pem_password_cb *cb, void *u)
{
return do_pk8pkey(bp, x, 0, nid, NULL, kstr, klen, cb, u, NULL, NULL);
return do_pk8pkey(bp, x, 0, nid, NULL, kstr, klen, cb, u, NULL);
}
int PEM_write_bio_PKCS8PrivateKey(BIO *bp, const EVP_PKEY *x, const EVP_CIPHER *enc,
const char *kstr, int klen,
pem_password_cb *cb, void *u)
{
return do_pk8pkey(bp, x, 0, -1, enc, kstr, klen, cb, u, NULL, NULL);
return do_pk8pkey(bp, x, 0, -1, enc, kstr, klen, cb, u, NULL);
}
int i2d_PKCS8PrivateKey_bio(BIO *bp, const EVP_PKEY *x, const EVP_CIPHER *enc,
const char *kstr, int klen,
pem_password_cb *cb, void *u)
{
return do_pk8pkey(bp, x, 1, -1, enc, kstr, klen, cb, u, NULL, NULL);
return do_pk8pkey(bp, x, 1, -1, enc, kstr, klen, cb, u, NULL);
}
int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, const EVP_PKEY *x, int nid,
const char *kstr, int klen,
pem_password_cb *cb, void *u)
{
return do_pk8pkey(bp, x, 1, nid, NULL, kstr, klen, cb, u, NULL, NULL);
return do_pk8pkey(bp, x, 1, nid, NULL, kstr, klen, cb, u, NULL);
}
static int do_pk8pkey(BIO *bp, const EVP_PKEY *x, int isder, int nid,
const EVP_CIPHER *enc, const char *kstr, int klen,
pem_password_cb *cb, void *u,
OSSL_LIB_CTX *libctx, const char *propq)
pem_password_cb *cb, void *u, const char *propq)
{
int ret = 0;
const char *outtype = isder ? "DER" : "PEM";
OSSL_ENCODER_CTX *ctx =
OSSL_ENCODER_CTX_new_by_EVP_PKEY(x, OSSL_KEYMGMT_SELECT_ALL,
outtype, "pkcs8", libctx, propq);
outtype, "pkcs8", propq);
if (ctx == NULL)
return 0;
......@@ -203,34 +202,33 @@ int i2d_PKCS8PrivateKey_fp(FILE *fp, const EVP_PKEY *x, const EVP_CIPHER *enc,
const char *kstr, int klen,
pem_password_cb *cb, void *u)
{
return do_pk8pkey_fp(fp, x, 1, -1, enc, kstr, klen, cb, u, NULL, NULL);
return do_pk8pkey_fp(fp, x, 1, -1, enc, kstr, klen, cb, u, NULL);
}
int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, const EVP_PKEY *x, int nid,
const char *kstr, int klen,
pem_password_cb *cb, void *u)
{
return do_pk8pkey_fp(fp, x, 1, nid, NULL, kstr, klen, cb, u, NULL, NULL);
return do_pk8pkey_fp(fp, x, 1, nid, NULL, kstr, klen, cb, u, NULL);
}
int PEM_write_PKCS8PrivateKey_nid(FILE *fp, const EVP_PKEY *x, int nid,
const char *kstr, int klen,
pem_password_cb *cb, void *u)
{
return do_pk8pkey_fp(fp, x, 0, nid, NULL, kstr, klen, cb, u, NULL, NULL);
return do_pk8pkey_fp(fp, x, 0, nid, NULL, kstr, klen, cb, u, NULL);
}
int PEM_write_PKCS8PrivateKey(FILE *fp, const EVP_PKEY *x, const EVP_CIPHER *enc,
const char *kstr, int klen,
pem_password_cb *cb, void *u)
{
return do_pk8pkey_fp(fp, x, 0, -1, enc, kstr, klen, cb, u, NULL, NULL);
return do_pk8pkey_fp(fp, x, 0, -1, enc, kstr, klen, cb, u, NULL);
}
static int do_pk8pkey_fp(FILE *fp, const EVP_PKEY *x, int isder, int nid,
const EVP_CIPHER *enc, const char *kstr, int klen,
pem_password_cb *cb, void *u,
OSSL_LIB_CTX *libctx, const char *propq)
pem_password_cb *cb, void *u, const char *propq)
{
BIO *bp;
int ret;
......@@ -239,7 +237,7 @@ static int do_pk8pkey_fp(FILE *fp, const EVP_PKEY *x, int isder, int nid,
ERR_raise(ERR_LIB_PEM, ERR_R_BUF_LIB);
return 0;
}
ret = do_pk8pkey(bp, x, isder, nid, enc, kstr, klen, cb, u, libctx, propq);
ret = do_pk8pkey(bp, x, isder, nid, enc, kstr, klen, cb, u, propq);
BIO_free(bp);
return ret;
}
......
......@@ -98,14 +98,12 @@ int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey)
goto error;
}
} else if (evp_pkey_is_provided(pkey)) {
const OSSL_PROVIDER *pkprov = EVP_KEYMGMT_provider(pkey->keymgmt);
OSSL_LIB_CTX *libctx = ossl_provider_libctx(pkprov);
unsigned char *der = NULL;
size_t derlen = 0;
OSSL_ENCODER_CTX *ectx =
OSSL_ENCODER_CTX_new_by_EVP_PKEY(pkey, EVP_PKEY_PUBLIC_KEY,
"DER", "SubjectPublicKeyInfo",
libctx, NULL);
NULL);
if (OSSL_ENCODER_to_data(ectx, &der, &derlen)) {
const unsigned char *pder = der;
......@@ -306,12 +304,10 @@ int i2d_PUBKEY(const EVP_PKEY *a, unsigned char **pp)
}
X509_PUBKEY_free(xpk);
} else if (a->keymgmt != NULL) {
const OSSL_PROVIDER *pkprov = EVP_KEYMGMT_provider(a->keymgmt);
OSSL_LIB_CTX *libctx = ossl_provider_libctx(pkprov);
OSSL_ENCODER_CTX *ctx =
OSSL_ENCODER_CTX_new_by_EVP_PKEY(a, EVP_PKEY_PUBLIC_KEY,
"DER", "SubjectPublicKeyInfo",
libctx, NULL);
NULL);
BIO *out = BIO_new(BIO_s_mem());
BUF_MEM *buf = NULL;
......
......@@ -195,7 +195,7 @@ static int encode_EVP_PKEY_prov(void **encoded, long *encoded_len,
if (!TEST_ptr(ectx = OSSL_ENCODER_CTX_new_by_EVP_PKEY(pkey, selection,
output_type,
output_structure,
NULL, NULL))
NULL))
|| !TEST_int_gt(OSSL_ENCODER_CTX_get_num_encoders(ectx), 0)
|| (pass != NULL
&& !TEST_true(OSSL_ENCODER_CTX_set_passphrase(ectx, upass,
......
......@@ -319,7 +319,7 @@ static int test_protected_PEM(const char *keytype, int evp_type,
if (!TEST_ptr(ectx =
OSSL_ENCODER_CTX_new_by_EVP_PKEY(provided_pkey, selection,
"PEM", structure,
NULL, NULL))
NULL))
|| !TEST_true(OSSL_ENCODER_to_bio(ectx, membio_provided))
|| !TEST_true(pem_write_bio(membio_legacy, legacy_key,
NULL, NULL, 0, NULL, NULL))
......@@ -387,7 +387,7 @@ static int test_unprotected_PEM(const char *keytype, int evp_type,
if (!TEST_ptr(ectx =
OSSL_ENCODER_CTX_new_by_EVP_PKEY(provided_pkey, selection,
"PEM", structure,
NULL, NULL))
NULL))
|| !TEST_true(OSSL_ENCODER_to_bio(ectx, membio_provided))
|| !TEST_true(pem_write_bio(membio_legacy, legacy_key))
|| !test_membio_str_eq(membio_provided, membio_legacy))
......@@ -452,7 +452,7 @@ static int test_DER(const char *keytype, int evp_type,
if (!TEST_ptr(ectx =
OSSL_ENCODER_CTX_new_by_EVP_PKEY(provided_pkey, selection,
"DER", structure,
NULL, NULL))
NULL))
|| !TEST_true(OSSL_ENCODER_to_data(ectx,
&der_provided, &der_provided_len))
|| !TEST_size_t_gt(der_legacy_len = i2d(legacy_key, &der_legacy), 0)
......
......@@ -461,7 +461,7 @@ static int rsa_keygen(int bits, EVP_PKEY **pub, EVP_PKEY **priv)
OSSL_ENCODER_CTX_new_by_EVP_PKEY(*priv,
EVP_PKEY_PUBLIC_KEY,
"DER", "type-specific",
libctx, NULL))
NULL))
|| !TEST_true(OSSL_ENCODER_to_data(ectx, &pub_der, &len)))
goto err;
pp = pub_der;
......
......@@ -217,7 +217,7 @@ static int test_print_key_type_using_encoder(const char *alg, int type,
if (!TEST_ptr(ctx = OSSL_ENCODER_CTX_new_by_EVP_PKEY(pk, selection,
output_type,
output_structure,
NULL, NULL))
NULL))
/* Check that this operation is supported */
|| !TEST_int_ne(OSSL_ENCODER_CTX_get_num_encoders(ctx), 0))
goto err;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册