37
37
#include "Poco/Net/X509Certificate.h"
38
#include "Poco/Net/SSLException.h"
39
#include "Poco/Net/SSLManager.h"
40
#include "Poco/Net/SecureSocketImpl.h"
41
#include "Poco/TemporaryFile.h"
42
#include "Poco/FileStream.h"
43
#include "Poco/StreamCopier.h"
44
#include <openssl/pem.h>
44
X509Certificate::X509Certificate(X509* pCert):_pCert(pCert)
50
X509Certificate::X509Certificate(std::istream& str):
56
Poco::TemporaryFile certFile;
58
if (!certFile.createFile())
59
throw Poco::FileException("No temporary file could be created for X509Certificate!");
60
_file = certFile.path();
61
Poco::FileOutputStream fout(_file);
62
Poco::StreamCopier::copyStream(str, fout);
65
BIO *fp=BIO_new(BIO_s_file());
66
const char* pFN = _file.c_str();
67
BIO_read_filename(fp, (void*)pFN);
69
throw Poco::PathNotFoundException("Failed to open temporary file for X509Certificate");
72
_pCert = PEM_read_bio_X509(fp,0,0,0);
80
throw SSLException("Faild to load certificate from " + _file);
84
X509Certificate::X509Certificate(const std::string& file):
90
BIO *fp=BIO_new(BIO_s_file());
91
const char* pFN = file.c_str();
92
BIO_read_filename(fp, (void*)pFN);
94
throw Poco::PathNotFoundException("Failed to open " + file);
97
_pCert = PEM_read_bio_X509(fp,0,0,0);
105
throw SSLException("Faild to load certificate from " + file);
110
X509Certificate::X509Certificate(X509* pCert):
46
116
poco_check_ptr(_pCert);
121
X509Certificate::X509Certificate(const X509Certificate& cert):
122
_issuerName(cert._issuerName),
123
_subjectName(cert._subjectName),
128
_pCert = X509_dup(_pCert);
132
X509Certificate& X509Certificate::operator=(const X509Certificate& cert)
136
X509Certificate c(cert);
143
void X509Certificate::swap(X509Certificate& cert)
146
swap(cert._file, _file);
147
swap(cert._issuerName, _issuerName);
148
swap(cert._subjectName, _subjectName);
149
swap(cert._pCert, _pCert);
51
153
X509Certificate::~X509Certificate()
155
if (!_file.empty() && _pCert)