read/write list of X509 certificates

This commit is contained in:
Alex Fabijanic 2017-09-26 21:43:22 -05:00
parent 4ac56bff0c
commit 1d18435e38
7 changed files with 496 additions and 89 deletions

View File

@ -38,13 +38,13 @@ class Crypto_API PKCS12Container
/// This class implements PKCS#12 container functionality.
{
public:
typedef std::vector<X509Certificate> CAList;
typedef X509Certificate::List CAList;
explicit PKCS12Container(std::istream& istr, const std::string& password = "");
/// Creates the PKCS12Container object from a stream.
explicit PKCS12Container(const std::string& str, const std::string& password = "");
/// Creates the PKCS12Container object from a string.
explicit PKCS12Container(const std::string& path, const std::string& password = "");
/// Creates the PKCS12Container object from a file.
PKCS12Container(const PKCS12Container& cont);
/// Copy constructor.

View File

@ -22,6 +22,7 @@
#include "Poco/Crypto/OpenSSLInitializer.h"
#include "Poco/DateTime.h"
#include "Poco/SharedPtr.h"
#include <vector>
#include <set>
#include <istream>
#include <openssl/ssl.h>
@ -35,6 +36,8 @@ class Crypto_API X509Certificate
/// This class represents a X509 Certificate.
{
public:
typedef std::vector<X509Certificate> List;
enum NID
/// Name identifier for extracting information from
/// a certificate subject's or issuer's distinguished name.
@ -144,6 +147,13 @@ public:
void print(std::ostream& out) const;
/// Prints the certificate information to ostream.
static List readPEM(const std::string& pemFileName);
/// Reads and returns a list of certificates from
/// the specified PEM file.
static void writePEM(const std::string& pemFileName, const List& list);
/// Writes the list of certificates to the specified PEM file.
protected:
void load(std::istream& stream);
/// Loads the certificate from the given stream. The

View File

@ -13,6 +13,7 @@
#include "Poco/Crypto/X509Certificate.h"
#include "Poco/Crypto/CryptoException.h"
#include "Poco/StreamCopier.h"
#include "Poco/String.h"
#include "Poco/DateTimeParser.h"
@ -294,6 +295,39 @@ bool X509Certificate::equals(const X509Certificate& otherCertificate) const
}
X509Certificate::List X509Certificate::readPEM(const std::string& pemFileName)
{
List caCertList;
BIO* pBIO = BIO_new_file(pemFileName.c_str(), "r");
if (pBIO == NULL) throw OpenFileException("X509Certificate::readPEM()");
X509* x = PEM_read_bio_X509(pBIO, NULL, 0, NULL);
while(x)
{
caCertList.push_back(X509Certificate(x));
x = PEM_read_bio_X509(pBIO, NULL, 0, NULL);
}
BIO_free(pBIO);
return caCertList;
}
void X509Certificate::writePEM(const std::string& pemFileName, const List& list)
{
BIO* pBIO = BIO_new_file(pemFileName.c_str(), "a");
if (pBIO == NULL) throw OpenFileException("X509Certificate::writePEM()");
List::const_iterator it = list.begin();
List::const_iterator end = list.end();
for (; it != end; ++it)
{
if (!PEM_write_bio_X509(pBIO, const_cast<X509*>(it->certificate())))
{
throw OpenSSLException("X509Certificate::writePEM()");
}
}
BIO_free(pBIO);
}
void X509Certificate::print(std::ostream& out) const
{
out << "subjectName: " << subjectName() << std::endl;

View File

@ -0,0 +1,171 @@
Bag Attributes
friendlyName: vally-ca
subject=/C=CH/ST=Zug/O=Crypto Vally/CN=CV Intermediate CA v3
issuer=/C=CH/ST=Zug/O=Crypto Vally/CN=CV Root CA v3
-----BEGIN CERTIFICATE-----
MIIFfjCCA2agAwIBAgICEAAwDQYJKoZIhvcNAQELBQAwSjELMAkGA1UEBhMCQ0gx
DDAKBgNVBAgMA1p1ZzEVMBMGA1UECgwMQ3J5cHRvIFZhbGx5MRYwFAYDVQQDDA1D
ViBSb290IENBIHYzMB4XDTE3MDkxMTA4Mjk0MFoXDTI3MDkwOTA4Mjk0MFowUjEL
MAkGA1UEBhMCQ0gxDDAKBgNVBAgMA1p1ZzEVMBMGA1UECgwMQ3J5cHRvIFZhbGx5
MR4wHAYDVQQDDBVDViBJbnRlcm1lZGlhdGUgQ0EgdjMwggIiMA0GCSqGSIb3DQEB
AQUAA4ICDwAwggIKAoICAQCpbBbK49j5/ib4YpUnI58bWn+Znu0dFkjgjNWzhMa6
DTqAWa1LWjoDtajRwfKdhLoArJLeG6Z+fcC+kZcPjHxODz+3iBT+Wk6CZpL/aK9R
wwrW1exQtbck/KcGxI6jT2wjGJZA8qXlbbmF6uWaLIMCGFEnYOX0cVRhDab4DUbk
7Sy+LqUpskOskTp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3eZIr4lgHd5NJhAEYlUCECmd1
Z9DKgorx1UWfZlYH0+uwZnS+XZJbY1+uEIqC8sOm1CPTXitG82rtx9By8/8zSomF
sLFvJE5O4LGmaA9zHgHQBAnthGlL68DlV6AJ2RZ0ZqrmKcsUgrFpTFg8VFcG9QiX
aGO9AMVKT9g6V0D2tIbFxjqLgdtbDRAD8/Cv3UyQpOxn7EH+yZEV7eYWN6+90dBe
fLkSM+vM6Ctrrv0zsEDf9zGCXQ/wIky5DQkDJq2A59Qg1hblbb+V+Ewg9Yn6W4gU
URAdKA40oMEYEt9bt+2lAy/Q
-----END CERTIFICATE-----
Bag Attributes
friendlyName: vally-ca
subject=/C=CH/ST=Zug/O=Crypto Vally/CN=CV Root CA v3
issuer=/C=CH/ST=Zug/O=Crypto Vally/CN=CV Root CA v3
-----BEGIN CERTIFICATE-----
MIIFejCCA2KgAwIBAgIJAMPsofzqoWBVMA0GCSqGSIb3DQEBCwUAMEoxCzAJBgNV
BAYTAkNIMQwwCgYDVQQIDANadWcxFTATBgNVBAoMDENyeXB0byBWYWxseTEWMBQG
A1UEAwwNQ1YgUm9vdCBDQSB2MzAeFw0xNzA5MTEwODI5MDFaFw0zNzA5MDYwODI5
MDFaMEoxCzAJBgNVBAYTAkNIMQwwCgYDVQQIDANadWcxFTATBgNVBAoMDENyeXB0
byBWYWxseTEWMBQGA1UEAwwNQ1YgUm9vdCBDQSB2MzCCAiIwDQYJKoZIhvcNAQEB
BQADggIPADCCAgoCggIBAM93vldqDimKC3kRzQAOXJg+zM6uJNBelMba2ekZh48D
RZwoGUtW83x6pfiLr/jk43fCEul/cLZRVlinb7+8DruImr22WFG7gI/qFW5xic+I
vyLZHHlwm3Pz3QmVhfVtfd7ACbJq8VYC0w5GY5pXnW6+q31tqMQqr7Ppz2t1RtC5
wYKKY/zYbKkW/DOWcac6kr4lyUKVuIBSHnptgpamWmx/8qgMHYge77Xr/0uYWps3
R9umGIMW3Jas59D47WbHQQgPGuyHASwrjO5VrGkGFF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w2RMK/5HqO+pj3rBRh3TgQlJAEGWV+A2w7cQ+KJOSvPtx5hKb
QId8jf/oOFu85LZtmTYFXEbumQNVlTw/q0yDAV3LMe2HgztIc1qFErzsrqX5SuR/
rru5AWuLoMM4K+kKr8WkkgrD31BL+SnRO8BMjZuiPncxWnNUonSqRw58SH5St4Bk
D9vIMsVTPxxnOIRWskE=
-----END CERTIFICATE-----
Bag Attributes: <No Attributes>
subject=/C=US/O=Internet Security Research Group/CN=ISRG Root X1
issuer=/C=US/O=Internet Security Research Group/CN=ISRG Root X1
-----BEGIN CERTIFICATE-----
MIIFazCCA1OgAwIBAgIRAIIQz7DSQONZRGPgu2OCiwAwDQYJKoZIhvcNAQELBQAw
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTUwNjA0MTEwNDM4
WhcNMzUwNjA0MTEwNDM4WjBPMQswCQYDVQQGEwJVUzEpMCcGA1UEChMgSW50ZXJu
ZXQgU2VjdXJpdHkgUmVzZWFyY2ggR3JvdXAxFTATBgNVBAMTDElTUkcgUm9vdCBY
MTCCAiIwDQYJKoZIhvcNAQEBBQADggIPADCCAgoCggIBAK3oJHP0FDfzm54rVygc
h77ct984kIxuPOZXoHj3dcKi/vVqbvYATyjb3miGbESTtrFj/RQSa78f0uoxmyF+
0TM8ukj13Xnfs7j/EvEhmkvBioZxaUpmZmyPfjxwv60pIgbz5MDmgK7iS4+3mX6U
A5/TR5d8mUgjU+g4rk8Kb4Mu0UlXjIB0ttov0DiNewNwIRt18jA8+o+u3dpjq+sW
T8KOEUt+zwvo/7V3LvSye0rgTBIlDHCNAymg4VMk7BPZ7hm/ELNKjD+Jo2FR3qyH
B5T0Y3HsLuJvW5iB4YlcNHlsdu87kGJ55tukmi8mxdAQ4Q7e2RCOFvu396j3x+UC
B5iPNgiV5+I3lg02dZ77DnKxHZu8A/lJ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EEzwxA57d
emyPxgcYxn/eR44/KJ4EBs+lVDR3veyJm+kXQ99b21/+jh5Xos1AnX5iItreGCc=
-----END CERTIFICATE-----
Bag Attributes: <No Attributes>
subject=/C=US/O=Let's Encrypt/CN=Let's Encrypt Authority X3
issuer=/O=Digital Signature Trust Co./CN=DST Root CA X3
-----BEGIN CERTIFICATE-----
MIIEkjCCA3qgAwIBAgIQCgFBQgAAAVOFc2oLheynCDANBgkqhkiG9w0BAQsFADA/
MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT
DkRTVCBSb290IENBIFgzMB4XDTE2MDMxNzE2NDA0NloXDTIxMDMxNzE2NDA0Nlow
SjELMAkGA1UEBhMCVVMxFjAUBgNVBAoTDUxldCdzIEVuY3J5cHQxIzAhBgNVBAMT
GkxldCdzIEVuY3J5cHQgQXV0aG9yaXR5IFgzMIIBIjANBgkqhkiG9w0BAQEFAAOC
AQ8AMIIBCgKCAQEAnNMM8FrlLke3cl03g7NoYzDq1zUmGSXhvb418XCSL7e4S0EF
q6meNQhY7LEqxGiHC6PjdeTm86dicbp5gWAf15Gan/PQeGdxyGkOlZHP/uaZ6WA8
SMx+yk13EiSdRxta67nsHjcAHJyse6cF6s5K671B5TaYucv9bTyWaN8jKkKQDIZ0
Z8h/pZq4UmEUEz9l6YKHy9v6Dlb2honzhT+Xhq+w3Brvaw2VFn3EK6BlspkENnWA
a6xK8xuQSXgvopZPKiAlKQTGdMDQMc2PMTiVFrqoM7hD8bEfwzB/onkxEz0tNvjj
/PIzark5McWvxI0NHWQWM6r6hCm21AvA2H3DkwIDAQABo4IBfTCCAXkwEgYDVR0T
AQH/BAgwBgEB/wIBADAOBgNVHQ8BAf8EBAMCAYYwfwYIKwYBBQUHAQEEczBxMDIG
CCsGAQUFBzABhiZodHRwOi8vaXNyZy50cnVzdGlkLm9jc3AuaWRlbnRydXN0LmNv
bTA7BggrBgEFBQcwAoYvaHR0cDovL2FwcHMuaWRlbnRydXN0LmNvbS9yb290cy9k
c3Ryb290Y2F4My5wN2MwHwYDVR0jBBgwFoAUxKexpHsscfrb4UuQdf/EFWCFiRAw
VAYDVR0gBE0wSzAIBgZngQwBAgEwPwYLKwYBBAGC3xMBAQEwMDAuBggrBgEFBQcC
ARYiaHR0cDovL2Nwcy5yb290LXgxLmxldHNlbmNyeXB0Lm9yZzA8BgNVHR8ENTAz
MDGgL6AthitodHRwOi8vY3JsLmlkZW50cnVzdC5jb20vRFNUUk9PVENBWDNDUkwu
Y3JsMB0GA1UdDgQWBBSoSmpjBH3duubRObemRWXv86jsoTANBgkqhkiG9w0BAQsF
AAOCAQEA3TPXEfNjWDjdGBX7CVW+dla5cEilaUcne8IkCJLxWh9KEik3JHRRHGJo
uM2VcGfl96S8TihRzZvoroed6ti6WqEBmtzw3Wodatg+VyOeph4EYpr/1wXKtx8/
wApIvJSwtmVi4MFU5aMqrSDE6ea73Mj2tcMyo5jMd6jmeWUHK8so/joWUoHOUgwu
X4Po1QYz+3dszkDqMp4fklxBwXRsW10KXzPMTZ+sOPAveyxindmjkW8lGy+QsRlG
PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6
KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg==
-----END CERTIFICATE-----
Bag Attributes: <No Attributes>
subject=/C=US/O=Let's Encrypt/CN=Let's Encrypt Authority X3
issuer=/C=US/O=Internet Security Research Group/CN=ISRG Root X1
-----BEGIN CERTIFICATE-----
MIIFjTCCA3WgAwIBAgIRANOxciY0IzLc9AUoUSrsnGowDQYJKoZIhvcNAQELBQAw
TzELMAkGA1UEBhMCVVMxKTAnBgNVBAoTIEludGVybmV0IFNlY3VyaXR5IFJlc2Vh
cmNoIEdyb3VwMRUwEwYDVQQDEwxJU1JHIFJvb3QgWDEwHhcNMTYxMDA2MTU0MzU1
WhcNMjExMDA2MTU0MzU1WjBKMQswCQYDVQQGEwJVUzEWMBQG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xN8RI8L9QFXrWi4xXnA2EqA10yjHiR6H9cj6MFiOnb5In1eWsRM
UM2v3e9tNsCAgBukPHAg1lQh07rvFKm/Bz9BCjaxorALINUfZ9DD64j2igLIxle2
DPxW8dI/F2loHMjXZjqG8RkqZUdoxtID5+90FgsGIfkMpqgRS05f4zPbCEHqCXl1
eO5HyELTgcVlLXXQDgAWnRzut1hFJeczY1tjQQno6f6s+nMydLN26WuU4s3UYvOu
OsUxRlJu7TSRHqDC3lSE5XggVkzdaPkuKGQbGpny+01/47hfXXNB7HntWNZ6N2Vw
p7G6OfY+YQrZwIaQmhrIqJZuigsrbe3W+gdn5ykE9+Ky0VgVUsfxo52mwFYs1JKY
2PGDuWx8M6DlS6qQkvHaRUo0FMd8TsSlbF0/v965qGFKhSDeQoMpYnwcmQilRh/0
ayLThlHLN81gSkJjVrPI0Y8xCVPB4twb1PFUd2fPM3sA1tJ83sZ5v8vgFv2yofKR
PB0t6JzUA81mSqM3kxl5e+IZwhYAyO0OTg3/fs8HqGTNKd9BqoUwSRBzp06JMg5b
rUCGwbCUDI0mxadJ3Bz4WxR6fyNpBK2yAinWEsikxqEt
-----END CERTIFICATE-----

View File

@ -0,0 +1,137 @@
Bag Attributes
friendlyName: vally
localKeyID: ED 49 E2 A7 BA 66 AF 36 58 98 85 03 44 85 AE 96 38 03 61 70
subject=/C=CH/ST=Zug/O=Crypto Vally/CN=CV Server
issuer=/C=CH/ST=Zug/O=Crypto Vally/CN=CV Intermediate CA v3
-----BEGIN CERTIFICATE-----
MIIFJjCCAw6gAwIBAgICEAAwDQYJKoZIhvcNAQELBQAwUjELMAkGA1UEBhMCQ0gx
DDAKBgNVBAgMA1p1ZzEVMBMGA1UECgwMQ3J5cHRvIFZhbGx5MR4wHAYDVQQDDBVD
ViBJbnRlcm1lZGlhdGUgQ0EgdjMwHhcNMTcwOTExMDgzMzM0WhcNMTgwOTIxMDgz
MzM0WjBGMQswCQYDVQQGEwJDSDEMMAoGA1UECAwDWnVnMRUwEw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DRCUAQPqz+hwXic/lbgpd0U0KKA2hGFQggmEzfgwZtmR8/5ppnQj7s2ic
WOusuzedXKfZWd8eLcCHVxW3jzNiFQznHHQiiB8a0YIxQwm9oJPET+swblsgNFQY
Fl/5Utm3kJEH6v8Kuln8vaOCK6ALOGiMXi82ZMHCgZeF3IUdT0bw6MmBja3aycHr
tUhQgaaUycOwktKRYh9/VLVmqpaU1Mg6xU2huWXK7y2M9e+RgvmeI6IGb45+3Xxk
AGUaV+7xtO7OlGSfCw18Llziz9aXGTVjXoutsixJJLgC2UuyyHsTcS5WAFjJGrgS
uGHy/C6BY17SAVTZ0ljsmTjm7uF/kLMlsvNrIMHFY9cO0hs980LFqaBf4hiNViay
jGvzyDHzn2qSM2I/O0U3qYXjqjEMEthX6iTb3nVZaowP8TOIGCtT8GkupBOpQLsw
uHEshBWQgBjpucUmigEQsbCbr7KjG5pBi3A=
-----END CERTIFICATE-----
Bag Attributes: <No Attributes>
subject=/C=CH/ST=Zug/O=Crypto Vally/CN=CV Intermediate CA v3
issuer=/C=CH/ST=Zug/O=Crypto Vally/CN=CV Root CA v3
-----BEGIN CERTIFICATE-----
MIIFfjCCA2agAwIBAgICEAAwDQYJKoZIhvcNAQELBQAwSjELMAkGA1UEBhMCQ0gx
DDAKBgNVBAgMA1p1ZzEVMBMGA1UECgwMQ3J5cHRvIFZhbGx5MRYwFAYDVQQDDA1D
ViBSb290IENBIHYzMB4XDTE3MDkxMTA4Mjk0MFoXDTI3MDkwOTA4Mjk0MFowUjEL
MAkGA1UEBhMCQ0gxDDAKBgNVBAgMA1p1ZzEVMBMGA1UECgwMQ3J5cHRvIFZhbGx5
MR4wHAYDVQQDDBVDViBJbnRlcm1lZGlhdGUgQ0EgdjMwggIiMA0GCSqGSIb3DQEB
AQUAA4ICDwAwggIKAoICAQCpbBbK49j5/ib4YpUnI58bWn+Znu0dFkjgjNWzhMa6
DTqAWa1LWjoDtajRwfKdhLoArJLeG6Z+fcC+kZcPjHxODz+3iBT+Wk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GTfKe7Wx6w9Gep4eFRySQafAgnSxq/5uhnF8eju0axS4QK8O9m
9WK3Dw9kvSpGhHWX9rAhybKUX/Xnz/ka6KeIckP3eZIr4lgHd5NJhAEYlUCECmd1
Z9DKgorx1UWfZlYH0+uwZnS+XZJbY1+uEIqC8sOm1CPTXitG82rtx9By8/8zSomF
sLFvJE5O4LGmaA9zHgHQBAnthGlL68DlV6AJ2RZ0ZqrmKcsUgrFpTFg8VFcG9QiX
aGO9AMVKT9g6V0D2tIbFxjqLgdtbDRAD8/Cv3UyQpOxn7EH+yZEV7eYWN6+90dBe
fLkSM+vM6Ctrrv0zsEDf9zGCXQ/wIky5DQkDJq2A59Qg1hblbb+V+Ewg9Yn6W4gU
URAdKA40oMEYEt9bt+2lAy/Q
-----END CERTIFICATE-----
Bag Attributes: <No Attributes>
subject=/C=CH/ST=Zug/O=Crypto Vally/CN=CV Root CA v3
issuer=/C=CH/ST=Zug/O=Crypto Vally/CN=CV Root CA v3
-----BEGIN CERTIFICATE-----
MIIFejCCA2KgAwIBAgIJAMPsofzqoWBVMA0GCSqGSIb3DQEBCwUAMEoxCzAJBgNV
BAYTAkNIMQwwCgYDVQQIDANadWcxFTATBgNVBAoMDENyeXB0byBWYWxseTEWMBQG
A1UEAwwNQ1YgUm9vdCBDQSB2MzAeFw0xNzA5MTEwODI5MDFaFw0zNzA5MDYwODI5
MDFaMEoxCzAJBgNVBAYTAkNIMQwwCgYDVQQIDANadWcxFTATBgNVBAoMDENyeXB0
byBWYWxseTEWMBQGA1UEAwwNQ1YgUm9vdCBDQSB2MzCCAiIwDQYJKoZIhvcNAQEB
BQADggIPADCCAgoCggIBAM93vldqDimKC3kRzQAOXJg+zM6uJNBelMba2ekZh48D
RZwoGUtW83x6pfiLr/jk43fCEul/cLZRVlinb7+8DruImr22WFG7gI/qFW5xic+I
vyLZHHlwm3Pz3QmVhfVtfd7ACbJq8VYC0w5GY5pXnW6+q31tqMQqr7Ppz2t1RtC5
wYKKY/zYbKkW/DO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Bxtj09
TPPH5vA6gWtBQhhZfcoe4Szdnp3fBWkGvJhtB73jz0kkegn1eakHNUMrRj0Bdhcz
YXU2BiveoNkHFOTw2RMK/5HqO+pj3rBRh3TgQlJAEGWV+A2w7cQ+KJOSvPtx5hKb
QId8jf/oOFu85LZtmTYFXEbumQNVlTw/q0yDAV3LMe2HgztIc1qFErzsrqX5SuR/
rru5AWuLoMM4K+kKr8WkkgrD31BL+SnRO8BMjZuiPncxWnNUonSqRw58SH5St4Bk
D9vIMsVTPxxnOIRWskE=
-----END CERTIFICATE-----
Bag Attributes
friendlyName: vally
localKeyID: ED 49 E2 A7 BA 66 AF 36 58 98 85 03 44 85 AE 96 38 03 61 70
Key Attributes: <No Attributes>
-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDXPX+EQwbPNE83
1bXBLa0Nh03piHD+QAOVtScvG7yhA4qsEfkMQGNdb3sbUXPEnP6ih3f6OqyyK3Sw
FIoGFoOz6g4A+0XTMV3FKbPIPoaUFZldOkJNqY3NvUjUAcWhgUhGS11wQWXKgCOZ
yrL6pPLYhoE719jey+x7Fa7bilmDHI1YQxMgd/A6ZMrXFfVWeIloYT5G/A1C7TyI
/1mOnvwuom+8ZBGtUtw3fxpf9HSdr9xZKNNOKMY2eJJe2FxNYethur00t2AqYhux
7ZE8GO8SV970yUKObkxkLXTvTC0zkfKf6GRYJ6hvgY5RtXq4PF+8lk/AonRbyyxv
O3grFii1AgMBAAECggEBAIgkaPzSnIMBNj492ennpzcQZzKYz8ex29Kcs70zURuT
Luppr9qU+4TFF9wOqCgrmVBaWYQYCtXjcLpTM35oTUPGfrcWOHM+HW6xUvsMuXj/
NHNofzm6TmxdFqyqtkPSj1GPJ/nyE52DcYE8Wfr5zHUylpmwjIdX+ytbaq+IkdfA
VLMuD+dObu5T1tDnLF7ZUF5TY+P8P0C53JwG+o6Mhf2T8m7HeXVD5PcN8gR7OXpZ
Tczay/Iyq80LNh/fzCWI6SN3jnB/PVzNr0fnr043RNnGgFI+X6zO1WqVmKFJRbR0
80KvkN663OBXlLccErFZEWSlDqD42Pyx3qx9V1Du150CgYEA/fi6EEWMB96DBYCE
a9G0mlOq5xyiSiCyh2UDKllQpHltd4eYvYkYDLgxf+izw1uuJm4om9Xwi6rmOyHT
GnaSoRYThDb9e4Er3/T+SHfie8ixzOCPJsIKY5T3F5BFGyzJ4HF677XORd2gUfN6
RJUiDiDgPoe9Nt1tLg78xwFjeNcCgYEA2PWUqgQRYuXkGSMstiZoxgVnfpBacj61
9zb4va8PEDlOCu67W1/1aC28Ru/xOvctbWCphIeWSlHSqMmcML4n9mWP4RFauh3V
OCC3Fy0rup3L0/v29HIniOFTVV5GWKvwh5IamwbHj7gJVYYEKawJkmx1WDYdDMuN
Mry7SyUzfVMCgYA1QeZKqTrfH5McIUIjlfsobakmA8QohUjKyazrQYV+qBQDf8TQ
4iHP8QQ4TWT874nKd0k+vJNPxou3FLW/E+RVsVpwXFO1hXXc5fQ44CL3UDOwwdpj
B0fEcCWMpG1JcI/45/Met2JFFl+bL9KQ9TEKA2ziz/YmvjI5+VyaorjoSwKBgQCW
C2FBI4cSqoLRj64AWxfiuyIUOakTkaMu0Wm9ZTA5vCfpD6mrS/XgkqC/PnnKmd9k
4ZDbAxpBU80oxiWq4BerJBoZQXNJfBBVvOpisO6pJTAt7vefnsMQuyRyybxE3sR+
PeEAjfO9xT1PVFvUphIIndGZq/LzQmLoT/YHxjaR2QKBgGH2jML4xgh1tDbuRH0/
2ywEBeG/T36w9RJ0/BLcCIK0AT31T5B5MGBzKCg3Lv48tIsRgVHjsMJ+KeXiGZ8S
UjDcYc2ybTUND+2zXzoan8EFsE3YnBOAzSFDhknPokj1b2+wpgYi972HacaVdUBg
InZ2KnKbFAQMeYww5jeBHAto
-----END PRIVATE KEY-----

View File

@ -11,11 +11,10 @@
#include "PKCS12ContainerTest.h"
#include "CppUnit/TestCaller.h"
#include "CppUnit/TestSuite.h"
#include "Poco/Crypto/X509Certificate.h"
#include "Poco/Crypto/PKCS12Container.h"
#include "Poco/Environment.h"
#include "Poco/Path.h"
#include "Poco/File.h"
#include "Poco/TemporaryFile.h"
#include <iostream>
#include <sstream>
#include <fstream>
@ -25,6 +24,7 @@ using namespace Poco::Crypto;
using Poco::Environment;
using Poco::Path;
using Poco::File;
using Poco::TemporaryFile;
PKCS12ContainerTest::PKCS12ContainerTest(const std::string& name): CppUnit::TestCase(name)
@ -83,8 +83,16 @@ void PKCS12ContainerTest::full(const PKCS12Container& pkcs12)
assert (EVP_PKEY_RSA == pKey.type());
assert (pkcs12.hasX509Certificate());
X509Certificate x509 = pkcs12.getX509Certificate();
fullCert(pkcs12.getX509Certificate());
std::vector<int> certOrder;
for (int i = 0; i < 2; ++i) certOrder.push_back(i);
fullList(pkcs12.getCACerts(), certOrder);
}
void PKCS12ContainerTest::fullCert(const X509Certificate& x509)
{
std::string subjectName(x509.subjectName());
std::string issuerName(x509.issuerName());
std::string commonName(x509.commonName());
@ -106,31 +114,34 @@ void PKCS12ContainerTest::full(const PKCS12Container& pkcs12)
assert (organizationUnitName.empty());
assert (emailAddress.empty());
assert (serialNumber.empty());
}
PKCS12Container::CAList caList = pkcs12.getCACerts();
assert (2 == caList.size());
assert (caList[0].subjectName() == "/C=CH/ST=Zug/O=Crypto Vally/CN=CV Root CA v3");
assert (caList[0].issuerName() == "/C=CH/ST=Zug/O=Crypto Vally/CN=CV Root CA v3");
assert (caList[0].commonName() == "CV Root CA v3");
assert (caList[0].subjectName(X509Certificate::NID_COUNTRY) == "CH");
assert (caList[0].subjectName(X509Certificate::NID_LOCALITY_NAME).empty());
assert (caList[0].subjectName(X509Certificate::NID_STATE_OR_PROVINCE) == "Zug");
assert (caList[0].subjectName(X509Certificate::NID_ORGANIZATION_NAME) == "Crypto Vally");
assert (caList[0].subjectName(X509Certificate::NID_ORGANIZATION_UNIT_NAME).empty());
assert (caList[0].subjectName(X509Certificate::NID_PKCS9_EMAIL_ADDRESS).empty());
assert (caList[0].subjectName(X509Certificate::NID_SERIAL_NUMBER).empty());
void PKCS12ContainerTest::fullList(const PKCS12Container::CAList& caList, const std::vector<int>& certOrder)
{
assert (certOrder.size() == caList.size());
assert (caList[1].subjectName() == "/C=CH/ST=Zug/O=Crypto Vally/CN=CV Intermediate CA v3");
assert (caList[1].issuerName() == "/C=CH/ST=Zug/O=Crypto Vally/CN=CV Root CA v3");
assert (caList[1].commonName() == "CV Intermediate CA v3");
assert (caList[1].subjectName(X509Certificate::NID_COUNTRY) == "CH");
assert (caList[1].subjectName(X509Certificate::NID_LOCALITY_NAME).empty());
assert (caList[1].subjectName(X509Certificate::NID_STATE_OR_PROVINCE) == "Zug");
assert (caList[1].subjectName(X509Certificate::NID_ORGANIZATION_NAME) == "Crypto Vally");
assert (caList[1].subjectName(X509Certificate::NID_ORGANIZATION_UNIT_NAME).empty());
assert (caList[1].subjectName(X509Certificate::NID_PKCS9_EMAIL_ADDRESS).empty());
assert (caList[1].subjectName(X509Certificate::NID_SERIAL_NUMBER).empty());
assert (caList[certOrder[0]].subjectName() == "/C=CH/ST=Zug/O=Crypto Vally/CN=CV Root CA v3");
assert (caList[certOrder[0]].issuerName() == "/C=CH/ST=Zug/O=Crypto Vally/CN=CV Root CA v3");
assert (caList[certOrder[0]].commonName() == "CV Root CA v3");
assert (caList[certOrder[0]].subjectName(X509Certificate::NID_COUNTRY) == "CH");
assert (caList[certOrder[0]].subjectName(X509Certificate::NID_LOCALITY_NAME).empty());
assert (caList[certOrder[0]].subjectName(X509Certificate::NID_STATE_OR_PROVINCE) == "Zug");
assert (caList[certOrder[0]].subjectName(X509Certificate::NID_ORGANIZATION_NAME) == "Crypto Vally");
assert (caList[certOrder[0]].subjectName(X509Certificate::NID_ORGANIZATION_UNIT_NAME).empty());
assert (caList[certOrder[0]].subjectName(X509Certificate::NID_PKCS9_EMAIL_ADDRESS).empty());
assert (caList[certOrder[0]].subjectName(X509Certificate::NID_SERIAL_NUMBER).empty());
assert (caList[certOrder[1]].subjectName() == "/C=CH/ST=Zug/O=Crypto Vally/CN=CV Intermediate CA v3");
assert (caList[certOrder[1]].issuerName() == "/C=CH/ST=Zug/O=Crypto Vally/CN=CV Root CA v3");
assert (caList[certOrder[1]].commonName() == "CV Intermediate CA v3");
assert (caList[certOrder[1]].subjectName(X509Certificate::NID_COUNTRY) == "CH");
assert (caList[certOrder[1]].subjectName(X509Certificate::NID_LOCALITY_NAME).empty());
assert (caList[certOrder[1]].subjectName(X509Certificate::NID_STATE_OR_PROVINCE) == "Zug");
assert (caList[certOrder[1]].subjectName(X509Certificate::NID_ORGANIZATION_NAME) == "Crypto Vally");
assert (caList[certOrder[1]].subjectName(X509Certificate::NID_ORGANIZATION_UNIT_NAME).empty());
assert (caList[certOrder[1]].subjectName(X509Certificate::NID_PKCS9_EMAIL_ADDRESS).empty());
assert (caList[certOrder[1]].subjectName(X509Certificate::NID_SERIAL_NUMBER).empty());
}
@ -157,65 +168,107 @@ void PKCS12ContainerTest::certsOnly(const PKCS12Container& pkcs12)
assert (!pkcs12.hasKey());
assert (!pkcs12.hasX509Certificate());
PKCS12Container::CAList caList = pkcs12.getCACerts();
std::vector<int> certOrder;
for (int i = 0; i < 5; ++i) certOrder.push_back(i);
certsOnlyList(pkcs12.getCACerts(), certOrder);
}
assert (5 == caList.size());
assert (caList[0].subjectName() == "/C=US/O=Let's Encrypt/CN=Let's Encrypt Authority X3");
assert (caList[0].issuerName() == "/C=US/O=Internet Security Research Group/CN=ISRG Root X1");
assert (caList[0].commonName() == "Let's Encrypt Authority X3");
assert (caList[0].subjectName(X509Certificate::NID_COUNTRY) == "US");
assert (caList[0].subjectName(X509Certificate::NID_LOCALITY_NAME).empty());
assert (caList[0].subjectName(X509Certificate::NID_STATE_OR_PROVINCE).empty());
assert (caList[0].subjectName(X509Certificate::NID_ORGANIZATION_NAME) == "Let's Encrypt");
assert (caList[0].subjectName(X509Certificate::NID_ORGANIZATION_UNIT_NAME).empty());
assert (caList[0].subjectName(X509Certificate::NID_PKCS9_EMAIL_ADDRESS).empty());
assert (caList[0].subjectName(X509Certificate::NID_SERIAL_NUMBER).empty());
void PKCS12ContainerTest::certsOnlyList(const PKCS12Container::CAList& caList, const std::vector<int>& certOrder)
{
assert (certOrder.size() == caList.size());
assert (caList[1].subjectName() == "/C=US/O=Let's Encrypt/CN=Let's Encrypt Authority X3");
assert (caList[1].issuerName() == "/O=Digital Signature Trust Co./CN=DST Root CA X3");
assert (caList[1].commonName() == "Let's Encrypt Authority X3");
assert (caList[1].subjectName(X509Certificate::NID_COUNTRY) == "US");
assert (caList[1].subjectName(X509Certificate::NID_LOCALITY_NAME).empty());
assert (caList[1].subjectName(X509Certificate::NID_STATE_OR_PROVINCE).empty());
assert (caList[1].subjectName(X509Certificate::NID_ORGANIZATION_NAME) == "Let's Encrypt");
assert (caList[1].subjectName(X509Certificate::NID_ORGANIZATION_UNIT_NAME).empty());
assert (caList[1].subjectName(X509Certificate::NID_PKCS9_EMAIL_ADDRESS).empty());
assert (caList[1].subjectName(X509Certificate::NID_SERIAL_NUMBER).empty());
assert (caList[certOrder[0]].subjectName() == "/C=US/O=Let's Encrypt/CN=Let's Encrypt Authority X3");
assert (caList[certOrder[0]].issuerName() == "/C=US/O=Internet Security Research Group/CN=ISRG Root X1");
assert (caList[certOrder[0]].commonName() == "Let's Encrypt Authority X3");
assert (caList[certOrder[0]].subjectName(X509Certificate::NID_COUNTRY) == "US");
assert (caList[certOrder[0]].subjectName(X509Certificate::NID_LOCALITY_NAME).empty());
assert (caList[certOrder[0]].subjectName(X509Certificate::NID_STATE_OR_PROVINCE).empty());
assert (caList[certOrder[0]].subjectName(X509Certificate::NID_ORGANIZATION_NAME) == "Let's Encrypt");
assert (caList[certOrder[0]].subjectName(X509Certificate::NID_ORGANIZATION_UNIT_NAME).empty());
assert (caList[certOrder[0]].subjectName(X509Certificate::NID_PKCS9_EMAIL_ADDRESS).empty());
assert (caList[certOrder[0]].subjectName(X509Certificate::NID_SERIAL_NUMBER).empty());
assert (caList[2].subjectName() == "/C=US/O=Internet Security Research Group/CN=ISRG Root X1");
assert (caList[2].issuerName() == "/C=US/O=Internet Security Research Group/CN=ISRG Root X1");
assert (caList[2].commonName() == "ISRG Root X1");
assert (caList[2].subjectName(X509Certificate::NID_COUNTRY) == "US");
assert (caList[2].subjectName(X509Certificate::NID_LOCALITY_NAME).empty());
assert (caList[2].subjectName(X509Certificate::NID_STATE_OR_PROVINCE).empty());
assert (caList[2].subjectName(X509Certificate::NID_ORGANIZATION_NAME) == "Internet Security Research Group");
assert (caList[2].subjectName(X509Certificate::NID_ORGANIZATION_UNIT_NAME).empty());
assert (caList[2].subjectName(X509Certificate::NID_PKCS9_EMAIL_ADDRESS).empty());
assert (caList[2].subjectName(X509Certificate::NID_SERIAL_NUMBER).empty());
assert (caList[certOrder[1]].subjectName() == "/C=US/O=Let's Encrypt/CN=Let's Encrypt Authority X3");
assert (caList[certOrder[1]].issuerName() == "/O=Digital Signature Trust Co./CN=DST Root CA X3");
assert (caList[certOrder[1]].commonName() == "Let's Encrypt Authority X3");
assert (caList[certOrder[1]].subjectName(X509Certificate::NID_COUNTRY) == "US");
assert (caList[certOrder[1]].subjectName(X509Certificate::NID_LOCALITY_NAME).empty());
assert (caList[certOrder[1]].subjectName(X509Certificate::NID_STATE_OR_PROVINCE).empty());
assert (caList[certOrder[1]].subjectName(X509Certificate::NID_ORGANIZATION_NAME) == "Let's Encrypt");
assert (caList[certOrder[1]].subjectName(X509Certificate::NID_ORGANIZATION_UNIT_NAME).empty());
assert (caList[certOrder[1]].subjectName(X509Certificate::NID_PKCS9_EMAIL_ADDRESS).empty());
assert (caList[certOrder[1]].subjectName(X509Certificate::NID_SERIAL_NUMBER).empty());
assert (caList[3].subjectName() == "/C=CH/ST=Zug/O=Crypto Vally/CN=CV Root CA v3");
assert (caList[3].issuerName() == "/C=CH/ST=Zug/O=Crypto Vally/CN=CV Root CA v3");
assert (caList[3].commonName() == "CV Root CA v3");
assert (caList[3].subjectName(X509Certificate::NID_COUNTRY) == "CH");
assert (caList[3].subjectName(X509Certificate::NID_LOCALITY_NAME).empty());
assert (caList[3].subjectName(X509Certificate::NID_STATE_OR_PROVINCE) == "Zug");
assert (caList[3].subjectName(X509Certificate::NID_ORGANIZATION_NAME) == "Crypto Vally");
assert (caList[3].subjectName(X509Certificate::NID_ORGANIZATION_UNIT_NAME).empty());
assert (caList[3].subjectName(X509Certificate::NID_PKCS9_EMAIL_ADDRESS).empty());
assert (caList[3].subjectName(X509Certificate::NID_SERIAL_NUMBER).empty());
assert (caList[certOrder[2]].subjectName() == "/C=US/O=Internet Security Research Group/CN=ISRG Root X1");
assert (caList[certOrder[2]].issuerName() == "/C=US/O=Internet Security Research Group/CN=ISRG Root X1");
assert (caList[certOrder[2]].commonName() == "ISRG Root X1");
assert (caList[certOrder[2]].subjectName(X509Certificate::NID_COUNTRY) == "US");
assert (caList[certOrder[2]].subjectName(X509Certificate::NID_LOCALITY_NAME).empty());
assert (caList[certOrder[2]].subjectName(X509Certificate::NID_STATE_OR_PROVINCE).empty());
assert (caList[certOrder[2]].subjectName(X509Certificate::NID_ORGANIZATION_NAME) == "Internet Security Research Group");
assert (caList[certOrder[2]].subjectName(X509Certificate::NID_ORGANIZATION_UNIT_NAME).empty());
assert (caList[certOrder[2]].subjectName(X509Certificate::NID_PKCS9_EMAIL_ADDRESS).empty());
assert (caList[certOrder[2]].subjectName(X509Certificate::NID_SERIAL_NUMBER).empty());
assert (caList[4].subjectName() == "/C=CH/ST=Zug/O=Crypto Vally/CN=CV Intermediate CA v3");
assert (caList[4].issuerName() == "/C=CH/ST=Zug/O=Crypto Vally/CN=CV Root CA v3");
assert (caList[4].commonName() == "CV Intermediate CA v3");
assert (caList[4].subjectName(X509Certificate::NID_COUNTRY) == "CH");
assert (caList[4].subjectName(X509Certificate::NID_LOCALITY_NAME).empty());
assert (caList[4].subjectName(X509Certificate::NID_STATE_OR_PROVINCE) == "Zug");
assert (caList[4].subjectName(X509Certificate::NID_ORGANIZATION_NAME) == "Crypto Vally");
assert (caList[4].subjectName(X509Certificate::NID_ORGANIZATION_UNIT_NAME).empty());
assert (caList[4].subjectName(X509Certificate::NID_PKCS9_EMAIL_ADDRESS).empty());
assert (caList[4].subjectName(X509Certificate::NID_SERIAL_NUMBER).empty());
assert (caList[certOrder[3]].subjectName() == "/C=CH/ST=Zug/O=Crypto Vally/CN=CV Root CA v3");
assert (caList[certOrder[3]].issuerName() == "/C=CH/ST=Zug/O=Crypto Vally/CN=CV Root CA v3");
assert (caList[certOrder[3]].commonName() == "CV Root CA v3");
assert (caList[certOrder[3]].subjectName(X509Certificate::NID_COUNTRY) == "CH");
assert (caList[certOrder[3]].subjectName(X509Certificate::NID_LOCALITY_NAME).empty());
assert (caList[certOrder[3]].subjectName(X509Certificate::NID_STATE_OR_PROVINCE) == "Zug");
assert (caList[certOrder[3]].subjectName(X509Certificate::NID_ORGANIZATION_NAME) == "Crypto Vally");
assert (caList[certOrder[3]].subjectName(X509Certificate::NID_ORGANIZATION_UNIT_NAME).empty());
assert (caList[certOrder[3]].subjectName(X509Certificate::NID_PKCS9_EMAIL_ADDRESS).empty());
assert (caList[certOrder[3]].subjectName(X509Certificate::NID_SERIAL_NUMBER).empty());
assert (caList[certOrder[4]].subjectName() == "/C=CH/ST=Zug/O=Crypto Vally/CN=CV Intermediate CA v3");
assert (caList[certOrder[4]].issuerName() == "/C=CH/ST=Zug/O=Crypto Vally/CN=CV Root CA v3");
assert (caList[certOrder[4]].commonName() == "CV Intermediate CA v3");
assert (caList[certOrder[4]].subjectName(X509Certificate::NID_COUNTRY) == "CH");
assert (caList[certOrder[4]].subjectName(X509Certificate::NID_LOCALITY_NAME).empty());
assert (caList[certOrder[4]].subjectName(X509Certificate::NID_STATE_OR_PROVINCE) == "Zug");
assert (caList[certOrder[4]].subjectName(X509Certificate::NID_ORGANIZATION_NAME) == "Crypto Vally");
assert (caList[certOrder[4]].subjectName(X509Certificate::NID_ORGANIZATION_UNIT_NAME).empty());
assert (caList[certOrder[4]].subjectName(X509Certificate::NID_PKCS9_EMAIL_ADDRESS).empty());
assert (caList[certOrder[4]].subjectName(X509Certificate::NID_SERIAL_NUMBER).empty());
}
void PKCS12ContainerTest::testPEMReadWrite()
{
std::string file = getTestFilesPath("certs-only", "pem");
X509Certificate::List certsOnly = X509Certificate::readPEM(file);
assert (certsOnly.size() == 5);
// PEM is written by openssl in reverse order from p12
std::vector<int> certOrder;
for (int i = (int) certsOnly.size() - 1; i >= 0 ; --i) certOrder.push_back(i);
certsOnlyList(certsOnly, certOrder);
TemporaryFile tmpFile;
X509Certificate::writePEM(tmpFile.path(), certsOnly);
certsOnly.clear();
certsOnly = X509Certificate::readPEM(tmpFile.path());
certsOnlyList(certsOnly, certOrder);
file = getTestFilesPath("full", "pem");
X509Certificate::List full = X509Certificate::readPEM(file);
assert (full.size() == 3);
fullCert(full[0]);
full.erase(full.begin());
assert (full.size() == 2);
certOrder.clear();
for (int i = (int) full.size() - 1; i >= 0 ; --i) certOrder.push_back(i);
fullList(full, certOrder);
TemporaryFile tmpFile2;
X509Certificate::writePEM(tmpFile2.path(), full);
full.clear();
full = X509Certificate::readPEM(tmpFile2.path());
fullList(full, certOrder);
}
@ -229,10 +282,10 @@ void PKCS12ContainerTest::tearDown()
}
std::string PKCS12ContainerTest::getTestFilesPath(const std::string& name)
std::string PKCS12ContainerTest::getTestFilesPath(const std::string& name, const std::string& ext)
{
std::ostringstream ostr;
ostr << "data/" << name << ".p12";
ostr << "data/" << name << '.' << ext;
std::string fileName(ostr.str());
Poco::Path path(fileName);
if (Poco::File(path).exists())
@ -260,6 +313,7 @@ CppUnit::Test* PKCS12ContainerTest::suite()
CppUnit_addTest(pSuite, PKCS12ContainerTest, testFullPKCS12);
CppUnit_addTest(pSuite, PKCS12ContainerTest, testCertsOnlyPKCS12);
CppUnit_addTest(pSuite, PKCS12ContainerTest, testPEMReadWrite);
return pSuite;
}

View File

@ -16,14 +16,10 @@
#include "Poco/Crypto/Crypto.h"
#include "CppUnit/TestCase.h"
#include "Poco/Crypto/PKCS12Container.h"
#include "Poco/Crypto/X509Certificate.h"
namespace Poco {
namespace Crypto {
class PKCS12Container;
}
}
class PKCS12ContainerTest: public CppUnit::TestCase
{
public:
@ -32,6 +28,7 @@ public:
void testFullPKCS12();
void testCertsOnlyPKCS12();
void testPEMReadWrite();
void setUp();
void tearDown();
@ -39,9 +36,13 @@ public:
static CppUnit::Test* suite();
private:
std::string getTestFilesPath(const std::string& name);
std::string getTestFilesPath(const std::string& name,
const std::string& ext = "p12");
void certsOnly(const Poco::Crypto::PKCS12Container& pkcs12);
void certsOnlyList(const Poco::Crypto::PKCS12Container::CAList& caList, const std::vector<int>& certOrder);
void full(const Poco::Crypto::PKCS12Container& pkcs12);
void fullCert(const Poco::Crypto::X509Certificate& x509);
void fullList(const Poco::Crypto::PKCS12Container::CAList& caList, const std::vector<int>& certOrder);
};