Platform SDK: Logon Authentication |
Code comparable to the following would be used in a client application to gracefully end a secure connection with a server.
DWORD dwType; SecBufferDesc OutBuffer; SecBuffer OutBuffers[1]; DWORD dwSSPIFlags; DWORD dwSSPIOutFlags; TimeStamp tsExpiry; DWORD Status; dwType = SCHANNEL_SHUTDOWN; OutBuffers[0].pvBuffer = &dwType; OutBuffers[0].BufferType = SECBUFFER_TOKEN; OutBuffers[0].cbBuffer = sizeof(dwType); OutBuffer.cBuffers = 1; OutBuffer.pBuffers = OutBuffers; OutBuffer.ulVersion = SECBUFFER_VERSION; Status = g_SecurityFunc.ApplyControlToken( phContext, &OutBuffer); if(FAILED(Status)) { printf("**** Error 0x%x returned by ApplyControlToken\n", Status); g_SecurityFunc.DeleteSecurityContext(phContext); return; } //-------------------------------------------------------------------- // Build an SSL CloseNotify message. dwSSPIFlags = ISC_REQ_SEQUENCE_DETECT | ISC_REQ_REPLAY_DETECT | ISC_REQ_CONFIDENTIALITY | ISC_RET_EXTENDED_ERROR | ISC_REQ_ALLOCATE_MEMORY | ISC_REQ_STREAM; OutBuffers[0].pvBuffer = NULL; OutBuffers[0].BufferType = SECBUFFER_TOKEN; OutBuffers[0].cbBuffer = 0; OutBuffer.cBuffers = 1; OutBuffer.pBuffers = OutBuffers; OutBuffer.ulVersion = SECBUFFER_VERSION; Status = g_SecurityFunc.InitializeSecurityContextA( phCreds, phContext, NULL, dwSSPIFlags, 0, SECURITY_NATIVE_DREP, NULL, 0, phContext, &OutBuffer, &dwSSPIOutFlags, &tsExpiry); if(FAILED(Status)) { printf("* Error 0x%x returned by InitializeSecurityContext\n", Status); g_SecurityFunc.DeleteSecurityContext(phContext); return; } //-------------------------------------------------------------------- // Send the CloseNotify message to the server. if(OutBuffers[0].pvBuffer != NULL && OutBuffers[0].cbBuffer != 0) { SendToServer( OutBuffers[0].pvBuffer, OutBuffers[0].cbBuffer); //---------------------------------------------------------------- // Free output buffer. g_SecurityFunc.FreeContextBuffer(OutBuffers[0].pvBuffer); } //-------------------------------------------------------------------- // Free the security context. g_SecurityFunc.DeleteSecurityContext(phContext);