diff options
Diffstat (limited to 'Swiften')
9 files changed, 272 insertions, 0 deletions
diff --git a/Swiften/TLS/PlatformTLSFactories.cpp b/Swiften/TLS/PlatformTLSFactories.cpp index 64a5ab3..4f2128c 100644 --- a/Swiften/TLS/PlatformTLSFactories.cpp +++ b/Swiften/TLS/PlatformTLSFactories.cpp @@ -18,6 +18,10 @@ #include "Swiften/TLS/Schannel/SchannelContextFactory.h" #include "Swiften/TLS/Schannel/SchannelCertificateFactory.h" #endif +#ifdef HAVE_SECURETRANSPORT + #include "Swiften/TLS/SecureTransport/SecureTransportContextFactory.h" + #include "Swiften/TLS/SecureTransport/SecureTransportCertificateFactory.h" +#endif namespace Swift { @@ -30,6 +34,10 @@ PlatformTLSFactories::PlatformTLSFactories() : contextFactory(NULL), certificate contextFactory = new SchannelContextFactory(); certificateFactory = new SchannelCertificateFactory(); #endif +#ifdef HAVE_SECURETRANSPORT + contextFactory = new SecureTransportContextFactory(); + certificateFactory = new SsecureTransportCertificateFactory(); +#endif } PlatformTLSFactories::~PlatformTLSFactories() { diff --git a/Swiften/TLS/SConscript b/Swiften/TLS/SConscript index fb327b9..f88d0a8 100644 --- a/Swiften/TLS/SConscript +++ b/Swiften/TLS/SConscript @@ -27,6 +27,15 @@ elif myenv.get("HAVE_SCHANNEL", 0) : "Schannel/SchannelContextFactory.cpp", ]) myenv.Append(CPPDEFINES = "HAVE_SCHANNEL") +elif myenv.get("HAVE_SECURETRANSPORT", 0) : + #swiften_env.Append(LIBS = ["Winscard"]) + myenv.MergeFlags(myenv["SECURETRANSPORT_FLAGS"]) + objects += myenv.StaticObject([ + "SecureTransport/SecureTransportContext.cpp", + "SecureTransport/SecureTransportCertificate.cpp", + "SecureTransport/SecureTransportContextFactory.cpp", + ]) + myenv.Append(CPPDEFINES = "HAVE_SECURETRANSPORT") objects += myenv.SwiftenObject(["PlatformTLSFactories.cpp"]) diff --git a/Swiften/TLS/SecureTransport/SecureTransportCertificate.cpp b/Swiften/TLS/SecureTransport/SecureTransportCertificate.cpp new file mode 100644 index 0000000..0ea8f83 --- /dev/null +++ b/Swiften/TLS/SecureTransport/SecureTransportCertificate.cpp @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2012 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/TLS/SecureTransport/SecureTransportCertificate.h> + +#include <Swiften/Base/ByteArray.h> +#include <Swiften/Base/Log.h> + +namespace Swift { + +} diff --git a/Swiften/TLS/SecureTransport/SecureTransportCertificate.h b/Swiften/TLS/SecureTransport/SecureTransportCertificate.h new file mode 100644 index 0000000..fe759a0 --- /dev/null +++ b/Swiften/TLS/SecureTransport/SecureTransportCertificate.h @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2012 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <boost/shared_ptr.hpp> + +#include <string> +#include <Swiften/TLS/Certificate.h> + +#include <Security/SecureTransport.h> + +namespace Swift { + class SecureTransportCertificate : public Certificate { + public: + SecureTransportCertificate(SecCertificateRef); + SecureTransportCertificate(const ByteArray& der); + + std::string getSubjectName() const { + return subjectName; + } + + std::vector<std::string> getCommonNames() const { + return commonNames; + } + + std::vector<std::string> getSRVNames() const { + return srvNames; + } + + std::vector<std::string> getDNSNames() const { + return dnsNames; + } + + std::vector<std::string> getXMPPAddresses() const { + return xmppAddresses; + } + + ByteArray toDER() const; + + private: + void parse(); + + void addSRVName(const std::string& name) { + srvNames.push_back(name); + } + + void addDNSName(const std::string& name) { + dnsNames.push_back(name); + } + + void addXMPPAddress(const std::string& addr) { + xmppAddresses.push_back(addr); + } + + private: + std::string subjectName; + std::vector<std::string> commonNames; + std::vector<std::string> dnsNames; + std::vector<std::string> xmppAddresses; + std::vector<std::string> srvNames; + }; +} diff --git a/Swiften/TLS/SecureTransport/SecureTransportCertificateFactory.h b/Swiften/TLS/SecureTransport/SecureTransportCertificateFactory.h new file mode 100644 index 0000000..8a8e009 --- /dev/null +++ b/Swiften/TLS/SecureTransport/SecureTransportCertificateFactory.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2012 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <Swiften/TLS/CertificateFactory.h> +#include <Swiften/TLS/SecureTransport/SecureTransportCertificate.h> + +namespace Swift { + class SecureTransportCertificateFactory : public CertificateFactory { + public: + virtual Certificate::ref createCertificateFromDER(const ByteArray& der) { + return Certificate::ref(new SecureTransportCertificate(der)); + } + }; +} diff --git a/Swiften/TLS/SecureTransport/SecureTransportContext.cpp b/Swiften/TLS/SecureTransport/SecureTransportContext.cpp new file mode 100644 index 0000000..1d073e0 --- /dev/null +++ b/Swiften/TLS/SecureTransport/SecureTransportContext.cpp @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2012 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ +#include <Swiften/Base/Platform.h> + +#include <vector> +#include <boost/smart_ptr/make_shared.hpp> + +#include <Swiften/TLS/SecureTransport/SecureTransportContext.h> +#include <Swiften/TLS/SecureTransport/SecureTransportCertificate.h> +#include <Swiften/TLS/CertificateWithKey.h> +#include <Swiften/TLS/PKCS12Certificate.h> + + +namespace Swift { + + +SecureTransportContext::SecureTransportContext() : state_(Start) { + assert(false); +} + +SecureTransportContext::~SecureTransportContext() { + assert(false); +} + +void SecureTransportContext::ensureLibraryInitialized() { + assert(false); +} + +void SecureTransportContext::connect() { + assert(false); +} + +void SecureTransportContext::doConnect() { + assert(false); +} + +void SecureTransportContext::handleDataFromNetwork(const SafeByteArray& data) { + assert(false); +} + +void SecureTransportContext::handleDataFromApplication(const SafeByteArray& data) { + assert(false); +} + +bool SecureTransportContext::setClientCertificate(CertificateWithKey::ref certificate) { + assert(false); +} + +std::vector<Certificate::ref> SecureTransportContext::getPeerCertificateChain() const { + assert(false); +} + +boost::shared_ptr<CertificateVerificationError> SecureTransportContext::getPeerCertificateVerificationError() const { + assert(false); +} + +ByteArray SecureTransportContext::getFinishMessage() const { + assert(false); +} + +CertificateVerificationError::Type SecureTransportContext::getVerificationErrorTypeForResult(int result) { + assert(false); +} + +} diff --git a/Swiften/TLS/SecureTransport/SecureTransportContext.h b/Swiften/TLS/SecureTransport/SecureTransportContext.h new file mode 100644 index 0000000..95fb929 --- /dev/null +++ b/Swiften/TLS/SecureTransport/SecureTransportContext.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2012 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <Security/SecureTransport.h> +#include <Swiften/Base/boost_bsignals.h> +#include <boost/noncopyable.hpp> + +#include <Swiften/TLS/TLSContext.h> +#include <Swiften/Base/ByteArray.h> +#include <Swiften/TLS/CertificateWithKey.h> + +namespace Swift { + + class SecureTransportContext : public TLSContext, boost::noncopyable { + public: + SecureTransportContext(); + ~SecureTransportContext(); + + void connect(); + bool setClientCertificate(CertificateWithKey::ref cert); + + void handleDataFromNetwork(const SafeByteArray&); + void handleDataFromApplication(const SafeByteArray&); + + std::vector<Certificate::ref> getPeerCertificateChain() const; + boost::shared_ptr<CertificateVerificationError> getPeerCertificateVerificationError() const; + + virtual ByteArray getFinishMessage() const; + + + private: + enum State { Start, Connecting, Connected, Error }; + + State state_; + + }; +} diff --git a/Swiften/TLS/SecureTransport/SecureTransportContextFactory.cpp b/Swiften/TLS/SecureTransport/SecureTransportContextFactory.cpp new file mode 100644 index 0000000..adc1a93 --- /dev/null +++ b/Swiften/TLS/SecureTransport/SecureTransportContextFactory.cpp @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2012 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#include <Swiften/TLS/SecureTransport/SecureTransportContextFactory.h> +#include <Swiften/TLS/SecureTransport/SecureTransportContext.h> +#include <Swiften/Base/Log.h> + +namespace Swift { + +bool SecureTransportContextFactory::canCreate() const { + return true; +} + +TLSContext* SecureTransportContextFactory::createTLSContext() { + return null; +} + +void SecureTransportContextFactory::setCheckCertificateRevocation(bool check) { + +} + +} diff --git a/Swiften/TLS/SecureTransport/SecureTransportContextFactory.h b/Swiften/TLS/SecureTransport/SecureTransportContextFactory.h new file mode 100644 index 0000000..f3ab1e7 --- /dev/null +++ b/Swiften/TLS/SecureTransport/SecureTransportContextFactory.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2012 Tobias Markmann + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include <Swiften/TLS/TLSContextFactory.h> + +#include <cassert> + +namespace Swift { + class SecureTransportContextFactory : public TLSContextFactory { + public: + bool canCreate() const; + virtual TLSContext* createTLSContext(); + + virtual void setCheckCertificateRevocation(bool b); + }; +} |