io/async/EventUtil.h \
io/async/NotificationQueue.h \
io/async/HHWheelTimer.h \
+ io/async/OpenSSLPtrTypes.h \
io/async/Request.h \
io/async/SSLContext.h \
io/async/ScopedEventBaseThread.h \
#include <folly/io/async/AsyncSocket.h>
#include <folly/io/async/SSLContext.h>
#include <folly/io/async/AsyncTimeout.h>
+#include <folly/io/async/OpenSSLPtrTypes.h>
#include <folly/io/async/TimeoutManager.h>
#include <folly/Bits.h>
/**
* Returns the peer certificate, or nullptr if no peer certificate received.
*/
- virtual std::unique_ptr<X509, X509_deleter> getPeerCert() const {
+ virtual X509_UniquePtr getPeerCert() const {
if (!ssl_) {
return nullptr;
}
X509* cert = SSL_get_peer_certificate(ssl_);
- return std::unique_ptr<X509, X509_deleter>(cert);
+ return X509_UniquePtr(cert);
}
private:
--- /dev/null
+/*
+ * Copyright 2016 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#pragma once
+
+#include <folly/Memory.h>
+#include <openssl/ssl.h>
+
+namespace folly {
+
+using X509_deleter = static_function_deleter<X509, &X509_free>;
+using X509_UniquePtr = std::unique_ptr<X509, X509_deleter>;
+
+using EVP_PKEY_deleter =
+ folly::static_function_deleter<EVP_PKEY, &EVP_PKEY_free>;
+using EVP_PKEY_UniquePtr = std::unique_ptr<EVP_PKEY, EVP_PKEY_deleter>;
+
+using SSL_deleter = folly::static_function_deleter<SSL, &SSL_free>;
+using SSL_UniquePtr = std::unique_ptr<SSL, SSL_deleter>;
+}
#include <folly/Format.h>
#include <folly/Memory.h>
#include <folly/SpinLock.h>
+#include <folly/io/async/OpenSSLPtrTypes.h>
// ---------------------------------------------------------------------
// SSLContext implementation
inline void BIO_free_fb(BIO* bio) { CHECK_EQ(1, BIO_free(bio)); }
using BIO_deleter = folly::static_function_deleter<BIO, &BIO_free_fb>;
-using X509_deleter = folly::static_function_deleter<X509, &X509_free>;
-using EVP_PKEY_deleter =
- folly::static_function_deleter<EVP_PKEY, &EVP_PKEY_free>;
} // anonymous namespace
throw std::runtime_error("BIO_write: " + getErrors());
}
- std::unique_ptr<X509, X509_deleter> x509(
- PEM_read_bio_X509(bio.get(), nullptr, nullptr, nullptr));
+ X509_UniquePtr x509(PEM_read_bio_X509(bio.get(), nullptr, nullptr, nullptr));
if (x509 == nullptr) {
throw std::runtime_error("PEM_read_bio_X509: " + getErrors());
}
throw std::runtime_error("BIO_write: " + getErrors());
}
- std::unique_ptr<EVP_PKEY, EVP_PKEY_deleter> key(
+ EVP_PKEY_UniquePtr key(
PEM_read_bio_PrivateKey(bio.get(), nullptr, nullptr, nullptr));
if (key == nullptr) {
throw std::runtime_error("PEM_read_bio_PrivateKey: " + getErrors());
inline void BIO_free_fb(BIO* bio) { CHECK_EQ(1, BIO_free(bio)); }
using BIO_deleter = folly::static_function_deleter<BIO, &BIO_free_fb>;
-using X509_deleter = folly::static_function_deleter<X509, &X509_free>;
-using SSL_deleter = folly::static_function_deleter<SSL, &SSL_free>;
-using EVP_PKEY_deleter =
- folly::static_function_deleter<EVP_PKEY, &EVP_PKEY_free>;
TestSSLServer::TestSSLServer(SSLServerAcceptCallbackBase* acb)
: ctx_(new folly::SSLContext),
BIO_write(keyBio.get(), key.data(), key.size());
// Create SSL structs from buffers to get properties
- std::unique_ptr<X509, X509_deleter> certStruct(
+ X509_UniquePtr certStruct(
PEM_read_bio_X509(certBio.get(), nullptr, nullptr, nullptr));
- std::unique_ptr<EVP_PKEY, EVP_PKEY_deleter> keyStruct(
+ EVP_PKEY_UniquePtr keyStruct(
PEM_read_bio_PrivateKey(keyBio.get(), nullptr, nullptr, nullptr));
certBio = nullptr;
keyBio = nullptr;
ctx->loadCertificateFromBufferPEM(cert);
ctx->loadTrustedCertificates(testCA);
- std::unique_ptr<SSL, SSL_deleter> ssl(ctx->createSSL());
+ SSL_UniquePtr ssl(ctx->createSSL());
auto newCert = SSL_get_certificate(ssl.get());
auto newKey = SSL_get_privatekey(ssl.get());