1//
2// X509CertificateTest.cpp
3//
4// $Id: //poco/1.4/NetSSL_OpenSSL/testsuite/src/X509CertificateTest.cpp#1 $
5//
6// Copyright (c) 2017, Applied Informatics Software Engineering GmbH.
7// and Contributors.
8//
9// SPDX-License-Identifier: BSL-1.0
10//
11
12
13#include "X509CertificateTest.h"
14#include "Poco/CppUnit/TestCaller.h"
15#include "Poco/CppUnit/TestSuite.h"
16#include "Poco/Net/X509Certificate.h"
17#include <openssl/opensslv.h>
18#include <sstream>
19
20using namespace Poco::Net;
21
22
23static const std::string BADSSL_PEM(
24 "-----BEGIN CERTIFICATE-----\n"
25 "MIIHGjCCBgKgAwIBAgIQC2as9L3V1BSoMGn+fB4NRjANBgkqhkiG9w0BAQ0FADBN\n"
26 "MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMScwJQYDVQQDEx5E\n"
27 "aWdpQ2VydCBTSEEyIFNlY3VyZSBTZXJ2ZXIgQ0EwHhcNMTcwMzE4MDAwMDAwWhcN\n"
28 "MjAwMzI1MTIwMDAwWjBnMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5p\n"
29 "YTEVMBMGA1UEBxMMV2FsbnV0IENyZWVrMRUwEwYDVQQKEwxMdWNhcyBHYXJyb24x\n"
30 "FTATBgNVBAMMDCouYmFkc3NsLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCC\n"
31 "AQoCggEBAMIE7PiM7gTCs9hQ1XBYzJMY61yoaEmwIrX5lZ6xKyx2PmzAS2BMTOqy\n"
32 "tMAPgLaw+XLJhgL5XEFdEyt/ccRLvOmULlA3pmccYYz2QULFRtMWhyefdOsKnRFS\n"
33 "JiFzbIRMeVXk0WvoBj1IFVKtsyjbqv9u/2CVSndrOfEk0TG23U3AxPxTuW1CrbV8\n"
34 "/q71FdIzSOciccfCFHpsKOo3St/qbLVytH5aohbcabFXRNsKEqveww9HdFxBIuGa\n"
35 "+RuT5q0iBikusbpJHAwnnqP7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+UmFXWidDdAAABWt+xlX0AAAQDAEcwRQIgWBrOlMeBTCBJ\n"
51 "ezx+6OwzmD1QSl7/Vq2k/xACoGInSjsCIQCii59Rjt8rZxNIHMQE6/lnYHWyCqEv\n"
52 "rNAJiUOrJAxJ3QB1AO5Lvbd1zmC64UJpH6vhnmajD35fsHLYgwDEe4l6qP3LAAAB\n"
53 "Wt+xlqkAAAQDAEYwRAIgEklGobMohZiTQwTgizi4Sfy2CQ/fL1K1EM2yZGrvSCAC\n"
54 "IGkDXy8uSUh3S09pAODVLHeyMYX8fdGM3UU1uv8ReNH3AHcAu9nfvB+KcbWTlCOX\n"
55 "qpJ7RzhXlQqrUugakJZkNo4e0YUAAAFa37GUwQAABAMASDBGAiEA2wazyXDaD1k3\n"
56 "4UVG0AJH+HhNBb728PHxuTJYGffXCckCIQDOb7subG8AQJFc5zWKeKPhnHhP2R56\n"
57 "28tXqM8mzCQGzzANBgkqhkiG9w0BAQ0FAAOCAQEAyA7NyduD8+zjNI/uclW9WkvG\n"
58 "6Oolon0vvbs+BGvCl5iY/3BBIxNTWPeRBDE0P+zOkceqGqjENce/d1O5I/H+oFZR\n"
59 "Y0fLjtILwg/BH5QKoRWJF/rqvu7wlSqnxlYGDducs2hY2WgtIl/BntMaDQXcyzXP\n"
60 "O+Pjbq0JLb6/Enss558t3DNIKvtspDidxnQIPBzKBVx8prG1C0ng4S+HmZYg166W\n"
61 "mShTOeNNQMYPIUr44ICQkw82gYuAsjsgxEEjAHo0zrkHlA3cnwXeERAX3qEUQ8WH\n"
62 "Dw/Py3T1TqiODDqvLLE/sFYUwqDaSdaaOo/geYvJmfqOYXQoaz2t1ptYXdvsfg==\n"
63 "-----END CERTIFICATE-----\n"
64);
65
66
67X509CertificateTest::X509CertificateTest(const std::string& name): CppUnit::TestCase(name)
68{
69}
70
71
72X509CertificateTest::~X509CertificateTest()
73{
74}
75
76
77void X509CertificateTest::testVerify()
78{
79 std::istringstream certStream(BADSSL_PEM);
80 X509Certificate cert(certStream);
81
82 assertTrue (cert.verify("badssl.com"));
83 assertTrue (cert.verify("host.badssl.com"));
84
85#if OPENSSL_VERSION_NUMBER < 0x10002000L
86 assertTrue (cert.verify("wrong.host.badssl.com"));
87#else
88 assertTrue (!cert.verify("wrong.host.badssl.com"));
89#endif
90}
91
92
93void X509CertificateTest::setUp()
94{
95}
96
97
98void X509CertificateTest::tearDown()
99{
100}
101
102
103CppUnit::Test* X509CertificateTest::suite()
104{
105 CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("X509CertificateTest");
106
107 CppUnit_addTest(pSuite, X509CertificateTest, testVerify);
108
109 return pSuite;
110}
111