13 #include "tlsschannelserver.h"
37 if( !m_handler || !m_valid )
40 if( m_haveCredentialsHandle )
47 SECURITY_STATUS error;
50 SecBuffer ibuf[2], obuf[1];
51 SecBufferDesc ibufs, obufs;
52 ULONG request = ISC_REQ_ALLOCATE_MEMORY
53 | ISC_REQ_CONFIDENTIALITY
54 | ISC_REQ_EXTENDED_ERROR
56 | ISC_REQ_REPLAY_DETECT
57 | ISC_REQ_SEQUENCE_DETECT
62 error = AcquireCredentialsHandle( 0,
72 if( error != SEC_E_OK )
81 ibuf[0].cbBuffer =
static_cast<unsigned long>( m_buffer.size() );
82 ibuf[0].pvBuffer =
static_cast<void*
>(
const_cast<char*
>( m_buffer.c_str() ) );
89 ibuf[0].BufferType = SECBUFFER_TOKEN;
90 ibuf[1].BufferType = SECBUFFER_EMPTY;
91 obuf[0].BufferType = SECBUFFER_EMPTY;
93 ibufs.ulVersion = obufs.ulVersion = SECBUFFER_VERSION;
96 ibufs.pBuffers = ibuf;
97 obufs.pBuffers = obuf;
103 error = AcceptSecurityContext( &m_credHandle,
114 if( error == SEC_I_CONTINUE_NEEDED )
122 std::string senddata( static_cast<char*>( obuf[0].pvBuffer ), obuf[0].cbBuffer );
123 FreeContextBuffer( obuf[0].pvBuffer );
124 m_haveCredentialsHandle =
true;
137 void SChannelServer::handshakeStage()
141 SECURITY_STATUS error;
144 SecBuffer ibuf[2], obuf[1];
145 SecBufferDesc ibufs, obufs;
146 ULONG request = ISC_REQ_ALLOCATE_MEMORY
147 | ISC_REQ_CONFIDENTIALITY
148 | ISC_REQ_EXTENDED_ERROR
150 | ISC_REQ_REPLAY_DETECT
151 | ISC_REQ_SEQUENCE_DETECT
153 | ISC_REQ_MANUAL_CRED_VALIDATION;
158 ibuf[0].cbBuffer =
static_cast<unsigned long>( m_buffer.size() );
159 ibuf[0].pvBuffer =
static_cast<void*
>(
const_cast<char*
>( m_buffer.c_str() ) );
161 ibuf[1].cbBuffer = 0;
162 ibuf[1].pvBuffer = 0;
163 obuf[0].cbBuffer = 0;
164 obuf[0].pvBuffer = 0;
166 ibuf[0].BufferType = SECBUFFER_TOKEN;
167 ibuf[1].BufferType = SECBUFFER_EMPTY;
168 obuf[0].BufferType = SECBUFFER_EMPTY;
170 ibufs.ulVersion = obufs.ulVersion = SECBUFFER_VERSION;
173 ibufs.pBuffers = ibuf;
174 obufs.pBuffers = obuf;
183 error = AcceptSecurityContext( &m_credHandle,
198 if( error == SEC_E_OK )
201 if( obuf[0].cbBuffer != 0 && obuf[0].pvBuffer != 0 )
203 std::string senddata( static_cast<char*>(obuf[0].pvBuffer), obuf[0].cbBuffer );
204 FreeContextBuffer( obuf[0].pvBuffer );
208 if( ibuf[1].BufferType == SECBUFFER_EXTRA )
210 m_buffer.erase( 0, m_buffer.size() - ibuf[1].cbBuffer );
223 else if( error == SEC_I_CONTINUE_NEEDED )
228 if( obuf[0].cbBuffer != 0 && obuf[0].pvBuffer != 0 )
230 std::string senddata( static_cast<char*>(obuf[0].pvBuffer), obuf[0].cbBuffer );
231 FreeContextBuffer( obuf[0].pvBuffer );
235 if( ibuf[1].BufferType == SECBUFFER_EXTRA )
237 m_buffer.erase( 0, m_buffer.size() - ibuf[1].cbBuffer );
241 if( obuf[0].cbBuffer == 0 )
250 else if( error == SEC_I_INCOMPLETE_CREDENTIALS )
254 else if( error == SEC_E_INCOMPLETE_MESSAGE )
269 void SChannelServer::privateCleanup()
272 CertFreeCertificateContext( m_cert );
274 CertCloseStore( m_store, 0 );
279 #endif // HAVE_WINTLS