2 * Copyright 2016 Facebook, Inc.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <glog/logging.h>
20 #include <openssl/evp.h>
21 #include <openssl/rsa.h>
22 #include <openssl/ssl.h>
24 #include <openssl/ec.h>
26 #include <folly/Memory.h>
27 #include <openssl/bio.h>
28 #include <openssl/x509.h>
34 using X509Deleter = folly::static_function_deleter<X509, &X509_free>;
35 using X509UniquePtr = std::unique_ptr<X509, X509Deleter>;
36 using X509StoreCtxDeleter =
37 folly::static_function_deleter<X509_STORE_CTX, &X509_STORE_CTX_free>;
38 using X509StoreCtxUniquePtr =
39 std::unique_ptr<X509_STORE_CTX, X509StoreCtxDeleter>;
40 using X509VerifyParamDeleter =
41 folly::static_function_deleter<X509_VERIFY_PARAM, &X509_VERIFY_PARAM_free>;
42 using X509VerifyParam =
43 std::unique_ptr<X509_VERIFY_PARAM, X509VerifyParamDeleter>;
46 using EvpPkeyDel = folly::static_function_deleter<EVP_PKEY, &EVP_PKEY_free>;
47 using EvpPkeyUniquePtr = std::unique_ptr<EVP_PKEY, EvpPkeyDel>;
48 using EvpPkeySharedPtr = std::shared_ptr<EVP_PKEY>;
50 // No EVP_PKEY_CTX <= 0.9.8b
51 #if OPENSSL_VERSION_NUMBER >= 0x10000002L
52 using EvpPkeyCtxDeleter =
53 folly::static_function_deleter<EVP_PKEY_CTX, &EVP_PKEY_CTX_free>;
54 using EvpPkeyCtxUniquePtr = std::unique_ptr<EVP_PKEY_CTX, EvpPkeyCtxDeleter>;
58 using EvpMdCtxDeleter =
59 folly::static_function_deleter<EVP_MD_CTX, &EVP_MD_CTX_destroy>;
60 using EvpMdCtxUniquePtr = std::unique_ptr<EVP_MD_CTX, EvpMdCtxDeleter>;
63 using BioDeleter = folly::static_function_deleter<BIO, &BIO_vfree>;
64 using BioUniquePtr = std::unique_ptr<BIO, BioDeleter>;
65 using BioChainDeleter = folly::static_function_deleter<BIO, &BIO_free_all>;
66 using BioChainUniquePtr = std::unique_ptr<BIO, BioChainDeleter>;
67 inline void BIO_free_fb(BIO* bio) { CHECK_EQ(1, BIO_free(bio)); }
68 using BioDeleterFb = folly::static_function_deleter<BIO, &BIO_free_fb>;
69 using BioUniquePtrFb = std::unique_ptr<BIO, BioDeleterFb>;
72 using RsaDeleter = folly::static_function_deleter<RSA, &RSA_free>;
73 using RsaUniquePtr = std::unique_ptr<RSA, RsaDeleter>;
75 using EcKeyDeleter = folly::static_function_deleter<EC_KEY, &EC_KEY_free>;
76 using EcKeyUniquePtr = std::unique_ptr<EC_KEY, EcKeyDeleter>;
80 using SSLDeleter = folly::static_function_deleter<SSL, &SSL_free>;
81 using SSLUniquePtr = std::unique_ptr<SSL, SSLDeleter>;