17 #ifndef __PROCESS_SSL_TEST_HPP__ 18 #define __PROCESS_SSL_TEST_HPP__ 29 #include <openssl/rsa.h> 30 #include <openssl/bio.h> 31 #include <openssl/x509.h> 32 #include <openssl/x509v3.h> 47 #endif // USE_SSL_SOCKET 63 #endif // USE_SSL_SOCKET 68 #ifndef USE_SSL_SOCKET 78 static void TearDownTestCase()
81 set_environment_variables({});
96 Path certificate_path()
104 Path scrap_key_path()
112 Path scrap_certificate_path()
121 static void set_environment_variables(
122 const std::map<std::string, std::string>&
environment)
146 const std::string&
name,
const std::string& value, environment) {
151 process::network::openssl::reinitialize();
161 void generate_keys_and_certs() {
170 auto cleanup = [&private_key, &certificate, &scrap_key, &scrap_certificate](
172 if (private_key.
isSome()) { EVP_PKEY_free(private_key.
get()); }
173 if (certificate.isSome()) { X509_free(certificate.get()); }
174 if (scrap_key.isSome()) { EVP_PKEY_free(scrap_key.get()); }
175 if (scrap_certificate.
isSome()) { X509_free(scrap_certificate.
get()); }
179 if (abort_message.isSome()) {
180 ABORT(abort_message.get());
185 private_key = process::network::openssl::generate_private_rsa_key();
187 cleanup(
"Could not generate private key: " + private_key.
error());
194 if (hostname.isError()) {
195 cleanup(
"Could not determine hostname of libprocess: " +
200 certificate = process::network::openssl::generate_x509(
209 if (certificate.isError()) {
210 cleanup(
"Could not generate certificate: " + certificate.error());
215 process::network::openssl::write_key_file(private_key.
get(), key_path());
217 if (key_write.isError()) {
218 cleanup(
"Could not write private key to disk: " + key_write.error());
223 process::network::openssl::write_certificate_file(
227 if (certificate_write.isError()) {
228 cleanup(
"Could not write certificate to disk: " +
229 certificate_write.error());
233 scrap_key = process::network::openssl::generate_private_rsa_key();
234 if (scrap_key.isError()) {
235 cleanup(
"Could not generate a scrap private key: " + scrap_key.error());
239 key_write = process::network::openssl::write_key_file(
243 if (key_write.isError()) {
244 cleanup(
"Could not write scrap key to disk: " + key_write.error());
248 scrap_certificate = process::network::openssl::generate_x509(
252 if (scrap_certificate.isError()) {
253 cleanup(
"Could not generate a scrap certificate: " +
254 scrap_certificate.error());
258 certificate_write = process::network::openssl::write_certificate_file(
259 scrap_certificate.get(),
260 scrap_certificate_path());
262 if (certificate_write.isError()) {
263 cleanup(
"Could not write scrap certificate to disk: " +
264 certificate_write.error());
284 SSLTest() : data(
"Hello World!") {}
286 void SetUp()
override 289 generate_keys_and_certs();
301 const std::map<std::string, std::string>&
environment)
303 set_environment_variables(environment);
307 process::network::internal::SocketImpl::Kind::SSL);
326 if (listen.isError()) {
327 return Error(listen.error());
351 const std::map<std::string, std::string>& environment,
358 std::vector<std::string> argv = {
360 "--use_ssl=" +
stringify(use_ssl_socket),
366 argv.push_back(
"--server_hostname=" + hostname.
get());
371 return Error(
"Could not establish build directory path");
377 std::map<std::string, std::string> full_environment(environment);
404 const std::map<std::string, std::string>& environment,
413 return launch_client(
421 static constexpr
size_t BACKLOG = 5;
423 const std::string data;
426 #endif // USE_SSL_SOCKET 428 #endif // __PROCESS_SSL_TEST_HPP__
Definition: errorbase.hpp:36
#define ABORT(...)
Definition: abort.hpp:40
T & get()&
Definition: try.hpp:80
Result< std::string > realpath(const std::string &path)
Definition: realpath.hpp:24
Try< Address > address(int_fd s)
Returns the Address with the assigned ip and assigned port.
Definition: network.hpp:79
static Result< T > error(const std::string &message)
Definition: result.hpp:54
process::Future< bool > cleanup(const std::string &hierarchy)
static Try< Socket > create(int_fd s, SocketImpl::Kind kind=SocketImpl::DEFAULT_KIND())
Returns an instance of a Socket using the specified kind of implementation.
Definition: socket.hpp:274
std::string getcwd()
Definition: getcwd.hpp:23
Try< std::string > getHostname(const IP &ip)
Definition: net.hpp:45
std::string join(const std::string &path1, const std::string &path2, const char _separator=os::PATH_SEPARATOR)
Definition: path.hpp:116
void setenv(const std::string &key, const std::string &value, bool overwrite=true)
Definition: os.hpp:157
#define STDERR_FILENO
Definition: windows.hpp:155
void unsetenv(const std::string &key)
Definition: os.hpp:167
constexpr char BACKLOG[]
Definition: statistics.hpp:29
process::Future< uint64_t > listen(const std::string &hierarchy, const std::string &cgroup, const std::string &control, const Option< std::string > &args=Option< std::string >::none())
bool isSome() const
Definition: option.hpp:116
Definition: utils.hpp:120
Try< Subprocess > subprocess(const std::string &path, std::vector< std::string > argv, const Subprocess::IO &in=Subprocess::FD(STDIN_FILENO), const Subprocess::IO &out=Subprocess::FD(STDOUT_FILENO), const Subprocess::IO &err=Subprocess::FD(STDERR_FILENO), const flags::FlagsBase *flags=nullptr, const Option< std::map< std::string, std::string >> &environment=None(), const Option< lambda::function< pid_t(const lambda::function< int()> &)>> &clone=None(), const std::vector< Subprocess::ParentHook > &parent_hooks={}, const std::vector< Subprocess::ChildHook > &child_hooks={}, const std::vector< int_fd > &whitelist_fds={})
Forks a subprocess and execs the specified 'path' with the specified 'argv', redirecting stdin...
Environment * environment
static IO FD(int_fd fd, IO::FDType type=IO::DUPLICATED)
void SetUp() override
Definition: utils.hpp:37
Represents a POSIX or Windows file system path and offers common path manipulations.
Definition: path.hpp:212
uint16_t port
Definition: address.hpp:141
const T & get() const &
Definition: option.hpp:119
#define foreachpair(KEY, VALUE, ELEMS)
Definition: foreach.hpp:51
Try< std::string > hostname()
Definition: net.hpp:154
static Try error(const E &e)
Definition: try.hpp:43
Definition: address.hpp:52
bool isError() const
Definition: try.hpp:78
T & get()&
Definition: result.hpp:116
Definition: executor.hpp:48
network::inet::Address address()
Returns the socket address associated with this instance of the library.
bool isSome() const
Definition: result.hpp:112
bool isError() const
Definition: result.hpp:114
Try< Nothing > create(const std::string &hierarchy, const std::string &cgroup, bool recursive=false)
Try< Nothing > bind(int_fd s, const Address &address)
Definition: network.hpp:46
std::string stringify(int flags)
net::IP ip
Definition: address.hpp:140
Try< AddressType > address() const
Definition: socket.hpp:338
constexpr const char * name
Definition: shell.hpp:41