summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2010-11-09 20:25:49 (GMT)
committerRemko Tronçon <git@el-tramo.be>2010-11-09 21:41:52 (GMT)
commite9be6f9bb696da4e1bcf750afd7015de4fe9220a (patch)
tree3a062f59f1c06d9c792f680c6c6e2105cfeaba87 /Swiften/TLS/OpenSSL
parentb23637e59839f5f28258f518ac234b2ff62b6da2 (diff)
downloadswift-contrib-e9be6f9bb696da4e1bcf750afd7015de4fe9220a.zip
swift-contrib-e9be6f9bb696da4e1bcf750afd7015de4fe9220a.tar.bz2
Implement DER conversion to/from certificates.
Diffstat (limited to 'Swiften/TLS/OpenSSL')
-rw-r--r--Swiften/TLS/OpenSSL/OpenSSLCertificate.cpp19
-rw-r--r--Swiften/TLS/OpenSSL/OpenSSLCertificate.h5
2 files changed, 24 insertions, 0 deletions
diff --git a/Swiften/TLS/OpenSSL/OpenSSLCertificate.cpp b/Swiften/TLS/OpenSSL/OpenSSLCertificate.cpp
index 3f134e7..7f13f88 100644
--- a/Swiften/TLS/OpenSSL/OpenSSLCertificate.cpp
+++ b/Swiften/TLS/OpenSSL/OpenSSLCertificate.cpp
@@ -16,6 +16,25 @@
namespace Swift {
OpenSSLCertificate::OpenSSLCertificate(boost::shared_ptr<X509> cert) : cert(cert) {
+ parse();
+}
+
+
+OpenSSLCertificate::OpenSSLCertificate(const ByteArray& der) {
+ const unsigned char* p = reinterpret_cast<const unsigned char*>(der.getData());
+ cert = boost::shared_ptr<X509>(d2i_X509(NULL, &p, der.getSize()), X509_free);
+ parse();
+}
+
+ByteArray OpenSSLCertificate::toDER() const {
+ ByteArray result;
+ result.resize(i2d_X509(cert.get(), NULL));
+ unsigned char* p = reinterpret_cast<unsigned char*>(result.getData());
+ i2d_X509(cert.get(), &p);
+ return result;
+}
+
+void OpenSSLCertificate::parse() {
// Common name
X509_NAME* subjectName = X509_get_subject_name(cert.get());
if (subjectName) {
diff --git a/Swiften/TLS/OpenSSL/OpenSSLCertificate.h b/Swiften/TLS/OpenSSL/OpenSSLCertificate.h
index 4708120..fe2cddf 100644
--- a/Swiften/TLS/OpenSSL/OpenSSLCertificate.h
+++ b/Swiften/TLS/OpenSSL/OpenSSLCertificate.h
@@ -16,6 +16,7 @@ namespace Swift {
class OpenSSLCertificate : public Certificate {
public:
OpenSSLCertificate(boost::shared_ptr<X509>);
+ OpenSSLCertificate(const ByteArray& der);
String getCommonName() const {
return commonName;
@@ -33,7 +34,11 @@ namespace Swift {
return xmppAddresses;
}
+ ByteArray toDER() const;
+
private:
+ void parse();
+
void addSRVName(const String& name) {
srvNames.push_back(name);
}