summaryrefslogtreecommitdiffstats
blob: 9d0ad722e11d71fdd576a4a82721b9c65096f4cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
 * Copyright (c) 2010-2018 Isode Limited.
 * All rights reserved.
 * See the COPYING file for more information.
 */

#include <Swiften/TLS/OpenSSL/OpenSSLContextFactory.h>

#include <openssl/bio.h>
#include <openssl/dh.h>
#include <openssl/pem.h>

#include <Swiften/Base/Log.h>
#include <Swiften/TLS/OpenSSL/OpenSSLContext.h>

#pragma clang diagnostic ignored "-Wshorten-64-to-32"

namespace Swift {

bool OpenSSLContextFactory::canCreate() const {
    return true;
}

TLSContext* OpenSSLContextFactory::createTLSContext(const TLSOptions&, TLSContext::Mode mode) {
    return new OpenSSLContext(mode);
}

ByteArray OpenSSLContextFactory::convertDHParametersFromPEMToDER(const std::string& dhParametersInPEM) {
    ByteArray dhParametersInDER;

    auto bio = std::unique_ptr<BIO, decltype(&BIO_free)>(BIO_new(BIO_s_mem()), BIO_free);
    if (bio) {
        BIO_write(bio.get(), dhParametersInPEM.data(), dhParametersInPEM.size());
        if (auto params = PEM_read_bio_DHparams(bio.get(), nullptr, nullptr, nullptr)) {
            unsigned char* buffer = nullptr;
            auto len = i2d_DHparams(params, &buffer);
            if (len > 0) {
                dhParametersInDER = createByteArray(buffer, static_cast<size_t>(len));
                free(buffer);
            }
            DH_free(params);

        }
    }
    return dhParametersInDER;
}

void OpenSSLContextFactory::setCheckCertificateRevocation(bool check) {
    if (check) {
        SWIFT_LOG(warning) << "CRL Checking not supported for OpenSSL" << std::endl;
        assert(false);
    }
}

void OpenSSLContextFactory::setDisconnectOnCardRemoval(bool check) {
    if (check) {
        SWIFT_LOG(warning) << "Smart cards not supported for OpenSSL" << std::endl;
    }
}



}