Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new provider encoders implementations for more output standards, take 2 #13167

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
2f54267
CORE: Add support for specifying the outermost object structure
levitte Oct 17, 2020
c153ef0
ENCODER: Add support for specifying the outermost output structure
levitte Oct 17, 2020
4ee52aa
ENCODER: Add support for OSSL_FUNC_encoder_does()
levitte Oct 17, 2020
3b3966f
ENCODER: Add output structure support for EVP_PKEY encoding
levitte Oct 17, 2020
a8b1d5a
ENCODER: Add tracing
levitte Oct 28, 2020
9f78033
PROV: Re-implement all the keypair encoders
levitte Oct 17, 2020
c5007dc
Adapt libcrypto functionality to specify the desired output structure
levitte Oct 17, 2020
92c22c6
test/endecode_test.c: Update to specify output structures
levitte Oct 17, 2020
e8ecba1
fixup! Adapt libcrypto functionality to specify the desired output st…
levitte Oct 17, 2020
071f390
test/evp_libctx_test.c: use i2d_PublicKey_ex() instead of i2d_PublicK…
levitte Oct 17, 2020
58f8d3b
test/recipes/30-test_evp_libctx.t: use fips-and-base.cnf
levitte Oct 17, 2020
5590e53
fixup! ENCODER: Add support for specifying the outermost output struc…
levitte Oct 28, 2020
d3945e6
fixup! ENCODER: Add output structure support for EVP_PKEY encoding
levitte Oct 28, 2020
e3afe7b
fixup! ENCODER: Add tracing
levitte Oct 28, 2020
755d636
squash! ENCODER: Add output structure support for EVP_PKEY encoding
levitte Oct 30, 2020
823474b
fixup! ENCODER: Add tracing
levitte Oct 30, 2020
82ef63a
fixup! ENCODER: Add output structure support for EVP_PKEY encoding
levitte Oct 30, 2020
16b26c1
fixup! PROV: Re-implement all the keypair encoders
levitte Oct 30, 2020
e6c54e2
fixup! Adapt libcrypto functionality to specify the desired output st…
levitte Oct 30, 2020
51012d1
fixup! Adapt libcrypto functionality to specify the desired output st…
levitte Oct 31, 2020
e3f5601
fixup! PROV: Re-implement all the keypair encoders
levitte Nov 1, 2020
dcdad08
squash! ENCODER: Add support for OSSL_FUNC_encoder_does()
levitte Nov 1, 2020
5ecec40
fixup! ENCODER: Add output structure support for EVP_PKEY encoding
levitte Nov 1, 2020
30bef93
fixup! PROV: Re-implement all the keypair encoders
levitte Nov 1, 2020
ac611e2
fixup! PROV: Re-implement all the keypair encoders
levitte Nov 2, 2020
391c3a6
fixup! PROV: Re-implement all the keypair encoders
levitte Nov 2, 2020
a0e94ca
fixup! Adapt libcrypto functionality to specify the desired output st…
levitte Nov 3, 2020
bb7ae33
fixup! PROV: Re-implement all the keypair encoders
levitte Nov 3, 2020
b5d2055
fixup! ENCODER: Add support for OSSL_FUNC_encoder_does()
levitte Nov 3, 2020
07fafef
fixup! ENCODER: Add output structure support for EVP_PKEY encoding
levitte Nov 3, 2020
bda66dd
fixup! ENCODER: Add output structure support for EVP_PKEY encoding
levitte Nov 3, 2020
f95bc2e
fixup! ENCODER: Add support for specifying the outermost output struc…
levitte Nov 3, 2020
801d2cd
fixup! ENCODER: Add output structure support for EVP_PKEY encoding
levitte Nov 3, 2020
707f02a
fixup! ENCODER: Add output structure support for EVP_PKEY encoding
levitte Nov 3, 2020
e762d58
squash! test/evp_libctx_test.c: use i2d_PublicKey_ex() instead of i2d…
levitte Nov 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions crypto/asn1/build.info
Expand Up @@ -5,7 +5,7 @@ SOURCE[../../libcrypto]=\
a_utf8.c a_sign.c a_digest.c a_verify.c a_mbstr.c a_strex.c \
x_algor.c x_val.c x_sig.c x_bignum.c \
x_int64.c x_info.c x_spki.c nsseq.c \
d2i_pu.c d2i_pr.c i2d_pu.c i2d_pr.c\
d2i_pu.c d2i_pr.c i2d_evp.c \
t_pkey.c t_spki.c t_bitst.c \
tasn_new.c tasn_fre.c tasn_enc.c tasn_dec.c tasn_utl.c tasn_typ.c \
tasn_prn.c tasn_scn.c ameth_lib.c \
Expand All @@ -14,7 +14,7 @@ SOURCE[../../libcrypto]=\
asn1_gen.c asn1_par.c asn1_lib.c asn1_err.c a_strnid.c \
evp_asn1.c asn_pack.c p5_pbe.c p5_pbev2.c p5_scrypt.c p8_pkey.c \
asn_moid.c asn_mstbl.c asn1_item_list.c \
d2i_param.c i2d_param.c
d2i_param.c
IF[{- !$disabled{'rsa'} and !$disabled{'rc4'} -}]
SOURCE[../../libcrypto]=n_pkey.c
ENDIF
Expand Down
124 changes: 124 additions & 0 deletions crypto/asn1/i2d_evp.c
@@ -0,0 +1,124 @@
/*
* Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/

/* We need to use some deprecated APIs to support the legacy bits */
#define OPENSSL_SUPPRESS_DEPRECATED
t8m marked this conversation as resolved.
Show resolved Hide resolved

#include <stdio.h>
#include "internal/cryptlib.h"
#include <openssl/evp.h>
#include <openssl/encoder.h>
#include <openssl/buffer.h>
#include <openssl/x509.h>
#include <openssl/rsa.h> /* For i2d_RSAPublicKey */
#include <openssl/dsa.h> /* For i2d_DSAPublicKey */
#include <openssl/ec.h> /* For i2o_ECPublicKey */
#include "crypto/asn1.h"
#include "crypto/evp.h"

static int i2d_provided(const EVP_PKEY *a, int selection,
const char *output_structures[],
unsigned char **pp)
{
OSSL_ENCODER_CTX *ctx = NULL;
int ret;

for (ret = -1;
ret == -1 && *output_structures != NULL;
output_structures++) {
/*
* The i2d_ calls don't take a boundary length for *pp. However,
* OSSL_ENCODER_CTX_get_num_encoders() needs one, so we make one
* up.
*/
size_t len = INT_MAX;

ctx = OSSL_ENCODER_CTX_new_by_EVP_PKEY(a, selection, "DER",
*output_structures,
NULL, NULL);
if (ctx == NULL)
return -1;
if (OSSL_ENCODER_to_data(ctx, pp, &len))
ret = (int)len;
OSSL_ENCODER_CTX_free(ctx);
ctx = NULL;
}

if (ret == -1)
ERR_raise(ERR_LIB_ASN1, ASN1_R_UNSUPPORTED_TYPE);
return ret;
}

int i2d_KeyParams(const EVP_PKEY *a, unsigned char **pp)
{
if (evp_pkey_is_provided(a)) {
const char *output_structures[] = { "type-specific", NULL };

return i2d_provided(a, EVP_PKEY_KEY_PARAMETERS, output_structures, pp);
}
if (a->ameth != NULL && a->ameth->param_encode != NULL)
return a->ameth->param_encode(a, pp);
ERR_raise(ERR_LIB_ASN1, ASN1_R_UNSUPPORTED_TYPE);
return -1;
}

int i2d_KeyParams_bio(BIO *bp, const EVP_PKEY *pkey)
{
return ASN1_i2d_bio_of(EVP_PKEY, i2d_KeyParams, bp, pkey);
}

int i2d_PrivateKey(const EVP_PKEY *a, unsigned char **pp)
{
if (evp_pkey_is_provided(a)) {
const char *output_structures[] = { "type-specific", "pkcs8", NULL };

return i2d_provided(a, EVP_PKEY_KEYPAIR, output_structures, pp);
}
if (a->ameth != NULL && a->ameth->old_priv_encode != NULL) {
return a->ameth->old_priv_encode(a, pp);
}
if (a->ameth != NULL && a->ameth->priv_encode != NULL) {
PKCS8_PRIV_KEY_INFO *p8 = EVP_PKEY2PKCS8(a);
int ret = 0;

if (p8 != NULL) {
ret = i2d_PKCS8_PRIV_KEY_INFO(p8, pp);
PKCS8_PRIV_KEY_INFO_free(p8);
}
return ret;
}
ERR_raise(ERR_LIB_ASN1, ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
return -1;
}

int i2d_PublicKey(const EVP_PKEY *a, unsigned char **pp)
{
if (evp_pkey_is_provided(a)) {
const char *output_structures[] = { "type-specific", NULL };

return i2d_provided(a, EVP_PKEY_PUBLIC_KEY, output_structures, pp);
}
switch (EVP_PKEY_id(a)) {
#ifndef OPENSSL_NO_RSA
case EVP_PKEY_RSA:
return i2d_RSAPublicKey(EVP_PKEY_get0_RSA(a), pp);
#endif
#ifndef OPENSSL_NO_DSA
case EVP_PKEY_DSA:
return i2d_DSAPublicKey(EVP_PKEY_get0_DSA(a), pp);
#endif
#ifndef OPENSSL_NO_EC
case EVP_PKEY_EC:
return i2o_ECPublicKey(EVP_PKEY_get0_EC_KEY(a), pp);
#endif
default:
ERR_raise(ERR_LIB_ASN1, ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
return -1;
}
}
30 changes: 0 additions & 30 deletions crypto/asn1/i2d_param.c

This file was deleted.

51 changes: 0 additions & 51 deletions crypto/asn1/i2d_pr.c

This file was deleted.

44 changes: 0 additions & 44 deletions crypto/asn1/i2d_pu.c

This file was deleted.