diff --git a/src/ssl.c b/src/ssl.c index 4bc3e04eb..fb1dfe657 100644 --- a/src/ssl.c +++ b/src/ssl.c @@ -4677,20 +4677,30 @@ int PemToDer(const unsigned char* buff, long longSz, int type, break; case CRL_TYPE: header=BEGIN_X509_CRL; footer=END_X509_CRL; break; +#ifndef NO_DH case DH_PARAM_TYPE: header=BEGIN_DH_PARAM; footer=END_DH_PARAM; break; +#endif +#ifndef NO_DSA case DSA_PARAM_TYPE: header=BEGIN_DSA_PARAM; footer=END_DSA_PARAM; break; +#endif +#ifdef WOLFSSL_CERT_REQ case CERTREQ_TYPE: header=BEGIN_CERT_REQ; footer=END_CERT_REQ; break; +#endif case DSA_TYPE: header=BEGIN_DSA_PRIV; footer=END_DSA_PRIV; break; +#ifdef HAVE_ECC case ECC_TYPE: header=BEGIN_EC_PRIV; footer=END_EC_PRIV; break; +#endif case RSA_TYPE: header=BEGIN_RSA_PRIV; footer=END_RSA_PRIV; break; +#ifdef HAVE_ED25519 case ED25519_TYPE: header=BEGIN_EDDSA_PRIV; footer=END_EDDSA_PRIV; break; +#endif case PUBLICKEY_TYPE: header=BEGIN_PUB_KEY; footer=END_PUB_KEY; break; default: header=BEGIN_RSA_PRIV; footer=END_RSA_PRIV; @@ -4703,18 +4713,29 @@ int PemToDer(const unsigned char* buff, long longSz, int type, if (headerEnd || type != PRIVATEKEY_TYPE) { break; - } else if (header == BEGIN_RSA_PRIV) { - header = BEGIN_PRIV_KEY; footer = END_PRIV_KEY; - } else if (header == BEGIN_PRIV_KEY) { - header = BEGIN_ENC_PRIV_KEY; footer = END_ENC_PRIV_KEY; - } else if (header == BEGIN_ENC_PRIV_KEY) { - header = BEGIN_EC_PRIV; footer = END_EC_PRIV; - } else if (header == BEGIN_EC_PRIV) { - header = BEGIN_DSA_PRIV; footer = END_DSA_PRIV; - } else if (header == BEGIN_DSA_PRIV) { - header = BEGIN_EDDSA_PRIV; footer = END_EDDSA_PRIV; } else + if (header == BEGIN_RSA_PRIV) { + header = BEGIN_PRIV_KEY; footer = END_PRIV_KEY; + } else + if (header == BEGIN_PRIV_KEY) { + header = BEGIN_ENC_PRIV_KEY; footer = END_ENC_PRIV_KEY; + } else +#ifdef HAVE_ECC + if (header == BEGIN_ENC_PRIV_KEY) { + header = BEGIN_EC_PRIV; footer = END_EC_PRIV; + } else + if (header == BEGIN_EC_PRIV) { + header = BEGIN_DSA_PRIV; footer = END_DSA_PRIV; + } else +#endif +#ifdef HAVE_ED25519 + if (header == BEGIN_DSA_PRIV) { + header = BEGIN_EDDSA_PRIV; footer = END_EDDSA_PRIV; + } else +#endif + { break; + } } if (!headerEnd) { @@ -4739,8 +4760,13 @@ int PemToDer(const unsigned char* buff, long longSz, int type, } if (type == PRIVATEKEY_TYPE) { - if (eccKey) + if (eccKey) { + #ifdef HAVE_ECC *eccKey = header == BEGIN_EC_PRIV; + #else + *eccKey = 0; + #endif + } } #if defined(OPENSSL_EXTRA) || defined(OPENSSL_EXTRA_X509_SMALL) || \ diff --git a/wolfcrypt/src/asn.c b/wolfcrypt/src/asn.c index 8fa638f13..6aba14ded 100755 --- a/wolfcrypt/src/asn.c +++ b/wolfcrypt/src/asn.c @@ -7077,12 +7077,18 @@ WOLFSSL_LOCAL int GetSerialNumber(const byte* input, word32* inOutIdx, const char* const BEGIN_CERT = "-----BEGIN CERTIFICATE-----"; const char* const END_CERT = "-----END CERTIFICATE-----"; -const char* const BEGIN_CERT_REQ = "-----BEGIN CERTIFICATE REQUEST-----"; -const char* const END_CERT_REQ = "-----END CERTIFICATE REQUEST-----"; -const char* const BEGIN_DH_PARAM = "-----BEGIN DH PARAMETERS-----"; -const char* const END_DH_PARAM = "-----END DH PARAMETERS-----"; -const char* const BEGIN_DSA_PARAM = "-----BEGIN DSA PARAMETERS-----"; -const char* const END_DSA_PARAM = "-----END DSA PARAMETERS-----"; +#ifdef WOLFSSL_CERT_REQ + const char* const BEGIN_CERT_REQ = "-----BEGIN CERTIFICATE REQUEST-----"; + const char* const END_CERT_REQ = "-----END CERTIFICATE REQUEST-----"; +#endif +#ifndef NO_DH + const char* const BEGIN_DH_PARAM = "-----BEGIN DH PARAMETERS-----"; + const char* const END_DH_PARAM = "-----END DH PARAMETERS-----"; +#endif +#ifndef NO_DSA + const char* const BEGIN_DSA_PARAM = "-----BEGIN DSA PARAMETERS-----"; + const char* const END_DSA_PARAM = "-----END DSA PARAMETERS-----"; +#endif const char* const BEGIN_X509_CRL = "-----BEGIN X509 CRL-----"; const char* const END_X509_CRL = "-----END X509 CRL-----"; const char* const BEGIN_RSA_PRIV = "-----BEGIN RSA PRIVATE KEY-----"; @@ -7091,14 +7097,18 @@ const char* const BEGIN_PRIV_KEY = "-----BEGIN PRIVATE KEY-----"; const char* const END_PRIV_KEY = "-----END PRIVATE KEY-----"; const char* const BEGIN_ENC_PRIV_KEY = "-----BEGIN ENCRYPTED PRIVATE KEY-----"; const char* const END_ENC_PRIV_KEY = "-----END ENCRYPTED PRIVATE KEY-----"; -const char* const BEGIN_EC_PRIV = "-----BEGIN EC PRIVATE KEY-----"; -const char* const END_EC_PRIV = "-----END EC PRIVATE KEY-----"; +#ifdef HAVE_ECC + const char* const BEGIN_EC_PRIV = "-----BEGIN EC PRIVATE KEY-----"; + const char* const END_EC_PRIV = "-----END EC PRIVATE KEY-----"; +#endif const char* const BEGIN_DSA_PRIV = "-----BEGIN DSA PRIVATE KEY-----"; const char* const END_DSA_PRIV = "-----END DSA PRIVATE KEY-----"; const char* const BEGIN_PUB_KEY = "-----BEGIN PUBLIC KEY-----"; const char* const END_PUB_KEY = "-----END PUBLIC KEY-----"; -const char* const BEGIN_EDDSA_PRIV = "-----BEGIN EDDSA PRIVATE KEY-----"; -const char* const END_EDDSA_PRIV = "-----END EDDSA PRIVATE KEY-----"; +#ifdef HAVE_ED25519 + const char* const BEGIN_EDDSA_PRIV = "-----BEGIN EDDSA PRIVATE KEY-----"; + const char* const END_EDDSA_PRIV = "-----END EDDSA PRIVATE KEY-----"; +#endif #if defined(WOLFSSL_KEY_GEN) || defined(WOLFSSL_CERT_GEN) || defined(OPENSSL_EXTRA)