Apache Mesos
utilities.hpp
Go to the documentation of this file.
1 // Licensed under the Apache License, Version 2.0 (the "License");
2 // you may not use this file except in compliance with the License.
3 // You may obtain a copy of the License at
4 //
5 // http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 // See the License for the specific language governing permissions and
11 // limitations under the License
12 
13 #ifndef __OPENSSL_UTIL_HPP__
14 #define __OPENSSL_UTIL_HPP__
15 
16 #ifdef USE_SSL_SOCKET
17 
18 #ifdef __WINDOWS__
19 // NOTE: This must be included before the OpenSSL headers as it includes
20 // `WinSock2.h` and `Windows.h` in the correct order.
21 #include <stout/windows.hpp>
22 #endif // __WINDOWS__
23 
24 #include <openssl/ssl.h>
25 #include <openssl/x509.h>
26 
27 #include <stout/ip.hpp>
28 #include <stout/nothing.hpp>
29 #include <stout/path.hpp>
30 #include <stout/try.hpp>
31 
32 namespace process {
33 namespace network {
34 namespace openssl {
35 
48 Try<EVP_PKEY*> generate_private_rsa_key(
49  int bits = 2048,
50  unsigned long exponent = RSA_F4);
51 
52 
86 Try<X509*> generate_x509(
87  EVP_PKEY* subject_key,
88  EVP_PKEY* sign_key,
89  const Option<X509*>& parent_certificate = None(),
90  int serial = 1,
91  int days = 365,
93  const Option<net::IP>& ip = None());
94 
95 
105 Try<Nothing> write_key_file(EVP_PKEY* private_key, const Path& path);
106 
107 
117 Try<Nothing> write_certificate_file(X509* x509, const Path& path);
118 
119 
129 Try<std::string> generate_hmac_sha256(
130  const std::string& message,
131  const std::string& key);
132 
133 
143 Try<std::shared_ptr<RSA>> pem_to_rsa_private_key(const std::string& pem);
144 
145 
155 Try<std::shared_ptr<RSA>> pem_to_rsa_public_key(const std::string& pem);
156 
157 
167 Try<std::string> sign_rsa_sha256(
168  const std::string& message,
169  std::shared_ptr<RSA> private_key);
170 
171 
182 Try<Nothing> verify_rsa_sha256(
183  const std::string& message,
184  const std::string& signature,
185  std::shared_ptr<RSA> public_key);
186 
187 } // namespace openssl {
188 } // namespace network {
189 } // namespace process {
190 
191 #endif // USE_SSL_SOCKET
192 
193 #endif // __OPENSSL_UTIL_HPP__
Definition: path.hpp:29
Definition: option.hpp:29
Definition: check.hpp:33
Definition: bits.hpp:21
Represents a POSIX or Windows file system path and offers common path manipulations.
Definition: path.hpp:212
Try< std::string > hostname()
Definition: net.hpp:154
Definition: none.hpp:27
Definition: executor.hpp:48