2019-02-25 08:48:22 -05:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2013-03-18 14:02:42 -04:00
|
|
|
|
|
|
|
|
#ifndef TLSUTILITY_H
|
|
|
|
|
#define TLSUTILITY_H
|
|
|
|
|
|
2014-05-25 10:23:35 -04:00
|
|
|
#include "base/i2-base.hpp"
|
2021-07-16 12:31:52 -04:00
|
|
|
#include "base/debuginfo.hpp"
|
2014-05-25 10:23:35 -04:00
|
|
|
#include "base/object.hpp"
|
2019-07-25 10:45:39 -04:00
|
|
|
#include "base/shared.hpp"
|
2020-02-17 11:42:20 -05:00
|
|
|
#include "base/array.hpp"
|
2014-10-19 08:48:19 -04:00
|
|
|
#include "base/string.hpp"
|
2013-03-18 14:02:42 -04:00
|
|
|
#include <openssl/ssl.h>
|
2013-09-03 08:05:03 -04:00
|
|
|
#include <openssl/bio.h>
|
2013-03-18 14:02:42 -04:00
|
|
|
#include <openssl/err.h>
|
2013-09-03 08:05:03 -04:00
|
|
|
#include <openssl/comp.h>
|
2013-09-04 09:47:15 -04:00
|
|
|
#include <openssl/sha.h>
|
2020-02-17 11:42:20 -05:00
|
|
|
#include <openssl/pem.h>
|
|
|
|
|
#include <openssl/x509.h>
|
2014-10-13 07:58:18 -04:00
|
|
|
#include <openssl/x509v3.h>
|
2014-10-16 07:36:25 -04:00
|
|
|
#include <openssl/evp.h>
|
2014-10-23 09:05:12 -04:00
|
|
|
#include <openssl/rand.h>
|
2019-02-08 08:23:10 -05:00
|
|
|
#include <boost/asio/ssl/context.hpp>
|
2014-12-15 04:16:06 -05:00
|
|
|
#include <boost/exception/info.hpp>
|
2013-03-18 14:02:42 -04:00
|
|
|
|
|
|
|
|
namespace icinga
|
|
|
|
|
{
|
|
|
|
|
|
2021-07-16 12:32:26 -04:00
|
|
|
const char * const DEFAULT_TLS_CIPHERS = "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:AES256-GCM-SHA384:AES128-GCM-SHA256";
|
|
|
|
|
|
|
|
|
|
const char * const DEFAULT_TLS_PROTOCOLMIN = "TLSv1.2";
|
2021-07-26 10:13:24 -04:00
|
|
|
const unsigned int DEFAULT_CONNECT_TIMEOUT = 15;
|
2021-07-16 12:32:26 -04:00
|
|
|
|
2022-03-30 12:38:57 -04:00
|
|
|
const auto ROOT_VALID_FOR = 60 * 60 * 24 * 365 * 15;
|
|
|
|
|
const auto LEAF_VALID_FOR = 60 * 60 * 24 * 397;
|
|
|
|
|
const auto RENEW_THRESHOLD = 60 * 60 * 24 * 30;
|
|
|
|
|
const auto RENEW_INTERVAL = 60 * 60 * 24;
|
|
|
|
|
|
2018-01-03 22:25:35 -05:00
|
|
|
void InitializeOpenSSL();
|
2019-05-28 07:03:34 -04:00
|
|
|
|
2020-02-13 09:25:03 -05:00
|
|
|
String GetOpenSSLVersion();
|
|
|
|
|
|
2019-07-25 10:45:39 -04:00
|
|
|
Shared<boost::asio::ssl::context>::Ptr MakeAsioSslContext(const String& pubkey = String(), const String& privkey = String(), const String& cakey = String());
|
|
|
|
|
void AddCRLToSSLContext(const Shared<boost::asio::ssl::context>::Ptr& context, const String& crlPath);
|
2020-12-07 07:27:48 -05:00
|
|
|
void AddCRLToSSLContext(X509_STORE *x509_store, const String& crlPath);
|
2019-07-25 10:45:39 -04:00
|
|
|
void SetCipherListToSSLContext(const Shared<boost::asio::ssl::context>::Ptr& context, const String& cipherList);
|
|
|
|
|
void SetTlsProtocolminToSSLContext(const Shared<boost::asio::ssl::context>::Ptr& context, const String& tlsProtocolmin);
|
2021-04-14 09:35:54 -04:00
|
|
|
int ResolveTlsProtocolVersion(const std::string& version);
|
2019-05-28 07:03:34 -04:00
|
|
|
|
2021-07-16 12:31:52 -04:00
|
|
|
Shared<boost::asio::ssl::context>::Ptr SetupSslContext(String certPath, String keyPath,
|
|
|
|
|
String caPath, String crlPath, String cipherList, String protocolmin, DebugInfo di);
|
|
|
|
|
|
2017-12-31 01:22:16 -05:00
|
|
|
String GetCertificateCN(const std::shared_ptr<X509>& certificate);
|
|
|
|
|
std::shared_ptr<X509> GetX509Certificate(const String& pemfile);
|
|
|
|
|
int MakeX509CSR(const String& cn, const String& keyfile, const String& csrfile = String(), const String& certfile = String(), bool ca = false);
|
|
|
|
|
std::shared_ptr<X509> CreateCert(EVP_PKEY *pubkey, X509_NAME *subject, X509_NAME *issuer, EVP_PKEY *cakey, bool ca);
|
2019-05-28 07:03:34 -04:00
|
|
|
|
2018-01-03 22:25:35 -05:00
|
|
|
String GetIcingaCADir();
|
2017-12-31 01:22:16 -05:00
|
|
|
String CertificateToString(const std::shared_ptr<X509>& cert);
|
2019-05-28 07:03:34 -04:00
|
|
|
|
2017-12-31 01:22:16 -05:00
|
|
|
std::shared_ptr<X509> StringToCertificate(const String& cert);
|
|
|
|
|
std::shared_ptr<X509> CreateCertIcingaCA(EVP_PKEY *pubkey, X509_NAME *subject);
|
|
|
|
|
std::shared_ptr<X509> CreateCertIcingaCA(const std::shared_ptr<X509>& cert);
|
2022-03-29 09:47:16 -04:00
|
|
|
bool IsCertUptodate(const std::shared_ptr<X509>& cert);
|
2019-05-28 07:03:34 -04:00
|
|
|
|
2017-12-31 01:22:16 -05:00
|
|
|
String PBKDF2_SHA1(const String& password, const String& salt, int iterations);
|
2017-08-11 10:23:24 -04:00
|
|
|
String PBKDF2_SHA256(const String& password, const String& salt, int iterations);
|
2017-12-31 01:22:16 -05:00
|
|
|
String SHA1(const String& s, bool binary = false);
|
|
|
|
|
String SHA256(const String& s);
|
|
|
|
|
String RandomString(int length);
|
2021-09-21 06:56:10 -04:00
|
|
|
String BinaryToHex(const unsigned char* data, size_t length);
|
2019-05-28 07:03:34 -04:00
|
|
|
|
2020-12-07 07:27:48 -05:00
|
|
|
bool VerifyCertificate(const std::shared_ptr<X509>& caCertificate, const std::shared_ptr<X509>& certificate, const String& crlFile);
|
2020-02-13 10:03:43 -05:00
|
|
|
bool IsCa(const std::shared_ptr<X509>& cacert);
|
2020-02-17 11:42:20 -05:00
|
|
|
int GetCertificateVersion(const std::shared_ptr<X509>& cert);
|
|
|
|
|
String GetSignatureAlgorithm(const std::shared_ptr<X509>& cert);
|
|
|
|
|
Array::Ptr GetSubjectAltNames(const std::shared_ptr<X509>& cert);
|
2013-03-18 14:02:42 -04:00
|
|
|
|
2017-12-31 01:22:16 -05:00
|
|
|
class openssl_error : virtual public std::exception, virtual public boost::exception { };
|
2013-03-18 14:02:42 -04:00
|
|
|
|
|
|
|
|
struct errinfo_openssl_error_;
|
2014-09-09 09:28:55 -04:00
|
|
|
typedef boost::error_info<struct errinfo_openssl_error_, unsigned long> errinfo_openssl_error;
|
2013-03-18 14:02:42 -04:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* TLSUTILITY_H */
|