summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften/QA/TLSTest/CertificateTest.cpp')
-rw-r--r--Swiften/QA/TLSTest/CertificateTest.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/Swiften/QA/TLSTest/CertificateTest.cpp b/Swiften/QA/TLSTest/CertificateTest.cpp
index 21f749c..624d953 100644
--- a/Swiften/QA/TLSTest/CertificateTest.cpp
+++ b/Swiften/QA/TLSTest/CertificateTest.cpp
@@ -15,6 +15,9 @@
15 15
16#include <Swiften/Base/ByteArray.h> 16#include <Swiften/Base/ByteArray.h>
17#include <Swiften/TLS/CertificateFactory.h> 17#include <Swiften/TLS/CertificateFactory.h>
18#include <Swiften/TLS/TLSContext.h>
19#include <Swiften/TLS/PlatformTLSFactories.h>
20#include <Swiften/TLS/TLSContextFactory.h>
18 21
19#include <SwifTools/Application/PlatformApplicationPathProvider.h> 22#include <SwifTools/Application/PlatformApplicationPathProvider.h>
20 23
@@ -31,6 +34,7 @@ class CertificateTest : public CppUnit::TestFixture {
31 CPPUNIT_TEST(testGetDNSNames); 34 CPPUNIT_TEST(testGetDNSNames);
32 CPPUNIT_TEST(testGetXMPPAddresses); 35 CPPUNIT_TEST(testGetXMPPAddresses);
33 CPPUNIT_TEST(testCreateCertificateChain); 36 CPPUNIT_TEST(testCreateCertificateChain);
37 CPPUNIT_TEST(testCreateTlsContext);
34 CPPUNIT_TEST_SUITE_END(); 38 CPPUNIT_TEST_SUITE_END();
35 39
36 public: 40 public:
@@ -38,7 +42,11 @@ class CertificateTest : public CppUnit::TestFixture {
38 pathProvider = std::make_unique<PlatformApplicationPathProvider>("FileReadBytestreamTest"); 42 pathProvider = std::make_unique<PlatformApplicationPathProvider>("FileReadBytestreamTest");
39 readByteArrayFromFile(certificateData, (pathProvider->getExecutableDir() / "jabber_org.crt")); 43 readByteArrayFromFile(certificateData, (pathProvider->getExecutableDir() / "jabber_org.crt"));
40 readByteArrayFromFile(chainData, (pathProvider->getExecutableDir() / "certificateChain.pem")); 44 readByteArrayFromFile(chainData, (pathProvider->getExecutableDir() / "certificateChain.pem"));
45 readByteArrayFromFile(keyData, (pathProvider->getExecutableDir() / "privateKey.pem"));
41 certificateFactory = std::unique_ptr<CertificateFactory>(new CERTIFICATE_FACTORY()); 46 certificateFactory = std::unique_ptr<CertificateFactory>(new CERTIFICATE_FACTORY());
47
48 PlatformTLSFactories* tlsFactories_ = new PlatformTLSFactories();
49 tlsContextFactory_ = tlsFactories_->getTLSContextFactory();
42 } 50 }
43 51
44 void testConstructFromDER() { 52 void testConstructFromDER() {
@@ -106,11 +114,29 @@ class CertificateTest : public CppUnit::TestFixture {
106 CPPUNIT_ASSERT_EQUAL(std::string("New Messaging CA"), chain[1]->getCommonNames()[0]); 114 CPPUNIT_ASSERT_EQUAL(std::string("New Messaging CA"), chain[1]->getCommonNames()[0]);
107 } 115 }
108 116
117 void testCreateTlsContext() {
118 // Create 2-certificate chain as in previous test
119 std::vector<std::shared_ptr<Certificate>> chain = certificateFactory->createCertificateChain(chainData);
120 CPPUNIT_ASSERT_EQUAL(2,static_cast<int>(chain.size()));
121
122 // Load private key from string
123 PrivateKey::ref key = certificateFactory->createPrivateKey(Swift::createSafeByteArray(keyData));
124 CPPUNIT_ASSERT(key);
125
126 const TLSOptions options;
127 auto context = tlsContextFactory_->createTLSContext(options, TLSContext::Mode::Server);
128 CPPUNIT_ASSERT(context);
129
130 context->setCertificateChain(chain);
131 context->setPrivateKey(key);
132 }
109 private: 133 private:
110 std::unique_ptr<PlatformApplicationPathProvider> pathProvider; 134 std::unique_ptr<PlatformApplicationPathProvider> pathProvider;
111 ByteArray certificateData; 135 ByteArray certificateData;
112 ByteArray chainData; 136 ByteArray chainData;
137 ByteArray keyData;
113 std::unique_ptr<CertificateFactory> certificateFactory; 138 std::unique_ptr<CertificateFactory> certificateFactory;
139 TLSContextFactory* tlsContextFactory_;
114}; 140};
115 141
116#ifdef HAVE_OPENSSL 142#ifdef HAVE_OPENSSL