2013-03-18 19:02:42 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2018-10-18 09:27:04 +02:00
|
|
|
* Copyright (C) 2012-2018 Icinga Development Team (https://icinga.com/) *
|
2013-03-18 19:02:42 +01:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 2 *
|
|
|
|
* of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software Foundation *
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#ifndef TLSUTILITY_H
|
|
|
|
#define TLSUTILITY_H
|
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "base/i2-base.hpp"
|
|
|
|
#include "base/object.hpp"
|
2014-10-19 14:48:19 +02:00
|
|
|
#include "base/string.hpp"
|
2013-03-18 19:02:42 +01:00
|
|
|
#include <openssl/ssl.h>
|
2013-09-03 14:05:03 +02:00
|
|
|
#include <openssl/bio.h>
|
2013-03-18 19:02:42 +01:00
|
|
|
#include <openssl/err.h>
|
2013-09-03 14:05:03 +02:00
|
|
|
#include <openssl/comp.h>
|
2013-09-04 15:47:15 +02:00
|
|
|
#include <openssl/sha.h>
|
2014-10-13 13:58:18 +02:00
|
|
|
#include <openssl/x509v3.h>
|
2014-10-16 13:36:25 +02:00
|
|
|
#include <openssl/evp.h>
|
2014-10-23 15:05:12 +02:00
|
|
|
#include <openssl/rand.h>
|
2014-12-15 10:16:06 +01:00
|
|
|
#include <boost/exception/info.hpp>
|
2013-03-18 19:02:42 +01:00
|
|
|
|
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
void InitializeOpenSSL();
|
2017-12-31 07:22:16 +01:00
|
|
|
std::shared_ptr<SSL_CTX> MakeSSLContext(const String& pubkey = String(), const String& privkey = String(), const String& cakey = String());
|
|
|
|
void AddCRLToSSLContext(const std::shared_ptr<SSL_CTX>& context, const String& crlPath);
|
|
|
|
void SetCipherListToSSLContext(const std::shared_ptr<SSL_CTX>& context, const String& cipherList);
|
|
|
|
void SetTlsProtocolminToSSLContext(const std::shared_ptr<SSL_CTX>& context, const String& tlsProtocolmin);
|
|
|
|
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);
|
2018-01-04 04:25:35 +01:00
|
|
|
String GetIcingaCADir();
|
2017-12-31 07:22:16 +01:00
|
|
|
String CertificateToString(const std::shared_ptr<X509>& cert);
|
|
|
|
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);
|
|
|
|
String PBKDF2_SHA1(const String& password, const String& salt, int iterations);
|
2017-08-11 16:23:24 +02:00
|
|
|
String PBKDF2_SHA256(const String& password, const String& salt, int iterations);
|
2017-12-31 07:22:16 +01:00
|
|
|
String SHA1(const String& s, bool binary = false);
|
|
|
|
String SHA256(const String& s);
|
|
|
|
String RandomString(int length);
|
|
|
|
bool VerifyCertificate(const std::shared_ptr<X509>& caCertificate, const std::shared_ptr<X509>& certificate);
|
2013-03-18 19:02:42 +01:00
|
|
|
|
2017-12-31 07:22:16 +01:00
|
|
|
class openssl_error : virtual public std::exception, virtual public boost::exception { };
|
2013-03-18 19:02:42 +01:00
|
|
|
|
|
|
|
struct errinfo_openssl_error_;
|
2014-09-09 15:28:55 +02:00
|
|
|
typedef boost::error_info<struct errinfo_openssl_error_, unsigned long> errinfo_openssl_error;
|
2013-03-18 19:02:42 +01:00
|
|
|
|
2018-01-04 10:36:35 +01:00
|
|
|
std::string to_string(const errinfo_openssl_error& e);
|
2013-03-18 19:02:42 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* TLSUTILITY_H */
|