Adding in curl and openssl repos

This commit is contained in:
2025-08-14 12:09:30 -04:00
parent af2117b574
commit 0ace93e303
21174 changed files with 3607720 additions and 2 deletions

View File

@@ -0,0 +1,4 @@
LIBS=../../libcrypto
SOURCE[../../libcrypto]=\
pem_sign.c pem_info.c pem_lib.c pem_all.c pem_err.c \
pem_x509.c pem_xaux.c pem_oth.c pem_pk8.c pem_pkey.c pvkfmt.c

View File

@@ -0,0 +1,27 @@
crypto/pem/libcrypto-lib-pem_all.o: crypto/pem/pem_all.c \
include/internal/deprecated.h include/openssl/configuration.h \
include/openssl/macros.h include/openssl/opensslconf.h \
include/openssl/opensslv.h include/internal/cryptlib.h \
include/internal/common.h include/internal/e_os.h \
include/openssl/e_os2.h include/openssl/crypto.h \
include/openssl/safestack.h include/openssl/stack.h \
include/openssl/types.h include/openssl/cryptoerr.h \
include/openssl/symhacks.h include/openssl/cryptoerr_legacy.h \
include/openssl/core.h include/internal/numbers.h \
include/internal/nelem.h include/openssl/buffer.h \
include/openssl/buffererr.h include/openssl/bio.h \
include/openssl/bioerr.h include/openssl/asn1.h \
include/openssl/asn1err.h include/openssl/bn.h include/openssl/bnerr.h \
include/openssl/err.h include/openssl/lhash.h include/openssl/evp.h \
include/openssl/core_dispatch.h include/openssl/indicator.h \
include/openssl/params.h include/openssl/evperr.h \
include/openssl/objects.h include/openssl/obj_mac.h \
include/openssl/objectserr.h include/openssl/x509.h include/openssl/ec.h \
include/openssl/ecerr.h include/openssl/rsa.h include/openssl/rsaerr.h \
include/openssl/dsa.h include/openssl/dh.h include/openssl/dherr.h \
include/openssl/dsaerr.h include/openssl/sha.h include/openssl/x509err.h \
include/openssl/x509_vfy.h include/openssl/pkcs7.h \
include/openssl/pkcs7err.h include/openssl/http.h include/openssl/conf.h \
include/openssl/conferr.h include/openssl/conftypes.h \
include/openssl/pem.h include/openssl/pemerr.h crypto/pem/pem_local.h \
include/openssl/encoder.h include/openssl/encodererr.h

View File

@@ -0,0 +1,10 @@
crypto/pem/libcrypto-lib-pem_err.o: crypto/pem/pem_err.c \
include/openssl/err.h include/openssl/macros.h \
include/openssl/opensslconf.h include/openssl/configuration.h \
include/openssl/opensslv.h include/openssl/e_os2.h \
include/openssl/types.h include/openssl/safestack.h \
include/openssl/stack.h include/openssl/bio.h include/openssl/crypto.h \
include/openssl/cryptoerr.h include/openssl/symhacks.h \
include/openssl/cryptoerr_legacy.h include/openssl/core.h \
include/openssl/bioerr.h include/openssl/lhash.h \
include/openssl/pemerr.h include/crypto/pemerr.h

View File

@@ -0,0 +1,28 @@
crypto/pem/libcrypto-lib-pem_info.o: crypto/pem/pem_info.c \
include/internal/deprecated.h include/openssl/configuration.h \
include/openssl/macros.h include/openssl/opensslconf.h \
include/openssl/opensslv.h include/internal/cryptlib.h \
include/internal/common.h include/internal/e_os.h \
include/openssl/e_os2.h include/openssl/crypto.h \
include/openssl/safestack.h include/openssl/stack.h \
include/openssl/types.h include/openssl/cryptoerr.h \
include/openssl/symhacks.h include/openssl/cryptoerr_legacy.h \
include/openssl/core.h include/internal/numbers.h \
include/internal/nelem.h include/openssl/buffer.h \
include/openssl/buffererr.h include/openssl/bio.h \
include/openssl/bioerr.h include/openssl/asn1.h \
include/openssl/asn1err.h include/openssl/bn.h include/openssl/bnerr.h \
include/openssl/err.h include/openssl/lhash.h include/openssl/objects.h \
include/openssl/obj_mac.h include/openssl/objectserr.h \
include/openssl/evp.h include/openssl/core_dispatch.h \
include/openssl/indicator.h include/openssl/params.h \
include/openssl/evperr.h include/openssl/x509.h include/openssl/ec.h \
include/openssl/ecerr.h include/openssl/rsa.h include/openssl/rsaerr.h \
include/openssl/dsa.h include/openssl/dh.h include/openssl/dherr.h \
include/openssl/dsaerr.h include/openssl/sha.h include/openssl/x509err.h \
include/openssl/x509_vfy.h include/openssl/pkcs7.h \
include/openssl/pkcs7err.h include/openssl/http.h include/openssl/conf.h \
include/openssl/conferr.h include/openssl/conftypes.h \
include/openssl/pem.h include/openssl/pemerr.h include/crypto/evp.h \
include/internal/refcount.h include/openssl/trace.h include/crypto/ecx.h \
include/crypto/types.h

View File

@@ -0,0 +1,29 @@
crypto/pem/libcrypto-lib-pem_lib.o: crypto/pem/pem_lib.c \
include/crypto/ctype.h include/openssl/e_os2.h include/openssl/macros.h \
include/openssl/opensslconf.h include/openssl/configuration.h \
include/openssl/opensslv.h include/internal/cryptlib.h \
include/internal/common.h include/internal/e_os.h \
include/openssl/crypto.h include/openssl/safestack.h \
include/openssl/stack.h include/openssl/types.h \
include/openssl/cryptoerr.h include/openssl/symhacks.h \
include/openssl/cryptoerr_legacy.h include/openssl/core.h \
include/internal/numbers.h include/internal/nelem.h \
include/openssl/buffer.h include/openssl/buffererr.h \
include/openssl/bio.h include/openssl/bioerr.h include/openssl/asn1.h \
include/openssl/asn1err.h include/openssl/bn.h include/openssl/bnerr.h \
include/openssl/err.h include/openssl/lhash.h include/openssl/objects.h \
include/openssl/obj_mac.h include/openssl/objectserr.h \
include/openssl/evp.h include/openssl/core_dispatch.h \
include/openssl/indicator.h include/openssl/params.h \
include/openssl/evperr.h include/openssl/rand.h \
include/openssl/randerr.h include/openssl/x509.h include/openssl/ec.h \
include/openssl/ecerr.h include/openssl/rsa.h include/openssl/rsaerr.h \
include/openssl/dsa.h include/openssl/dh.h include/openssl/dherr.h \
include/openssl/dsaerr.h include/openssl/sha.h include/openssl/x509err.h \
include/openssl/x509_vfy.h include/openssl/pkcs7.h \
include/openssl/pkcs7err.h include/openssl/http.h include/openssl/conf.h \
include/openssl/conferr.h include/openssl/conftypes.h \
include/openssl/pem.h include/openssl/pemerr.h include/openssl/pkcs12.h \
include/openssl/pkcs12err.h include/crypto/asn1.h include/openssl/des.h \
include/openssl/engine.h include/openssl/ui.h include/openssl/uierr.h \
include/openssl/engineerr.h

View File

@@ -0,0 +1,25 @@
crypto/pem/libcrypto-lib-pem_oth.o: crypto/pem/pem_oth.c \
include/internal/cryptlib.h include/internal/common.h \
include/openssl/configuration.h include/internal/e_os.h \
include/openssl/opensslconf.h include/openssl/macros.h \
include/openssl/opensslv.h include/openssl/e_os2.h \
include/openssl/crypto.h include/openssl/safestack.h \
include/openssl/stack.h include/openssl/types.h \
include/openssl/cryptoerr.h include/openssl/symhacks.h \
include/openssl/cryptoerr_legacy.h include/openssl/core.h \
include/internal/numbers.h include/internal/nelem.h \
include/openssl/buffer.h include/openssl/buffererr.h \
include/openssl/bio.h include/openssl/bioerr.h include/openssl/asn1.h \
include/openssl/asn1err.h include/openssl/bn.h include/openssl/bnerr.h \
include/openssl/err.h include/openssl/lhash.h include/openssl/objects.h \
include/openssl/obj_mac.h include/openssl/objectserr.h \
include/openssl/evp.h include/openssl/core_dispatch.h \
include/openssl/indicator.h include/openssl/params.h \
include/openssl/evperr.h include/openssl/x509.h include/openssl/ec.h \
include/openssl/ecerr.h include/openssl/rsa.h include/openssl/rsaerr.h \
include/openssl/dsa.h include/openssl/dh.h include/openssl/dherr.h \
include/openssl/dsaerr.h include/openssl/sha.h include/openssl/x509err.h \
include/openssl/x509_vfy.h include/openssl/pkcs7.h \
include/openssl/pkcs7err.h include/openssl/http.h include/openssl/conf.h \
include/openssl/conferr.h include/openssl/conftypes.h \
include/openssl/pem.h include/openssl/pemerr.h

View File

@@ -0,0 +1,28 @@
crypto/pem/libcrypto-lib-pem_pk8.o: crypto/pem/pem_pk8.c \
include/internal/cryptlib.h include/internal/common.h \
include/openssl/configuration.h include/internal/e_os.h \
include/openssl/opensslconf.h include/openssl/macros.h \
include/openssl/opensslv.h include/openssl/e_os2.h \
include/openssl/crypto.h include/openssl/safestack.h \
include/openssl/stack.h include/openssl/types.h \
include/openssl/cryptoerr.h include/openssl/symhacks.h \
include/openssl/cryptoerr_legacy.h include/openssl/core.h \
include/internal/numbers.h include/internal/nelem.h \
include/openssl/buffer.h include/openssl/buffererr.h \
include/openssl/bio.h include/openssl/bioerr.h include/openssl/asn1.h \
include/openssl/asn1err.h include/openssl/bn.h include/openssl/bnerr.h \
include/openssl/err.h include/openssl/lhash.h \
include/openssl/core_dispatch.h include/openssl/indicator.h \
include/openssl/params.h include/openssl/objects.h \
include/openssl/obj_mac.h include/openssl/objectserr.h \
include/openssl/evp.h include/openssl/evperr.h include/openssl/x509.h \
include/openssl/ec.h include/openssl/ecerr.h include/openssl/rsa.h \
include/openssl/rsaerr.h include/openssl/dsa.h include/openssl/dh.h \
include/openssl/dherr.h include/openssl/dsaerr.h include/openssl/sha.h \
include/openssl/x509err.h include/openssl/x509_vfy.h \
include/openssl/pkcs7.h include/openssl/pkcs7err.h \
include/openssl/http.h include/openssl/conf.h include/openssl/conferr.h \
include/openssl/conftypes.h include/openssl/pkcs12.h \
include/openssl/pkcs12err.h include/openssl/pem.h \
include/openssl/pemerr.h include/openssl/encoder.h \
include/openssl/encodererr.h

View File

@@ -0,0 +1,34 @@
crypto/pem/libcrypto-lib-pem_pkey.o: crypto/pem/pem_pkey.c \
include/openssl/buffer.h include/openssl/macros.h \
include/openssl/opensslconf.h include/openssl/configuration.h \
include/openssl/opensslv.h include/openssl/types.h \
include/openssl/e_os2.h include/openssl/safestack.h \
include/openssl/stack.h include/openssl/crypto.h \
include/openssl/cryptoerr.h include/openssl/symhacks.h \
include/openssl/cryptoerr_legacy.h include/openssl/core.h \
include/openssl/buffererr.h include/openssl/objects.h \
include/openssl/obj_mac.h include/openssl/bio.h include/openssl/bioerr.h \
include/openssl/asn1.h include/openssl/asn1err.h include/openssl/bn.h \
include/openssl/bnerr.h include/openssl/objectserr.h \
include/openssl/evp.h include/openssl/core_dispatch.h \
include/openssl/indicator.h include/openssl/params.h \
include/openssl/evperr.h include/openssl/x509.h include/openssl/ec.h \
include/openssl/ecerr.h include/openssl/rsa.h include/openssl/rsaerr.h \
include/openssl/dsa.h include/openssl/dh.h include/openssl/dherr.h \
include/openssl/dsaerr.h include/openssl/sha.h include/openssl/x509err.h \
include/openssl/x509_vfy.h include/openssl/lhash.h \
include/openssl/pkcs7.h include/openssl/pkcs7err.h \
include/openssl/http.h include/openssl/conf.h include/openssl/conferr.h \
include/openssl/conftypes.h include/openssl/pkcs12.h \
include/openssl/pkcs12err.h include/openssl/pem.h \
include/openssl/pemerr.h include/openssl/engine.h include/openssl/rand.h \
include/openssl/randerr.h include/openssl/ui.h include/openssl/uierr.h \
include/openssl/err.h include/openssl/engineerr.h \
include/openssl/decoder.h include/openssl/decodererr.h \
include/internal/cryptlib.h include/internal/common.h \
include/internal/e_os.h include/internal/numbers.h \
include/internal/nelem.h include/internal/passphrase.h \
include/crypto/asn1.h include/crypto/x509.h include/internal/refcount.h \
include/openssl/trace.h include/crypto/types.h include/crypto/evp.h \
include/crypto/ecx.h crypto/pem/pem_local.h include/openssl/encoder.h \
include/openssl/encodererr.h

View File

@@ -0,0 +1,25 @@
crypto/pem/libcrypto-lib-pem_sign.o: crypto/pem/pem_sign.c \
include/internal/cryptlib.h include/internal/common.h \
include/openssl/configuration.h include/internal/e_os.h \
include/openssl/opensslconf.h include/openssl/macros.h \
include/openssl/opensslv.h include/openssl/e_os2.h \
include/openssl/crypto.h include/openssl/safestack.h \
include/openssl/stack.h include/openssl/types.h \
include/openssl/cryptoerr.h include/openssl/symhacks.h \
include/openssl/cryptoerr_legacy.h include/openssl/core.h \
include/internal/numbers.h include/internal/nelem.h \
include/openssl/buffer.h include/openssl/buffererr.h \
include/openssl/bio.h include/openssl/bioerr.h include/openssl/asn1.h \
include/openssl/asn1err.h include/openssl/bn.h include/openssl/bnerr.h \
include/openssl/err.h include/openssl/lhash.h include/openssl/evp.h \
include/openssl/core_dispatch.h include/openssl/indicator.h \
include/openssl/params.h include/openssl/evperr.h \
include/openssl/objects.h include/openssl/obj_mac.h \
include/openssl/objectserr.h include/openssl/x509.h include/openssl/ec.h \
include/openssl/ecerr.h include/openssl/rsa.h include/openssl/rsaerr.h \
include/openssl/dsa.h include/openssl/dh.h include/openssl/dherr.h \
include/openssl/dsaerr.h include/openssl/sha.h include/openssl/x509err.h \
include/openssl/x509_vfy.h include/openssl/pkcs7.h \
include/openssl/pkcs7err.h include/openssl/http.h include/openssl/conf.h \
include/openssl/conferr.h include/openssl/conftypes.h \
include/openssl/pem.h include/openssl/pemerr.h

View File

@@ -0,0 +1,25 @@
crypto/pem/libcrypto-lib-pem_x509.o: crypto/pem/pem_x509.c \
include/internal/cryptlib.h include/internal/common.h \
include/openssl/configuration.h include/internal/e_os.h \
include/openssl/opensslconf.h include/openssl/macros.h \
include/openssl/opensslv.h include/openssl/e_os2.h \
include/openssl/crypto.h include/openssl/safestack.h \
include/openssl/stack.h include/openssl/types.h \
include/openssl/cryptoerr.h include/openssl/symhacks.h \
include/openssl/cryptoerr_legacy.h include/openssl/core.h \
include/internal/numbers.h include/internal/nelem.h \
include/openssl/buffer.h include/openssl/buffererr.h \
include/openssl/bio.h include/openssl/bioerr.h include/openssl/asn1.h \
include/openssl/asn1err.h include/openssl/bn.h include/openssl/bnerr.h \
include/openssl/err.h include/openssl/lhash.h include/openssl/evp.h \
include/openssl/core_dispatch.h include/openssl/indicator.h \
include/openssl/params.h include/openssl/evperr.h \
include/openssl/objects.h include/openssl/obj_mac.h \
include/openssl/objectserr.h include/openssl/x509.h include/openssl/ec.h \
include/openssl/ecerr.h include/openssl/rsa.h include/openssl/rsaerr.h \
include/openssl/dsa.h include/openssl/dh.h include/openssl/dherr.h \
include/openssl/dsaerr.h include/openssl/sha.h include/openssl/x509err.h \
include/openssl/x509_vfy.h include/openssl/pkcs7.h \
include/openssl/pkcs7err.h include/openssl/http.h include/openssl/conf.h \
include/openssl/conferr.h include/openssl/conftypes.h \
include/openssl/pem.h include/openssl/pemerr.h

View File

@@ -0,0 +1,25 @@
crypto/pem/libcrypto-lib-pem_xaux.o: crypto/pem/pem_xaux.c \
include/internal/cryptlib.h include/internal/common.h \
include/openssl/configuration.h include/internal/e_os.h \
include/openssl/opensslconf.h include/openssl/macros.h \
include/openssl/opensslv.h include/openssl/e_os2.h \
include/openssl/crypto.h include/openssl/safestack.h \
include/openssl/stack.h include/openssl/types.h \
include/openssl/cryptoerr.h include/openssl/symhacks.h \
include/openssl/cryptoerr_legacy.h include/openssl/core.h \
include/internal/numbers.h include/internal/nelem.h \
include/openssl/buffer.h include/openssl/buffererr.h \
include/openssl/bio.h include/openssl/bioerr.h include/openssl/asn1.h \
include/openssl/asn1err.h include/openssl/bn.h include/openssl/bnerr.h \
include/openssl/err.h include/openssl/lhash.h include/openssl/evp.h \
include/openssl/core_dispatch.h include/openssl/indicator.h \
include/openssl/params.h include/openssl/evperr.h \
include/openssl/objects.h include/openssl/obj_mac.h \
include/openssl/objectserr.h include/openssl/x509.h include/openssl/ec.h \
include/openssl/ecerr.h include/openssl/rsa.h include/openssl/rsaerr.h \
include/openssl/dsa.h include/openssl/dh.h include/openssl/dherr.h \
include/openssl/dsaerr.h include/openssl/sha.h include/openssl/x509err.h \
include/openssl/x509_vfy.h include/openssl/pkcs7.h \
include/openssl/pkcs7err.h include/openssl/http.h include/openssl/conf.h \
include/openssl/conferr.h include/openssl/conftypes.h \
include/openssl/pem.h include/openssl/pemerr.h

View File

@@ -0,0 +1,30 @@
crypto/pem/libcrypto-lib-pvkfmt.o: crypto/pem/pvkfmt.c \
include/internal/deprecated.h include/openssl/configuration.h \
include/openssl/macros.h include/openssl/opensslconf.h \
include/openssl/opensslv.h include/openssl/pem.h include/openssl/e_os2.h \
include/openssl/bio.h include/openssl/crypto.h \
include/openssl/safestack.h include/openssl/stack.h \
include/openssl/types.h include/openssl/cryptoerr.h \
include/openssl/symhacks.h include/openssl/cryptoerr_legacy.h \
include/openssl/core.h include/openssl/bioerr.h include/openssl/evp.h \
include/openssl/core_dispatch.h include/openssl/indicator.h \
include/openssl/params.h include/openssl/bn.h include/openssl/bnerr.h \
include/openssl/evperr.h include/openssl/objects.h \
include/openssl/obj_mac.h include/openssl/asn1.h \
include/openssl/asn1err.h include/openssl/objectserr.h \
include/openssl/x509.h include/openssl/buffer.h \
include/openssl/buffererr.h include/openssl/ec.h include/openssl/ecerr.h \
include/openssl/rsa.h include/openssl/rsaerr.h include/openssl/dsa.h \
include/openssl/dh.h include/openssl/dherr.h include/openssl/dsaerr.h \
include/openssl/sha.h include/openssl/x509err.h \
include/openssl/x509_vfy.h include/openssl/lhash.h \
include/openssl/pkcs7.h include/openssl/pkcs7err.h \
include/openssl/http.h include/openssl/conf.h include/openssl/conferr.h \
include/openssl/conftypes.h include/openssl/pemerr.h \
include/openssl/rand.h include/openssl/randerr.h include/openssl/kdf.h \
include/openssl/core_names.h include/internal/cryptlib.h \
include/internal/common.h include/internal/e_os.h \
include/internal/numbers.h include/internal/nelem.h \
include/openssl/err.h include/crypto/pem.h include/crypto/types.h \
include/crypto/evp.h include/internal/refcount.h include/openssl/trace.h \
include/crypto/ecx.h

View File

@@ -0,0 +1,226 @@
/*
* Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
/*
* DSA low level APIs are deprecated for public use, but still ok for
* internal use.
*/
#include "internal/deprecated.h"
#include <stdio.h>
#include "internal/cryptlib.h"
#include <openssl/bio.h>
#include <openssl/evp.h>
#include <openssl/x509.h>
#include <openssl/pkcs7.h>
#include <openssl/pem.h>
#include <openssl/rsa.h>
#include <openssl/dsa.h>
#include <openssl/dh.h>
#include "pem_local.h"
static RSA *pkey_get_rsa(EVP_PKEY *key, RSA **rsa);
#ifndef OPENSSL_NO_DSA
static DSA *pkey_get_dsa(EVP_PKEY *key, DSA **dsa);
#endif
#ifndef OPENSSL_NO_EC
static EC_KEY *pkey_get_eckey(EVP_PKEY *key, EC_KEY **eckey);
#endif
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(X509_PUBKEY, X509_PUBKEY, PEM_STRING_PUBLIC, X509_PUBKEY)
IMPLEMENT_PEM_rw(PKCS7, PKCS7, PEM_STRING_PKCS7, PKCS7)
IMPLEMENT_PEM_rw(NETSCAPE_CERT_SEQUENCE, NETSCAPE_CERT_SEQUENCE,
PEM_STRING_X509, NETSCAPE_CERT_SEQUENCE)
#ifndef OPENSSL_NO_DEPRECATED_3_0
/*
* 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 *PEM_read_bio_RSAPrivateKey(BIO *bp, RSA **rsa, pem_password_cb *cb,
void *u)
{
EVP_PKEY *pktmp;
pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u);
return pkey_get_rsa(pktmp, rsa);
}
# ifndef OPENSSL_NO_STDIO
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);
}
# endif
IMPLEMENT_PEM_write_cb(RSAPrivateKey, RSA, PEM_STRING_RSA, RSAPrivateKey)
IMPLEMENT_PEM_rw(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 *PEM_read_bio_DSAPrivateKey(BIO *bp, DSA **dsa, pem_password_cb *cb,
void *u)
{
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(DSAPrivateKey, DSA, PEM_STRING_DSA, DSAPrivateKey)
IMPLEMENT_PEM_rw(DSA_PUBKEY, DSA, PEM_STRING_PUBLIC, DSA_PUBKEY)
# ifndef OPENSSL_NO_STDIO
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(DSAparams, DSA, PEM_STRING_DSAPARAMS, DSAparams)
#endif
#ifndef OPENSSL_NO_DEPRECATED_3_0
# 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 *PEM_read_bio_ECPrivateKey(BIO *bp, EC_KEY **key, pem_password_cb *cb,
void *u)
{
EVP_PKEY *pktmp;
pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u);
return pkey_get_eckey(pktmp, key); /* will free pktmp */
}
IMPLEMENT_PEM_rw(ECPKParameters, EC_GROUP, PEM_STRING_ECPARAMETERS,
ECPKParameters)
IMPLEMENT_PEM_write_cb(ECPrivateKey, EC_KEY, PEM_STRING_ECPRIVATEKEY,
ECPrivateKey)
IMPLEMENT_PEM_rw(EC_PUBKEY, EC_KEY, PEM_STRING_PUBLIC, EC_PUBKEY)
# ifndef OPENSSL_NO_STDIO
EC_KEY *PEM_read_ECPrivateKey(FILE *fp, EC_KEY **eckey, pem_password_cb *cb,
void *u)
{
EVP_PKEY *pktmp;
pktmp = PEM_read_PrivateKey(fp, NULL, cb, u);
return pkey_get_eckey(pktmp, eckey); /* will free pktmp */
}
# endif
# endif /* !OPENSSL_NO_EC */
#endif /* !OPENSSL_NO_DEPRECATED_3_0 */
#ifndef OPENSSL_NO_DH
IMPLEMENT_PEM_write(DHparams, DH, PEM_STRING_DHPARAMS, DHparams)
IMPLEMENT_PEM_write(DHxparams, DH, PEM_STRING_DHXPARAMS, DHxparams)
/* 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) == 0)
ret = d2i_DHxparams(x, &p, len);
else
ret = d2i_DHparams(x, &p, len);
if (ret == NULL)
ERR_raise(ERR_LIB_PEM, ERR_R_ASN1_LIB);
OPENSSL_free(nm);
OPENSSL_free(data);
return ret;
}
# ifndef OPENSSL_NO_STDIO
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) {
ERR_raise(ERR_LIB_PEM, 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
IMPLEMENT_PEM_provided_write(PUBKEY, EVP_PKEY, pkey, PEM_STRING_PUBLIC, PUBKEY)

View File

@@ -0,0 +1,74 @@
/*
* Generated by util/mkerr.pl DO NOT EDIT
* Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <openssl/err.h>
#include <openssl/pemerr.h>
#include "crypto/pemerr.h"
#ifndef OPENSSL_NO_ERR
static const ERR_STRING_DATA PEM_str_reasons[] = {
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_BAD_BASE64_DECODE), "bad base64 decode"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_BAD_DECRYPT), "bad decrypt"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_BAD_END_LINE), "bad end line"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_BAD_IV_CHARS), "bad iv chars"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_BAD_MAGIC_NUMBER), "bad magic number"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_BAD_PASSWORD_READ), "bad password read"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_BAD_VERSION_NUMBER), "bad version number"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_BIO_WRITE_FAILURE), "bio write failure"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_CIPHER_IS_NULL), "cipher is null"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_ERROR_CONVERTING_PRIVATE_KEY),
"error converting private key"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_EXPECTING_DSS_KEY_BLOB),
"expecting dss key blob"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_EXPECTING_PRIVATE_KEY_BLOB),
"expecting private key blob"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_EXPECTING_PUBLIC_KEY_BLOB),
"expecting public key blob"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_EXPECTING_RSA_KEY_BLOB),
"expecting rsa key blob"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_HEADER_TOO_LONG), "header too long"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_INCONSISTENT_HEADER),
"inconsistent header"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_KEYBLOB_HEADER_PARSE_ERROR),
"keyblob header parse error"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_KEYBLOB_TOO_SHORT), "keyblob too short"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_MISSING_DEK_IV), "missing dek iv"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_NOT_DEK_INFO), "not dek info"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_NOT_ENCRYPTED), "not encrypted"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_NOT_PROC_TYPE), "not proc type"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_NO_START_LINE), "no start line"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_PROBLEMS_GETTING_PASSWORD),
"problems getting password"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_PVK_DATA_TOO_SHORT), "pvk data too short"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_PVK_TOO_SHORT), "pvk too short"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_READ_KEY), "read key"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_SHORT_HEADER), "short header"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_UNEXPECTED_DEK_IV), "unexpected dek iv"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_UNSUPPORTED_CIPHER), "unsupported cipher"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_UNSUPPORTED_ENCRYPTION),
"unsupported encryption"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_UNSUPPORTED_KEY_COMPONENTS),
"unsupported key components"},
{ERR_PACK(ERR_LIB_PEM, 0, PEM_R_UNSUPPORTED_PUBLIC_KEY_TYPE),
"unsupported public key type"},
{0, NULL}
};
#endif
int ossl_err_load_PEM_strings(void)
{
#ifndef OPENSSL_NO_ERR
if (ERR_reason_error_string(PEM_str_reasons[0].error) == NULL)
ERR_load_strings_const(PEM_str_reasons);
#endif
return 1;
}

View File

@@ -0,0 +1,311 @@
/*
* Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
/*
* DSA low level APIs are deprecated for public use, but still ok for
* internal use.
*/
#include "internal/deprecated.h"
#include <stdio.h>
#include "internal/cryptlib.h"
#include <openssl/buffer.h>
#include <openssl/objects.h>
#include <openssl/evp.h>
#include <openssl/x509.h>
#include <openssl/pem.h>
#include <openssl/rsa.h>
#include <openssl/dsa.h>
#include "crypto/evp.h"
#ifndef OPENSSL_NO_STDIO
STACK_OF(X509_INFO)
*PEM_X509_INFO_read_ex(FILE *fp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb,
void *u, OSSL_LIB_CTX *libctx, const char *propq)
{
BIO *b;
STACK_OF(X509_INFO) *ret;
if ((b = BIO_new(BIO_s_file())) == NULL) {
ERR_raise(ERR_LIB_PEM, ERR_R_BUF_LIB);
return 0;
}
BIO_set_fp(b, fp, BIO_NOCLOSE);
ret = PEM_X509_INFO_read_bio_ex(b, sk, cb, u, libctx, propq);
BIO_free(b);
return ret;
}
STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk,
pem_password_cb *cb, void *u)
{
return PEM_X509_INFO_read_ex(fp, sk, cb, u, NULL, NULL);
}
#endif
STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio_ex(BIO *bp, STACK_OF(X509_INFO) *sk,
pem_password_cb *cb, void *u,
OSSL_LIB_CTX *libctx,
const char *propq)
{
X509_INFO *xi = NULL;
char *name = NULL, *header = NULL, *str;
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) {
ERR_raise(ERR_LIB_PEM, ERR_R_CRYPTO_LIB);
goto err;
}
} else
ret = sk;
if ((xi = X509_INFO_new()) == NULL)
goto err;
for (;;) {
raw = 0;
ptype = 0;
ERR_set_mark();
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_pop_to_mark();
break;
}
ERR_clear_last_mark();
goto err;
}
ERR_clear_last_mark();
start:
if (strcmp(name, PEM_STRING_X509) == 0
|| strcmp(name, PEM_STRING_X509_OLD) == 0
|| strcmp(name, PEM_STRING_X509_TRUSTED) == 0) {
if (xi->x509 != 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_X509_TRUSTED) == 0))
d2i = (D2I_OF(void)) d2i_X509_AUX;
else
d2i = (D2I_OF(void)) d2i_X509;
xi->x509 = X509_new_ex(libctx, propq);
if (xi->x509 == NULL)
goto err;
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 ((str = strstr(name, PEM_STRING_PKCS8INF)) != NULL) {
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 (str == name || strcmp(name, PEM_STRING_PKCS8) == 0) {
ptype = EVP_PKEY_NONE;
} else {
/* chop " PRIVATE KEY" */
*--str = '\0';
ptype = evp_pkey_name2type(name);
}
xi->enc_data = NULL;
xi->enc_len = 0;
d2i = (D2I_OF(void)) d2i_AutoPrivateKey;
xi->x_pkey = X509_PKEY_new();
if (xi->x_pkey == NULL)
goto err;
pp = &xi->x_pkey->dec_pkey;
if ((int)strlen(header) > 10 /* assume encrypted */
|| strcmp(name, PEM_STRING_PKCS8) == 0)
raw = 1;
} else { /* unknown */
d2i = NULL;
pp = NULL;
}
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_ex(ptype, pp, &p, len,
libctx, propq) == NULL) {
ERR_raise(ERR_LIB_PEM, ERR_R_ASN1_LIB);
goto err;
}
} else if (d2i(pp, &p, len) == NULL) {
ERR_raise(ERR_LIB_PEM, ERR_R_ASN1_LIB);
goto err;
}
} else { /* encrypted key 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;
}
}
OPENSSL_free(name);
name = NULL;
OPENSSL_free(header);
header = NULL;
OPENSSL_free(data);
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:
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;
}
OPENSSL_free(name);
OPENSSL_free(header);
OPENSSL_free(data);
return ret;
}
STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk,
pem_password_cb *cb, void *u)
{
return PEM_X509_INFO_read_bio_ex(bp, sk, cb, u, NULL, NULL);
}
/* A TJH addition */
int PEM_X509_INFO_write_bio(BIO *bp, const X509_INFO *xi, EVP_CIPHER *enc,
const unsigned char *kstr, int klen,
pem_password_cb *cb, void *u)
{
int i, ret = 0;
unsigned char *data = NULL;
const char *objstr = NULL;
char buf[PEM_BUFSIZE];
const unsigned char *iv = NULL;
if (enc != NULL) {
objstr = EVP_CIPHER_get0_name(enc);
if (objstr == NULL
/*
* Check "Proc-Type: 4,Encrypted\nDEK-Info: objstr,hex-iv\n"
* fits into buf
*/
|| strlen(objstr) + 23 + 2 * EVP_CIPHER_get_iv_length(enc) + 13
> sizeof(buf)) {
ERR_raise(ERR_LIB_PEM, PEM_R_UNSUPPORTED_CIPHER);
goto err;
}
}
/*
* 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) {
ERR_raise(ERR_LIB_PEM, PEM_R_CIPHER_IS_NULL);
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;
/*
* 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 = EVP_CIPHER_get0_name(xi->enc_cipher.cipher);
if (objstr == NULL) {
ERR_raise(ERR_LIB_PEM, PEM_R_UNSUPPORTED_CIPHER);
goto err;
}
/* Create the right magic header stuff */
buf[0] = '\0';
PEM_proc_type(buf, PEM_TYPE_ENCRYPTED);
PEM_dek_info(buf, objstr, EVP_CIPHER_get_iv_length(enc),
(const 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 */
/* normal optionally encrypted stuff */
if (PEM_write_bio_RSAPrivateKey(bp,
EVP_PKEY_get0_RSA(xi->x_pkey->dec_pkey),
enc, kstr, klen, cb, u) <= 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
*/
ret = 1;
err:
OPENSSL_cleanse(buf, PEM_BUFSIZE);
return ret;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,167 @@
/*
* Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <openssl/core_dispatch.h>
#include <openssl/pem.h>
#include <openssl/encoder.h>
/*
* Selectors, named according to the ASN.1 names used throughout libcrypto.
*
* Note that these are not absolutely mandatory, they are rather a wishlist
* of sorts. The provider implementations are free to make choices that
* make sense for them, based on these selectors.
* For example, the EC backend is likely to really just output the private
* key to a PKCS#8 structure, even thought PEM_SELECTION_PrivateKey specifies
* the public key as well. This is fine, as long as the corresponding
* decoding operation can return an object that contains what libcrypto
* expects.
*/
# define PEM_SELECTION_PUBKEY EVP_PKEY_PUBLIC_KEY
# define PEM_SELECTION_PrivateKey EVP_PKEY_KEYPAIR
# define PEM_SELECTION_Parameters EVP_PKEY_KEY_PARAMETERS
/*
* Properties, named according to the ASN.1 names used throughout libcrypto.
*/
# define PEM_STRUCTURE_PUBKEY "SubjectPublicKeyInfo"
# define PEM_STRUCTURE_PrivateKey "PrivateKeyInfo"
# define PEM_STRUCTURE_Parameters "type-specific"
# define PEM_STRUCTURE_RSAPrivateKey "type-specific"
# define PEM_STRUCTURE_RSAPublicKey "type-specific"
/* Alternative IMPLEMENT macros for provided encoders */
# define IMPLEMENT_PEM_provided_write_body_vars(type, asn1, pq) \
int ret = 0; \
OSSL_ENCODER_CTX *ctx = \
OSSL_ENCODER_CTX_new_for_##type(x, PEM_SELECTION_##asn1, \
"PEM", PEM_STRUCTURE_##asn1, \
(pq)); \
\
if (OSSL_ENCODER_CTX_get_num_encoders(ctx) == 0) { \
OSSL_ENCODER_CTX_free(ctx); \
goto legacy; \
}
# define IMPLEMENT_PEM_provided_write_body_pass() \
ret = 1; \
if (kstr == NULL && cb == NULL) { \
if (u != NULL) { \
kstr = u; \
klen = strlen(u); \
} else { \
cb = PEM_def_callback; \
} \
} \
if (enc != NULL) { \
ret = 0; \
if (OSSL_ENCODER_CTX_set_cipher(ctx, EVP_CIPHER_get0_name(enc), \
NULL)) { \
ret = 1; \
if (kstr != NULL \
&& !OSSL_ENCODER_CTX_set_passphrase(ctx, kstr, klen)) \
ret = 0; \
else if (cb != NULL \
&& !OSSL_ENCODER_CTX_set_pem_password_cb(ctx, \
cb, u)) \
ret = 0; \
} \
} \
if (!ret) { \
OSSL_ENCODER_CTX_free(ctx); \
return 0; \
}
# define IMPLEMENT_PEM_provided_write_body_main(type, outtype) \
ret = OSSL_ENCODER_to_##outtype(ctx, out); \
OSSL_ENCODER_CTX_free(ctx); \
return ret
# define IMPLEMENT_PEM_provided_write_body_fallback(str, asn1, \
writename) \
legacy: \
return PEM_ASN1_##writename((i2d_of_void *)i2d_##asn1, str, out, \
x, NULL, NULL, 0, NULL, NULL)
# define IMPLEMENT_PEM_provided_write_body_fallback_cb(str, asn1, \
writename) \
legacy: \
return PEM_ASN1_##writename##((i2d_of_void *)i2d_##asn1, str, out, \
x, enc, kstr, klen, cb, u)
# define IMPLEMENT_PEM_provided_write_to(name, TYPE, type, str, asn1, \
OUTTYPE, outtype, writename) \
PEM_write_fnsig(name, TYPE, OUTTYPE, writename) \
{ \
IMPLEMENT_PEM_provided_write_body_vars(type, asn1, NULL); \
IMPLEMENT_PEM_provided_write_body_main(type, outtype); \
IMPLEMENT_PEM_provided_write_body_fallback(str, asn1, \
writename); \
} \
PEM_write_ex_fnsig(name, TYPE, OUTTYPE, writename) \
{ \
IMPLEMENT_PEM_provided_write_body_vars(type, asn1, propq); \
IMPLEMENT_PEM_provided_write_body_main(type, outtype); \
IMPLEMENT_PEM_provided_write_body_fallback(str, asn1, \
writename); \
}
# define IMPLEMENT_PEM_provided_write_cb_to(name, TYPE, type, str, asn1, \
OUTTYPE, outtype, writename) \
PEM_write_cb_fnsig(name, TYPE, OUTTYPE, writename) \
{ \
IMPLEMENT_PEM_provided_write_body_vars(type, asn1, NULL); \
IMPLEMENT_PEM_provided_write_body_pass(); \
IMPLEMENT_PEM_provided_write_body_main(type, outtype); \
IMPLEMENT_PEM_provided_write_body_fallback_cb(str, asn1, \
writename); \
} \
PEM_write_ex_cb_fnsig(name, TYPE, OUTTYPE, writename) \
{ \
IMPLEMENT_PEM_provided_write_body_vars(type, asn1, propq); \
IMPLEMENT_PEM_provided_write_body_pass(); \
IMPLEMENT_PEM_provided_write_body_main(type, outtype); \
IMPLEMENT_PEM_provided_write_body_fallback(str, asn1, \
writename); \
}
# ifdef OPENSSL_NO_STDIO
# define IMPLEMENT_PEM_provided_write_fp(name, TYPE, type, str, asn1)
# define IMPLEMENT_PEM_provided_write_cb_fp(name, TYPE, type, str, asn1)
# else
# define IMPLEMENT_PEM_provided_write_fp(name, TYPE, type, str, asn1) \
IMPLEMENT_PEM_provided_write_to(name, TYPE, type, str, asn1, FILE, fp, write)
# define IMPLEMENT_PEM_provided_write_cb_fp(name, TYPE, type, str, asn1) \
IMPLEMENT_PEM_provided_write_cb_to(name, TYPE, type, str, asn1, FILE, fp, write)
# endif
# define IMPLEMENT_PEM_provided_write_bio(name, TYPE, type, str, asn1) \
IMPLEMENT_PEM_provided_write_to(name, TYPE, type, str, asn1, BIO, bio, write_bio)
# define IMPLEMENT_PEM_provided_write_cb_bio(name, TYPE, type, str, asn1) \
IMPLEMENT_PEM_provided_write_cb_to(name, TYPE, type, str, asn1, BIO, bio, write_bio)
# define IMPLEMENT_PEM_provided_write(name, TYPE, type, str, asn1) \
IMPLEMENT_PEM_provided_write_bio(name, TYPE, type, str, asn1) \
IMPLEMENT_PEM_provided_write_fp(name, TYPE, type, str, asn1)
# define IMPLEMENT_PEM_provided_write_cb(name, TYPE, type, str, asn1) \
IMPLEMENT_PEM_provided_write_cb_bio(name, TYPE, type, str, asn1) \
IMPLEMENT_PEM_provided_write_cb_fp(name, TYPE, type, str, asn1)
# define IMPLEMENT_PEM_provided_rw(name, TYPE, type, str, asn1) \
IMPLEMENT_PEM_read(name, TYPE, str, asn1) \
IMPLEMENT_PEM_provided_write(name, TYPE, type, str, asn1)
# define IMPLEMENT_PEM_provided_rw_cb(name, TYPE, type, str, asn1) \
IMPLEMENT_PEM_read(name, TYPE, str, asn1) \
IMPLEMENT_PEM_provided_write_cb(name, TYPE, type, str, asn1)

View File

@@ -0,0 +1,36 @@
/*
* Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <stdio.h>
#include "internal/cryptlib.h"
#include <openssl/buffer.h>
#include <openssl/objects.h>
#include <openssl/evp.h>
#include <openssl/x509.h>
#include <openssl/pem.h>
/* 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;
if (!PEM_bytes_read_bio(&data, &len, NULL, name, bp, cb, u))
return NULL;
p = data;
ret = d2i(x, &p, len);
if (ret == NULL)
ERR_raise(ERR_LIB_PEM, ERR_R_ASN1_LIB);
OPENSSL_free(data);
return ret;
}

View File

@@ -0,0 +1,273 @@
/*
* Copyright 1995-2024 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <stdio.h>
#include "internal/cryptlib.h"
#include <openssl/core_dispatch.h>
#include <openssl/buffer.h>
#include <openssl/objects.h>
#include <openssl/evp.h>
#include <openssl/x509.h>
#include <openssl/pkcs12.h>
#include <openssl/pem.h>
#include <openssl/encoder.h>
static int do_pk8pkey(BIO *bp, const EVP_PKEY *x, int isder,
int nid, const EVP_CIPHER *enc,
const char *kstr, int klen,
pem_password_cb *cb, void *u,
const char *propq);
#ifndef OPENSSL_NO_STDIO
static int do_pk8pkey_fp(FILE *bp, const EVP_PKEY *x, int isder,
int nid, const EVP_CIPHER *enc,
const char *kstr, int klen,
pem_password_cb *cb, void *u,
const char *propq);
#endif
/*
* 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, const EVP_PKEY *x, int nid,
const char *kstr, int klen,
pem_password_cb *cb, void *u)
{
return do_pk8pkey(bp, x, 0, nid, NULL, kstr, klen, cb, u, NULL);
}
int PEM_write_bio_PKCS8PrivateKey(BIO *bp, const EVP_PKEY *x, const EVP_CIPHER *enc,
const char *kstr, int klen,
pem_password_cb *cb, void *u)
{
return do_pk8pkey(bp, x, 0, -1, enc, kstr, klen, cb, u, NULL);
}
int i2d_PKCS8PrivateKey_bio(BIO *bp, const EVP_PKEY *x, const EVP_CIPHER *enc,
const char *kstr, int klen,
pem_password_cb *cb, void *u)
{
return do_pk8pkey(bp, x, 1, -1, enc, kstr, klen, cb, u, NULL);
}
int i2d_PKCS8PrivateKey_nid_bio(BIO *bp, const EVP_PKEY *x, int nid,
const char *kstr, int klen,
pem_password_cb *cb, void *u)
{
return do_pk8pkey(bp, x, 1, nid, NULL, kstr, klen, cb, u, NULL);
}
static int do_pk8pkey(BIO *bp, const EVP_PKEY *x, int isder, int nid,
const EVP_CIPHER *enc, const char *kstr, int klen,
pem_password_cb *cb, void *u, const char *propq)
{
int ret = 0;
const char *outtype = isder ? "DER" : "PEM";
OSSL_ENCODER_CTX *ctx =
OSSL_ENCODER_CTX_new_for_pkey(x, OSSL_KEYMGMT_SELECT_ALL,
outtype, "PrivateKeyInfo", propq);
if (ctx == NULL)
return 0;
/*
* If no keystring or callback is set, OpenSSL traditionally uses the
* user's cb argument as a password string, or if that's NULL, it falls
* back on PEM_def_callback().
*/
if (kstr == NULL && cb == NULL) {
if (u != NULL) {
kstr = u;
klen = strlen(u);
} else {
cb = PEM_def_callback;
}
}
/*
* NOTE: There is no attempt to do a EVP_CIPHER_fetch() using the nid,
* since the nid is a PBE algorithm which can't be fetched currently.
* (e.g. NID_pbe_WithSHA1And2_Key_TripleDES_CBC). Just use the legacy
* path if the NID is passed.
*/
if (nid == -1 && OSSL_ENCODER_CTX_get_num_encoders(ctx) != 0) {
ret = 1;
if (enc != NULL) {
ret = 0;
if (OSSL_ENCODER_CTX_set_cipher(ctx, EVP_CIPHER_get0_name(enc),
NULL)) {
const unsigned char *ukstr = (const unsigned char *)kstr;
/*
* Try to pass the passphrase if one was given, or the
* passphrase callback if one was given. If none of them
* are given and that's wrong, we rely on the _to_bio()
* call to generate errors.
*/
ret = 1;
if (kstr != NULL
&& !OSSL_ENCODER_CTX_set_passphrase(ctx, ukstr, klen))
ret = 0;
else if (cb != NULL
&& !OSSL_ENCODER_CTX_set_pem_password_cb(ctx, cb, u))
ret = 0;
}
}
ret = ret && OSSL_ENCODER_to_bio(ctx, bp);
} else {
X509_SIG *p8;
PKCS8_PRIV_KEY_INFO *p8inf;
char buf[PEM_BUFSIZE];
ret = 0;
if ((p8inf = EVP_PKEY2PKCS8(x)) == NULL) {
ERR_raise(ERR_LIB_PEM, PEM_R_ERROR_CONVERTING_PRIVATE_KEY);
goto legacy_end;
}
if (enc || (nid != -1)) {
if (kstr == NULL) {
klen = cb(buf, PEM_BUFSIZE, 1, u);
if (klen < 0) {
ERR_raise(ERR_LIB_PEM, PEM_R_READ_KEY);
goto legacy_end;
}
kstr = buf;
}
p8 = PKCS8_encrypt(nid, enc, kstr, klen, NULL, 0, 0, p8inf);
if (kstr == buf)
OPENSSL_cleanse(buf, klen);
if (p8 == NULL)
goto legacy_end;
if (isder)
ret = i2d_PKCS8_bio(bp, p8);
else
ret = PEM_write_bio_PKCS8(bp, p8);
X509_SIG_free(p8);
} else {
if (isder)
ret = i2d_PKCS8_PRIV_KEY_INFO_bio(bp, p8inf);
else
ret = PEM_write_bio_PKCS8_PRIV_KEY_INFO(bp, p8inf);
}
legacy_end:
PKCS8_PRIV_KEY_INFO_free(p8inf);
}
OSSL_ENCODER_CTX_free(ctx);
return ret;
}
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 + 1]; /* reserve one byte at the end */
p8 = d2i_PKCS8_bio(bp, NULL);
if (p8 == NULL)
return NULL;
if (cb != NULL)
klen = cb(psbuf, PEM_BUFSIZE, 0, u);
else
klen = PEM_def_callback(psbuf, PEM_BUFSIZE, 0, u);
if (klen < 0 || klen > PEM_BUFSIZE) {
ERR_raise(ERR_LIB_PEM, PEM_R_BAD_PASSWORD_READ);
X509_SIG_free(p8);
return NULL;
}
p8inf = PKCS8_decrypt(p8, psbuf, klen);
X509_SIG_free(p8);
OPENSSL_cleanse(psbuf, klen);
if (p8inf == NULL)
return NULL;
ret = EVP_PKCS82PKEY(p8inf);
PKCS8_PRIV_KEY_INFO_free(p8inf);
if (!ret)
return NULL;
if (x != NULL) {
EVP_PKEY_free(*x);
*x = ret;
}
return ret;
}
#ifndef OPENSSL_NO_STDIO
int i2d_PKCS8PrivateKey_fp(FILE *fp, const EVP_PKEY *x, const EVP_CIPHER *enc,
const char *kstr, int klen,
pem_password_cb *cb, void *u)
{
return do_pk8pkey_fp(fp, x, 1, -1, enc, kstr, klen, cb, u, NULL);
}
int i2d_PKCS8PrivateKey_nid_fp(FILE *fp, const EVP_PKEY *x, int nid,
const char *kstr, int klen,
pem_password_cb *cb, void *u)
{
return do_pk8pkey_fp(fp, x, 1, nid, NULL, kstr, klen, cb, u, NULL);
}
int PEM_write_PKCS8PrivateKey_nid(FILE *fp, const EVP_PKEY *x, int nid,
const char *kstr, int klen,
pem_password_cb *cb, void *u)
{
return do_pk8pkey_fp(fp, x, 0, nid, NULL, kstr, klen, cb, u, NULL);
}
int PEM_write_PKCS8PrivateKey(FILE *fp, const EVP_PKEY *x, const EVP_CIPHER *enc,
const char *kstr, int klen,
pem_password_cb *cb, void *u)
{
return do_pk8pkey_fp(fp, x, 0, -1, enc, kstr, klen, cb, u, NULL);
}
static int do_pk8pkey_fp(FILE *fp, const EVP_PKEY *x, int isder, int nid,
const EVP_CIPHER *enc, const char *kstr, int klen,
pem_password_cb *cb, void *u, const char *propq)
{
BIO *bp;
int ret;
if ((bp = BIO_new_fp(fp, BIO_NOCLOSE)) == NULL) {
ERR_raise(ERR_LIB_PEM, ERR_R_BUF_LIB);
return 0;
}
ret = do_pk8pkey(bp, x, isder, nid, enc, kstr, klen, cb, u, propq);
BIO_free(bp);
return ret;
}
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)) == NULL) {
ERR_raise(ERR_LIB_PEM, 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)

View File

@@ -0,0 +1,449 @@
/*
* Copyright 1995-2024 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
/* We need to use some deprecated APIs */
#define OPENSSL_SUPPRESS_DEPRECATED
#include <stdio.h>
#include <openssl/buffer.h>
#include <openssl/objects.h>
#include <openssl/evp.h>
#include <openssl/x509.h>
#include <openssl/pkcs12.h>
#include <openssl/pem.h>
#include <openssl/engine.h>
#include <openssl/dh.h>
#include <openssl/decoder.h>
#include <openssl/ui.h>
#include "internal/cryptlib.h"
#include "internal/passphrase.h"
#include "crypto/asn1.h"
#include "crypto/x509.h"
#include "crypto/evp.h"
#include "pem_local.h"
int ossl_pem_check_suffix(const char *pem_str, const char *suffix);
static EVP_PKEY *pem_read_bio_key_decoder(BIO *bp, EVP_PKEY **x,
pem_password_cb *cb, void *u,
OSSL_LIB_CTX *libctx,
const char *propq,
int selection)
{
EVP_PKEY *pkey = NULL;
OSSL_DECODER_CTX *dctx = NULL;
int pos, newpos;
if ((pos = BIO_tell(bp)) < 0)
/* We can depend on BIO_tell() thanks to the BIO_f_readbuffer() */
return NULL;
dctx = OSSL_DECODER_CTX_new_for_pkey(&pkey, "PEM", NULL, NULL,
selection, libctx, propq);
if (dctx == NULL)
return NULL;
if (cb == NULL)
cb = PEM_def_callback;
if (!OSSL_DECODER_CTX_set_pem_password_cb(dctx, cb, u))
goto err;
ERR_set_mark();
while (!OSSL_DECODER_from_bio(dctx, bp) || pkey == NULL)
if (BIO_eof(bp) != 0 || (newpos = BIO_tell(bp)) < 0 || newpos <= pos) {
ERR_clear_last_mark();
goto err;
} else {
if (ERR_GET_REASON(ERR_peek_error()) == ERR_R_UNSUPPORTED) {
/* unsupported PEM data, try again */
ERR_pop_to_mark();
ERR_set_mark();
} else {
/* other error, bail out */
ERR_clear_last_mark();
goto err;
}
pos = newpos;
}
ERR_pop_to_mark();
/* if we were asked for private key, the public key is optional */
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0)
selection = selection & ~OSSL_KEYMGMT_SELECT_PUBLIC_KEY;
if (!evp_keymgmt_util_has(pkey, selection)) {
EVP_PKEY_free(pkey);
pkey = NULL;
ERR_raise(ERR_LIB_PEM, PEM_R_UNSUPPORTED_KEY_COMPONENTS);
goto err;
}
if (x != NULL) {
EVP_PKEY_free(*x);
*x = pkey;
}
err:
OSSL_DECODER_CTX_free(dctx);
return pkey;
}
static EVP_PKEY *pem_read_bio_key_legacy(BIO *bp, EVP_PKEY **x,
pem_password_cb *cb, void *u,
OSSL_LIB_CTX *libctx,
const char *propq,
int selection)
{
char *nm = NULL;
const unsigned char *p = NULL;
unsigned char *data = NULL;
long len;
int slen;
EVP_PKEY *ret = NULL;
ERR_set_mark(); /* not interested in PEM read errors */
if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) {
if (!PEM_bytes_read_bio_secmem(&data, &len, &nm,
PEM_STRING_EVP_PKEY,
bp, cb, u)) {
ERR_pop_to_mark();
return NULL;
}
} else {
const char *pem_string = PEM_STRING_PARAMETERS;
if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0)
pem_string = PEM_STRING_PUBLIC;
if (!PEM_bytes_read_bio(&data, &len, &nm,
pem_string,
bp, cb, u)) {
ERR_pop_to_mark();
return NULL;
}
}
ERR_clear_last_mark();
p = data;
if (strcmp(nm, PEM_STRING_PKCS8INF) == 0) {
PKCS8_PRIV_KEY_INFO *p8inf;
if ((p8inf = d2i_PKCS8_PRIV_KEY_INFO(NULL, &p, len)) == NULL)
goto p8err;
ret = evp_pkcs82pkey_legacy(p8inf, libctx, propq);
if (x != NULL) {
EVP_PKEY_free(*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];
if ((p8 = d2i_X509_SIG(NULL, &p, len)) == NULL)
goto p8err;
if (cb != NULL)
klen = cb(psbuf, PEM_BUFSIZE, 0, u);
else
klen = PEM_def_callback(psbuf, PEM_BUFSIZE, 0, u);
if (klen < 0) {
ERR_raise(ERR_LIB_PEM, PEM_R_BAD_PASSWORD_READ);
X509_SIG_free(p8);
goto err;
}
p8inf = PKCS8_decrypt(p8, psbuf, klen);
X509_SIG_free(p8);
OPENSSL_cleanse(psbuf, klen);
if (p8inf == NULL)
goto p8err;
ret = evp_pkcs82pkey_legacy(p8inf, libctx, propq);
if (x != NULL) {
EVP_PKEY_free(*x);
*x = ret;
}
PKCS8_PRIV_KEY_INFO_free(p8inf);
} else if ((slen = ossl_pem_check_suffix(nm, "PRIVATE KEY")) > 0) {
const EVP_PKEY_ASN1_METHOD *ameth;
ameth = EVP_PKEY_asn1_find_str(NULL, nm, slen);
if (ameth == NULL || ameth->old_priv_decode == NULL)
goto p8err;
ret = ossl_d2i_PrivateKey_legacy(ameth->pkey_id, x, &p, len, libctx,
propq);
} else if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) == 0
&& (selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) {
/* Trying legacy PUBKEY decoding only if we do not want private key. */
ret = ossl_d2i_PUBKEY_legacy(x, &p, len);
} else if ((selection & EVP_PKEY_KEYPAIR) == 0
&& (slen = ossl_pem_check_suffix(nm, "PARAMETERS")) > 0) {
/* Trying legacy params decoding only if we do not want a key. */
ret = EVP_PKEY_new();
if (ret == NULL)
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) {
EVP_PKEY_free(*x);
*x = ret;
}
}
p8err:
if (ret == NULL && ERR_peek_last_error() == 0)
/* ensure some error is reported but do not hide the real one */
ERR_raise(ERR_LIB_PEM, ERR_R_ASN1_LIB);
err:
OPENSSL_secure_free(nm);
OPENSSL_secure_clear_free(data, len);
return ret;
}
static EVP_PKEY *pem_read_bio_key(BIO *bp, EVP_PKEY **x,
pem_password_cb *cb, void *u,
OSSL_LIB_CTX *libctx,
const char *propq,
int selection)
{
EVP_PKEY *ret = NULL;
BIO *new_bio = NULL;
int pos;
struct ossl_passphrase_data_st pwdata = { 0 };
if ((pos = BIO_tell(bp)) < 0) {
new_bio = BIO_new(BIO_f_readbuffer());
if (new_bio == NULL)
return NULL;
bp = BIO_push(new_bio, bp);
pos = BIO_tell(bp);
}
if (cb == NULL)
cb = PEM_def_callback;
if (!ossl_pw_set_pem_password_cb(&pwdata, cb, u)
|| !ossl_pw_enable_passphrase_caching(&pwdata))
goto err;
ERR_set_mark();
ret = pem_read_bio_key_decoder(bp, x, ossl_pw_pem_password, &pwdata,
libctx, propq, selection);
if (ret == NULL
&& (BIO_seek(bp, pos) < 0
|| (ret = pem_read_bio_key_legacy(bp, x,
ossl_pw_pem_password, &pwdata,
libctx, propq,
selection)) == NULL))
ERR_clear_last_mark();
else
ERR_pop_to_mark();
err:
ossl_pw_clear_passphrase_data(&pwdata);
if (new_bio != NULL) {
BIO_pop(new_bio);
BIO_free(new_bio);
}
return ret;
}
EVP_PKEY *PEM_read_bio_PUBKEY_ex(BIO *bp, EVP_PKEY **x,
pem_password_cb *cb, void *u,
OSSL_LIB_CTX *libctx, const char *propq)
{
return pem_read_bio_key(bp, x, cb, u, libctx, propq,
EVP_PKEY_PUBLIC_KEY);
}
EVP_PKEY *PEM_read_bio_PUBKEY(BIO *bp, EVP_PKEY **x, pem_password_cb *cb,
void *u)
{
return PEM_read_bio_PUBKEY_ex(bp, x, cb, u, NULL, NULL);
}
#ifndef OPENSSL_NO_STDIO
EVP_PKEY *PEM_read_PUBKEY_ex(FILE *fp, EVP_PKEY **x,
pem_password_cb *cb, void *u,
OSSL_LIB_CTX *libctx, const char *propq)
{
BIO *b;
EVP_PKEY *ret;
if ((b = BIO_new(BIO_s_file())) == NULL) {
ERR_raise(ERR_LIB_PEM, ERR_R_BUF_LIB);
return 0;
}
BIO_set_fp(b, fp, BIO_NOCLOSE);
ret = PEM_read_bio_PUBKEY_ex(b, x, cb, u, libctx, propq);
BIO_free(b);
return ret;
}
EVP_PKEY *PEM_read_PUBKEY(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void *u)
{
return PEM_read_PUBKEY_ex(fp, x, cb, u, NULL, NULL);
}
#endif
EVP_PKEY *PEM_read_bio_PrivateKey_ex(BIO *bp, EVP_PKEY **x,
pem_password_cb *cb, void *u,
OSSL_LIB_CTX *libctx, const char *propq)
{
return pem_read_bio_key(bp, x, cb, u, libctx, propq,
/* we also want the public key, if available */
EVP_PKEY_KEYPAIR);
}
EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb,
void *u)
{
return PEM_read_bio_PrivateKey_ex(bp, x, cb, u, NULL, NULL);
}
PEM_write_cb_ex_fnsig(PrivateKey, EVP_PKEY, BIO, write_bio)
{
IMPLEMENT_PEM_provided_write_body_vars(pkey, PrivateKey, propq);
IMPLEMENT_PEM_provided_write_body_pass();
IMPLEMENT_PEM_provided_write_body_main(pkey, bio);
legacy:
if (x != NULL && (x->ameth == NULL || x->ameth->priv_encode != NULL))
return PEM_write_bio_PKCS8PrivateKey(out, x, enc,
(const char *)kstr, klen, cb, u);
return PEM_write_bio_PrivateKey_traditional(out, x, enc, kstr, klen, cb, u);
}
PEM_write_cb_fnsig(PrivateKey, EVP_PKEY, BIO, write_bio)
{
return PEM_write_bio_PrivateKey_ex(out, x, enc, kstr, klen, cb, u,
NULL, NULL);
}
/*
* Note: there is no way to tell a provided pkey encoder to use "traditional"
* encoding. Therefore, if the pkey is provided, we try to take a copy
*/
int PEM_write_bio_PrivateKey_traditional(BIO *bp, const EVP_PKEY *x,
const EVP_CIPHER *enc,
const unsigned char *kstr, int klen,
pem_password_cb *cb, void *u)
{
char pem_str[80];
EVP_PKEY *copy = NULL;
int ret;
if (x == NULL)
return 0;
if (evp_pkey_is_assigned(x)
&& evp_pkey_is_provided(x)
&& evp_pkey_copy_downgraded(&copy, x))
x = copy;
if (x->ameth == NULL || x->ameth->old_priv_encode == NULL) {
ERR_raise(ERR_LIB_PEM, PEM_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
EVP_PKEY_free(copy);
return 0;
}
BIO_snprintf(pem_str, 80, "%s PRIVATE KEY", x->ameth->pem_str);
ret = PEM_ASN1_write_bio((i2d_of_void *)i2d_PrivateKey,
pem_str, bp, x, enc, kstr, klen, cb, u);
EVP_PKEY_free(copy);
return ret;
}
static int no_password_cb(char *buf, int num, int rwflag, void *userdata)
{
return -1;
}
EVP_PKEY *PEM_read_bio_Parameters_ex(BIO *bp, EVP_PKEY **x,
OSSL_LIB_CTX *libctx, const char *propq)
{
/*
* PEM_read_bio_Parameters(_ex) should never ask for a password. Any attempt
* to get a password just fails.
*/
return pem_read_bio_key(bp, x, no_password_cb, NULL, libctx, propq,
EVP_PKEY_KEY_PARAMETERS);
}
EVP_PKEY *PEM_read_bio_Parameters(BIO *bp, EVP_PKEY **x)
{
return PEM_read_bio_Parameters_ex(bp, x, NULL, NULL);
}
PEM_write_fnsig(Parameters, EVP_PKEY, BIO, write_bio)
{
char pem_str[80];
IMPLEMENT_PEM_provided_write_body_vars(pkey, Parameters, NULL);
IMPLEMENT_PEM_provided_write_body_main(pkey, bio);
legacy:
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, out, x, NULL, NULL, 0, 0, NULL);
}
#ifndef OPENSSL_NO_STDIO
EVP_PKEY *PEM_read_PrivateKey_ex(FILE *fp, EVP_PKEY **x, pem_password_cb *cb,
void *u, OSSL_LIB_CTX *libctx,
const char *propq)
{
BIO *b;
EVP_PKEY *ret;
if ((b = BIO_new(BIO_s_file())) == NULL) {
ERR_raise(ERR_LIB_PEM, ERR_R_BUF_LIB);
return 0;
}
BIO_set_fp(b, fp, BIO_NOCLOSE);
ret = PEM_read_bio_PrivateKey_ex(b, x, cb, u, libctx, propq);
BIO_free(b);
return ret;
}
EVP_PKEY *PEM_read_PrivateKey(FILE *fp, EVP_PKEY **x, pem_password_cb *cb,
void *u)
{
return PEM_read_PrivateKey_ex(fp, x, cb, u, NULL, NULL);
}
PEM_write_cb_ex_fnsig(PrivateKey, EVP_PKEY, FILE, write)
{
BIO *b;
int ret;
if ((b = BIO_new_fp(out, BIO_NOCLOSE)) == NULL) {
ERR_raise(ERR_LIB_PEM, ERR_R_BUF_LIB);
return 0;
}
ret = PEM_write_bio_PrivateKey_ex(b, x, enc, kstr, klen, cb, u,
libctx, propq);
BIO_free(b);
return ret;
}
PEM_write_cb_fnsig(PrivateKey, EVP_PKEY, FILE, write)
{
return PEM_write_PrivateKey_ex(out, x, enc, kstr, klen, cb, u, NULL, NULL);
}
#endif

View File

@@ -0,0 +1,49 @@
/*
* Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <stdio.h>
#include "internal/cryptlib.h"
#include <openssl/evp.h>
#include <openssl/objects.h>
#include <openssl/x509.h>
#include <openssl/pem.h>
int PEM_SignInit(EVP_MD_CTX *ctx, EVP_MD *type)
{
return EVP_DigestInit_ex(ctx, type, NULL);
}
int PEM_SignUpdate(EVP_MD_CTX *ctx,
const unsigned char *data, unsigned int count)
{
return 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;
m = OPENSSL_malloc(EVP_PKEY_get_size(pkey));
if (m == NULL)
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() */
OPENSSL_free(m);
return ret;
}

View File

@@ -0,0 +1,18 @@
/*
* Copyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <stdio.h>
#include "internal/cryptlib.h"
#include <openssl/bio.h>
#include <openssl/evp.h>
#include <openssl/x509.h>
#include <openssl/pkcs7.h>
#include <openssl/pem.h>
IMPLEMENT_PEM_rw(X509, X509, PEM_STRING_X509, X509)

View File

@@ -0,0 +1,18 @@
/*
* Copyright 2001-2016 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
#include <stdio.h>
#include "internal/cryptlib.h"
#include <openssl/bio.h>
#include <openssl/evp.h>
#include <openssl/x509.h>
#include <openssl/pkcs7.h>
#include <openssl/pem.h>
IMPLEMENT_PEM_rw(X509_AUX, X509, PEM_STRING_X509_TRUSTED, X509_AUX)

File diff suppressed because it is too large Load Diff