diff options
author | dreijer <dreijer@echobit.net> | 2010-11-12 18:33:40 (GMT) |
---|---|---|
committer | Kevin Smith <git@kismith.co.uk> | 2011-11-03 18:49:22 (GMT) |
commit | 7b0795215f601a9561dbedbed3af32dbe9aba032 (patch) | |
tree | 554a6693de362fb3403a44a586f48865c4d949bf /Swiften/TLS/Schannel/SchannelContext.h | |
parent | 16d50c0df983e96a28a6572da27b3633b40a41d7 (diff) | |
download | swift-7b0795215f601a9561dbedbed3af32dbe9aba032.zip swift-7b0795215f601a9561dbedbed3af32dbe9aba032.tar.bz2 |
* Added Schannel support.
License: This patch is BSD-licensed, see http://www.opensource.org/licenses/bsd-license.php
Diffstat (limited to 'Swiften/TLS/Schannel/SchannelContext.h')
-rw-r--r-- | Swiften/TLS/Schannel/SchannelContext.h | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/Swiften/TLS/Schannel/SchannelContext.h b/Swiften/TLS/Schannel/SchannelContext.h new file mode 100644 index 0000000..66467fe --- /dev/null +++ b/Swiften/TLS/Schannel/SchannelContext.h @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2011 Soren Dreijer + * Licensed under the simplified BSD license. + * See Documentation/Licenses/BSD-simplified.txt for more information. + */ + +#pragma once + +#include "Swiften/Base/boost_bsignals.h" + +#include "Swiften/TLS/TLSContext.h" +#include "Swiften/TLS/Schannel/SchannelUtil.h" +#include "Swiften/Base/ByteArray.h" + +#define SECURITY_WIN32 +#include <Windows.h> +#include <Schannel.h> +#include <security.h> +#include <schnlsp.h> + +#include <boost/noncopyable.hpp> + +namespace Swift +{ + class SchannelContext : public TLSContext, boost::noncopyable + { + public: + typedef boost::shared_ptr<SchannelContext> sp_t; + + public: + SchannelContext(); + + // + // TLSContext + // + virtual void connect(); + virtual bool setClientCertificate(const PKCS12Certificate&); + + virtual void handleDataFromNetwork(const SafeByteArray& data); + virtual void handleDataFromApplication(const SafeByteArray& data); + + virtual Certificate::ref getPeerCertificate() const; + virtual CertificateVerificationError::ref getPeerCertificateVerificationError() const; + + virtual ByteArray getFinishMessage() const; + + private: + void determineStreamSizes(); + void continueHandshake(const SafeByteArray& data); + void indicateError(); + + void sendDataOnNetwork(const void* pData, size_t dataSize); + void forwardDataToApplication(const void* pData, size_t dataSize); + + void decryptAndProcessData(const SafeByteArray& data); + void encryptAndSendData(const SafeByteArray& data); + + void appendNewData(const SafeByteArray& data); + + private: + enum SchannelState + { + Start, + Connecting, + Connected, + Error + + }; + + SchannelState m_state; + CertificateVerificationError m_verificationError; + + ULONG m_secContext; + ScopedCredHandle m_credHandle; + ScopedCtxtHandle m_ctxtHandle; + DWORD m_ctxtFlags; + SecPkgContext_StreamSizes m_streamSizes; + + std::vector<char> m_receivedData; + }; +} |