mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-05-29 19:56:16 +08:00
update
This commit is contained in:
@@ -64,6 +64,8 @@ tests:
|
||||
lint:
|
||||
lint -DLINT $(INCLUDES) $(SRC)>fluff
|
||||
|
||||
update: depend
|
||||
|
||||
depend:
|
||||
@[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
|
||||
$(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(LIBSRC)
|
||||
@@ -169,12 +171,13 @@ pem_pk8.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
|
||||
pem_pk8.o: ../cryptlib.h pem_pk8.c
|
||||
pem_pkey.o: ../../e_os.h ../../include/openssl/asn1.h
|
||||
pem_pkey.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
|
||||
pem_pkey.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
|
||||
pem_pkey.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
|
||||
pem_pkey.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
|
||||
pem_pkey.o: ../../include/openssl/err.h ../../include/openssl/evp.h
|
||||
pem_pkey.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
|
||||
pem_pkey.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
|
||||
pem_pkey.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
|
||||
pem_pkey.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
|
||||
pem_pkey.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
|
||||
pem_pkey.o: ../../include/openssl/engine.h ../../include/openssl/err.h
|
||||
pem_pkey.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
|
||||
pem_pkey.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
|
||||
pem_pkey.o: ../../include/openssl/opensslconf.h
|
||||
pem_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
|
||||
pem_pkey.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
|
||||
pem_pkey.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
|
||||
|
||||
830
crypto/pem/pem.h
830
crypto/pem/pem.h
File diff suppressed because it is too large
Load Diff
@@ -6,7 +6,7 @@
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
|
||||
@@ -5,21 +5,21 @@
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
@@ -34,10 +34,10 @@
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
@@ -49,7 +49,7 @@
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
@@ -63,7 +63,7 @@
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
@@ -117,13 +117,13 @@
|
||||
#include <openssl/pkcs7.h>
|
||||
#include <openssl/pem.h>
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
#include <openssl/rsa.h>
|
||||
# include <openssl/rsa.h>
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
#include <openssl/dsa.h>
|
||||
# include <openssl/dsa.h>
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DH
|
||||
#include <openssl/dh.h>
|
||||
# include <openssl/dh.h>
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
@@ -140,157 +140,288 @@ static EC_KEY *pkey_get_eckey(EVP_PKEY *key, EC_KEY **eckey);
|
||||
IMPLEMENT_PEM_rw(X509_REQ, X509_REQ, PEM_STRING_X509_REQ, X509_REQ)
|
||||
|
||||
IMPLEMENT_PEM_write(X509_REQ_NEW, X509_REQ, PEM_STRING_X509_REQ_OLD, X509_REQ)
|
||||
|
||||
IMPLEMENT_PEM_rw(X509_CRL, X509_CRL, PEM_STRING_X509_CRL, X509_CRL)
|
||||
|
||||
IMPLEMENT_PEM_rw(PKCS7, PKCS7, PEM_STRING_PKCS7, PKCS7)
|
||||
|
||||
IMPLEMENT_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE,
|
||||
PEM_STRING_X509, NETSCAPE_CERT_SEQUENCE)
|
||||
|
||||
|
||||
PEM_STRING_X509, NETSCAPE_CERT_SEQUENCE)
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
|
||||
/* We treat RSA or DSA private keys as a special case.
|
||||
*
|
||||
* For private keys we read in an EVP_PKEY structure with
|
||||
* PEM_read_bio_PrivateKey() and extract the relevant private
|
||||
* key: this means can handle "traditional" and PKCS#8 formats
|
||||
* transparently.
|
||||
/*
|
||||
* We treat RSA or DSA private keys as a special case. For private keys we
|
||||
* read in an EVP_PKEY structure with PEM_read_bio_PrivateKey() and extract
|
||||
* the relevant private key: this means can handle "traditional" and PKCS#8
|
||||
* formats transparently.
|
||||
*/
|
||||
|
||||
static RSA *pkey_get_rsa(EVP_PKEY *key, RSA **rsa)
|
||||
{
|
||||
RSA *rtmp;
|
||||
if(!key) return NULL;
|
||||
rtmp = EVP_PKEY_get1_RSA(key);
|
||||
EVP_PKEY_free(key);
|
||||
if(!rtmp) return NULL;
|
||||
if(rsa) {
|
||||
RSA_free(*rsa);
|
||||
*rsa = rtmp;
|
||||
}
|
||||
return rtmp;
|
||||
RSA *rtmp;
|
||||
if (!key)
|
||||
return NULL;
|
||||
rtmp = EVP_PKEY_get1_RSA(key);
|
||||
EVP_PKEY_free(key);
|
||||
if (!rtmp)
|
||||
return NULL;
|
||||
if (rsa) {
|
||||
RSA_free(*rsa);
|
||||
*rsa = rtmp;
|
||||
}
|
||||
return rtmp;
|
||||
}
|
||||
|
||||
RSA *PEM_read_bio_RSAPrivateKey(BIO *bp, RSA **rsa, pem_password_cb *cb,
|
||||
void *u)
|
||||
void *u)
|
||||
{
|
||||
EVP_PKEY *pktmp;
|
||||
pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u);
|
||||
return pkey_get_rsa(pktmp, rsa);
|
||||
EVP_PKEY *pktmp;
|
||||
pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u);
|
||||
return pkey_get_rsa(pktmp, rsa);
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_FP_API
|
||||
# ifndef OPENSSL_NO_FP_API
|
||||
|
||||
RSA *PEM_read_RSAPrivateKey(FILE *fp, RSA **rsa, pem_password_cb *cb,
|
||||
void *u)
|
||||
RSA *PEM_read_RSAPrivateKey(FILE *fp, RSA **rsa, pem_password_cb *cb, void *u)
|
||||
{
|
||||
EVP_PKEY *pktmp;
|
||||
pktmp = PEM_read_PrivateKey(fp, NULL, cb, u);
|
||||
return pkey_get_rsa(pktmp, rsa);
|
||||
EVP_PKEY *pktmp;
|
||||
pktmp = PEM_read_PrivateKey(fp, NULL, cb, u);
|
||||
return pkey_get_rsa(pktmp, rsa);
|
||||
}
|
||||
|
||||
# endif
|
||||
|
||||
# ifdef OPENSSL_FIPS
|
||||
|
||||
int PEM_write_bio_RSAPrivateKey(BIO *bp, RSA *x, const EVP_CIPHER *enc,
|
||||
unsigned char *kstr, int klen,
|
||||
pem_password_cb *cb, void *u)
|
||||
{
|
||||
if (FIPS_mode()) {
|
||||
EVP_PKEY *k;
|
||||
int ret;
|
||||
k = EVP_PKEY_new();
|
||||
if (!k)
|
||||
return 0;
|
||||
EVP_PKEY_set1_RSA(k, x);
|
||||
|
||||
ret = PEM_write_bio_PrivateKey(bp, k, enc, kstr, klen, cb, u);
|
||||
EVP_PKEY_free(k);
|
||||
return ret;
|
||||
} else
|
||||
return PEM_ASN1_write_bio((i2d_of_void *)i2d_RSAPrivateKey,
|
||||
PEM_STRING_RSA, bp, x, enc, kstr, klen, cb,
|
||||
u);
|
||||
}
|
||||
|
||||
# ifndef OPENSSL_NO_FP_API
|
||||
int PEM_write_RSAPrivateKey(FILE *fp, RSA *x, const EVP_CIPHER *enc,
|
||||
unsigned char *kstr, int klen,
|
||||
pem_password_cb *cb, void *u)
|
||||
{
|
||||
if (FIPS_mode()) {
|
||||
EVP_PKEY *k;
|
||||
int ret;
|
||||
k = EVP_PKEY_new();
|
||||
if (!k)
|
||||
return 0;
|
||||
|
||||
EVP_PKEY_set1_RSA(k, x);
|
||||
|
||||
ret = PEM_write_PrivateKey(fp, k, enc, kstr, klen, cb, u);
|
||||
EVP_PKEY_free(k);
|
||||
return ret;
|
||||
} else
|
||||
return PEM_ASN1_write((i2d_of_void *)i2d_RSAPrivateKey,
|
||||
PEM_STRING_RSA, fp, x, enc, kstr, klen, cb, u);
|
||||
}
|
||||
# endif
|
||||
|
||||
# else
|
||||
|
||||
IMPLEMENT_PEM_write_cb_const(RSAPrivateKey, RSA, PEM_STRING_RSA,
|
||||
RSAPrivateKey)
|
||||
# endif
|
||||
IMPLEMENT_PEM_rw_const(RSAPublicKey, RSA, PEM_STRING_RSA_PUBLIC,
|
||||
RSAPublicKey) IMPLEMENT_PEM_rw(RSA_PUBKEY, RSA,
|
||||
PEM_STRING_PUBLIC,
|
||||
RSA_PUBKEY)
|
||||
#endif
|
||||
|
||||
IMPLEMENT_PEM_write_cb_const(RSAPrivateKey, RSA, PEM_STRING_RSA, RSAPrivateKey)
|
||||
IMPLEMENT_PEM_rw_const(RSAPublicKey, RSA, PEM_STRING_RSA_PUBLIC, RSAPublicKey)
|
||||
IMPLEMENT_PEM_rw(RSA_PUBKEY, RSA, PEM_STRING_PUBLIC, RSA_PUBKEY)
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
|
||||
static DSA *pkey_get_dsa(EVP_PKEY *key, DSA **dsa)
|
||||
{
|
||||
DSA *dtmp;
|
||||
if(!key) return NULL;
|
||||
dtmp = EVP_PKEY_get1_DSA(key);
|
||||
EVP_PKEY_free(key);
|
||||
if(!dtmp) return NULL;
|
||||
if(dsa) {
|
||||
DSA_free(*dsa);
|
||||
*dsa = dtmp;
|
||||
}
|
||||
return dtmp;
|
||||
DSA *dtmp;
|
||||
if (!key)
|
||||
return NULL;
|
||||
dtmp = EVP_PKEY_get1_DSA(key);
|
||||
EVP_PKEY_free(key);
|
||||
if (!dtmp)
|
||||
return NULL;
|
||||
if (dsa) {
|
||||
DSA_free(*dsa);
|
||||
*dsa = dtmp;
|
||||
}
|
||||
return dtmp;
|
||||
}
|
||||
|
||||
DSA *PEM_read_bio_DSAPrivateKey(BIO *bp, DSA **dsa, pem_password_cb *cb,
|
||||
void *u)
|
||||
void *u)
|
||||
{
|
||||
EVP_PKEY *pktmp;
|
||||
pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u);
|
||||
return pkey_get_dsa(pktmp, dsa); /* will free pktmp */
|
||||
EVP_PKEY *pktmp;
|
||||
pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u);
|
||||
return pkey_get_dsa(pktmp, dsa); /* will free pktmp */
|
||||
}
|
||||
|
||||
IMPLEMENT_PEM_write_cb_const(DSAPrivateKey, DSA, PEM_STRING_DSA, DSAPrivateKey)
|
||||
IMPLEMENT_PEM_rw(DSA_PUBKEY, DSA, PEM_STRING_PUBLIC, DSA_PUBKEY)
|
||||
# ifdef OPENSSL_FIPS
|
||||
|
||||
#ifndef OPENSSL_NO_FP_API
|
||||
|
||||
DSA *PEM_read_DSAPrivateKey(FILE *fp, DSA **dsa, pem_password_cb *cb,
|
||||
void *u)
|
||||
int PEM_write_bio_DSAPrivateKey(BIO *bp, DSA *x, const EVP_CIPHER *enc,
|
||||
unsigned char *kstr, int klen,
|
||||
pem_password_cb *cb, void *u)
|
||||
{
|
||||
EVP_PKEY *pktmp;
|
||||
pktmp = PEM_read_PrivateKey(fp, NULL, cb, u);
|
||||
return pkey_get_dsa(pktmp, dsa); /* will free pktmp */
|
||||
if (FIPS_mode()) {
|
||||
EVP_PKEY *k;
|
||||
int ret;
|
||||
k = EVP_PKEY_new();
|
||||
if (!k)
|
||||
return 0;
|
||||
EVP_PKEY_set1_DSA(k, x);
|
||||
|
||||
ret = PEM_write_bio_PrivateKey(bp, k, enc, kstr, klen, cb, u);
|
||||
EVP_PKEY_free(k);
|
||||
return ret;
|
||||
} else
|
||||
return PEM_ASN1_write_bio((i2d_of_void *)i2d_DSAPrivateKey,
|
||||
PEM_STRING_DSA, bp, x, enc, kstr, klen, cb,
|
||||
u);
|
||||
}
|
||||
|
||||
#endif
|
||||
# ifndef OPENSSL_NO_FP_API
|
||||
int PEM_write_DSAPrivateKey(FILE *fp, DSA *x, const EVP_CIPHER *enc,
|
||||
unsigned char *kstr, int klen,
|
||||
pem_password_cb *cb, void *u)
|
||||
{
|
||||
if (FIPS_mode()) {
|
||||
EVP_PKEY *k;
|
||||
int ret;
|
||||
k = EVP_PKEY_new();
|
||||
if (!k)
|
||||
return 0;
|
||||
EVP_PKEY_set1_DSA(k, x);
|
||||
ret = PEM_write_PrivateKey(fp, k, enc, kstr, klen, cb, u);
|
||||
EVP_PKEY_free(k);
|
||||
return ret;
|
||||
} else
|
||||
return PEM_ASN1_write((i2d_of_void *)i2d_DSAPrivateKey,
|
||||
PEM_STRING_DSA, fp, x, enc, kstr, klen, cb, u);
|
||||
}
|
||||
# endif
|
||||
|
||||
# else
|
||||
|
||||
IMPLEMENT_PEM_write_cb_const(DSAPrivateKey, DSA, PEM_STRING_DSA,
|
||||
DSAPrivateKey)
|
||||
# endif
|
||||
IMPLEMENT_PEM_rw(DSA_PUBKEY, DSA, PEM_STRING_PUBLIC, DSA_PUBKEY)
|
||||
# ifndef OPENSSL_NO_FP_API
|
||||
DSA *PEM_read_DSAPrivateKey(FILE *fp, DSA **dsa, pem_password_cb *cb, void *u)
|
||||
{
|
||||
EVP_PKEY *pktmp;
|
||||
pktmp = PEM_read_PrivateKey(fp, NULL, cb, u);
|
||||
return pkey_get_dsa(pktmp, dsa); /* will free pktmp */
|
||||
}
|
||||
|
||||
# endif
|
||||
|
||||
IMPLEMENT_PEM_rw_const(DSAparams, DSA, PEM_STRING_DSAPARAMS, DSAparams)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef OPENSSL_NO_EC
|
||||
static EC_KEY *pkey_get_eckey(EVP_PKEY *key, EC_KEY **eckey)
|
||||
{
|
||||
EC_KEY *dtmp;
|
||||
if(!key) return NULL;
|
||||
dtmp = EVP_PKEY_get1_EC_KEY(key);
|
||||
EVP_PKEY_free(key);
|
||||
if(!dtmp) return NULL;
|
||||
if(eckey)
|
||||
{
|
||||
EC_KEY_free(*eckey);
|
||||
*eckey = dtmp;
|
||||
}
|
||||
return dtmp;
|
||||
EC_KEY *dtmp;
|
||||
if (!key)
|
||||
return NULL;
|
||||
dtmp = EVP_PKEY_get1_EC_KEY(key);
|
||||
EVP_PKEY_free(key);
|
||||
if (!dtmp)
|
||||
return NULL;
|
||||
if (eckey) {
|
||||
EC_KEY_free(*eckey);
|
||||
*eckey = dtmp;
|
||||
}
|
||||
return dtmp;
|
||||
}
|
||||
|
||||
EC_KEY *PEM_read_bio_ECPrivateKey(BIO *bp, EC_KEY **key, pem_password_cb *cb,
|
||||
void *u)
|
||||
void *u)
|
||||
{
|
||||
EVP_PKEY *pktmp;
|
||||
pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u);
|
||||
return pkey_get_eckey(pktmp, key); /* will free pktmp */
|
||||
EVP_PKEY *pktmp;
|
||||
pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u);
|
||||
return pkey_get_eckey(pktmp, key); /* will free pktmp */
|
||||
}
|
||||
|
||||
IMPLEMENT_PEM_rw_const(ECPKParameters, EC_GROUP, PEM_STRING_ECPARAMETERS, ECPKParameters)
|
||||
IMPLEMENT_PEM_rw_const(ECPKParameters, EC_GROUP, PEM_STRING_ECPARAMETERS,
|
||||
ECPKParameters)
|
||||
# ifdef OPENSSL_FIPS
|
||||
int PEM_write_bio_ECPrivateKey(BIO *bp, EC_KEY *x, const EVP_CIPHER *enc,
|
||||
unsigned char *kstr, int klen,
|
||||
pem_password_cb *cb, void *u)
|
||||
{
|
||||
if (FIPS_mode()) {
|
||||
EVP_PKEY *k;
|
||||
int ret;
|
||||
k = EVP_PKEY_new();
|
||||
if (!k)
|
||||
return 0;
|
||||
EVP_PKEY_set1_EC_KEY(k, x);
|
||||
|
||||
IMPLEMENT_PEM_write_cb(ECPrivateKey, EC_KEY, PEM_STRING_ECPRIVATEKEY, ECPrivateKey)
|
||||
ret = PEM_write_bio_PrivateKey(bp, k, enc, kstr, klen, cb, u);
|
||||
EVP_PKEY_free(k);
|
||||
return ret;
|
||||
} else
|
||||
return PEM_ASN1_write_bio((i2d_of_void *)i2d_ECPrivateKey,
|
||||
PEM_STRING_ECPRIVATEKEY,
|
||||
bp, x, enc, kstr, klen, cb, u);
|
||||
}
|
||||
|
||||
# ifndef OPENSSL_NO_FP_API
|
||||
int PEM_write_ECPrivateKey(FILE *fp, EC_KEY *x, const EVP_CIPHER *enc,
|
||||
unsigned char *kstr, int klen,
|
||||
pem_password_cb *cb, void *u)
|
||||
{
|
||||
if (FIPS_mode()) {
|
||||
EVP_PKEY *k;
|
||||
int ret;
|
||||
k = EVP_PKEY_new();
|
||||
if (!k)
|
||||
return 0;
|
||||
EVP_PKEY_set1_EC_KEY(k, x);
|
||||
ret = PEM_write_PrivateKey(fp, k, enc, kstr, klen, cb, u);
|
||||
EVP_PKEY_free(k);
|
||||
return ret;
|
||||
} else
|
||||
return PEM_ASN1_write((i2d_of_void *)i2d_ECPrivateKey,
|
||||
PEM_STRING_ECPRIVATEKEY,
|
||||
fp, x, enc, kstr, klen, cb, u);
|
||||
}
|
||||
# endif
|
||||
|
||||
# else
|
||||
IMPLEMENT_PEM_write_cb(ECPrivateKey, EC_KEY, PEM_STRING_ECPRIVATEKEY,
|
||||
ECPrivateKey)
|
||||
# endif
|
||||
IMPLEMENT_PEM_rw(EC_PUBKEY, EC_KEY, PEM_STRING_PUBLIC, EC_PUBKEY)
|
||||
|
||||
#ifndef OPENSSL_NO_FP_API
|
||||
|
||||
# ifndef OPENSSL_NO_FP_API
|
||||
EC_KEY *PEM_read_ECPrivateKey(FILE *fp, EC_KEY **eckey, pem_password_cb *cb,
|
||||
void *u)
|
||||
void *u)
|
||||
{
|
||||
EVP_PKEY *pktmp;
|
||||
pktmp = PEM_read_PrivateKey(fp, NULL, cb, u);
|
||||
return pkey_get_eckey(pktmp, eckey); /* will free pktmp */
|
||||
EVP_PKEY *pktmp;
|
||||
pktmp = PEM_read_PrivateKey(fp, NULL, cb, u);
|
||||
return pkey_get_eckey(pktmp, eckey); /* will free pktmp */
|
||||
}
|
||||
|
||||
#endif
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_DH
|
||||
|
||||
IMPLEMENT_PEM_rw_const(DHparams, DH, PEM_STRING_DHPARAMS, DHparams)
|
||||
|
||||
IMPLEMENT_PEM_write_const(DHparams, DH, PEM_STRING_DHPARAMS, DHparams)
|
||||
IMPLEMENT_PEM_write_const(DHxparams, DH, PEM_STRING_DHXPARAMS, DHxparams)
|
||||
#endif
|
||||
|
||||
IMPLEMENT_PEM_rw(PUBKEY, EVP_PKEY, PEM_STRING_PUBLIC, PUBKEY)
|
||||
|
||||
Binary file not shown.
@@ -1,13 +1,13 @@
|
||||
/* crypto/pem/pem_err.c */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved.
|
||||
* Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
@@ -53,7 +53,8 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/* NOTE: this file was auto generated by the mkerr.pl script: any changes
|
||||
/*
|
||||
* NOTE: this file was auto generated by the mkerr.pl script: any changes
|
||||
* made to it will be overwritten when the script next updates this file,
|
||||
* only reason strings will be preserved.
|
||||
*/
|
||||
@@ -65,97 +66,103 @@
|
||||
/* BEGIN ERROR CODES */
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
|
||||
#define ERR_FUNC(func) ERR_PACK(ERR_LIB_PEM,func,0)
|
||||
#define ERR_REASON(reason) ERR_PACK(ERR_LIB_PEM,0,reason)
|
||||
# define ERR_FUNC(func) ERR_PACK(ERR_LIB_PEM,func,0)
|
||||
# define ERR_REASON(reason) ERR_PACK(ERR_LIB_PEM,0,reason)
|
||||
|
||||
static ERR_STRING_DATA PEM_str_functs[]=
|
||||
{
|
||||
{ERR_FUNC(PEM_F_B2I_DSS), "B2I_DSS"},
|
||||
{ERR_FUNC(PEM_F_B2I_PVK_BIO), "b2i_PVK_bio"},
|
||||
{ERR_FUNC(PEM_F_B2I_RSA), "B2I_RSA"},
|
||||
{ERR_FUNC(PEM_F_CHECK_BITLEN_DSA), "CHECK_BITLEN_DSA"},
|
||||
{ERR_FUNC(PEM_F_CHECK_BITLEN_RSA), "CHECK_BITLEN_RSA"},
|
||||
{ERR_FUNC(PEM_F_D2I_PKCS8PRIVATEKEY_BIO), "d2i_PKCS8PrivateKey_bio"},
|
||||
{ERR_FUNC(PEM_F_D2I_PKCS8PRIVATEKEY_FP), "d2i_PKCS8PrivateKey_fp"},
|
||||
{ERR_FUNC(PEM_F_DO_B2I), "DO_B2I"},
|
||||
{ERR_FUNC(PEM_F_DO_B2I_BIO), "DO_B2I_BIO"},
|
||||
{ERR_FUNC(PEM_F_DO_BLOB_HEADER), "DO_BLOB_HEADER"},
|
||||
{ERR_FUNC(PEM_F_DO_PK8PKEY), "DO_PK8PKEY"},
|
||||
{ERR_FUNC(PEM_F_DO_PK8PKEY_FP), "DO_PK8PKEY_FP"},
|
||||
{ERR_FUNC(PEM_F_DO_PVK_BODY), "DO_PVK_BODY"},
|
||||
{ERR_FUNC(PEM_F_DO_PVK_HEADER), "DO_PVK_HEADER"},
|
||||
{ERR_FUNC(PEM_F_I2B_PVK), "I2B_PVK"},
|
||||
{ERR_FUNC(PEM_F_I2B_PVK_BIO), "i2b_PVK_bio"},
|
||||
{ERR_FUNC(PEM_F_LOAD_IV), "LOAD_IV"},
|
||||
{ERR_FUNC(PEM_F_PEM_ASN1_READ), "PEM_ASN1_read"},
|
||||
{ERR_FUNC(PEM_F_PEM_ASN1_READ_BIO), "PEM_ASN1_read_bio"},
|
||||
{ERR_FUNC(PEM_F_PEM_ASN1_WRITE), "PEM_ASN1_write"},
|
||||
{ERR_FUNC(PEM_F_PEM_ASN1_WRITE_BIO), "PEM_ASN1_write_bio"},
|
||||
{ERR_FUNC(PEM_F_PEM_DEF_CALLBACK), "PEM_def_callback"},
|
||||
{ERR_FUNC(PEM_F_PEM_DO_HEADER), "PEM_do_header"},
|
||||
{ERR_FUNC(PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY), "PEM_F_PEM_WRITE_PKCS8PRIVATEKEY"},
|
||||
{ERR_FUNC(PEM_F_PEM_GET_EVP_CIPHER_INFO), "PEM_get_EVP_CIPHER_INFO"},
|
||||
{ERR_FUNC(PEM_F_PEM_PK8PKEY), "PEM_PK8PKEY"},
|
||||
{ERR_FUNC(PEM_F_PEM_READ), "PEM_read"},
|
||||
{ERR_FUNC(PEM_F_PEM_READ_BIO), "PEM_read_bio"},
|
||||
{ERR_FUNC(PEM_F_PEM_READ_BIO_PARAMETERS), "PEM_read_bio_Parameters"},
|
||||
{ERR_FUNC(PEM_F_PEM_READ_BIO_PRIVATEKEY), "PEM_READ_BIO_PRIVATEKEY"},
|
||||
{ERR_FUNC(PEM_F_PEM_READ_PRIVATEKEY), "PEM_READ_PRIVATEKEY"},
|
||||
{ERR_FUNC(PEM_F_PEM_SEALFINAL), "PEM_SealFinal"},
|
||||
{ERR_FUNC(PEM_F_PEM_SEALINIT), "PEM_SealInit"},
|
||||
{ERR_FUNC(PEM_F_PEM_SIGNFINAL), "PEM_SignFinal"},
|
||||
{ERR_FUNC(PEM_F_PEM_WRITE), "PEM_write"},
|
||||
{ERR_FUNC(PEM_F_PEM_WRITE_BIO), "PEM_write_bio"},
|
||||
{ERR_FUNC(PEM_F_PEM_WRITE_PRIVATEKEY), "PEM_WRITE_PRIVATEKEY"},
|
||||
{ERR_FUNC(PEM_F_PEM_X509_INFO_READ), "PEM_X509_INFO_read"},
|
||||
{ERR_FUNC(PEM_F_PEM_X509_INFO_READ_BIO), "PEM_X509_INFO_read_bio"},
|
||||
{ERR_FUNC(PEM_F_PEM_X509_INFO_WRITE_BIO), "PEM_X509_INFO_write_bio"},
|
||||
{0,NULL}
|
||||
};
|
||||
static ERR_STRING_DATA PEM_str_functs[] = {
|
||||
{ERR_FUNC(PEM_F_B2I_DSS), "B2I_DSS"},
|
||||
{ERR_FUNC(PEM_F_B2I_PVK_BIO), "b2i_PVK_bio"},
|
||||
{ERR_FUNC(PEM_F_B2I_RSA), "B2I_RSA"},
|
||||
{ERR_FUNC(PEM_F_CHECK_BITLEN_DSA), "CHECK_BITLEN_DSA"},
|
||||
{ERR_FUNC(PEM_F_CHECK_BITLEN_RSA), "CHECK_BITLEN_RSA"},
|
||||
{ERR_FUNC(PEM_F_D2I_PKCS8PRIVATEKEY_BIO), "d2i_PKCS8PrivateKey_bio"},
|
||||
{ERR_FUNC(PEM_F_D2I_PKCS8PRIVATEKEY_FP), "d2i_PKCS8PrivateKey_fp"},
|
||||
{ERR_FUNC(PEM_F_DO_B2I), "DO_B2I"},
|
||||
{ERR_FUNC(PEM_F_DO_B2I_BIO), "DO_B2I_BIO"},
|
||||
{ERR_FUNC(PEM_F_DO_BLOB_HEADER), "DO_BLOB_HEADER"},
|
||||
{ERR_FUNC(PEM_F_DO_PK8PKEY), "DO_PK8PKEY"},
|
||||
{ERR_FUNC(PEM_F_DO_PK8PKEY_FP), "DO_PK8PKEY_FP"},
|
||||
{ERR_FUNC(PEM_F_DO_PVK_BODY), "DO_PVK_BODY"},
|
||||
{ERR_FUNC(PEM_F_DO_PVK_HEADER), "DO_PVK_HEADER"},
|
||||
{ERR_FUNC(PEM_F_I2B_PVK), "I2B_PVK"},
|
||||
{ERR_FUNC(PEM_F_I2B_PVK_BIO), "i2b_PVK_bio"},
|
||||
{ERR_FUNC(PEM_F_LOAD_IV), "LOAD_IV"},
|
||||
{ERR_FUNC(PEM_F_PEM_ASN1_READ), "PEM_ASN1_read"},
|
||||
{ERR_FUNC(PEM_F_PEM_ASN1_READ_BIO), "PEM_ASN1_read_bio"},
|
||||
{ERR_FUNC(PEM_F_PEM_ASN1_WRITE), "PEM_ASN1_write"},
|
||||
{ERR_FUNC(PEM_F_PEM_ASN1_WRITE_BIO), "PEM_ASN1_write_bio"},
|
||||
{ERR_FUNC(PEM_F_PEM_DEF_CALLBACK), "PEM_def_callback"},
|
||||
{ERR_FUNC(PEM_F_PEM_DO_HEADER), "PEM_do_header"},
|
||||
{ERR_FUNC(PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY),
|
||||
"PEM_F_PEM_WRITE_PKCS8PRIVATEKEY"},
|
||||
{ERR_FUNC(PEM_F_PEM_GET_EVP_CIPHER_INFO), "PEM_get_EVP_CIPHER_INFO"},
|
||||
{ERR_FUNC(PEM_F_PEM_PK8PKEY), "PEM_PK8PKEY"},
|
||||
{ERR_FUNC(PEM_F_PEM_READ), "PEM_read"},
|
||||
{ERR_FUNC(PEM_F_PEM_READ_BIO), "PEM_read_bio"},
|
||||
{ERR_FUNC(PEM_F_PEM_READ_BIO_DHPARAMS), "PEM_READ_BIO_DHPARAMS"},
|
||||
{ERR_FUNC(PEM_F_PEM_READ_BIO_PARAMETERS), "PEM_read_bio_Parameters"},
|
||||
{ERR_FUNC(PEM_F_PEM_READ_BIO_PRIVATEKEY), "PEM_READ_BIO_PRIVATEKEY"},
|
||||
{ERR_FUNC(PEM_F_PEM_READ_DHPARAMS), "PEM_READ_DHPARAMS"},
|
||||
{ERR_FUNC(PEM_F_PEM_READ_PRIVATEKEY), "PEM_READ_PRIVATEKEY"},
|
||||
{ERR_FUNC(PEM_F_PEM_SEALFINAL), "PEM_SealFinal"},
|
||||
{ERR_FUNC(PEM_F_PEM_SEALINIT), "PEM_SealInit"},
|
||||
{ERR_FUNC(PEM_F_PEM_SIGNFINAL), "PEM_SignFinal"},
|
||||
{ERR_FUNC(PEM_F_PEM_WRITE), "PEM_write"},
|
||||
{ERR_FUNC(PEM_F_PEM_WRITE_BIO), "PEM_write_bio"},
|
||||
{ERR_FUNC(PEM_F_PEM_WRITE_PRIVATEKEY), "PEM_WRITE_PRIVATEKEY"},
|
||||
{ERR_FUNC(PEM_F_PEM_X509_INFO_READ), "PEM_X509_INFO_read"},
|
||||
{ERR_FUNC(PEM_F_PEM_X509_INFO_READ_BIO), "PEM_X509_INFO_read_bio"},
|
||||
{ERR_FUNC(PEM_F_PEM_X509_INFO_WRITE_BIO), "PEM_X509_INFO_write_bio"},
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
static ERR_STRING_DATA PEM_str_reasons[]=
|
||||
{
|
||||
{ERR_REASON(PEM_R_BAD_BASE64_DECODE) ,"bad base64 decode"},
|
||||
{ERR_REASON(PEM_R_BAD_DECRYPT) ,"bad decrypt"},
|
||||
{ERR_REASON(PEM_R_BAD_END_LINE) ,"bad end line"},
|
||||
{ERR_REASON(PEM_R_BAD_IV_CHARS) ,"bad iv chars"},
|
||||
{ERR_REASON(PEM_R_BAD_MAGIC_NUMBER) ,"bad magic number"},
|
||||
{ERR_REASON(PEM_R_BAD_PASSWORD_READ) ,"bad password read"},
|
||||
{ERR_REASON(PEM_R_BAD_VERSION_NUMBER) ,"bad version number"},
|
||||
{ERR_REASON(PEM_R_BIO_WRITE_FAILURE) ,"bio write failure"},
|
||||
{ERR_REASON(PEM_R_CIPHER_IS_NULL) ,"cipher is null"},
|
||||
{ERR_REASON(PEM_R_ERROR_CONVERTING_PRIVATE_KEY),"error converting private key"},
|
||||
{ERR_REASON(PEM_R_EXPECTING_PRIVATE_KEY_BLOB),"expecting private key blob"},
|
||||
{ERR_REASON(PEM_R_EXPECTING_PUBLIC_KEY_BLOB),"expecting public key blob"},
|
||||
{ERR_REASON(PEM_R_INCONSISTENT_HEADER) ,"inconsistent header"},
|
||||
{ERR_REASON(PEM_R_KEYBLOB_HEADER_PARSE_ERROR),"keyblob header parse error"},
|
||||
{ERR_REASON(PEM_R_KEYBLOB_TOO_SHORT) ,"keyblob too short"},
|
||||
{ERR_REASON(PEM_R_NOT_DEK_INFO) ,"not dek info"},
|
||||
{ERR_REASON(PEM_R_NOT_ENCRYPTED) ,"not encrypted"},
|
||||
{ERR_REASON(PEM_R_NOT_PROC_TYPE) ,"not proc type"},
|
||||
{ERR_REASON(PEM_R_NO_START_LINE) ,"no start line"},
|
||||
{ERR_REASON(PEM_R_PROBLEMS_GETTING_PASSWORD),"problems getting password"},
|
||||
{ERR_REASON(PEM_R_PUBLIC_KEY_NO_RSA) ,"public key no rsa"},
|
||||
{ERR_REASON(PEM_R_PVK_DATA_TOO_SHORT) ,"pvk data too short"},
|
||||
{ERR_REASON(PEM_R_PVK_TOO_SHORT) ,"pvk too short"},
|
||||
{ERR_REASON(PEM_R_READ_KEY) ,"read key"},
|
||||
{ERR_REASON(PEM_R_SHORT_HEADER) ,"short header"},
|
||||
{ERR_REASON(PEM_R_UNSUPPORTED_CIPHER) ,"unsupported cipher"},
|
||||
{ERR_REASON(PEM_R_UNSUPPORTED_ENCRYPTION),"unsupported encryption"},
|
||||
{ERR_REASON(PEM_R_UNSUPPORTED_KEY_COMPONENTS),"unsupported key components"},
|
||||
{0,NULL}
|
||||
};
|
||||
static ERR_STRING_DATA PEM_str_reasons[] = {
|
||||
{ERR_REASON(PEM_R_BAD_BASE64_DECODE), "bad base64 decode"},
|
||||
{ERR_REASON(PEM_R_BAD_DECRYPT), "bad decrypt"},
|
||||
{ERR_REASON(PEM_R_BAD_END_LINE), "bad end line"},
|
||||
{ERR_REASON(PEM_R_BAD_IV_CHARS), "bad iv chars"},
|
||||
{ERR_REASON(PEM_R_BAD_MAGIC_NUMBER), "bad magic number"},
|
||||
{ERR_REASON(PEM_R_BAD_PASSWORD_READ), "bad password read"},
|
||||
{ERR_REASON(PEM_R_BAD_VERSION_NUMBER), "bad version number"},
|
||||
{ERR_REASON(PEM_R_BIO_WRITE_FAILURE), "bio write failure"},
|
||||
{ERR_REASON(PEM_R_CIPHER_IS_NULL), "cipher is null"},
|
||||
{ERR_REASON(PEM_R_ERROR_CONVERTING_PRIVATE_KEY),
|
||||
"error converting private key"},
|
||||
{ERR_REASON(PEM_R_EXPECTING_PRIVATE_KEY_BLOB),
|
||||
"expecting private key blob"},
|
||||
{ERR_REASON(PEM_R_EXPECTING_PUBLIC_KEY_BLOB),
|
||||
"expecting public key blob"},
|
||||
{ERR_REASON(PEM_R_INCONSISTENT_HEADER), "inconsistent header"},
|
||||
{ERR_REASON(PEM_R_KEYBLOB_HEADER_PARSE_ERROR),
|
||||
"keyblob header parse error"},
|
||||
{ERR_REASON(PEM_R_KEYBLOB_TOO_SHORT), "keyblob too short"},
|
||||
{ERR_REASON(PEM_R_NOT_DEK_INFO), "not dek info"},
|
||||
{ERR_REASON(PEM_R_NOT_ENCRYPTED), "not encrypted"},
|
||||
{ERR_REASON(PEM_R_NOT_PROC_TYPE), "not proc type"},
|
||||
{ERR_REASON(PEM_R_NO_START_LINE), "no start line"},
|
||||
{ERR_REASON(PEM_R_PROBLEMS_GETTING_PASSWORD),
|
||||
"problems getting password"},
|
||||
{ERR_REASON(PEM_R_PUBLIC_KEY_NO_RSA), "public key no rsa"},
|
||||
{ERR_REASON(PEM_R_PVK_DATA_TOO_SHORT), "pvk data too short"},
|
||||
{ERR_REASON(PEM_R_PVK_TOO_SHORT), "pvk too short"},
|
||||
{ERR_REASON(PEM_R_READ_KEY), "read key"},
|
||||
{ERR_REASON(PEM_R_SHORT_HEADER), "short header"},
|
||||
{ERR_REASON(PEM_R_UNSUPPORTED_CIPHER), "unsupported cipher"},
|
||||
{ERR_REASON(PEM_R_UNSUPPORTED_ENCRYPTION), "unsupported encryption"},
|
||||
{ERR_REASON(PEM_R_UNSUPPORTED_KEY_COMPONENTS),
|
||||
"unsupported key components"},
|
||||
{0, NULL}
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
void ERR_load_PEM_strings(void)
|
||||
{
|
||||
{
|
||||
#ifndef OPENSSL_NO_ERR
|
||||
|
||||
if (ERR_func_error_string(PEM_str_functs[0].error) == NULL)
|
||||
{
|
||||
ERR_load_strings(0,PEM_str_functs);
|
||||
ERR_load_strings(0,PEM_str_reasons);
|
||||
}
|
||||
if (ERR_func_error_string(PEM_str_functs[0].error) == NULL) {
|
||||
ERR_load_strings(0, PEM_str_functs);
|
||||
ERR_load_strings(0, PEM_str_reasons);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -5,21 +5,21 @@
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
@@ -34,10 +34,10 @@
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
@@ -49,7 +49,7 @@
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
@@ -64,342 +64,325 @@
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/pem.h>
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
#include <openssl/rsa.h>
|
||||
# include <openssl/rsa.h>
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
#include <openssl/dsa.h>
|
||||
# include <openssl/dsa.h>
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_FP_API
|
||||
STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u)
|
||||
{
|
||||
BIO *b;
|
||||
STACK_OF(X509_INFO) *ret;
|
||||
STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk,
|
||||
pem_password_cb *cb, void *u)
|
||||
{
|
||||
BIO *b;
|
||||
STACK_OF(X509_INFO) *ret;
|
||||
|
||||
if ((b=BIO_new(BIO_s_file())) == NULL)
|
||||
{
|
||||
PEMerr(PEM_F_PEM_X509_INFO_READ,ERR_R_BUF_LIB);
|
||||
return(0);
|
||||
}
|
||||
BIO_set_fp(b,fp,BIO_NOCLOSE);
|
||||
ret=PEM_X509_INFO_read_bio(b,sk,cb,u);
|
||||
BIO_free(b);
|
||||
return(ret);
|
||||
}
|
||||
if ((b = BIO_new(BIO_s_file())) == NULL) {
|
||||
PEMerr(PEM_F_PEM_X509_INFO_READ, ERR_R_BUF_LIB);
|
||||
return (0);
|
||||
}
|
||||
BIO_set_fp(b, fp, BIO_NOCLOSE);
|
||||
ret = PEM_X509_INFO_read_bio(b, sk, cb, u);
|
||||
BIO_free(b);
|
||||
return (ret);
|
||||
}
|
||||
#endif
|
||||
|
||||
STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u)
|
||||
{
|
||||
X509_INFO *xi=NULL;
|
||||
char *name=NULL,*header=NULL;
|
||||
void *pp;
|
||||
unsigned char *data=NULL;
|
||||
const unsigned char *p;
|
||||
long len,error=0;
|
||||
int ok=0;
|
||||
STACK_OF(X509_INFO) *ret=NULL;
|
||||
unsigned int i,raw,ptype;
|
||||
d2i_of_void *d2i = 0;
|
||||
STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk,
|
||||
pem_password_cb *cb, void *u)
|
||||
{
|
||||
X509_INFO *xi = NULL;
|
||||
char *name = NULL, *header = NULL;
|
||||
void *pp;
|
||||
unsigned char *data = NULL;
|
||||
const unsigned char *p;
|
||||
long len, error = 0;
|
||||
int ok = 0;
|
||||
STACK_OF(X509_INFO) *ret = NULL;
|
||||
unsigned int i, raw, ptype;
|
||||
d2i_of_void *d2i = 0;
|
||||
|
||||
if (sk == NULL)
|
||||
{
|
||||
if ((ret=sk_X509_INFO_new_null()) == NULL)
|
||||
{
|
||||
PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
else
|
||||
ret=sk;
|
||||
if (sk == NULL) {
|
||||
if ((ret = sk_X509_INFO_new_null()) == NULL) {
|
||||
PEMerr(PEM_F_PEM_X509_INFO_READ_BIO, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
} else
|
||||
ret = sk;
|
||||
|
||||
if ((xi=X509_INFO_new()) == NULL) goto err;
|
||||
for (;;)
|
||||
{
|
||||
raw=0;
|
||||
ptype = 0;
|
||||
i=PEM_read_bio(bp,&name,&header,&data,&len);
|
||||
if (i == 0)
|
||||
{
|
||||
error=ERR_GET_REASON(ERR_peek_last_error());
|
||||
if (error == PEM_R_NO_START_LINE)
|
||||
{
|
||||
ERR_clear_error();
|
||||
break;
|
||||
}
|
||||
goto err;
|
||||
}
|
||||
start:
|
||||
if ( (strcmp(name,PEM_STRING_X509) == 0) ||
|
||||
(strcmp(name,PEM_STRING_X509_OLD) == 0))
|
||||
{
|
||||
d2i=(D2I_OF(void))d2i_X509;
|
||||
if (xi->x509 != NULL)
|
||||
{
|
||||
if (!sk_X509_INFO_push(ret,xi)) goto err;
|
||||
if ((xi=X509_INFO_new()) == NULL) goto err;
|
||||
goto start;
|
||||
}
|
||||
pp=&(xi->x509);
|
||||
}
|
||||
else if ((strcmp(name,PEM_STRING_X509_TRUSTED) == 0))
|
||||
{
|
||||
d2i=(D2I_OF(void))d2i_X509_AUX;
|
||||
if (xi->x509 != NULL)
|
||||
{
|
||||
if (!sk_X509_INFO_push(ret,xi)) goto err;
|
||||
if ((xi=X509_INFO_new()) == NULL) goto err;
|
||||
goto start;
|
||||
}
|
||||
pp=&(xi->x509);
|
||||
}
|
||||
else if (strcmp(name,PEM_STRING_X509_CRL) == 0)
|
||||
{
|
||||
d2i=(D2I_OF(void))d2i_X509_CRL;
|
||||
if (xi->crl != NULL)
|
||||
{
|
||||
if (!sk_X509_INFO_push(ret,xi)) goto err;
|
||||
if ((xi=X509_INFO_new()) == NULL) goto err;
|
||||
goto start;
|
||||
}
|
||||
pp=&(xi->crl);
|
||||
}
|
||||
else
|
||||
if ((xi = X509_INFO_new()) == NULL)
|
||||
goto err;
|
||||
for (;;) {
|
||||
raw = 0;
|
||||
ptype = 0;
|
||||
i = PEM_read_bio(bp, &name, &header, &data, &len);
|
||||
if (i == 0) {
|
||||
error = ERR_GET_REASON(ERR_peek_last_error());
|
||||
if (error == PEM_R_NO_START_LINE) {
|
||||
ERR_clear_error();
|
||||
break;
|
||||
}
|
||||
goto err;
|
||||
}
|
||||
start:
|
||||
if ((strcmp(name, PEM_STRING_X509) == 0) ||
|
||||
(strcmp(name, PEM_STRING_X509_OLD) == 0)) {
|
||||
d2i = (D2I_OF(void)) d2i_X509;
|
||||
if (xi->x509 != NULL) {
|
||||
if (!sk_X509_INFO_push(ret, xi))
|
||||
goto err;
|
||||
if ((xi = X509_INFO_new()) == NULL)
|
||||
goto err;
|
||||
goto start;
|
||||
}
|
||||
pp = &(xi->x509);
|
||||
} else if ((strcmp(name, PEM_STRING_X509_TRUSTED) == 0)) {
|
||||
d2i = (D2I_OF(void)) d2i_X509_AUX;
|
||||
if (xi->x509 != NULL) {
|
||||
if (!sk_X509_INFO_push(ret, xi))
|
||||
goto err;
|
||||
if ((xi = X509_INFO_new()) == NULL)
|
||||
goto err;
|
||||
goto start;
|
||||
}
|
||||
pp = &(xi->x509);
|
||||
} else if (strcmp(name, PEM_STRING_X509_CRL) == 0) {
|
||||
d2i = (D2I_OF(void)) d2i_X509_CRL;
|
||||
if (xi->crl != NULL) {
|
||||
if (!sk_X509_INFO_push(ret, xi))
|
||||
goto err;
|
||||
if ((xi = X509_INFO_new()) == NULL)
|
||||
goto err;
|
||||
goto start;
|
||||
}
|
||||
pp = &(xi->crl);
|
||||
} else
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
if (strcmp(name,PEM_STRING_RSA) == 0)
|
||||
{
|
||||
if (xi->x_pkey != NULL)
|
||||
{
|
||||
if (!sk_X509_INFO_push(ret,xi)) goto err;
|
||||
if ((xi=X509_INFO_new()) == NULL) goto err;
|
||||
goto start;
|
||||
}
|
||||
if (strcmp(name, PEM_STRING_RSA) == 0) {
|
||||
d2i = (D2I_OF(void)) d2i_RSAPrivateKey;
|
||||
if (xi->x_pkey != NULL) {
|
||||
if (!sk_X509_INFO_push(ret, xi))
|
||||
goto err;
|
||||
if ((xi = X509_INFO_new()) == NULL)
|
||||
goto err;
|
||||
goto start;
|
||||
}
|
||||
|
||||
xi->enc_data=NULL;
|
||||
xi->enc_len=0;
|
||||
xi->enc_data = NULL;
|
||||
xi->enc_len = 0;
|
||||
|
||||
xi->x_pkey=X509_PKEY_new();
|
||||
ptype=EVP_PKEY_RSA;
|
||||
pp=&xi->x_pkey->dec_pkey;
|
||||
if ((int)strlen(header) > 10) /* assume encrypted */
|
||||
raw=1;
|
||||
}
|
||||
else
|
||||
xi->x_pkey = X509_PKEY_new();
|
||||
ptype = EVP_PKEY_RSA;
|
||||
pp = &xi->x_pkey->dec_pkey;
|
||||
if ((int)strlen(header) > 10) /* assume encrypted */
|
||||
raw = 1;
|
||||
} else
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DSA
|
||||
if (strcmp(name,PEM_STRING_DSA) == 0)
|
||||
{
|
||||
d2i=(D2I_OF(void))d2i_DSAPrivateKey;
|
||||
if (xi->x_pkey != NULL)
|
||||
{
|
||||
if (!sk_X509_INFO_push(ret,xi)) goto err;
|
||||
if ((xi=X509_INFO_new()) == NULL) goto err;
|
||||
goto start;
|
||||
}
|
||||
if (strcmp(name, PEM_STRING_DSA) == 0) {
|
||||
d2i = (D2I_OF(void)) d2i_DSAPrivateKey;
|
||||
if (xi->x_pkey != NULL) {
|
||||
if (!sk_X509_INFO_push(ret, xi))
|
||||
goto err;
|
||||
if ((xi = X509_INFO_new()) == NULL)
|
||||
goto err;
|
||||
goto start;
|
||||
}
|
||||
|
||||
xi->enc_data=NULL;
|
||||
xi->enc_len=0;
|
||||
xi->enc_data = NULL;
|
||||
xi->enc_len = 0;
|
||||
|
||||
xi->x_pkey=X509_PKEY_new();
|
||||
ptype = EVP_PKEY_DSA;
|
||||
pp=&xi->x_pkey->dec_pkey;
|
||||
if ((int)strlen(header) > 10) /* assume encrypted */
|
||||
raw=1;
|
||||
}
|
||||
else
|
||||
xi->x_pkey = X509_PKEY_new();
|
||||
ptype = EVP_PKEY_DSA;
|
||||
pp = &xi->x_pkey->dec_pkey;
|
||||
if ((int)strlen(header) > 10) /* assume encrypted */
|
||||
raw = 1;
|
||||
} else
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_EC
|
||||
if (strcmp(name,PEM_STRING_ECPRIVATEKEY) == 0)
|
||||
{
|
||||
d2i=(D2I_OF(void))d2i_ECPrivateKey;
|
||||
if (xi->x_pkey != NULL)
|
||||
{
|
||||
if (!sk_X509_INFO_push(ret,xi)) goto err;
|
||||
if ((xi=X509_INFO_new()) == NULL) goto err;
|
||||
goto start;
|
||||
}
|
||||
|
||||
xi->enc_data=NULL;
|
||||
xi->enc_len=0;
|
||||
|
||||
xi->x_pkey=X509_PKEY_new();
|
||||
ptype = EVP_PKEY_EC;
|
||||
pp=&xi->x_pkey->dec_pkey;
|
||||
if ((int)strlen(header) > 10) /* assume encrypted */
|
||||
raw=1;
|
||||
}
|
||||
else
|
||||
if (strcmp(name, PEM_STRING_ECPRIVATEKEY) == 0) {
|
||||
d2i = (D2I_OF(void)) d2i_ECPrivateKey;
|
||||
if (xi->x_pkey != NULL) {
|
||||
if (!sk_X509_INFO_push(ret, xi))
|
||||
goto err;
|
||||
if ((xi = X509_INFO_new()) == NULL)
|
||||
goto err;
|
||||
goto start;
|
||||
}
|
||||
|
||||
xi->enc_data = NULL;
|
||||
xi->enc_len = 0;
|
||||
|
||||
xi->x_pkey = X509_PKEY_new();
|
||||
ptype = EVP_PKEY_EC;
|
||||
pp = &xi->x_pkey->dec_pkey;
|
||||
if ((int)strlen(header) > 10) /* assume encrypted */
|
||||
raw = 1;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
d2i=NULL;
|
||||
pp=NULL;
|
||||
}
|
||||
{
|
||||
d2i = NULL;
|
||||
pp = NULL;
|
||||
}
|
||||
|
||||
if (d2i != NULL)
|
||||
{
|
||||
if (!raw)
|
||||
{
|
||||
EVP_CIPHER_INFO cipher;
|
||||
if (d2i != NULL) {
|
||||
if (!raw) {
|
||||
EVP_CIPHER_INFO cipher;
|
||||
|
||||
if (!PEM_get_EVP_CIPHER_INFO(header,&cipher))
|
||||
goto err;
|
||||
if (!PEM_do_header(&cipher,data,&len,cb,u))
|
||||
goto err;
|
||||
p=data;
|
||||
if (ptype)
|
||||
{
|
||||
if (!d2i_PrivateKey(ptype, pp, &p, len))
|
||||
{
|
||||
PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_ASN1_LIB);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
else if (d2i(pp,&p,len) == NULL)
|
||||
{
|
||||
PEMerr(PEM_F_PEM_X509_INFO_READ_BIO,ERR_R_ASN1_LIB);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
else
|
||||
{ /* encrypted RSA data */
|
||||
if (!PEM_get_EVP_CIPHER_INFO(header,
|
||||
&xi->enc_cipher)) goto err;
|
||||
xi->enc_data=(char *)data;
|
||||
xi->enc_len=(int)len;
|
||||
data=NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* unknown */
|
||||
}
|
||||
if (name != NULL) OPENSSL_free(name);
|
||||
if (header != NULL) OPENSSL_free(header);
|
||||
if (data != NULL) OPENSSL_free(data);
|
||||
name=NULL;
|
||||
header=NULL;
|
||||
data=NULL;
|
||||
}
|
||||
if (!PEM_get_EVP_CIPHER_INFO(header, &cipher))
|
||||
goto err;
|
||||
if (!PEM_do_header(&cipher, data, &len, cb, u))
|
||||
goto err;
|
||||
p = data;
|
||||
if (ptype) {
|
||||
if (!d2i_PrivateKey(ptype, pp, &p, len)) {
|
||||
PEMerr(PEM_F_PEM_X509_INFO_READ_BIO, ERR_R_ASN1_LIB);
|
||||
goto err;
|
||||
}
|
||||
} else if (d2i(pp, &p, len) == NULL) {
|
||||
PEMerr(PEM_F_PEM_X509_INFO_READ_BIO, ERR_R_ASN1_LIB);
|
||||
goto err;
|
||||
}
|
||||
} else { /* encrypted RSA data */
|
||||
if (!PEM_get_EVP_CIPHER_INFO(header, &xi->enc_cipher))
|
||||
goto err;
|
||||
xi->enc_data = (char *)data;
|
||||
xi->enc_len = (int)len;
|
||||
data = NULL;
|
||||
}
|
||||
} else {
|
||||
/* unknown */
|
||||
}
|
||||
if (name != NULL)
|
||||
OPENSSL_free(name);
|
||||
if (header != NULL)
|
||||
OPENSSL_free(header);
|
||||
if (data != NULL)
|
||||
OPENSSL_free(data);
|
||||
name = NULL;
|
||||
header = NULL;
|
||||
data = NULL;
|
||||
}
|
||||
|
||||
/* if the last one hasn't been pushed yet and there is anything
|
||||
* in it then add it to the stack ...
|
||||
*/
|
||||
if ((xi->x509 != NULL) || (xi->crl != NULL) ||
|
||||
(xi->x_pkey != NULL) || (xi->enc_data != NULL))
|
||||
{
|
||||
if (!sk_X509_INFO_push(ret,xi)) goto err;
|
||||
xi=NULL;
|
||||
}
|
||||
ok=1;
|
||||
err:
|
||||
if (xi != NULL) X509_INFO_free(xi);
|
||||
if (!ok)
|
||||
{
|
||||
for (i=0; ((int)i)<sk_X509_INFO_num(ret); i++)
|
||||
{
|
||||
xi=sk_X509_INFO_value(ret,i);
|
||||
X509_INFO_free(xi);
|
||||
}
|
||||
if (ret != sk) sk_X509_INFO_free(ret);
|
||||
ret=NULL;
|
||||
}
|
||||
|
||||
if (name != NULL) OPENSSL_free(name);
|
||||
if (header != NULL) OPENSSL_free(header);
|
||||
if (data != NULL) OPENSSL_free(data);
|
||||
return(ret);
|
||||
}
|
||||
/*
|
||||
* if the last one hasn't been pushed yet and there is anything in it
|
||||
* then add it to the stack ...
|
||||
*/
|
||||
if ((xi->x509 != NULL) || (xi->crl != NULL) ||
|
||||
(xi->x_pkey != NULL) || (xi->enc_data != NULL)) {
|
||||
if (!sk_X509_INFO_push(ret, xi))
|
||||
goto err;
|
||||
xi = NULL;
|
||||
}
|
||||
ok = 1;
|
||||
err:
|
||||
if (xi != NULL)
|
||||
X509_INFO_free(xi);
|
||||
if (!ok) {
|
||||
for (i = 0; ((int)i) < sk_X509_INFO_num(ret); i++) {
|
||||
xi = sk_X509_INFO_value(ret, i);
|
||||
X509_INFO_free(xi);
|
||||
}
|
||||
if (ret != sk)
|
||||
sk_X509_INFO_free(ret);
|
||||
ret = NULL;
|
||||
}
|
||||
|
||||
if (name != NULL)
|
||||
OPENSSL_free(name);
|
||||
if (header != NULL)
|
||||
OPENSSL_free(header);
|
||||
if (data != NULL)
|
||||
OPENSSL_free(data);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/* A TJH addition */
|
||||
int PEM_X509_INFO_write_bio(BIO *bp, X509_INFO *xi, EVP_CIPHER *enc,
|
||||
unsigned char *kstr, int klen, pem_password_cb *cb, void *u)
|
||||
{
|
||||
EVP_CIPHER_CTX ctx;
|
||||
int i,ret=0;
|
||||
unsigned char *data=NULL;
|
||||
const char *objstr=NULL;
|
||||
char buf[PEM_BUFSIZE];
|
||||
unsigned char *iv=NULL;
|
||||
|
||||
if (enc != NULL)
|
||||
{
|
||||
objstr=OBJ_nid2sn(EVP_CIPHER_nid(enc));
|
||||
if (objstr == NULL)
|
||||
{
|
||||
PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO,PEM_R_UNSUPPORTED_CIPHER);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
unsigned char *kstr, int klen,
|
||||
pem_password_cb *cb, void *u)
|
||||
{
|
||||
EVP_CIPHER_CTX ctx;
|
||||
int i, ret = 0;
|
||||
unsigned char *data = NULL;
|
||||
const char *objstr = NULL;
|
||||
char buf[PEM_BUFSIZE];
|
||||
unsigned char *iv = NULL;
|
||||
|
||||
/* now for the fun part ... if we have a private key then
|
||||
* we have to be able to handle a not-yet-decrypted key
|
||||
* being written out correctly ... if it is decrypted or
|
||||
* it is non-encrypted then we use the base code
|
||||
*/
|
||||
if (xi->x_pkey!=NULL)
|
||||
{
|
||||
if ( (xi->enc_data!=NULL) && (xi->enc_len>0) )
|
||||
{
|
||||
if (enc == NULL)
|
||||
{
|
||||
PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO,PEM_R_CIPHER_IS_NULL);
|
||||
goto err;
|
||||
}
|
||||
if (enc != NULL) {
|
||||
objstr = OBJ_nid2sn(EVP_CIPHER_nid(enc));
|
||||
if (objstr == NULL) {
|
||||
PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO, PEM_R_UNSUPPORTED_CIPHER);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
|
||||
/* copy from weirdo names into more normal things */
|
||||
iv=xi->enc_cipher.iv;
|
||||
data=(unsigned char *)xi->enc_data;
|
||||
i=xi->enc_len;
|
||||
/*
|
||||
* now for the fun part ... if we have a private key then we have to be
|
||||
* able to handle a not-yet-decrypted key being written out correctly ...
|
||||
* if it is decrypted or it is non-encrypted then we use the base code
|
||||
*/
|
||||
if (xi->x_pkey != NULL) {
|
||||
if ((xi->enc_data != NULL) && (xi->enc_len > 0)) {
|
||||
if (enc == NULL) {
|
||||
PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO, PEM_R_CIPHER_IS_NULL);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* we take the encryption data from the
|
||||
* internal stuff rather than what the
|
||||
* user has passed us ... as we have to
|
||||
* match exactly for some strange reason
|
||||
*/
|
||||
objstr=OBJ_nid2sn(
|
||||
EVP_CIPHER_nid(xi->enc_cipher.cipher));
|
||||
if (objstr == NULL)
|
||||
{
|
||||
PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO,PEM_R_UNSUPPORTED_CIPHER);
|
||||
goto err;
|
||||
}
|
||||
/* copy from weirdo names into more normal things */
|
||||
iv = xi->enc_cipher.iv;
|
||||
data = (unsigned char *)xi->enc_data;
|
||||
i = xi->enc_len;
|
||||
|
||||
/* create the right magic header stuff */
|
||||
OPENSSL_assert(strlen(objstr)+23+2*enc->iv_len+13 <= sizeof buf);
|
||||
buf[0]='\0';
|
||||
PEM_proc_type(buf,PEM_TYPE_ENCRYPTED);
|
||||
PEM_dek_info(buf,objstr,enc->iv_len,(char *)iv);
|
||||
/*
|
||||
* we take the encryption data from the internal stuff rather
|
||||
* than what the user has passed us ... as we have to match
|
||||
* exactly for some strange reason
|
||||
*/
|
||||
objstr = OBJ_nid2sn(EVP_CIPHER_nid(xi->enc_cipher.cipher));
|
||||
if (objstr == NULL) {
|
||||
PEMerr(PEM_F_PEM_X509_INFO_WRITE_BIO,
|
||||
PEM_R_UNSUPPORTED_CIPHER);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* use the normal code to write things out */
|
||||
i=PEM_write_bio(bp,PEM_STRING_RSA,buf,data,i);
|
||||
if (i <= 0) goto err;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Add DSA/DH */
|
||||
/* create the right magic header stuff */
|
||||
OPENSSL_assert(strlen(objstr) + 23 + 2 * enc->iv_len + 13 <=
|
||||
sizeof buf);
|
||||
buf[0] = '\0';
|
||||
PEM_proc_type(buf, PEM_TYPE_ENCRYPTED);
|
||||
PEM_dek_info(buf, objstr, enc->iv_len, (char *)iv);
|
||||
|
||||
/* use the normal code to write things out */
|
||||
i = PEM_write_bio(bp, PEM_STRING_RSA, buf, data, i);
|
||||
if (i <= 0)
|
||||
goto err;
|
||||
} else {
|
||||
/* Add DSA/DH */
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
/* normal optionally encrypted stuff */
|
||||
if (PEM_write_bio_RSAPrivateKey(bp,
|
||||
xi->x_pkey->dec_pkey->pkey.rsa,
|
||||
enc,kstr,klen,cb,u)<=0)
|
||||
goto err;
|
||||
/* normal optionally encrypted stuff */
|
||||
if (PEM_write_bio_RSAPrivateKey(bp,
|
||||
xi->x_pkey->dec_pkey->pkey.rsa,
|
||||
enc, kstr, klen, cb, u) <= 0)
|
||||
goto err;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* if we have a certificate then write it out now */
|
||||
if ((xi->x509 != NULL) && (PEM_write_bio_X509(bp,xi->x509) <= 0))
|
||||
goto err;
|
||||
/* if we have a certificate then write it out now */
|
||||
if ((xi->x509 != NULL) && (PEM_write_bio_X509(bp, xi->x509) <= 0))
|
||||
goto err;
|
||||
|
||||
/* we are ignoring anything else that is loaded into the X509_INFO
|
||||
* structure for the moment ... as I don't need it so I'm not
|
||||
* coding it here and Eric can do it when this makes it into the
|
||||
* base library --tjh
|
||||
*/
|
||||
/*
|
||||
* we are ignoring anything else that is loaded into the X509_INFO
|
||||
* structure for the moment ... as I don't need it so I'm not coding it
|
||||
* here and Eric can do it when this makes it into the base library --tjh
|
||||
*/
|
||||
|
||||
ret=1;
|
||||
ret = 1;
|
||||
|
||||
err:
|
||||
OPENSSL_cleanse((char *)&ctx,sizeof(ctx));
|
||||
OPENSSL_cleanse(buf,PEM_BUFSIZE);
|
||||
return(ret);
|
||||
}
|
||||
err:
|
||||
OPENSSL_cleanse((char *)&ctx, sizeof(ctx));
|
||||
OPENSSL_cleanse(buf, PEM_BUFSIZE);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
Binary file not shown.
1347
crypto/pem/pem_lib.c
1347
crypto/pem/pem_lib.c
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -5,21 +5,21 @@
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
@@ -34,10 +34,10 @@
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
@@ -49,7 +49,7 @@
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
@@ -68,19 +68,19 @@
|
||||
/* Handle 'other' PEMs: not private keys */
|
||||
|
||||
void *PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, void **x,
|
||||
pem_password_cb *cb, void *u)
|
||||
{
|
||||
const unsigned char *p=NULL;
|
||||
unsigned char *data=NULL;
|
||||
long len;
|
||||
char *ret=NULL;
|
||||
pem_password_cb *cb, void *u)
|
||||
{
|
||||
const unsigned char *p = NULL;
|
||||
unsigned char *data = NULL;
|
||||
long len;
|
||||
char *ret = NULL;
|
||||
|
||||
if (!PEM_bytes_read_bio(&data, &len, NULL, name, bp, cb, u))
|
||||
return NULL;
|
||||
p = data;
|
||||
ret=d2i(x,&p,len);
|
||||
if (ret == NULL)
|
||||
PEMerr(PEM_F_PEM_ASN1_READ_BIO,ERR_R_ASN1_LIB);
|
||||
OPENSSL_free(data);
|
||||
return(ret);
|
||||
}
|
||||
if (!PEM_bytes_read_bio(&data, &len, NULL, name, bp, cb, u))
|
||||
return NULL;
|
||||
p = data;
|
||||
ret = d2i(x, &p, len);
|
||||
if (ret == NULL)
|
||||
PEMerr(PEM_F_PEM_ASN1_READ_BIO, ERR_R_ASN1_LIB);
|
||||
OPENSSL_free(data);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -5,21 +5,21 @@
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
@@ -34,10 +34,10 @@
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
@@ -49,7 +49,7 @@
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
@@ -67,176 +67,193 @@
|
||||
#include <openssl/pem.h>
|
||||
|
||||
static int do_pk8pkey(BIO *bp, EVP_PKEY *x, int isder,
|
||||
int nid, const EVP_CIPHER *enc,
|
||||
char *kstr, int klen,
|
||||
pem_password_cb *cb, void *u);
|
||||
int nid, const EVP_CIPHER *enc,
|
||||
char *kstr, int klen, pem_password_cb *cb, void *u);
|
||||
static int do_pk8pkey_fp(FILE *bp, EVP_PKEY *x, int isder,
|
||||
int nid, const EVP_CIPHER *enc,
|
||||
char *kstr, int klen,
|
||||
pem_password_cb *cb, void *u);
|
||||
int nid, const EVP_CIPHER *enc,
|
||||
char *kstr, int klen, pem_password_cb *cb, void *u);
|
||||
|
||||
/* These functions write a private key in PKCS#8 format: it is a "drop in"
|
||||
/*
|
||||
* These functions write a private key in PKCS#8 format: it is a "drop in"
|
||||
* replacement for PEM_write_bio_PrivateKey() and friends. As usual if 'enc'
|
||||
* is NULL then it uses the unencrypted private key form. The 'nid' versions
|
||||
* uses PKCS#5 v1.5 PBE algorithms whereas the others use PKCS#5 v2.0.
|
||||
*/
|
||||
|
||||
int PEM_write_bio_PKCS8PrivateKey_nid(BIO *bp, EVP_PKEY *x, int nid,
|
||||
char *kstr, int klen,
|
||||
pem_password_cb *cb, void *u)
|
||||
char *kstr, int klen,
|
||||
pem_password_cb *cb, void *u)
|
||||
{
|
||||
return do_pk8pkey(bp, x, 0, nid, NULL, kstr, klen, cb, u);
|
||||
return do_pk8pkey(bp, x, 0, nid, NULL, kstr, klen, cb, u);
|
||||
}
|
||||
|
||||
int PEM_write_bio_PKCS8PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
|
||||
char *kstr, int klen,
|
||||
pem_password_cb *cb, void *u)
|
||||
char *kstr, int klen,
|
||||
pem_password_cb *cb, void *u)
|
||||
{
|
||||
return do_pk8pkey(bp, x, 0, -1, enc, kstr, klen, cb, u);
|
||||
return do_pk8pkey(bp, x, 0, -1, enc, kstr, klen, cb, u);
|
||||
}
|
||||
|
||||
int i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
|
||||
char *kstr, int klen,
|
||||
pem_password_cb *cb, void *u)
|
||||
char *kstr, int klen,
|
||||
pem_password_cb *cb, void *u)
|
||||
{
|
||||
return do_pk8pkey(bp, x, 1, -1, enc, kstr, klen, cb, u);
|
||||
return do_pk8pkey(bp, x, 1, -1, enc, kstr, klen, cb, u);
|
||||
}
|
||||
|
||||
int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, EVP_PKEY *x, int nid,
|
||||
char *kstr, int klen,
|
||||
pem_password_cb *cb, void *u)
|
||||
char *kstr, int klen,
|
||||
pem_password_cb *cb, void *u)
|
||||
{
|
||||
return do_pk8pkey(bp, x, 1, nid, NULL, kstr, klen, cb, u);
|
||||
return do_pk8pkey(bp, x, 1, nid, NULL, kstr, klen, cb, u);
|
||||
}
|
||||
|
||||
static int do_pk8pkey(BIO *bp, EVP_PKEY *x, int isder, int nid, const EVP_CIPHER *enc,
|
||||
char *kstr, int klen,
|
||||
pem_password_cb *cb, void *u)
|
||||
static int do_pk8pkey(BIO *bp, EVP_PKEY *x, int isder, int nid,
|
||||
const EVP_CIPHER *enc, char *kstr, int klen,
|
||||
pem_password_cb *cb, void *u)
|
||||
{
|
||||
X509_SIG *p8;
|
||||
PKCS8_PRIV_KEY_INFO *p8inf;
|
||||
char buf[PEM_BUFSIZE];
|
||||
int ret;
|
||||
if(!(p8inf = EVP_PKEY2PKCS8(x))) {
|
||||
PEMerr(PEM_F_DO_PK8PKEY,
|
||||
PEM_R_ERROR_CONVERTING_PRIVATE_KEY);
|
||||
return 0;
|
||||
}
|
||||
if(enc || (nid != -1)) {
|
||||
if(!kstr) {
|
||||
if(!cb) klen = PEM_def_callback(buf, PEM_BUFSIZE, 1, u);
|
||||
else klen = cb(buf, PEM_BUFSIZE, 1, u);
|
||||
if(klen <= 0) {
|
||||
PEMerr(PEM_F_DO_PK8PKEY,PEM_R_READ_KEY);
|
||||
PKCS8_PRIV_KEY_INFO_free(p8inf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
kstr = buf;
|
||||
}
|
||||
p8 = PKCS8_encrypt(nid, enc, kstr, klen, NULL, 0, 0, p8inf);
|
||||
if(kstr == buf) OPENSSL_cleanse(buf, klen);
|
||||
PKCS8_PRIV_KEY_INFO_free(p8inf);
|
||||
if(isder) ret = i2d_PKCS8_bio(bp, p8);
|
||||
else ret = PEM_write_bio_PKCS8(bp, p8);
|
||||
X509_SIG_free(p8);
|
||||
return ret;
|
||||
} else {
|
||||
if(isder) ret = i2d_PKCS8_PRIV_KEY_INFO_bio(bp, p8inf);
|
||||
else ret = PEM_write_bio_PKCS8_PRIV_KEY_INFO(bp, p8inf);
|
||||
PKCS8_PRIV_KEY_INFO_free(p8inf);
|
||||
return ret;
|
||||
}
|
||||
X509_SIG *p8;
|
||||
PKCS8_PRIV_KEY_INFO *p8inf;
|
||||
char buf[PEM_BUFSIZE];
|
||||
int ret;
|
||||
if (!(p8inf = EVP_PKEY2PKCS8(x))) {
|
||||
PEMerr(PEM_F_DO_PK8PKEY, PEM_R_ERROR_CONVERTING_PRIVATE_KEY);
|
||||
return 0;
|
||||
}
|
||||
if (enc || (nid != -1)) {
|
||||
if (!kstr) {
|
||||
if (!cb)
|
||||
klen = PEM_def_callback(buf, PEM_BUFSIZE, 1, u);
|
||||
else
|
||||
klen = cb(buf, PEM_BUFSIZE, 1, u);
|
||||
if (klen <= 0) {
|
||||
PEMerr(PEM_F_DO_PK8PKEY, PEM_R_READ_KEY);
|
||||
PKCS8_PRIV_KEY_INFO_free(p8inf);
|
||||
return 0;
|
||||
}
|
||||
|
||||
kstr = buf;
|
||||
}
|
||||
p8 = PKCS8_encrypt(nid, enc, kstr, klen, NULL, 0, 0, p8inf);
|
||||
if (kstr == buf)
|
||||
OPENSSL_cleanse(buf, klen);
|
||||
PKCS8_PRIV_KEY_INFO_free(p8inf);
|
||||
if (p8 == NULL)
|
||||
return 0;
|
||||
if (isder)
|
||||
ret = i2d_PKCS8_bio(bp, p8);
|
||||
else
|
||||
ret = PEM_write_bio_PKCS8(bp, p8);
|
||||
X509_SIG_free(p8);
|
||||
return ret;
|
||||
} else {
|
||||
if (isder)
|
||||
ret = i2d_PKCS8_PRIV_KEY_INFO_bio(bp, p8inf);
|
||||
else
|
||||
ret = PEM_write_bio_PKCS8_PRIV_KEY_INFO(bp, p8inf);
|
||||
PKCS8_PRIV_KEY_INFO_free(p8inf);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u)
|
||||
EVP_PKEY *d2i_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY **x, pem_password_cb *cb,
|
||||
void *u)
|
||||
{
|
||||
PKCS8_PRIV_KEY_INFO *p8inf = NULL;
|
||||
X509_SIG *p8 = NULL;
|
||||
int klen;
|
||||
EVP_PKEY *ret;
|
||||
char psbuf[PEM_BUFSIZE];
|
||||
p8 = d2i_PKCS8_bio(bp, NULL);
|
||||
if(!p8) return NULL;
|
||||
if (cb) klen=cb(psbuf,PEM_BUFSIZE,0,u);
|
||||
else klen=PEM_def_callback(psbuf,PEM_BUFSIZE,0,u);
|
||||
if (klen <= 0) {
|
||||
PEMerr(PEM_F_D2I_PKCS8PRIVATEKEY_BIO, PEM_R_BAD_PASSWORD_READ);
|
||||
X509_SIG_free(p8);
|
||||
return NULL;
|
||||
}
|
||||
p8inf = PKCS8_decrypt(p8, psbuf, klen);
|
||||
X509_SIG_free(p8);
|
||||
if(!p8inf) return NULL;
|
||||
ret = EVP_PKCS82PKEY(p8inf);
|
||||
PKCS8_PRIV_KEY_INFO_free(p8inf);
|
||||
if(!ret) return NULL;
|
||||
if(x) {
|
||||
if(*x) EVP_PKEY_free(*x);
|
||||
*x = ret;
|
||||
}
|
||||
return ret;
|
||||
PKCS8_PRIV_KEY_INFO *p8inf = NULL;
|
||||
X509_SIG *p8 = NULL;
|
||||
int klen;
|
||||
EVP_PKEY *ret;
|
||||
char psbuf[PEM_BUFSIZE];
|
||||
p8 = d2i_PKCS8_bio(bp, NULL);
|
||||
if (!p8)
|
||||
return NULL;
|
||||
if (cb)
|
||||
klen = cb(psbuf, PEM_BUFSIZE, 0, u);
|
||||
else
|
||||
klen = PEM_def_callback(psbuf, PEM_BUFSIZE, 0, u);
|
||||
if (klen <= 0) {
|
||||
PEMerr(PEM_F_D2I_PKCS8PRIVATEKEY_BIO, PEM_R_BAD_PASSWORD_READ);
|
||||
X509_SIG_free(p8);
|
||||
return NULL;
|
||||
}
|
||||
p8inf = PKCS8_decrypt(p8, psbuf, klen);
|
||||
X509_SIG_free(p8);
|
||||
if (!p8inf)
|
||||
return NULL;
|
||||
ret = EVP_PKCS82PKEY(p8inf);
|
||||
PKCS8_PRIV_KEY_INFO_free(p8inf);
|
||||
if (!ret)
|
||||
return NULL;
|
||||
if (x) {
|
||||
if (*x)
|
||||
EVP_PKEY_free(*x);
|
||||
*x = ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_FP_API
|
||||
|
||||
int i2d_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
|
||||
char *kstr, int klen,
|
||||
pem_password_cb *cb, void *u)
|
||||
char *kstr, int klen, pem_password_cb *cb, void *u)
|
||||
{
|
||||
return do_pk8pkey_fp(fp, x, 1, -1, enc, kstr, klen, cb, u);
|
||||
return do_pk8pkey_fp(fp, x, 1, -1, enc, kstr, klen, cb, u);
|
||||
}
|
||||
|
||||
int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, EVP_PKEY *x, int nid,
|
||||
char *kstr, int klen,
|
||||
pem_password_cb *cb, void *u)
|
||||
char *kstr, int klen,
|
||||
pem_password_cb *cb, void *u)
|
||||
{
|
||||
return do_pk8pkey_fp(fp, x, 1, nid, NULL, kstr, klen, cb, u);
|
||||
return do_pk8pkey_fp(fp, x, 1, nid, NULL, kstr, klen, cb, u);
|
||||
}
|
||||
|
||||
int PEM_write_PKCS8PrivateKey_nid(FILE *fp, EVP_PKEY *x, int nid,
|
||||
char *kstr, int klen,
|
||||
pem_password_cb *cb, void *u)
|
||||
char *kstr, int klen,
|
||||
pem_password_cb *cb, void *u)
|
||||
{
|
||||
return do_pk8pkey_fp(fp, x, 0, nid, NULL, kstr, klen, cb, u);
|
||||
return do_pk8pkey_fp(fp, x, 0, nid, NULL, kstr, klen, cb, u);
|
||||
}
|
||||
|
||||
int PEM_write_PKCS8PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
|
||||
char *kstr, int klen, pem_password_cb *cb, void *u)
|
||||
char *kstr, int klen, pem_password_cb *cb,
|
||||
void *u)
|
||||
{
|
||||
return do_pk8pkey_fp(fp, x, 0, -1, enc, kstr, klen, cb, u);
|
||||
return do_pk8pkey_fp(fp, x, 0, -1, enc, kstr, klen, cb, u);
|
||||
}
|
||||
|
||||
static int do_pk8pkey_fp(FILE *fp, EVP_PKEY *x, int isder, int nid, const EVP_CIPHER *enc,
|
||||
char *kstr, int klen,
|
||||
pem_password_cb *cb, void *u)
|
||||
static int do_pk8pkey_fp(FILE *fp, EVP_PKEY *x, int isder, int nid,
|
||||
const EVP_CIPHER *enc, char *kstr, int klen,
|
||||
pem_password_cb *cb, void *u)
|
||||
{
|
||||
BIO *bp;
|
||||
int ret;
|
||||
if(!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) {
|
||||
PEMerr(PEM_F_DO_PK8PKEY_FP,ERR_R_BUF_LIB);
|
||||
return(0);
|
||||
}
|
||||
ret = do_pk8pkey(bp, x, isder, nid, enc, kstr, klen, cb, u);
|
||||
BIO_free(bp);
|
||||
return ret;
|
||||
BIO *bp;
|
||||
int ret;
|
||||
if (!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) {
|
||||
PEMerr(PEM_F_DO_PK8PKEY_FP, ERR_R_BUF_LIB);
|
||||
return (0);
|
||||
}
|
||||
ret = do_pk8pkey(bp, x, isder, nid, enc, kstr, klen, cb, u);
|
||||
BIO_free(bp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u)
|
||||
EVP_PKEY *d2i_PKCS8PrivateKey_fp(FILE *fp, EVP_PKEY **x, pem_password_cb *cb,
|
||||
void *u)
|
||||
{
|
||||
BIO *bp;
|
||||
EVP_PKEY *ret;
|
||||
if(!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) {
|
||||
PEMerr(PEM_F_D2I_PKCS8PRIVATEKEY_FP,ERR_R_BUF_LIB);
|
||||
return NULL;
|
||||
}
|
||||
ret = d2i_PKCS8PrivateKey_bio(bp, x, cb, u);
|
||||
BIO_free(bp);
|
||||
return ret;
|
||||
BIO *bp;
|
||||
EVP_PKEY *ret;
|
||||
if (!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) {
|
||||
PEMerr(PEM_F_D2I_PKCS8PRIVATEKEY_FP, ERR_R_BUF_LIB);
|
||||
return NULL;
|
||||
}
|
||||
ret = d2i_PKCS8PrivateKey_bio(bp, x, cb, u);
|
||||
BIO_free(bp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
IMPLEMENT_PEM_rw(PKCS8, X509_SIG, PEM_STRING_PKCS8, X509_SIG)
|
||||
|
||||
|
||||
IMPLEMENT_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO, PEM_STRING_PKCS8INF,
|
||||
PKCS8_PRIV_KEY_INFO)
|
||||
PKCS8_PRIV_KEY_INFO)
|
||||
|
||||
Binary file not shown.
@@ -5,21 +5,21 @@
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
@@ -34,10 +34,10 @@
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
@@ -49,7 +49,7 @@
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
@@ -66,177 +66,228 @@
|
||||
#include <openssl/pkcs12.h>
|
||||
#include <openssl/pem.h>
|
||||
#ifndef OPENSSL_NO_ENGINE
|
||||
#include <openssl/engine.h>
|
||||
# include <openssl/engine.h>
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_DH
|
||||
# include <openssl/dh.h>
|
||||
#endif
|
||||
#include "asn1_locl.h"
|
||||
|
||||
int pem_check_suffix(const char *pem_str, const char *suffix);
|
||||
|
||||
EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u)
|
||||
{
|
||||
char *nm=NULL;
|
||||
const unsigned char *p=NULL;
|
||||
unsigned char *data=NULL;
|
||||
long len;
|
||||
int slen;
|
||||
EVP_PKEY *ret=NULL;
|
||||
EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb,
|
||||
void *u)
|
||||
{
|
||||
char *nm = NULL;
|
||||
const unsigned char *p = NULL;
|
||||
unsigned char *data = NULL;
|
||||
long len;
|
||||
int slen;
|
||||
EVP_PKEY *ret = NULL;
|
||||
|
||||
if (!PEM_bytes_read_bio(&data, &len, &nm, PEM_STRING_EVP_PKEY, bp, cb, u))
|
||||
return NULL;
|
||||
p = data;
|
||||
if (!PEM_bytes_read_bio(&data, &len, &nm, PEM_STRING_EVP_PKEY, bp, cb, u))
|
||||
return NULL;
|
||||
p = data;
|
||||
|
||||
if (strcmp(nm,PEM_STRING_PKCS8INF) == 0) {
|
||||
PKCS8_PRIV_KEY_INFO *p8inf;
|
||||
p8inf=d2i_PKCS8_PRIV_KEY_INFO(NULL, &p, len);
|
||||
if(!p8inf) goto p8err;
|
||||
ret = EVP_PKCS82PKEY(p8inf);
|
||||
if(x) {
|
||||
if(*x) EVP_PKEY_free((EVP_PKEY *)*x);
|
||||
*x = ret;
|
||||
}
|
||||
PKCS8_PRIV_KEY_INFO_free(p8inf);
|
||||
} else if (strcmp(nm,PEM_STRING_PKCS8) == 0) {
|
||||
PKCS8_PRIV_KEY_INFO *p8inf;
|
||||
X509_SIG *p8;
|
||||
int klen;
|
||||
char psbuf[PEM_BUFSIZE];
|
||||
p8 = d2i_X509_SIG(NULL, &p, len);
|
||||
if(!p8) goto p8err;
|
||||
if (cb) klen=cb(psbuf,PEM_BUFSIZE,0,u);
|
||||
else klen=PEM_def_callback(psbuf,PEM_BUFSIZE,0,u);
|
||||
if (klen <= 0) {
|
||||
PEMerr(PEM_F_PEM_READ_BIO_PRIVATEKEY,
|
||||
PEM_R_BAD_PASSWORD_READ);
|
||||
X509_SIG_free(p8);
|
||||
goto err;
|
||||
}
|
||||
p8inf = PKCS8_decrypt(p8, psbuf, klen);
|
||||
X509_SIG_free(p8);
|
||||
if(!p8inf) goto p8err;
|
||||
ret = EVP_PKCS82PKEY(p8inf);
|
||||
if(x) {
|
||||
if(*x) EVP_PKEY_free((EVP_PKEY *)*x);
|
||||
*x = ret;
|
||||
}
|
||||
PKCS8_PRIV_KEY_INFO_free(p8inf);
|
||||
} else if ((slen = pem_check_suffix(nm, "PRIVATE KEY")) > 0)
|
||||
{
|
||||
const EVP_PKEY_ASN1_METHOD *ameth;
|
||||
ameth = EVP_PKEY_asn1_find_str(NULL, nm, slen);
|
||||
if (!ameth || !ameth->old_priv_decode)
|
||||
goto p8err;
|
||||
ret=d2i_PrivateKey(ameth->pkey_id,x,&p,len);
|
||||
}
|
||||
p8err:
|
||||
if (ret == NULL)
|
||||
PEMerr(PEM_F_PEM_READ_BIO_PRIVATEKEY,ERR_R_ASN1_LIB);
|
||||
err:
|
||||
OPENSSL_free(nm);
|
||||
OPENSSL_cleanse(data, len);
|
||||
OPENSSL_free(data);
|
||||
return(ret);
|
||||
}
|
||||
if (strcmp(nm, PEM_STRING_PKCS8INF) == 0) {
|
||||
PKCS8_PRIV_KEY_INFO *p8inf;
|
||||
p8inf = d2i_PKCS8_PRIV_KEY_INFO(NULL, &p, len);
|
||||
if (!p8inf)
|
||||
goto p8err;
|
||||
ret = EVP_PKCS82PKEY(p8inf);
|
||||
if (x) {
|
||||
if (*x)
|
||||
EVP_PKEY_free((EVP_PKEY *)*x);
|
||||
*x = ret;
|
||||
}
|
||||
PKCS8_PRIV_KEY_INFO_free(p8inf);
|
||||
} else if (strcmp(nm, PEM_STRING_PKCS8) == 0) {
|
||||
PKCS8_PRIV_KEY_INFO *p8inf;
|
||||
X509_SIG *p8;
|
||||
int klen;
|
||||
char psbuf[PEM_BUFSIZE];
|
||||
p8 = d2i_X509_SIG(NULL, &p, len);
|
||||
if (!p8)
|
||||
goto p8err;
|
||||
if (cb)
|
||||
klen = cb(psbuf, PEM_BUFSIZE, 0, u);
|
||||
else
|
||||
klen = PEM_def_callback(psbuf, PEM_BUFSIZE, 0, u);
|
||||
if (klen <= 0) {
|
||||
PEMerr(PEM_F_PEM_READ_BIO_PRIVATEKEY, PEM_R_BAD_PASSWORD_READ);
|
||||
X509_SIG_free(p8);
|
||||
goto err;
|
||||
}
|
||||
p8inf = PKCS8_decrypt(p8, psbuf, klen);
|
||||
X509_SIG_free(p8);
|
||||
if (!p8inf)
|
||||
goto p8err;
|
||||
ret = EVP_PKCS82PKEY(p8inf);
|
||||
if (x) {
|
||||
if (*x)
|
||||
EVP_PKEY_free((EVP_PKEY *)*x);
|
||||
*x = ret;
|
||||
}
|
||||
PKCS8_PRIV_KEY_INFO_free(p8inf);
|
||||
} else if ((slen = pem_check_suffix(nm, "PRIVATE KEY")) > 0) {
|
||||
const EVP_PKEY_ASN1_METHOD *ameth;
|
||||
ameth = EVP_PKEY_asn1_find_str(NULL, nm, slen);
|
||||
if (!ameth || !ameth->old_priv_decode)
|
||||
goto p8err;
|
||||
ret = d2i_PrivateKey(ameth->pkey_id, x, &p, len);
|
||||
}
|
||||
p8err:
|
||||
if (ret == NULL)
|
||||
PEMerr(PEM_F_PEM_READ_BIO_PRIVATEKEY, ERR_R_ASN1_LIB);
|
||||
err:
|
||||
OPENSSL_free(nm);
|
||||
OPENSSL_cleanse(data, len);
|
||||
OPENSSL_free(data);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int PEM_write_bio_PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
|
||||
unsigned char *kstr, int klen,
|
||||
pem_password_cb *cb, void *u)
|
||||
{
|
||||
char pem_str[80];
|
||||
if (!x->ameth || x->ameth->priv_encode)
|
||||
return PEM_write_bio_PKCS8PrivateKey(bp, x, enc,
|
||||
(char *)kstr, klen,
|
||||
cb, u);
|
||||
unsigned char *kstr, int klen,
|
||||
pem_password_cb *cb, void *u)
|
||||
{
|
||||
char pem_str[80];
|
||||
if (!x->ameth || x->ameth->priv_encode)
|
||||
return PEM_write_bio_PKCS8PrivateKey(bp, x, enc,
|
||||
(char *)kstr, klen, cb, u);
|
||||
|
||||
BIO_snprintf(pem_str, 80, "%s PRIVATE KEY", x->ameth->pem_str);
|
||||
return PEM_ASN1_write_bio((i2d_of_void *)i2d_PrivateKey,
|
||||
pem_str,bp,x,enc,kstr,klen,cb,u);
|
||||
}
|
||||
BIO_snprintf(pem_str, 80, "%s PRIVATE KEY", x->ameth->pem_str);
|
||||
return PEM_ASN1_write_bio((i2d_of_void *)i2d_PrivateKey,
|
||||
pem_str, bp, x, enc, kstr, klen, cb, u);
|
||||
}
|
||||
|
||||
EVP_PKEY *PEM_read_bio_Parameters(BIO *bp, EVP_PKEY **x)
|
||||
{
|
||||
char *nm=NULL;
|
||||
const unsigned char *p=NULL;
|
||||
unsigned char *data=NULL;
|
||||
long len;
|
||||
int slen;
|
||||
EVP_PKEY *ret=NULL;
|
||||
{
|
||||
char *nm = NULL;
|
||||
const unsigned char *p = NULL;
|
||||
unsigned char *data = NULL;
|
||||
long len;
|
||||
int slen;
|
||||
EVP_PKEY *ret = NULL;
|
||||
|
||||
if (!PEM_bytes_read_bio(&data, &len, &nm, PEM_STRING_PARAMETERS,
|
||||
bp, 0, NULL))
|
||||
return NULL;
|
||||
p = data;
|
||||
if (!PEM_bytes_read_bio(&data, &len, &nm, PEM_STRING_PARAMETERS,
|
||||
bp, 0, NULL))
|
||||
return NULL;
|
||||
p = data;
|
||||
|
||||
if ((slen = pem_check_suffix(nm, "PARAMETERS")) > 0)
|
||||
{
|
||||
ret = EVP_PKEY_new();
|
||||
if (!ret)
|
||||
goto err;
|
||||
if (!EVP_PKEY_set_type_str(ret, nm, slen)
|
||||
|| !ret->ameth->param_decode
|
||||
|| !ret->ameth->param_decode(ret, &p, len))
|
||||
{
|
||||
EVP_PKEY_free(ret);
|
||||
ret = NULL;
|
||||
goto err;
|
||||
}
|
||||
if(x)
|
||||
{
|
||||
if(*x) EVP_PKEY_free((EVP_PKEY *)*x);
|
||||
*x = ret;
|
||||
}
|
||||
}
|
||||
err:
|
||||
if (ret == NULL)
|
||||
PEMerr(PEM_F_PEM_READ_BIO_PARAMETERS,ERR_R_ASN1_LIB);
|
||||
OPENSSL_free(nm);
|
||||
OPENSSL_free(data);
|
||||
return(ret);
|
||||
}
|
||||
if ((slen = pem_check_suffix(nm, "PARAMETERS")) > 0) {
|
||||
ret = EVP_PKEY_new();
|
||||
if (!ret)
|
||||
goto err;
|
||||
if (!EVP_PKEY_set_type_str(ret, nm, slen)
|
||||
|| !ret->ameth->param_decode
|
||||
|| !ret->ameth->param_decode(ret, &p, len)) {
|
||||
EVP_PKEY_free(ret);
|
||||
ret = NULL;
|
||||
goto err;
|
||||
}
|
||||
if (x) {
|
||||
if (*x)
|
||||
EVP_PKEY_free((EVP_PKEY *)*x);
|
||||
*x = ret;
|
||||
}
|
||||
}
|
||||
err:
|
||||
if (ret == NULL)
|
||||
PEMerr(PEM_F_PEM_READ_BIO_PARAMETERS, ERR_R_ASN1_LIB);
|
||||
OPENSSL_free(nm);
|
||||
OPENSSL_free(data);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int PEM_write_bio_Parameters(BIO *bp, EVP_PKEY *x)
|
||||
{
|
||||
char pem_str[80];
|
||||
if (!x->ameth || !x->ameth->param_encode)
|
||||
return 0;
|
||||
{
|
||||
char pem_str[80];
|
||||
if (!x->ameth || !x->ameth->param_encode)
|
||||
return 0;
|
||||
|
||||
BIO_snprintf(pem_str, 80, "%s PARAMETERS", x->ameth->pem_str);
|
||||
return PEM_ASN1_write_bio(
|
||||
(i2d_of_void *)x->ameth->param_encode,
|
||||
pem_str,bp,x,NULL,NULL,0,0,NULL);
|
||||
}
|
||||
BIO_snprintf(pem_str, 80, "%s PARAMETERS", x->ameth->pem_str);
|
||||
return PEM_ASN1_write_bio((i2d_of_void *)x->ameth->param_encode,
|
||||
pem_str, bp, x, NULL, NULL, 0, 0, NULL);
|
||||
}
|
||||
|
||||
#ifndef OPENSSL_NO_FP_API
|
||||
EVP_PKEY *PEM_read_PrivateKey(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u)
|
||||
{
|
||||
BIO *b;
|
||||
EVP_PKEY *ret;
|
||||
EVP_PKEY *PEM_read_PrivateKey(FILE *fp, EVP_PKEY **x, pem_password_cb *cb,
|
||||
void *u)
|
||||
{
|
||||
BIO *b;
|
||||
EVP_PKEY *ret;
|
||||
|
||||
if ((b=BIO_new(BIO_s_file())) == NULL)
|
||||
{
|
||||
PEMerr(PEM_F_PEM_READ_PRIVATEKEY,ERR_R_BUF_LIB);
|
||||
return(0);
|
||||
}
|
||||
BIO_set_fp(b,fp,BIO_NOCLOSE);
|
||||
ret=PEM_read_bio_PrivateKey(b,x,cb,u);
|
||||
BIO_free(b);
|
||||
return(ret);
|
||||
}
|
||||
if ((b = BIO_new(BIO_s_file())) == NULL) {
|
||||
PEMerr(PEM_F_PEM_READ_PRIVATEKEY, ERR_R_BUF_LIB);
|
||||
return (0);
|
||||
}
|
||||
BIO_set_fp(b, fp, BIO_NOCLOSE);
|
||||
ret = PEM_read_bio_PrivateKey(b, x, cb, u);
|
||||
BIO_free(b);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
int PEM_write_PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
|
||||
unsigned char *kstr, int klen,
|
||||
pem_password_cb *cb, void *u)
|
||||
{
|
||||
BIO *b;
|
||||
int ret;
|
||||
unsigned char *kstr, int klen,
|
||||
pem_password_cb *cb, void *u)
|
||||
{
|
||||
BIO *b;
|
||||
int ret;
|
||||
|
||||
if ((b=BIO_new_fp(fp, BIO_NOCLOSE)) == NULL)
|
||||
{
|
||||
PEMerr(PEM_F_PEM_WRITE_PRIVATEKEY,ERR_R_BUF_LIB);
|
||||
return 0;
|
||||
}
|
||||
ret=PEM_write_bio_PrivateKey(b, x, enc, kstr, klen, cb, u);
|
||||
BIO_free(b);
|
||||
return ret;
|
||||
}
|
||||
if ((b = BIO_new_fp(fp, BIO_NOCLOSE)) == NULL) {
|
||||
PEMerr(PEM_F_PEM_WRITE_PRIVATEKEY, ERR_R_BUF_LIB);
|
||||
return 0;
|
||||
}
|
||||
ret = PEM_write_bio_PrivateKey(b, x, enc, kstr, klen, cb, u);
|
||||
BIO_free(b);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef OPENSSL_NO_DH
|
||||
|
||||
/* Transparently read in PKCS#3 or X9.42 DH parameters */
|
||||
|
||||
DH *PEM_read_bio_DHparams(BIO *bp, DH **x, pem_password_cb *cb, void *u)
|
||||
{
|
||||
char *nm = NULL;
|
||||
const unsigned char *p = NULL;
|
||||
unsigned char *data = NULL;
|
||||
long len;
|
||||
DH *ret = NULL;
|
||||
|
||||
if (!PEM_bytes_read_bio(&data, &len, &nm, PEM_STRING_DHPARAMS, bp, cb, u))
|
||||
return NULL;
|
||||
p = data;
|
||||
|
||||
if (!strcmp(nm, PEM_STRING_DHXPARAMS))
|
||||
ret = d2i_DHxparams(x, &p, len);
|
||||
else
|
||||
ret = d2i_DHparams(x, &p, len);
|
||||
|
||||
if (ret == NULL)
|
||||
PEMerr(PEM_F_PEM_READ_BIO_DHPARAMS, ERR_R_ASN1_LIB);
|
||||
OPENSSL_free(nm);
|
||||
OPENSSL_free(data);
|
||||
return ret;
|
||||
}
|
||||
|
||||
# ifndef OPENSSL_NO_FP_API
|
||||
DH *PEM_read_DHparams(FILE *fp, DH **x, pem_password_cb *cb, void *u)
|
||||
{
|
||||
BIO *b;
|
||||
DH *ret;
|
||||
|
||||
if ((b = BIO_new(BIO_s_file())) == NULL) {
|
||||
PEMerr(PEM_F_PEM_READ_DHPARAMS, ERR_R_BUF_LIB);
|
||||
return (0);
|
||||
}
|
||||
BIO_set_fp(b, fp, BIO_NOCLOSE);
|
||||
ret = PEM_read_bio_DHparams(b, x, cb, u);
|
||||
BIO_free(b);
|
||||
return (ret);
|
||||
}
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
Binary file not shown.
@@ -5,21 +5,21 @@
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
@@ -34,10 +34,10 @@
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
@@ -49,141 +49,143 @@
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#include <openssl/opensslconf.h> /* for OPENSSL_NO_RSA */
|
||||
#include <openssl/opensslconf.h> /* for OPENSSL_NO_RSA */
|
||||
#ifndef OPENSSL_NO_RSA
|
||||
#include <stdio.h>
|
||||
#include "cryptlib.h"
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/objects.h>
|
||||
#include <openssl/x509.h>
|
||||
#include <openssl/pem.h>
|
||||
#include <openssl/rsa.h>
|
||||
# include <stdio.h>
|
||||
# include "cryptlib.h"
|
||||
# include <openssl/evp.h>
|
||||
# include <openssl/rand.h>
|
||||
# include <openssl/objects.h>
|
||||
# include <openssl/x509.h>
|
||||
# include <openssl/pem.h>
|
||||
# include <openssl/rsa.h>
|
||||
|
||||
int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type,
|
||||
unsigned char **ek, int *ekl, unsigned char *iv, EVP_PKEY **pubk,
|
||||
int npubk)
|
||||
{
|
||||
unsigned char key[EVP_MAX_KEY_LENGTH];
|
||||
int ret= -1;
|
||||
int i,j,max=0;
|
||||
char *s=NULL;
|
||||
unsigned char **ek, int *ekl, unsigned char *iv,
|
||||
EVP_PKEY **pubk, int npubk)
|
||||
{
|
||||
unsigned char key[EVP_MAX_KEY_LENGTH];
|
||||
int ret = -1;
|
||||
int i, j, max = 0;
|
||||
char *s = NULL;
|
||||
|
||||
for (i=0; i<npubk; i++)
|
||||
{
|
||||
if (pubk[i]->type != EVP_PKEY_RSA)
|
||||
{
|
||||
PEMerr(PEM_F_PEM_SEALINIT,PEM_R_PUBLIC_KEY_NO_RSA);
|
||||
goto err;
|
||||
}
|
||||
j=RSA_size(pubk[i]->pkey.rsa);
|
||||
if (j > max) max=j;
|
||||
}
|
||||
s=(char *)OPENSSL_malloc(max*2);
|
||||
if (s == NULL)
|
||||
{
|
||||
PEMerr(PEM_F_PEM_SEALINIT,ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
for (i = 0; i < npubk; i++) {
|
||||
if (pubk[i]->type != EVP_PKEY_RSA) {
|
||||
PEMerr(PEM_F_PEM_SEALINIT, PEM_R_PUBLIC_KEY_NO_RSA);
|
||||
goto err;
|
||||
}
|
||||
j = RSA_size(pubk[i]->pkey.rsa);
|
||||
if (j > max)
|
||||
max = j;
|
||||
}
|
||||
s = (char *)OPENSSL_malloc(max * 2);
|
||||
if (s == NULL) {
|
||||
PEMerr(PEM_F_PEM_SEALINIT, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
EVP_EncodeInit(&ctx->encode);
|
||||
EVP_EncodeInit(&ctx->encode);
|
||||
|
||||
EVP_MD_CTX_init(&ctx->md);
|
||||
EVP_SignInit(&ctx->md,md_type);
|
||||
EVP_MD_CTX_init(&ctx->md);
|
||||
if (!EVP_SignInit(&ctx->md, md_type))
|
||||
goto err;
|
||||
|
||||
EVP_CIPHER_CTX_init(&ctx->cipher);
|
||||
ret=EVP_SealInit(&ctx->cipher,type,ek,ekl,iv,pubk,npubk);
|
||||
if (ret <= 0) goto err;
|
||||
EVP_CIPHER_CTX_init(&ctx->cipher);
|
||||
ret = EVP_SealInit(&ctx->cipher, type, ek, ekl, iv, pubk, npubk);
|
||||
if (ret <= 0)
|
||||
goto err;
|
||||
|
||||
/* base64 encode the keys */
|
||||
for (i=0; i<npubk; i++)
|
||||
{
|
||||
j=EVP_EncodeBlock((unsigned char *)s,ek[i],
|
||||
RSA_size(pubk[i]->pkey.rsa));
|
||||
ekl[i]=j;
|
||||
memcpy(ek[i],s,j+1);
|
||||
}
|
||||
/* base64 encode the keys */
|
||||
for (i = 0; i < npubk; i++) {
|
||||
j = EVP_EncodeBlock((unsigned char *)s, ek[i],
|
||||
RSA_size(pubk[i]->pkey.rsa));
|
||||
ekl[i] = j;
|
||||
memcpy(ek[i], s, j + 1);
|
||||
}
|
||||
|
||||
ret=npubk;
|
||||
err:
|
||||
if (s != NULL) OPENSSL_free(s);
|
||||
OPENSSL_cleanse(key,EVP_MAX_KEY_LENGTH);
|
||||
return(ret);
|
||||
}
|
||||
ret = npubk;
|
||||
err:
|
||||
if (s != NULL)
|
||||
OPENSSL_free(s);
|
||||
OPENSSL_cleanse(key, EVP_MAX_KEY_LENGTH);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
void PEM_SealUpdate(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *out, int *outl,
|
||||
unsigned char *in, int inl)
|
||||
{
|
||||
unsigned char buffer[1600];
|
||||
int i,j;
|
||||
unsigned char *in, int inl)
|
||||
{
|
||||
unsigned char buffer[1600];
|
||||
int i, j;
|
||||
|
||||
*outl=0;
|
||||
EVP_SignUpdate(&ctx->md,in,inl);
|
||||
for (;;)
|
||||
{
|
||||
if (inl <= 0) break;
|
||||
if (inl > 1200)
|
||||
i=1200;
|
||||
else
|
||||
i=inl;
|
||||
EVP_EncryptUpdate(&ctx->cipher,buffer,&j,in,i);
|
||||
EVP_EncodeUpdate(&ctx->encode,out,&j,buffer,j);
|
||||
*outl+=j;
|
||||
out+=j;
|
||||
in+=i;
|
||||
inl-=i;
|
||||
}
|
||||
}
|
||||
*outl = 0;
|
||||
EVP_SignUpdate(&ctx->md, in, inl);
|
||||
for (;;) {
|
||||
if (inl <= 0)
|
||||
break;
|
||||
if (inl > 1200)
|
||||
i = 1200;
|
||||
else
|
||||
i = inl;
|
||||
EVP_EncryptUpdate(&ctx->cipher, buffer, &j, in, i);
|
||||
EVP_EncodeUpdate(&ctx->encode, out, &j, buffer, j);
|
||||
*outl += j;
|
||||
out += j;
|
||||
in += i;
|
||||
inl -= i;
|
||||
}
|
||||
}
|
||||
|
||||
int PEM_SealFinal(PEM_ENCODE_SEAL_CTX *ctx, unsigned char *sig, int *sigl,
|
||||
unsigned char *out, int *outl, EVP_PKEY *priv)
|
||||
{
|
||||
unsigned char *s=NULL;
|
||||
int ret=0,j;
|
||||
unsigned int i;
|
||||
unsigned char *out, int *outl, EVP_PKEY *priv)
|
||||
{
|
||||
unsigned char *s = NULL;
|
||||
int ret = 0, j;
|
||||
unsigned int i;
|
||||
|
||||
if (priv->type != EVP_PKEY_RSA)
|
||||
{
|
||||
PEMerr(PEM_F_PEM_SEALFINAL,PEM_R_PUBLIC_KEY_NO_RSA);
|
||||
goto err;
|
||||
}
|
||||
i=RSA_size(priv->pkey.rsa);
|
||||
if (i < 100) i=100;
|
||||
s=(unsigned char *)OPENSSL_malloc(i*2);
|
||||
if (s == NULL)
|
||||
{
|
||||
PEMerr(PEM_F_PEM_SEALFINAL,ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
if (priv->type != EVP_PKEY_RSA) {
|
||||
PEMerr(PEM_F_PEM_SEALFINAL, PEM_R_PUBLIC_KEY_NO_RSA);
|
||||
goto err;
|
||||
}
|
||||
i = RSA_size(priv->pkey.rsa);
|
||||
if (i < 100)
|
||||
i = 100;
|
||||
s = (unsigned char *)OPENSSL_malloc(i * 2);
|
||||
if (s == NULL) {
|
||||
PEMerr(PEM_F_PEM_SEALFINAL, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
EVP_EncryptFinal_ex(&ctx->cipher,s,(int *)&i);
|
||||
EVP_EncodeUpdate(&ctx->encode,out,&j,s,i);
|
||||
*outl=j;
|
||||
out+=j;
|
||||
EVP_EncodeFinal(&ctx->encode,out,&j);
|
||||
*outl+=j;
|
||||
if (!EVP_EncryptFinal_ex(&ctx->cipher, s, (int *)&i))
|
||||
goto err;
|
||||
EVP_EncodeUpdate(&ctx->encode, out, &j, s, i);
|
||||
*outl = j;
|
||||
out += j;
|
||||
EVP_EncodeFinal(&ctx->encode, out, &j);
|
||||
*outl += j;
|
||||
|
||||
if (!EVP_SignFinal(&ctx->md,s,&i,priv)) goto err;
|
||||
*sigl=EVP_EncodeBlock(sig,s,i);
|
||||
if (!EVP_SignFinal(&ctx->md, s, &i, priv))
|
||||
goto err;
|
||||
*sigl = EVP_EncodeBlock(sig, s, i);
|
||||
|
||||
ret=1;
|
||||
err:
|
||||
EVP_MD_CTX_cleanup(&ctx->md);
|
||||
EVP_CIPHER_CTX_cleanup(&ctx->cipher);
|
||||
if (s != NULL) OPENSSL_free(s);
|
||||
return(ret);
|
||||
}
|
||||
#else /* !OPENSSL_NO_RSA */
|
||||
ret = 1;
|
||||
err:
|
||||
EVP_MD_CTX_cleanup(&ctx->md);
|
||||
EVP_CIPHER_CTX_cleanup(&ctx->cipher);
|
||||
if (s != NULL)
|
||||
OPENSSL_free(s);
|
||||
return (ret);
|
||||
}
|
||||
#else /* !OPENSSL_NO_RSA */
|
||||
|
||||
# if PEDANTIC
|
||||
static void *dummy=&dummy;
|
||||
static void *dummy = &dummy;
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
Binary file not shown.
@@ -5,21 +5,21 @@
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
@@ -34,10 +34,10 @@
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
@@ -49,7 +49,7 @@
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
@@ -65,38 +65,37 @@
|
||||
#include <openssl/pem.h>
|
||||
|
||||
void PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type)
|
||||
{
|
||||
EVP_DigestInit_ex(ctx, type, NULL);
|
||||
}
|
||||
{
|
||||
EVP_DigestInit_ex(ctx, type, NULL);
|
||||
}
|
||||
|
||||
void PEM_SignUpdate(EVP_MD_CTX *ctx, unsigned char *data,
|
||||
unsigned int count)
|
||||
{
|
||||
EVP_DigestUpdate(ctx,data,count);
|
||||
}
|
||||
void PEM_SignUpdate(EVP_MD_CTX *ctx, unsigned char *data, unsigned int count)
|
||||
{
|
||||
EVP_DigestUpdate(ctx, data, count);
|
||||
}
|
||||
|
||||
int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, unsigned int *siglen,
|
||||
EVP_PKEY *pkey)
|
||||
{
|
||||
unsigned char *m;
|
||||
int i,ret=0;
|
||||
unsigned int m_len;
|
||||
int PEM_SignFinal(EVP_MD_CTX *ctx, unsigned char *sigret,
|
||||
unsigned int *siglen, EVP_PKEY *pkey)
|
||||
{
|
||||
unsigned char *m;
|
||||
int i, ret = 0;
|
||||
unsigned int m_len;
|
||||
|
||||
m=(unsigned char *)OPENSSL_malloc(EVP_PKEY_size(pkey)+2);
|
||||
if (m == NULL)
|
||||
{
|
||||
PEMerr(PEM_F_PEM_SIGNFINAL,ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
m = (unsigned char *)OPENSSL_malloc(EVP_PKEY_size(pkey) + 2);
|
||||
if (m == NULL) {
|
||||
PEMerr(PEM_F_PEM_SIGNFINAL, ERR_R_MALLOC_FAILURE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
if (EVP_SignFinal(ctx,m,&m_len,pkey) <= 0) goto err;
|
||||
|
||||
i=EVP_EncodeBlock(sigret,m,m_len);
|
||||
*siglen=i;
|
||||
ret=1;
|
||||
err:
|
||||
/* ctx has been zeroed by EVP_SignFinal() */
|
||||
if (m != NULL) OPENSSL_free(m);
|
||||
return(ret);
|
||||
}
|
||||
if (EVP_SignFinal(ctx, m, &m_len, pkey) <= 0)
|
||||
goto err;
|
||||
|
||||
i = EVP_EncodeBlock(sigret, m, m_len);
|
||||
*siglen = i;
|
||||
ret = 1;
|
||||
err:
|
||||
/* ctx has been zeroed by EVP_SignFinal() */
|
||||
if (m != NULL)
|
||||
OPENSSL_free(m);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -1,6 +1,7 @@
|
||||
/* pem_x509.c */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 2001.
|
||||
/*
|
||||
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
|
||||
* 2001.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2001 The OpenSSL Project. All rights reserved.
|
||||
@@ -10,7 +11,7 @@
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
@@ -65,4 +66,3 @@
|
||||
#include <openssl/pem.h>
|
||||
|
||||
IMPLEMENT_PEM_rw(X509, X509, PEM_STRING_X509, X509)
|
||||
|
||||
|
||||
Binary file not shown.
@@ -1,6 +1,7 @@
|
||||
/* pem_xaux.c */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 2001.
|
||||
/*
|
||||
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
|
||||
* 2001.
|
||||
*/
|
||||
/* ====================================================================
|
||||
* Copyright (c) 2001 The OpenSSL Project. All rights reserved.
|
||||
@@ -10,7 +11,7 @@
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
@@ -65,4 +66,5 @@
|
||||
#include <openssl/pem.h>
|
||||
|
||||
IMPLEMENT_PEM_rw(X509_AUX, X509, PEM_STRING_X509_TRUSTED, X509_AUX)
|
||||
IMPLEMENT_PEM_rw(X509_CERT_PAIR, X509_CERT_PAIR, PEM_STRING_X509_PAIR, X509_CERT_PAIR)
|
||||
IMPLEMENT_PEM_rw(X509_CERT_PAIR, X509_CERT_PAIR, PEM_STRING_X509_PAIR,
|
||||
X509_CERT_PAIR)
|
||||
|
||||
Binary file not shown.
1503
crypto/pem/pvkfmt.c
1503
crypto/pem/pvkfmt.c
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Reference in New Issue
Block a user