⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tls_schannel.c

📁 IEEE802.11 a/b/g 客户端应用程序源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
			out_buf = os_malloc(*out_len);			if (out_buf)				os_memcpy(out_buf, outbufs[0].pvBuffer,					  *out_len);			global->sspi->FreeContextBuffer(outbufs[0].pvBuffer);			outbufs[0].pvBuffer = NULL;			if (out_buf == NULL)				return NULL;		}	}	switch (status) {	case SEC_E_INCOMPLETE_MESSAGE:		wpa_printf(MSG_DEBUG, "Schannel: SEC_E_INCOMPLETE_MESSAGE");		break;	case SEC_I_CONTINUE_NEEDED:		wpa_printf(MSG_DEBUG, "Schannel: SEC_I_CONTINUE_NEEDED");		break;	case SEC_E_OK:		/* TODO: verify server certificate chain */		wpa_printf(MSG_DEBUG, "Schannel: SEC_E_OK - Handshake "			   "completed successfully");		conn->established = 1;		tls_get_eap(global, conn);		/* Need to return something to get final TLS ACK. */		if (out_buf == NULL)			out_buf = os_malloc(1);		if (inbufs[1].BufferType == SECBUFFER_EXTRA) {			wpa_hexdump(MSG_MSGDUMP, "SChannel - Encrypted "				    "application data",				    inbufs[1].pvBuffer, inbufs[1].cbBuffer);			if (appl_data) {				*appl_data_len = outbufs[1].cbBuffer;				appl_data = os_malloc(*appl_data_len);				if (appl_data)					os_memcpy(appl_data,						  outbufs[1].pvBuffer,						  *appl_data_len);			}			global->sspi->FreeContextBuffer(inbufs[1].pvBuffer);			inbufs[1].pvBuffer = NULL;		}		break;	case SEC_I_INCOMPLETE_CREDENTIALS:		wpa_printf(MSG_DEBUG,			   "Schannel: SEC_I_INCOMPLETE_CREDENTIALS");		break;	case SEC_E_WRONG_PRINCIPAL:		wpa_printf(MSG_DEBUG, "Schannel: SEC_E_WRONG_PRINCIPAL");		break;	case SEC_E_INTERNAL_ERROR:		wpa_printf(MSG_DEBUG, "Schannel: SEC_E_INTERNAL_ERROR");		break;	}	if (FAILED(status)) {		wpa_printf(MSG_DEBUG, "Schannel: Handshake failed "			   "(out_buf=%p)", out_buf);		conn->failed++;		global->sspi->DeleteSecurityContext(&conn->context);		return out_buf;	}	if (inbufs[1].BufferType == SECBUFFER_EXTRA) {		/* TODO: Can this happen? What to do with this data? */		wpa_hexdump(MSG_MSGDUMP, "SChannel - Leftover data",			    inbufs[1].pvBuffer, inbufs[1].cbBuffer);		global->sspi->FreeContextBuffer(inbufs[1].pvBuffer);		inbufs[1].pvBuffer = NULL;	}	return out_buf;}u8 * tls_connection_server_handshake(void *ssl_ctx,				     struct tls_connection *conn,				     const u8 *in_data, size_t in_len,				     size_t *out_len){	return NULL;}int tls_connection_encrypt(void *ssl_ctx, struct tls_connection *conn,			   const u8 *in_data, size_t in_len,			   u8 *out_data, size_t out_len){	struct tls_global *global = ssl_ctx;	SECURITY_STATUS status;	SecBufferDesc buf;	SecBuffer bufs[4];	SecPkgContext_StreamSizes sizes;	int i;	size_t total_len;	status = global->sspi->QueryContextAttributes(&conn->context,						      SECPKG_ATTR_STREAM_SIZES,						      &sizes);	if (status != SEC_E_OK) {		wpa_printf(MSG_DEBUG, "%s: QueryContextAttributes failed",			   __func__);		return -1;	}	wpa_printf(MSG_DEBUG, "%s: Stream sizes: header=%u trailer=%u",		   __func__,		   (unsigned int) sizes.cbHeader,		   (unsigned int) sizes.cbTrailer);	total_len = sizes.cbHeader + in_len + sizes.cbTrailer;	if (out_len < total_len) {		wpa_printf(MSG_DEBUG, "%s: too short out_data (out_len=%lu "			   "in_len=%lu total_len=%lu)", __func__,			   (unsigned long) out_len, (unsigned long) in_len,			   (unsigned long) total_len);		return -1;	}	os_memset(&bufs, 0, sizeof(bufs));	bufs[0].pvBuffer = out_data;	bufs[0].cbBuffer = sizes.cbHeader;	bufs[0].BufferType = SECBUFFER_STREAM_HEADER;	os_memcpy(out_data + sizes.cbHeader, in_data, in_len);	bufs[1].pvBuffer = out_data + sizes.cbHeader;	bufs[1].cbBuffer = in_len;	bufs[1].BufferType = SECBUFFER_DATA;	bufs[2].pvBuffer = out_data + sizes.cbHeader + in_len;	bufs[2].cbBuffer = sizes.cbTrailer;	bufs[2].BufferType = SECBUFFER_STREAM_TRAILER;	buf.ulVersion = SECBUFFER_VERSION;	buf.cBuffers = 3;	buf.pBuffers = bufs;	status = global->sspi->EncryptMessage(&conn->context, 0, &buf, 0);	wpa_printf(MSG_MSGDUMP, "Schannel: EncryptMessage -> "		   "status=%d len[0]=%d type[0]=%d len[1]=%d type[1]=%d "		   "len[2]=%d type[2]=%d",		   (int) status,		   (int) bufs[0].cbBuffer, (int) bufs[0].BufferType,		   (int) bufs[1].cbBuffer, (int) bufs[1].BufferType,		   (int) bufs[2].cbBuffer, (int) bufs[2].BufferType);	wpa_printf(MSG_MSGDUMP, "Schannel: EncryptMessage pointers: "		   "out_data=%p bufs %p %p %p",		   out_data, bufs[0].pvBuffer, bufs[1].pvBuffer,		   bufs[2].pvBuffer);	for (i = 0; i < 3; i++) {		if (bufs[i].pvBuffer && bufs[i].BufferType != SECBUFFER_EMPTY)		{			wpa_hexdump(MSG_MSGDUMP, "SChannel: bufs",				    bufs[i].pvBuffer, bufs[i].cbBuffer);		}	}	if (status == SEC_E_OK) {		wpa_printf(MSG_DEBUG, "%s: SEC_E_OK", __func__);		wpa_hexdump_key(MSG_MSGDUMP, "Schannel: Encrypted data from "				"EncryptMessage", out_data, total_len);		return total_len;	}	wpa_printf(MSG_DEBUG, "%s: Failed - status=%d",		   __func__, (int) status);	return -1;}int tls_connection_decrypt(void *ssl_ctx, struct tls_connection *conn,			   const u8 *in_data, size_t in_len,			   u8 *out_data, size_t out_len){	struct tls_global *global = ssl_ctx;	SECURITY_STATUS status;	SecBufferDesc buf;	SecBuffer bufs[4];	int i;	if (out_len < in_len) {		wpa_printf(MSG_DEBUG, "%s: out_len=%lu < in_len=%lu", __func__,			   (unsigned long) out_len, (unsigned long) in_len);		return -1;	}	wpa_hexdump(MSG_MSGDUMP, "Schannel: Encrypted data to DecryptMessage",		    in_data, in_len);	os_memset(&bufs, 0, sizeof(bufs));	os_memcpy(out_data, in_data, in_len);	bufs[0].pvBuffer = out_data;	bufs[0].cbBuffer = in_len;	bufs[0].BufferType = SECBUFFER_DATA;	bufs[1].BufferType = SECBUFFER_EMPTY;	bufs[2].BufferType = SECBUFFER_EMPTY;	bufs[3].BufferType = SECBUFFER_EMPTY;	buf.ulVersion = SECBUFFER_VERSION;	buf.cBuffers = 4;	buf.pBuffers = bufs;	status = global->sspi->DecryptMessage(&conn->context, &buf, 0,						    NULL);	wpa_printf(MSG_MSGDUMP, "Schannel: DecryptMessage -> "		   "status=%d len[0]=%d type[0]=%d len[1]=%d type[1]=%d "		   "len[2]=%d type[2]=%d len[3]=%d type[3]=%d",		   (int) status,		   (int) bufs[0].cbBuffer, (int) bufs[0].BufferType,		   (int) bufs[1].cbBuffer, (int) bufs[1].BufferType,		   (int) bufs[2].cbBuffer, (int) bufs[2].BufferType,		   (int) bufs[3].cbBuffer, (int) bufs[3].BufferType);	wpa_printf(MSG_MSGDUMP, "Schannel: DecryptMessage pointers: "		   "out_data=%p bufs %p %p %p %p",		   out_data, bufs[0].pvBuffer, bufs[1].pvBuffer,		   bufs[2].pvBuffer, bufs[3].pvBuffer);	switch (status) {	case SEC_E_INCOMPLETE_MESSAGE:		wpa_printf(MSG_DEBUG, "%s: SEC_E_INCOMPLETE_MESSAGE",			   __func__);		break;	case SEC_E_OK:		wpa_printf(MSG_DEBUG, "%s: SEC_E_OK", __func__);		for (i = 0; i < 4; i++) {			if (bufs[i].BufferType == SECBUFFER_DATA)				break;		}		if (i == 4) {			wpa_printf(MSG_DEBUG, "%s: No output data from "				   "DecryptMessage", __func__);			return -1;		}		wpa_hexdump_key(MSG_MSGDUMP, "Schannel: Decrypted data from "				"DecryptMessage",				bufs[i].pvBuffer, bufs[i].cbBuffer);		if (bufs[i].cbBuffer > out_len) {			wpa_printf(MSG_DEBUG, "%s: Too long output data",				   __func__);			return -1;		}		os_memmove(out_data, bufs[i].pvBuffer, bufs[i].cbBuffer);		return bufs[i].cbBuffer;	}	wpa_printf(MSG_DEBUG, "%s: Failed - status=%d",		   __func__, (int) status);	return -1;}int tls_connection_resumed(void *ssl_ctx, struct tls_connection *conn){	return 0;}int tls_connection_set_cipher_list(void *tls_ctx, struct tls_connection *conn,				   u8 *ciphers){	return -1;}int tls_get_cipher(void *ssl_ctx, struct tls_connection *conn,		   char *buf, size_t buflen){	return -1;}int tls_connection_enable_workaround(void *ssl_ctx,				     struct tls_connection *conn){	return 0;}int tls_connection_client_hello_ext(void *ssl_ctx, struct tls_connection *conn,				    int ext_type, const u8 *data,				    size_t data_len){	return -1;}int tls_connection_get_failed(void *ssl_ctx, struct tls_connection *conn){	if (conn == NULL)		return -1;	return conn->failed;}int tls_connection_get_read_alerts(void *ssl_ctx, struct tls_connection *conn){	if (conn == NULL)		return -1;	return conn->read_alerts;}int tls_connection_get_write_alerts(void *ssl_ctx, struct tls_connection *conn){	if (conn == NULL)		return -1;	return conn->write_alerts;}int tls_connection_set_params(void *tls_ctx, struct tls_connection *conn,			      const struct tls_connection_params *params){	struct tls_global *global = tls_ctx;	ALG_ID algs[1];	SECURITY_STATUS status;	TimeStamp ts_expiry;	if (conn == NULL)		return -1;	if (global->my_cert_store == NULL &&	    (global->my_cert_store = CertOpenSystemStore(0, TEXT("MY"))) ==	    NULL) {		wpa_printf(MSG_ERROR, "%s: CertOpenSystemStore failed - 0x%x",			   __func__, (unsigned int) GetLastError());		return -1;	}	os_memset(&conn->schannel_cred, 0, sizeof(conn->schannel_cred));	conn->schannel_cred.dwVersion = SCHANNEL_CRED_VERSION;	conn->schannel_cred.grbitEnabledProtocols = SP_PROT_TLS1;	algs[0] = CALG_RSA_KEYX;	conn->schannel_cred.cSupportedAlgs = 1;	conn->schannel_cred.palgSupportedAlgs = algs;	conn->schannel_cred.dwFlags |= SCH_CRED_NO_DEFAULT_CREDS;#ifdef UNICODE	status = global->sspi->AcquireCredentialsHandleW(		NULL, UNISP_NAME_W, SECPKG_CRED_OUTBOUND, NULL,		&conn->schannel_cred, NULL, NULL, &conn->creds, &ts_expiry);#else /* UNICODE */	status = global->sspi->AcquireCredentialsHandleA(		NULL, UNISP_NAME_A, SECPKG_CRED_OUTBOUND, NULL,		&conn->schannel_cred, NULL, NULL, &conn->creds, &ts_expiry);#endif /* UNICODE */	if (status != SEC_E_OK) {		wpa_printf(MSG_DEBUG, "%s: AcquireCredentialsHandleA failed - "			   "0x%x", __func__, (unsigned int) status);		return -1;	}	return 0;}unsigned int tls_capabilities(void *tls_ctx){	return 0;}int tls_connection_set_ia(void *tls_ctx, struct tls_connection *conn,			  int tls_ia){	return -1;}int tls_connection_ia_send_phase_finished(void *tls_ctx,					  struct tls_connection *conn,					  int final,					  u8 *out_data, size_t out_len){	return -1;}int tls_connection_ia_final_phase_finished(void *tls_ctx,					   struct tls_connection *conn){	return -1;}int tls_connection_ia_permute_inner_secret(void *tls_ctx,					   struct tls_connection *conn,					   const u8 *key, size_t key_len){	return -1;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -