Make EVP_PKEY_ASN1_METHOD opaque. Add application level functions to
initialize it. Initial support for application added public key ASN1.
This commit is contained in:
parent
043b2e9c2e
commit
18e377b4ff
@ -7,7 +7,7 @@ TOP= ..
|
||||
CC= cc
|
||||
INCLUDE= -I. -I$(TOP) -I../include
|
||||
# INCLUDES targets sudbirs!
|
||||
INCLUDES= -I.. -I../.. -I../../include
|
||||
INCLUDES= -I.. -I../.. -I../asn1 -I../../include
|
||||
CFLAG= -g
|
||||
MAKEDEPPROG= makedepend
|
||||
MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
|
||||
|
@ -81,6 +81,11 @@ const EVP_PKEY_ASN1_METHOD *standard_methods[] =
|
||||
&eckey_asn1_meth
|
||||
};
|
||||
|
||||
typedef int sk_cmp_fn_type(const char * const *a, const char * const *b);
|
||||
static STACK *app_methods = NULL;
|
||||
|
||||
|
||||
|
||||
#ifdef TEST
|
||||
void main()
|
||||
{
|
||||
@ -97,14 +102,21 @@ void main()
|
||||
static int ameth_cmp(const EVP_PKEY_ASN1_METHOD * const *a,
|
||||
const EVP_PKEY_ASN1_METHOD * const *b)
|
||||
{
|
||||
/*fprintf(stderr, "Comparing %d with %d\n", (*a)->pkey_id, (*b)->pkey_id);*/
|
||||
return ((*a)->pkey_id - (*b)->pkey_id);
|
||||
}
|
||||
|
||||
const EVP_PKEY_ASN1_METHOD *EVP_PKEY_ASN1_find(int type)
|
||||
const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(int type)
|
||||
{
|
||||
EVP_PKEY_ASN1_METHOD tmp, *t = &tmp, **ret;
|
||||
tmp.pkey_id = type;
|
||||
if (app_methods)
|
||||
{
|
||||
int idx;
|
||||
idx = sk_find(app_methods, (char *)&t);
|
||||
if (idx > 0)
|
||||
return (EVP_PKEY_ASN1_METHOD *)
|
||||
sk_value(app_methods, idx);
|
||||
}
|
||||
ret = (EVP_PKEY_ASN1_METHOD **) OBJ_bsearch((char *)&t,
|
||||
(char *)standard_methods,
|
||||
sizeof(standard_methods)/sizeof(EVP_PKEY_ASN1_METHOD *),
|
||||
@ -113,7 +125,117 @@ const EVP_PKEY_ASN1_METHOD *EVP_PKEY_ASN1_find(int type)
|
||||
if (!ret || !*ret)
|
||||
return NULL;
|
||||
if ((*ret)->pkey_flags & ASN1_PKEY_ALIAS)
|
||||
return EVP_PKEY_ASN1_find((*ret)->pkey_base_id);
|
||||
return EVP_PKEY_asn1_find((*ret)->pkey_base_id);
|
||||
return *ret;
|
||||
}
|
||||
|
||||
int EVP_PKEY_asn1_add(const EVP_PKEY_ASN1_METHOD *ameth)
|
||||
{
|
||||
if (app_methods == NULL)
|
||||
{
|
||||
app_methods = sk_new((sk_cmp_fn_type *)ameth_cmp);
|
||||
if (!app_methods)
|
||||
return 0;
|
||||
}
|
||||
if (!sk_push(app_methods, (char *)ameth))
|
||||
return 0;
|
||||
sk_sort(app_methods);
|
||||
return 1;
|
||||
}
|
||||
|
||||
EVP_PKEY_ASN1_METHOD* EVP_PKEY_asn1_new(int id)
|
||||
{
|
||||
EVP_PKEY_ASN1_METHOD *ameth;
|
||||
ameth = OPENSSL_malloc(sizeof(EVP_PKEY_ASN1_METHOD));
|
||||
if (!ameth)
|
||||
return NULL;
|
||||
|
||||
ameth->pkey_id = id;
|
||||
ameth->pkey_base_id = id;
|
||||
ameth->pkey_flags = ASN1_PKEY_DYNAMIC;
|
||||
|
||||
ameth->pub_decode = 0;
|
||||
ameth->pub_encode = 0;
|
||||
ameth->pub_cmp = 0;
|
||||
ameth->pub_print = 0;
|
||||
|
||||
|
||||
ameth->priv_decode = 0;
|
||||
ameth->priv_encode = 0;
|
||||
ameth->priv_print = 0;
|
||||
|
||||
|
||||
ameth->pkey_size = 0;
|
||||
ameth->pkey_bits = 0;
|
||||
|
||||
ameth->param_decode = 0;
|
||||
ameth->param_encode = 0;
|
||||
ameth->param_missing = 0;
|
||||
ameth->param_copy = 0;
|
||||
ameth->param_cmp = 0;
|
||||
ameth->param_print = 0;
|
||||
|
||||
|
||||
ameth->pkey_free = 0;
|
||||
ameth->pkey_ctrl = 0;
|
||||
|
||||
return ameth;
|
||||
}
|
||||
|
||||
void EVP_PKEY_asn1_set_public(EVP_PKEY_ASN1_METHOD *ameth,
|
||||
int (*pub_decode)(EVP_PKEY *pk, X509_PUBKEY *pub),
|
||||
int (*pub_encode)(X509_PUBKEY *pub, const EVP_PKEY *pk),
|
||||
int (*pub_cmp)(const EVP_PKEY *a, const EVP_PKEY *b),
|
||||
int (*pub_print)(BIO *out, const EVP_PKEY *pkey, int indent,
|
||||
ASN1_PCTX *pctx),
|
||||
int (*pkey_size)(const EVP_PKEY *pk),
|
||||
int (*pkey_bits)(const EVP_PKEY *pk))
|
||||
{
|
||||
ameth->pub_decode = pub_decode;
|
||||
ameth->pub_encode = pub_encode;
|
||||
ameth->pub_cmp = pub_cmp;
|
||||
ameth->pub_print = pub_print;
|
||||
ameth->pkey_size = pkey_size;
|
||||
ameth->pkey_bits = pkey_bits;
|
||||
}
|
||||
|
||||
void EVP_PKEY_asn1_set_private(EVP_PKEY_ASN1_METHOD *ameth,
|
||||
int (*priv_decode)(EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf),
|
||||
int (*priv_encode)(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk),
|
||||
int (*priv_print)(BIO *out, const EVP_PKEY *pkey, int indent,
|
||||
ASN1_PCTX *pctx))
|
||||
{
|
||||
ameth->priv_decode = priv_decode;
|
||||
ameth->priv_encode = priv_encode;
|
||||
ameth->priv_print = priv_print;
|
||||
}
|
||||
|
||||
void EVP_PKEY_asn1_set_param(EVP_PKEY_ASN1_METHOD *ameth,
|
||||
int (*param_decode)(const EVP_PKEY *pk, X509_PUBKEY *pub),
|
||||
int (*param_encode)(X509_PUBKEY *pub, const EVP_PKEY *pk),
|
||||
int (*param_missing)(const EVP_PKEY *pk),
|
||||
int (*param_copy)(EVP_PKEY *to, const EVP_PKEY *from),
|
||||
int (*param_cmp)(const EVP_PKEY *a, const EVP_PKEY *b),
|
||||
int (*param_print)(BIO *out, const EVP_PKEY *pkey, int indent,
|
||||
ASN1_PCTX *pctx))
|
||||
{
|
||||
ameth->param_decode = param_decode;
|
||||
ameth->param_encode = param_encode;
|
||||
ameth->param_missing = param_missing;
|
||||
ameth->param_copy = param_copy;
|
||||
ameth->param_cmp = param_cmp;
|
||||
ameth->param_print = param_print;
|
||||
}
|
||||
|
||||
void EVP_PKEY_asn1_set_free(EVP_PKEY_ASN1_METHOD *ameth,
|
||||
void (*pkey_free)(EVP_PKEY *pkey))
|
||||
{
|
||||
ameth->pkey_free = pkey_free;
|
||||
}
|
||||
|
||||
void EVP_PKEY_asn1_set_ctrl(EVP_PKEY_ASN1_METHOD *ameth,
|
||||
void (*pkey_ctrl)(EVP_PKEY *pkey, int op,
|
||||
long arg1, void *arg2))
|
||||
{
|
||||
ameth->pkey_ctrl = pkey_ctrl;
|
||||
}
|
||||
|
@ -282,42 +282,6 @@ typedef struct ASN1_TLC_st ASN1_TLC;
|
||||
/* This is just an opaque pointer */
|
||||
typedef struct ASN1_VALUE_st ASN1_VALUE;
|
||||
|
||||
/* ASN1 public key method structure */
|
||||
|
||||
#define ASN1_PKEY_ALIAS 0x1
|
||||
|
||||
struct evp_pkey_asn1_method_st
|
||||
{
|
||||
int pkey_id;
|
||||
int pkey_base_id;
|
||||
unsigned long pkey_flags;
|
||||
|
||||
int (*pub_decode)(EVP_PKEY *pk, X509_PUBKEY *pub);
|
||||
int (*pub_encode)(X509_PUBKEY *pub, const EVP_PKEY *pk);
|
||||
int (*pub_cmp)(const EVP_PKEY *a, const EVP_PKEY *b);
|
||||
int (*pub_print)(BIO *out, const EVP_PKEY *pkey, int indent,
|
||||
ASN1_PCTX *pctx);
|
||||
|
||||
int (*priv_decode)(EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf);
|
||||
int (*priv_encode)(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk);
|
||||
int (*priv_print)(BIO *out, const EVP_PKEY *pkey, int indent,
|
||||
ASN1_PCTX *pctx);
|
||||
|
||||
int (*pkey_size)(const EVP_PKEY *pk);
|
||||
int (*pkey_bits)(const EVP_PKEY *pk);
|
||||
|
||||
int (*param_decode)(const EVP_PKEY *pk, X509_PUBKEY *pub);
|
||||
int (*param_encode)(X509_PUBKEY *pub, const EVP_PKEY *pk);
|
||||
int (*param_missing)(const EVP_PKEY *pk);
|
||||
int (*param_copy)(EVP_PKEY *to, const EVP_PKEY *from);
|
||||
int (*param_cmp)(const EVP_PKEY *a, const EVP_PKEY *b);
|
||||
int (*param_print)(BIO *out, const EVP_PKEY *pkey, int indent,
|
||||
ASN1_PCTX *pctx);
|
||||
|
||||
void (*pkey_free)(EVP_PKEY *pkey);
|
||||
void (*pkey_ctrl)(EVP_PKEY *pkey, int op, long arg1, void *arg2);
|
||||
} /* EVP_PKEY_ASN1_METHOD */;
|
||||
|
||||
/* Declare ASN1 functions: the implement macro in in asn1t.h */
|
||||
|
||||
#define DECLARE_ASN1_FUNCTIONS(type) DECLARE_ASN1_FUNCTIONS_name(type, type)
|
||||
|
@ -68,3 +68,40 @@ struct asn1_pctx_st
|
||||
unsigned long oid_flags;
|
||||
unsigned long str_flags;
|
||||
} /* ASN1_PCTX */;
|
||||
|
||||
/* ASN1 public key method structure */
|
||||
|
||||
#define ASN1_PKEY_ALIAS 0x1
|
||||
#define ASN1_PKEY_DYNAMIC 0x2
|
||||
|
||||
struct evp_pkey_asn1_method_st
|
||||
{
|
||||
int pkey_id;
|
||||
int pkey_base_id;
|
||||
unsigned long pkey_flags;
|
||||
|
||||
int (*pub_decode)(EVP_PKEY *pk, X509_PUBKEY *pub);
|
||||
int (*pub_encode)(X509_PUBKEY *pub, const EVP_PKEY *pk);
|
||||
int (*pub_cmp)(const EVP_PKEY *a, const EVP_PKEY *b);
|
||||
int (*pub_print)(BIO *out, const EVP_PKEY *pkey, int indent,
|
||||
ASN1_PCTX *pctx);
|
||||
|
||||
int (*priv_decode)(EVP_PKEY *pk, PKCS8_PRIV_KEY_INFO *p8inf);
|
||||
int (*priv_encode)(PKCS8_PRIV_KEY_INFO *p8, const EVP_PKEY *pk);
|
||||
int (*priv_print)(BIO *out, const EVP_PKEY *pkey, int indent,
|
||||
ASN1_PCTX *pctx);
|
||||
|
||||
int (*pkey_size)(const EVP_PKEY *pk);
|
||||
int (*pkey_bits)(const EVP_PKEY *pk);
|
||||
|
||||
int (*param_decode)(const EVP_PKEY *pk, X509_PUBKEY *pub);
|
||||
int (*param_encode)(X509_PUBKEY *pub, const EVP_PKEY *pk);
|
||||
int (*param_missing)(const EVP_PKEY *pk);
|
||||
int (*param_copy)(EVP_PKEY *to, const EVP_PKEY *from);
|
||||
int (*param_cmp)(const EVP_PKEY *a, const EVP_PKEY *b);
|
||||
int (*param_print)(BIO *out, const EVP_PKEY *pkey, int indent,
|
||||
ASN1_PCTX *pctx);
|
||||
|
||||
void (*pkey_free)(EVP_PKEY *pkey);
|
||||
void (*pkey_ctrl)(EVP_PKEY *pkey, int op, long arg1, void *arg2);
|
||||
} /* EVP_PKEY_ASN1_METHOD */;
|
||||
|
@ -89,7 +89,7 @@ EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp,
|
||||
|
||||
ret->save_type=type;
|
||||
ret->type=EVP_PKEY_type(type);
|
||||
ret->ameth = EVP_PKEY_ASN1_find(type);
|
||||
ret->ameth = EVP_PKEY_asn1_find(type);
|
||||
switch (ret->type)
|
||||
{
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
|
@ -60,6 +60,7 @@
|
||||
#include "cryptlib.h"
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/x509.h>
|
||||
#include "asn1_locl.h"
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
#include <openssl/rsa.h>
|
||||
#endif
|
||||
@ -95,7 +96,7 @@ int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey)
|
||||
|
||||
if ((pk=X509_PUBKEY_new()) == NULL) goto error;
|
||||
|
||||
meth = EVP_PKEY_ASN1_find(pkey->type);
|
||||
meth = EVP_PKEY_asn1_find(pkey->type);
|
||||
|
||||
if (meth)
|
||||
{
|
||||
@ -153,7 +154,7 @@ EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)
|
||||
goto error;
|
||||
}
|
||||
|
||||
meth = EVP_PKEY_ASN1_find(OBJ_obj2nid(key->algor->algorithm));
|
||||
meth = EVP_PKEY_asn1_find(OBJ_obj2nid(key->algor->algorithm));
|
||||
|
||||
if (meth)
|
||||
{
|
||||
|
@ -60,6 +60,7 @@
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/dh.h>
|
||||
#include "asn1_locl.h"
|
||||
|
||||
static void int_dh_free(EVP_PKEY *pkey)
|
||||
{
|
||||
|
@ -60,6 +60,7 @@
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/asn1.h>
|
||||
#include <openssl/dsa.h>
|
||||
#include "asn1_locl.h"
|
||||
|
||||
static int dsa_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey)
|
||||
{
|
||||
|
@ -59,6 +59,7 @@
|
||||
#include "cryptlib.h"
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/ec.h>
|
||||
#include "asn1_locl.h"
|
||||
|
||||
static int eckey_param2type(int *pptype, void **ppval, EC_KEY *ec_key)
|
||||
{
|
||||
|
@ -855,7 +855,7 @@ int EVP_PBE_alg_add(int nid, const EVP_CIPHER *cipher, const EVP_MD *md,
|
||||
EVP_PBE_KEYGEN *keygen);
|
||||
void EVP_PBE_cleanup(void);
|
||||
|
||||
const EVP_PKEY_ASN1_METHOD *EVP_PKEY_ASN1_find(int type);
|
||||
const EVP_PKEY_ASN1_METHOD *EVP_PKEY_asn1_find(int type);
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
/* The following lines are auto generated by the script mkerr.pl. Any changes
|
||||
|
@ -61,13 +61,7 @@
|
||||
#include "cryptlib.h"
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/rand.h>
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
#include <openssl/rsa.h>
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
#include <openssl/dsa.h>
|
||||
#endif
|
||||
#include <openssl/bn.h>
|
||||
#include "asn1_locl.h"
|
||||
|
||||
/* Extract a private key from a PKCS8 structure */
|
||||
|
||||
@ -86,7 +80,7 @@ EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
meth = EVP_PKEY_ASN1_find(OBJ_obj2nid(algoid));
|
||||
meth = EVP_PKEY_asn1_find(OBJ_obj2nid(algoid));
|
||||
|
||||
if (meth)
|
||||
{
|
||||
@ -138,7 +132,7 @@ PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8_broken(EVP_PKEY *pkey, int broken)
|
||||
}
|
||||
p8->broken = broken;
|
||||
|
||||
meth = EVP_PKEY_ASN1_find(pkey->type);
|
||||
meth = EVP_PKEY_asn1_find(pkey->type);
|
||||
|
||||
if (meth)
|
||||
{
|
||||
|
@ -74,6 +74,8 @@
|
||||
#include <openssl/dh.h>
|
||||
#endif
|
||||
|
||||
#include "asn1_locl.h"
|
||||
|
||||
static void EVP_PKEY_free_it(EVP_PKEY *x);
|
||||
|
||||
int EVP_PKEY_bits(EVP_PKEY *pkey)
|
||||
@ -189,7 +191,7 @@ int EVP_PKEY_assign(EVP_PKEY *pkey, int type, char *key)
|
||||
if (pkey == NULL) return(0);
|
||||
if (pkey->pkey.ptr != NULL)
|
||||
EVP_PKEY_free_it(pkey);
|
||||
ameth = EVP_PKEY_ASN1_find(type);
|
||||
ameth = EVP_PKEY_asn1_find(type);
|
||||
pkey->ameth = ameth;
|
||||
pkey->type = ameth->pkey_id;
|
||||
pkey->save_type=type;
|
||||
@ -284,7 +286,7 @@ DH *EVP_PKEY_get1_DH(EVP_PKEY *pkey)
|
||||
int EVP_PKEY_type(int type)
|
||||
{
|
||||
const EVP_PKEY_ASN1_METHOD *ameth;
|
||||
ameth = EVP_PKEY_ASN1_find(type);
|
||||
ameth = EVP_PKEY_asn1_find(type);
|
||||
if (ameth)
|
||||
return ameth->pkey_id;
|
||||
return NID_undef;
|
||||
|
@ -60,6 +60,7 @@
|
||||
#include <openssl/asn1t.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/rsa.h>
|
||||
#include "asn1_locl.h"
|
||||
|
||||
static int rsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user