2017-02-16 23:30:29 -06:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
2020-04-18 03:39:50 -05:00
|
|
|
#pragma once
|
2017-02-16 23:30:29 -06:00
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
#include <memory>
|
2017-02-17 00:15:42 -06:00
|
|
|
#include <mutex>
|
2017-02-16 23:30:29 -06:00
|
|
|
#include <string>
|
2017-02-17 00:15:42 -06:00
|
|
|
#include <vector>
|
2017-02-16 23:30:29 -06:00
|
|
|
|
|
|
|
#include <openssl/ssl.h>
|
|
|
|
#include <openssl/rand.h>
|
|
|
|
#include <openssl/crypto.h>
|
|
|
|
#include <openssl/err.h>
|
|
|
|
#if OPENSSL_VERSION_NUMBER >= 0x0907000L
|
|
|
|
#include <openssl/conf.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class SslContext
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static void initialize(const std::string& certFilePath,
|
|
|
|
const std::string& keyFilePath,
|
2017-11-22 09:54:42 -06:00
|
|
|
const std::string& caFilePath,
|
|
|
|
const std::string& cipherList = "")
|
2017-02-16 23:30:29 -06:00
|
|
|
{
|
2017-03-27 14:14:16 -05:00
|
|
|
assert (!Instance);
|
2017-11-22 09:54:42 -06:00
|
|
|
Instance.reset(new SslContext(certFilePath, keyFilePath, caFilePath, cipherList));
|
2017-02-16 23:30:29 -06:00
|
|
|
}
|
|
|
|
|
2017-03-27 14:14:16 -05:00
|
|
|
static void uninitialize();
|
2017-02-16 23:30:29 -06:00
|
|
|
|
|
|
|
static SSL* newSsl()
|
|
|
|
{
|
|
|
|
return SSL_new(Instance->_ctx);
|
|
|
|
}
|
|
|
|
|
|
|
|
~SslContext();
|
|
|
|
|
|
|
|
private:
|
|
|
|
SslContext(const std::string& certFilePath,
|
|
|
|
const std::string& keyFilePath,
|
2017-11-22 09:54:42 -06:00
|
|
|
const std::string& caFilePath,
|
|
|
|
const std::string& cipherList);
|
2017-02-16 23:30:29 -06:00
|
|
|
|
2017-02-17 00:40:55 -06:00
|
|
|
void initDH();
|
|
|
|
void initECDH();
|
2017-03-27 14:14:16 -05:00
|
|
|
void shutdown();
|
2017-02-17 00:40:55 -06:00
|
|
|
|
|
|
|
std::string getLastErrorMsg();
|
|
|
|
|
2017-02-17 00:15:42 -06:00
|
|
|
// Multithreading support for OpenSSL.
|
|
|
|
// Not needed in recent (1.x?) versions.
|
|
|
|
static void lock(int mode, int n, const char* file, int line);
|
|
|
|
static unsigned long id();
|
|
|
|
static struct CRYPTO_dynlock_value* dynlockCreate(const char* file, int line);
|
|
|
|
static void dynlock(int mode, struct CRYPTO_dynlock_value* lock, const char* file, int line);
|
|
|
|
static void dynlockDestroy(struct CRYPTO_dynlock_value* lock, const char* file, int line);
|
|
|
|
|
2017-02-16 23:30:29 -06:00
|
|
|
private:
|
|
|
|
static std::unique_ptr<SslContext> Instance;
|
2017-04-03 20:06:51 -05:00
|
|
|
|
|
|
|
std::vector<std::unique_ptr<std::mutex>> _mutexes;
|
2017-02-16 23:30:29 -06:00
|
|
|
|
|
|
|
SSL_CTX* _ctx;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|