]> granicus.if.org Git - icinga2/blob - lib/base/tlsutility.hpp
Merge pull request #7002 from Icinga/bugfix/check_network-percent-6155
[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/exception/info.hpp>
18
19 namespace icinga
20 {
21
22 void InitializeOpenSSL();
23 std::shared_ptr<SSL_CTX> MakeSSLContext(const String& pubkey = String(), const String& privkey = String(), const String& cakey = String());
24 void AddCRLToSSLContext(const std::shared_ptr<SSL_CTX>& context, const String& crlPath);
25 void SetCipherListToSSLContext(const std::shared_ptr<SSL_CTX>& context, const String& cipherList);
26 void SetTlsProtocolminToSSLContext(const std::shared_ptr<SSL_CTX>& context, const String& tlsProtocolmin);
27 String GetCertificateCN(const std::shared_ptr<X509>& certificate);
28 std::shared_ptr<X509> GetX509Certificate(const String& pemfile);
29 int MakeX509CSR(const String& cn, const String& keyfile, const String& csrfile = String(), const String& certfile = String(), bool ca = false);
30 std::shared_ptr<X509> CreateCert(EVP_PKEY *pubkey, X509_NAME *subject, X509_NAME *issuer, EVP_PKEY *cakey, bool ca);
31 String GetIcingaCADir();
32 String CertificateToString(const std::shared_ptr<X509>& cert);
33 std::shared_ptr<X509> StringToCertificate(const String& cert);
34 std::shared_ptr<X509> CreateCertIcingaCA(EVP_PKEY *pubkey, X509_NAME *subject);
35 std::shared_ptr<X509> CreateCertIcingaCA(const std::shared_ptr<X509>& cert);
36 String PBKDF2_SHA1(const String& password, const String& salt, int iterations);
37 String PBKDF2_SHA256(const String& password, const String& salt, int iterations);
38 String SHA1(const String& s, bool binary = false);
39 String SHA256(const String& s);
40 String RandomString(int length);
41 bool VerifyCertificate(const std::shared_ptr<X509>& caCertificate, const std::shared_ptr<X509>& certificate);
42
43 class openssl_error : virtual public std::exception, virtual public boost::exception { };
44
45 struct errinfo_openssl_error_;
46 typedef boost::error_info<struct errinfo_openssl_error_, unsigned long> errinfo_openssl_error;
47
48 std::string to_string(const errinfo_openssl_error& e);
49
50 }
51
52 #endif /* TLSUTILITY_H */