From: Dr. Stephen Henson Date: Sun, 26 Dec 1999 19:20:03 +0000 (+0000) Subject: New {i2d,d2i}_PrivateKey_{bio, fp} functions. X-Git-Tag: OpenSSL_0_9_5beta1~350 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=e6f3c5850e64145eaecdcf44737e873530f7d37b;p=oweals%2Fopenssl.git New {i2d,d2i}_PrivateKey_{bio, fp} functions. --- diff --git a/CHANGES b/CHANGES index b26145ce44..b612be6577 100644 --- a/CHANGES +++ b/CHANGES @@ -4,9 +4,13 @@ Changes between 0.9.4 and 0.9.5 [xx XXX 1999] + *) Add d2i,i2d bio/fp functions for PrivateKey: these convert the + traditional format into an EVP_PKEY structure. + [Steve Henson] + *) Add a password callback function PEM_cb() which either prompts for a password if usr_data is NULL or otherwise assumes it is a null - terminate password. Allow passwords to be passed on command line + terminated password. Allow passwords to be passed on command line environment or config files in a few more utilities. [Steve Henson] diff --git a/crypto/asn1/asn1.h b/crypto/asn1/asn1.h index 42c63ddede..ccec930522 100644 --- a/crypto/asn1/asn1.h +++ b/crypto/asn1/asn1.h @@ -890,6 +890,8 @@ void ASN1_STRING_TABLE_cleanup(void); #define ASN1_F_D2I_POLICYINFO 269 #define ASN1_F_D2I_POLICYQUALINFO 270 #define ASN1_F_D2I_PRIVATEKEY 155 +#define ASN1_F_D2I_PRIVATEKEY_BIO 293 +#define ASN1_F_D2I_PRIVATEKEY_FP 294 #define ASN1_F_D2I_PUBLICKEY 156 #define ASN1_F_D2I_RSAPRIVATEKEY 157 #define ASN1_F_D2I_RSAPUBLICKEY 158 diff --git a/crypto/asn1/asn1_err.c b/crypto/asn1/asn1_err.c index ffcc6076b0..3471c48165 100644 --- a/crypto/asn1/asn1_err.c +++ b/crypto/asn1/asn1_err.c @@ -163,6 +163,8 @@ static ERR_STRING_DATA ASN1_str_functs[]= {ERR_PACK(0,ASN1_F_D2I_POLICYINFO,0), "d2i_POLICYINFO"}, {ERR_PACK(0,ASN1_F_D2I_POLICYQUALINFO,0), "d2i_POLICYQUALINFO"}, {ERR_PACK(0,ASN1_F_D2I_PRIVATEKEY,0), "d2i_PrivateKey"}, +{ERR_PACK(0,ASN1_F_D2I_PRIVATEKEY_BIO,0), "d2i_PrivateKey_bio"}, +{ERR_PACK(0,ASN1_F_D2I_PRIVATEKEY_FP,0), "d2i_PrivateKey_fp"}, {ERR_PACK(0,ASN1_F_D2I_PUBLICKEY,0), "d2i_PublicKey"}, {ERR_PACK(0,ASN1_F_D2I_RSAPRIVATEKEY,0), "d2i_RSAPrivateKey"}, {ERR_PACK(0,ASN1_F_D2I_RSAPUBLICKEY,0), "d2i_RSAPublicKey"}, diff --git a/crypto/x509/x509.h b/crypto/x509/x509.h index a5e83ee824..90bebb17a8 100644 --- a/crypto/x509/x509.h +++ b/crypto/x509/x509.h @@ -658,13 +658,15 @@ DSA *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa); int i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa); DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa); int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa); +#endif X509_SIG *d2i_PKCS8_fp(FILE *fp,X509_SIG **p8); int i2d_PKCS8_fp(FILE *fp,X509_SIG *p8); PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, PKCS8_PRIV_KEY_INFO **p8inf); int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,PKCS8_PRIV_KEY_INFO *p8inf); int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key); -#endif +int i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey); +EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, int type, EVP_PKEY **a); #endif #ifdef HEADER_BIO_H @@ -694,6 +696,8 @@ PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, PKCS8_PRIV_KEY_INFO **p8inf); int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,PKCS8_PRIV_KEY_INFO *p8inf); int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key); +int i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey); +EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, int type, EVP_PKEY **a); #endif X509 *X509_dup(X509 *x509); diff --git a/crypto/x509/x_all.c b/crypto/x509/x_all.c index 887999f89d..e1d70dfdfe 100644 --- a/crypto/x509/x_all.c +++ b/crypto/x509/x_all.c @@ -481,6 +481,24 @@ int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key) return ret; } +int i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey) + { + return(ASN1_i2d_fp(i2d_PrivateKey,fp,(unsigned char *)pkey)); + } + +EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, int type, EVP_PKEY **a) +{ + BIO *bp; + EVP_PKEY *ret; + if(!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) { + ASN1err(ASN1_F_D2I_PRIVATEKEY_FP,ERR_R_MALLOC_FAILURE); + return NULL; + } + ret = d2i_PrivateKey_bio(bp, type, a); + BIO_free(bp); + return ret; +} + #endif PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, @@ -507,3 +525,56 @@ int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key) PKCS8_PRIV_KEY_INFO_free(p8inf); return ret; } + +int i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey) + { + return(ASN1_i2d_bio(i2d_PrivateKey,bp,(unsigned char *)pkey)); + } + +EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, int type, EVP_PKEY **a) + { + EVP_PKEY *ret; + + if ((a == NULL) || (*a == NULL)) + { + if ((ret=EVP_PKEY_new()) == NULL) + { + ASN1err(ASN1_F_D2I_PRIVATEKEY_BIO,ERR_R_EVP_LIB); + return(NULL); + } + } + else ret= *a; + + ret->save_type=type; + ret->type=EVP_PKEY_type(type); + switch (ret->type) + { +#ifndef NO_RSA + case EVP_PKEY_RSA: + if ((ret->pkey.rsa=d2i_RSAPrivateKey_bio(bp,NULL)) == NULL) + { + ASN1err(ASN1_F_D2I_PRIVATEKEY_BIO,ERR_R_ASN1_LIB); + goto err; + } + break; +#endif +#ifndef NO_DSA + case EVP_PKEY_DSA: + if ((ret->pkey.dsa=d2i_DSAPrivateKey_bio(bp, NULL)) == NULL) + { + ASN1err(ASN1_F_D2I_PRIVATEKEY_BIO,ERR_R_ASN1_LIB); + goto err; + } + break; +#endif + default: + ASN1err(ASN1_F_D2I_PRIVATEKEY_BIO,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); + goto err; + /* break; */ + } + if (a != NULL) (*a)=ret; + return(ret); +err: + if ((ret != NULL) && ((a == NULL) || (*a != ret))) EVP_PKEY_free(ret); + return(NULL); + } diff --git a/util/libeay.num b/util/libeay.num index 7db8acf8bd..b163ab24f3 100755 --- a/util/libeay.num +++ b/util/libeay.num @@ -2152,3 +2152,7 @@ i2d_PKCS8PrivateKey_nid_bio 2176 i2d_PKCS8PrivateKeyInfo_fp 2177 i2d_PKCS8PrivateKeyInfo_bio 2178 PEM_cb 2179 +i2d_PrivateKey_fp 2180 +d2i_PrivateKey_bio 2181 +d2i_PrivateKey_fp 2182 +i2d_PrivateKey_bio 2183