]> granicus.if.org Git - icinga2/blob - lib/base/tlsutility.hpp
Make ApiListener#m_SSLContext a Boost ASIO SSL context
[icinga2] / lib / base / tlsutility.hpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #ifndef TLSUTILITY_H
4 #define TLSUTILITY_H
5
6 #include "base/i2-base.hpp"
7 #include "base/object.hpp"
8 #include "base/string.hpp"
9 #include <openssl/ssl.h>
10 #include <openssl/bio.h>
11 #include <openssl/err.h>
12 #include <openssl/comp.h>
13 #include <openssl/sha.h>
14 #include <openssl/x509v3.h>
15 #include <openssl/evp.h>
16 #include <openssl/rand.h>
17 #include <boost/asio/ssl/context.hpp>
18 #include <boost/exception/info.hpp>
19
20 namespace icinga
21 {
22
23 void InitializeOpenSSL();
24 std::shared_ptr<SSL_CTX> MakeSSLContext(const String& pubkey = String(), const String& privkey = String(), const String& cakey = String());
25 std::shared_ptr<boost::asio::ssl::context> MakeAsioSslContext(const String& pubkey = String(), const String& privkey = String(), const String& cakey = String());
26 void AddCRLToSSLContext(const std::shared_ptr<boost::asio::ssl::context>& context, const String& crlPath);
27 void SetCipherListToSSLContext(const std::shared_ptr<boost::asio::ssl::context>& context, const String& cipherList);
28 void SetTlsProtocolminToSSLContext(const std::shared_ptr<boost::asio::ssl::context>& context, const String& tlsProtocolmin);
29 String GetCertificateCN(const std::shared_ptr<X509>& certificate);
30 std::shared_ptr<X509> GetX509Certificate(const String& pemfile);
31 int MakeX509CSR(const String& cn, const String& keyfile, const String& csrfile = String(), const String& certfile = String(), bool ca = false);
32 std::shared_ptr<X509> CreateCert(EVP_PKEY *pubkey, X509_NAME *subject, X509_NAME *issuer, EVP_PKEY *cakey, bool ca);
33 String GetIcingaCADir();
34 String CertificateToString(const std::shared_ptr<X509>& cert);
35 std::shared_ptr<X509> StringToCertificate(const String& cert);
36 std::shared_ptr<X509> CreateCertIcingaCA(EVP_PKEY *pubkey, X509_NAME *subject);
37 std::shared_ptr<X509> CreateCertIcingaCA(const std::shared_ptr<X509>& cert);
38 String PBKDF2_SHA1(const String& password, const String& salt, int iterations);
39 String PBKDF2_SHA256(const String& password, const String& salt, int iterations);
40 String SHA1(const String& s, bool binary = false);
41 String SHA256(const String& s);
42 String RandomString(int length);
43 bool VerifyCertificate(const std::shared_ptr<X509>& caCertificate, const std::shared_ptr<X509>& certificate);
44
45 class openssl_error : virtual public std::exception, virtual public boost::exception { };
46
47 struct errinfo_openssl_error_;
48 typedef boost::error_info<struct errinfo_openssl_error_, unsigned long> errinfo_openssl_error;
49
50 std::string to_string(const errinfo_openssl_error& e);
51
52 }
53
54 #endif /* TLSUTILITY_H */