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>;
42 using EvpPkeyDel = folly::static_function_deleter<EVP_PKEY, &EVP_PKEY_free>;
43 using EvpPkeyUniquePtr = std::unique_ptr<EVP_PKEY, EvpPkeyDel>;
44 using EvpPkeySharedPtr = std::shared_ptr<EVP_PKEY>;
46 // No EVP_PKEY_CTX <= 0.9.8b
47 #if OPENSSL_VERSION_NUMBER >= 0x10000002L
48 using EvpPkeyCtxDeleter =
49 folly::static_function_deleter<EVP_PKEY_CTX, &EVP_PKEY_CTX_free>;
50 using EvpPkeyCtxUniquePtr = std::unique_ptr<EVP_PKEY_CTX, EvpPkeyCtxDeleter>;
54 using EvpMdCtxDeleter =
55 folly::static_function_deleter<EVP_MD_CTX, &EVP_MD_CTX_destroy>;
56 using EvpMdCtxUniquePtr = std::unique_ptr<EVP_MD_CTX, EvpMdCtxDeleter>;
59 using BioDeleter = folly::static_function_deleter<BIO, &BIO_vfree>;
60 using BioUniquePtr = std::unique_ptr<BIO, BioDeleter>;
61 using BioChainDeleter = folly::static_function_deleter<BIO, &BIO_free_all>;
62 using BioChainUniquePtr = std::unique_ptr<BIO, BioChainDeleter>;
63 inline void BIO_free_fb(BIO* bio) { CHECK_EQ(1, BIO_free(bio)); }
64 using BioDeleterFb = folly::static_function_deleter<BIO, &BIO_free_fb>;
65 using BioUniquePtrFb = std::unique_ptr<BIO, BioDeleterFb>;
68 using RsaDeleter = folly::static_function_deleter<RSA, &RSA_free>;
69 using RsaUniquePtr = std::unique_ptr<RSA, RsaDeleter>;
71 using EcKeyDeleter = folly::static_function_deleter<EC_KEY, &EC_KEY_free>;
72 using EcKeyUniquePtr = std::unique_ptr<EC_KEY, EcKeyDeleter>;
76 using SSLDeleter = folly::static_function_deleter<SSL, &SSL_free>;
77 using SSLUniquePtr = std::unique_ptr<SSL, SSLDeleter>;