亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? certificates.c

?? linux 下通過802.1認證的安裝包
?? C
字號:
/**
 * Trusted Server (Server Certificate) handler
 * 
 * Licensed under a dual GPL/BSD license.  (See LICENSE file for more info.)
 *
 * \file certificates.c
 *
 * \author chris@open1x.org
 *
 * $Id: certificates.c,v 1.1.2.14 2008/01/21 22:51:49 chessing Exp $
 * $Date: 2008/01/21 22:51:49 $
 **/

#include <stdio.h>
#include <string.h>

#ifdef WINDOWS
#include <windows.h>
#include <wincrypt.h>

#include "../../stdintwin.h"
#endif

#include <openssl/ssl.h>
#include <openssl/x509.h>
#include <openssl/err.h>

#include "../../xsup_debug.h"
#include "../../xsup_err.h"
#include "../../../lib/libxsupconfig/xsupconfig.h"
#include "../../../lib/libxsupconfig/xsupconfig_structs.h"
#include "../../context.h"
#include "tls_funcs.h"
#include "certificates.h"
#include "../../ipc_events.h"
#include "../../ipc_events_index.h"
#include "tls_funcs.h"

/**
 * \brief Locate the trusted server block that the profile has asked us to use.
 *
 * @param[in] svrs   A linked list of all of the available trusted servers.
 * @param[in] trusted_servername   The "<Name>" of the trusted server that we are looking for.
 *
 * \retval NULL on error
 * \retval ptr to the desired trusted server on success
 **/
struct config_trusted_server *certificates_find_trusted_server(struct config_trusted_servers *svrs, char *trusted_servername)
{
	struct config_trusted_server *cur = NULL;

	if (trusted_servername == NULL) return NULL;

	cur = svrs->servers;

	while ((cur != NULL) && (strcmp(cur->name, trusted_servername) != 0))
	{
		cur = cur->next;
	}

	if (cur == NULL) return NULL;

	return cur;
}

#ifdef WINDOWS
/**
 * \brief Add a certificate from Windows in to the OpenSSL store in memory.
 *
 * @param[in] mytls_vars  The TLS context information for this session.
 *
 * \retval 0 on success
 **/
int certificates_windows_add_cert_to_ossl_mem_store(struct tls_vars *mytls_vars, PCCERT_CONTEXT mycert)
{
	X509 *wincert = NULL;
	unsigned long err = 0;
	int reason = 0;
	char *tempptr = NULL;

	tempptr = mycert->pbCertEncoded;

	ERR_clear_error();  // Clear the error queue for this thread.
	wincert = d2i_X509(NULL, &tempptr, mycert->cbCertEncoded);
	if (wincert == NULL)
	{
		err = ERR_get_error();
		debug_printf(DEBUG_NORMAL, "Couldn't load certificate from Windows certificate store!\n");
		debug_printf(DEBUG_AUTHTYPES, "OpenSSL error is : %s\n", ERR_error_string(err, NULL));
		return -1;
	}

	ERR_clear_error();

	if ((mytls_vars == NULL) || (mytls_vars->ctx == NULL))
	{
		debug_printf(DEBUG_NORMAL, "No SSL context available.  Unable to load your certificates.\n");
		return -1;
	}

	if (!X509_STORE_add_cert(mytls_vars->ctx->cert_store, wincert))
	{
		err = ERR_get_error();
		if (err != 0)
		{
			reason = ERR_GET_REASON(err);

			if (reason == X509_R_CERT_ALREADY_IN_HASH_TABLE)
			{
				debug_printf(DEBUG_AUTHTYPES, "Certificate was already in the hash table!\n");
			}
			else
			{
				debug_printf(DEBUG_NORMAL, "Failed to add certificate to the OpenSSL store!\n");
				debug_printf(DEBUG_AUTHTYPES, "OpenSSL error is : %s\n", ERR_error_string(err, NULL));
				return -1;
			}
		}
	}

	return 0;
}

/**
 * \brief Log the certification chain failure error.
 *
 * @param[in] dwErr  An error value from the dwErrorStatus member of the CERT_TRUST_STATUS structure.
 **/
void certificates_log_error(DWORD dwErr)
{
	switch (dwErr)
	{
	case CERT_TRUST_NO_ERROR:
		debug_printf(DEBUG_NORMAL, "There was no error reading the certificate chain.\n");
		break;

	case CERT_TRUST_IS_NOT_TIME_VALID:
		debug_printf(DEBUG_NORMAL, "One of the certificates in the chain is not time valid.  (It either becomes valid in the future, or has expired.)\n");
		break;

	case CERT_TRUST_IS_NOT_TIME_NESTED:
		debug_printf(DEBUG_NORMAL, "The certificates in the chain are not properly time nested.\n");
		break;

	case CERT_TRUST_IS_REVOKED:
		debug_printf(DEBUG_NORMAL, "Trust for at least one certificate in the chain has been revoked.\n");
		break;

	case CERT_TRUST_IS_NOT_SIGNATURE_VALID:
		debug_printf(DEBUG_NORMAL, "One of the certificates in the chain does not have a valid signature.\n");
		break;

	case CERT_TRUST_IS_NOT_VALID_FOR_USAGE:
		debug_printf(DEBUG_NORMAL, "The certificate chain is not valid for use with 802.1X.\n");
		break;

	case CERT_TRUST_IS_UNTRUSTED_ROOT:
		debug_printf(DEBUG_NORMAL, "The certificate chain is built off of an untrusted root certificate.\n");
		break;

	case CERT_TRUST_REVOCATION_STATUS_UNKNOWN:
		debug_printf(DEBUG_NORMAL, "The revocation status of at least one certificate in the chain is unknown.\n");
		break;

	case CERT_TRUST_IS_CYCLIC:
		debug_printf(DEBUG_NORMAL, "One of the certificates in the chain was issued by a certification authority that the original certificate had certified.  (The chain is cyclic.)\n");
		break;

	case CERT_TRUST_INVALID_EXTENSION:
		debug_printf(DEBUG_NORMAL, "One of the certificates in the chain had an extension that is not valid.\n");
		break;

	case CERT_TRUST_INVALID_POLICY_CONSTRAINTS:
		debug_printf(DEBUG_NORMAL, "The certificate or one of the certificates in the certificate chain has a policy constraints extension, and one of the issued certificates has a disallowed policy mapping extension or does not have a required issuance policies extension.\n");
		break;

	case CERT_TRUST_INVALID_BASIC_CONSTRAINTS:
		debug_printf(DEBUG_NORMAL, "The certificate or one of the certificates in the certificate chain has a basic constraints extension, and either the certificate cannot be used to issue other certificates, or the chain path length has been exceeded.\n");
		break;

	case CERT_TRUST_INVALID_NAME_CONSTRAINTS:
		debug_printf(DEBUG_NORMAL, "One of the certificates in the chain has a name constraints extension that is not valid.\n");
		break;

	case CERT_TRUST_HAS_NOT_SUPPORTED_NAME_CONSTRAINT:
		debug_printf(DEBUG_NORMAL, "One of the certificates in the chain has a name constraints extension that contains unsupported fields.\n");
		break;

	case CERT_TRUST_HAS_NOT_DEFINED_NAME_CONSTRAINT:
		debug_printf(DEBUG_NORMAL, "One of the certificates in the chain has a name constraints extension and a name constraint is missing fro one of the name choices in the end certificate.\n");
		break;

	case CERT_TRUST_HAS_NOT_PERMITTED_NAME_CONSTRAINT:
		debug_printf(DEBUG_NORMAL, "One of the certificates in the chain has a name constraints extension and a name constraint is missing from one of the name choices in the end certificate.\n");
		break;

	case CERT_TRUST_HAS_EXCLUDED_NAME_CONSTRAINT:
		debug_printf(DEBUG_NORMAL, "One of the certificates in the chain has a name constraints extension, and one of the name choices in the end certificate is explicitly excluded.\n");
		break;

	case CERT_TRUST_IS_OFFLINE_REVOCATION:
		debug_printf(DEBUG_NORMAL, "The recovation status of the certificate or one of the certificates in the certificate chain is either offline or stale.\n");
		break;

	case CERT_TRUST_NO_ISSUANCE_CHAIN_POLICY:
		debug_printf(DEBUG_NORMAL, "The end certificate does not have any resultant issuance policies, and one of the issuing certification authority certificates has a policy constraints extension requiring it.\n");
		break;

	case CERT_TRUST_IS_EXPLICIT_DISTRUST:
		debug_printf(DEBUG_NORMAL, "A certificate in the chain is explicitly distrusted.\n");
		break;

	case CERT_TRUST_HAS_NOT_SUPPORTED_CRITICAL_EXT:
		debug_printf(DEBUG_NORMAL, "A certificate in the chain does not support a critical extension.\n");
		break;

	default:
		debug_printf(DEBUG_NORMAL, "Unknown/Unexpected certificate error : %04x\n", dwErr);
		break;
	}
}

/**
 * \brief Build an certificate chain from the Windows cert store, and put it in to
 *        OpenSSL's in memory certificate store.
 *
 * @param[in] mytls_vars   The TLS context information for this session.
 * @param[in] mycert   The Windows certificate store context for the trusted certificate we want to
 *                     build a chain with.
 *
 * \retval 0 on success
 **/
int certificates_windows_build_ossl_mem_chain(struct tls_vars *mytls_vars, 	PCCERT_CONTEXT mycert)
{
	CERT_CHAIN_PARA myPara;
	PCCERT_CHAIN_CONTEXT pChainContext = NULL;
	PCERT_SIMPLE_CHAIN pChain = NULL;
	PCERT_CHAIN_ELEMENT pElement = NULL;
	int i = 0;
	int c = 0;

	myPara.cbSize = sizeof(CERT_CHAIN_PARA);
	myPara.RequestedUsage.dwType = USAGE_MATCH_TYPE_OR;
	myPara.RequestedUsage.Usage.cUsageIdentifier = 0;
	myPara.RequestedUsage.Usage.rgpszUsageIdentifier = NULL;

	if (CertGetCertificateChain(HCCE_LOCAL_MACHINE, mycert,	NULL, NULL, &myPara, 
								CERT_CHAIN_REVOCATION_CHECK_CACHE_ONLY,
								NULL, &pChainContext) == 0)
	{
		debug_printf(DEBUG_NORMAL, "Unable to create certificate chain from Windows certificate store!  (Error was : %d)\n", GetLastError());
		return -1;
	}

	if (pChainContext == NULL)
	{
		debug_printf(DEBUG_NORMAL, "Windows return a NULL chain context, but didn't return an error!?\n");
		return -1;
	}

	// Otherwise, we should have the chain, so load it in to OpenSSL.
	if (pChainContext->TrustStatus.dwErrorStatus != CERT_TRUST_NO_ERROR)
	{
		certificates_log_error(pChainContext->TrustStatus.dwErrorStatus);
		CertFreeCertificateChain(pChainContext);
		return -1;
	}

	debug_printf(DEBUG_AUTHTYPES, "There are %d chain(s) in the structure.\n", pChainContext->cChain);

	for (i = 0; i < pChainContext->cChain; i++)
	{
		pChain = pChainContext->rgpChain[i];

		if (pChain == NULL)
		{
			debug_printf(DEBUG_NORMAL, "Windows return a NULL simple chain context?\n");
			CertFreeCertificateChain(pChainContext);
			return -1;
		}

		debug_printf(DEBUG_AUTHTYPES, "There are %d certificate(s) in this chain.\n", pChain->cElement);
		for (c = 0; c < pChain->cElement; c++)
		{
			pElement = pChain->rgpElement[c];

			if (pElement == NULL)
			{
				debug_printf(DEBUG_NORMAL, "Windows returned a NULL element in a simple chain context!?\n");
				CertFreeCertificateChain(pChainContext);
				return -1;
			}

			if (certificates_windows_add_cert_to_ossl_mem_store(mytls_vars, pElement->pCertContext) != 0)
			{
				debug_printf(DEBUG_NORMAL, "Failed to load one of the certificates in the chain.  Aborting.\n");
				CertFreeCertificateChain(pChainContext);
				return -1;
			}
		}
	}

	CertFreeCertificateChain(pChainContext);

	return 0;
}

/**
 * \brief Locate the certificate that we want to load, and load it in to OpenSSL.
 *
 * @param[in] mytls_vars   The TLS context information for this session.
 * @param[in] location   The location information used to locate the certificate.
 *
 * \retval XENONE on success
 * \retval !XENONE on error
 **/
int certificates_windows_load_root_certs(struct tls_vars *mytls_vars, char *location)
{
	PCCERT_CONTEXT mycert = NULL;

	if (mytls_vars == NULL)
	{
		debug_printf(DEBUG_NORMAL, "mytls_vars was NULL in %s() at %d!\n", __FUNCTION__, __LINE__);
		return -1;
	}

	if (location == NULL)
	{
		debug_printf(DEBUG_NORMAL, "Attempt to load a root certificate that doesn't have a location set!?\n");
		return -1;
	}

	mycert = win_cert_handler_get_from_win_store("WINDOWS", location);
	if (mycert == NULL)
	{ 
		debug_printf(DEBUG_NORMAL, "Couldn't locate the certificate!\n");
		return -1;
	}
	else
	{
		debug_printf(DEBUG_AUTHTYPES, "Located the certificate for '%s'!\n", location);
	}

	return certificates_windows_build_ossl_mem_chain(mytls_vars, mycert);
}
#endif

/**
 * \brief Attempt to load the certificate(s) for the trusted server in to OpenSSL.
 *
 * @param[in] trusted_servername   The <Trusted_Server> setting from the configuration file.
 * @param[in] mytls_vars   The TLS context information for this session.
 *
 * \retval XENONE on success
 * \retval !XENONE on error
 **/
int certificates_load_root(struct tls_vars *mytls_vars, char *trusted_servername)
{
	struct config_trusted_server *svr = NULL;

	svr = certificates_find_trusted_server(config_get_trusted_servers(), trusted_servername);
	if (svr == NULL)
	{
		debug_printf(DEBUG_NORMAL, "Couldn't locate the server '%s'!\n", trusted_servername);
		return -1;   // XXX Make this a real return value!
	}

	// Set up the CN match, and if it should be exact.
	mytls_vars->cncheck = svr->common_name;
	mytls_vars->cnexact = svr->exact_common_name;

	if (strcmp(svr->store_type, "WINDOWS") == 0)
	{
#ifndef WINDOWS
		return -1;
#else
		// Get the certificate out of the WINDOWS certificate store.  (If we are using Windows. ;)
		if (certificates_windows_load_root_certs(mytls_vars, svr->location) != XENONE)
		{
			debug_printf(DEBUG_NORMAL, "Unable to load the root certificate from the Windows "
					"certificate store!\n");
			ipc_events_error(NULL, IPC_EVENT_ERROR_FAILED_ROOT_CA_LOAD, NULL);
			return -1;
		}

		return XENONE;
#endif
	}

	if (strcmp(svr->store_type, "FILE") == 0)
	{
		// Get the certificate out of a FILE on the filesystem.
		if (tls_funcs_load_root_certs(mytls_vars, svr->location, NULL, NULL) != XENONE)
			{
			  debug_printf(DEBUG_NORMAL, "Unable to load the root certificate from file "
				  "'%s'!\n", svr->location);
			  ipc_events_error(NULL, IPC_EVENT_ERROR_FAILED_ROOT_CA_LOAD, NULL);
			  return -1;
			}
		return XENONE;
	}

	if (strcmp(svr->store_type, "DIRECTORY") == 0)
	{
		// Get the certificate out of an OpenSSL directory.
		if (tls_funcs_load_root_certs(mytls_vars, NULL, svr->location, NULL) != XENONE)
			{
			  debug_printf(DEBUG_NORMAL, "Unable to load the root certificate from directory "
				  "'%s'!\n", svr->location);
			  ipc_events_error(NULL, IPC_EVENT_ERROR_FAILED_ROOT_CA_LOAD, NULL);
			  return -1;
			}
		return XENONE;
	}

	return -1;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
最新高清无码专区| 99免费精品在线| 成人精品鲁一区一区二区| 在线一区二区三区四区五区| 欧美成人三级电影在线| 国产精品乱码人人做人人爱| 日本va欧美va欧美va精品| 99麻豆久久久国产精品免费优播| 日韩免费在线观看| 亚洲国产综合色| 99精品视频一区| 欧美国产精品专区| 韩国欧美国产一区| 67194成人在线观看| 亚洲免费观看高清完整版在线观看| 久久精品国产77777蜜臀| 精品视频999| 亚洲欧洲综合另类| www.66久久| 中文字幕免费观看一区| 韩国av一区二区三区| 精品欧美一区二区在线观看| 午夜欧美在线一二页| 精品1区2区3区| 亚洲国产wwwccc36天堂| 在线观看视频欧美| 亚洲最快最全在线视频| 色婷婷国产精品综合在线观看| 欧美经典三级视频一区二区三区| 国产成人在线网站| 国产午夜精品一区二区三区四区 | 51精品国自产在线| 一区2区3区在线看| 欧美在线观看视频一区二区三区| 亚洲天堂网中文字| 一本色道久久综合亚洲aⅴ蜜桃 | 国产日韩欧美激情| 国产成人综合网站| √…a在线天堂一区| 9久草视频在线视频精品| 亚洲人一二三区| 欧美视频一区在线| 男男gaygay亚洲| 欧美成人在线直播| 国产成人av电影在线观看| 国产精品欧美一级免费| 91老师片黄在线观看| 夜夜亚洲天天久久| 欧美一级国产精品| 国产福利91精品一区二区三区| 中文字幕欧美日本乱码一线二线| www.久久精品| 午夜免费久久看| 精品蜜桃在线看| 99久久精品国产导航| 亚洲国产欧美日韩另类综合 | 国产综合色精品一区二区三区| 久久久不卡网国产精品二区| thepron国产精品| 一区二区三区中文免费| 欧美一区二区三区视频免费| 国产一区999| 一区二区三区蜜桃| 精品1区2区在线观看| 99久久精品国产一区| 免费在线一区观看| 国产精品久久久久久久久果冻传媒 | 色视频成人在线观看免| 日韩av中文字幕一区二区| 中文幕一区二区三区久久蜜桃| 欧洲精品在线观看| 精品无人码麻豆乱码1区2区| 中文字幕亚洲一区二区av在线| 欧美老肥妇做.爰bbww视频| 国产在线麻豆精品观看| 一区二区三区在线观看网站| 日韩免费观看高清完整版在线观看| av电影在线观看完整版一区二区| 日韩精品乱码免费| 日韩一区欧美小说| 欧美精品一区二区三区视频| 在线这里只有精品| 懂色av一区二区三区免费观看| 午夜精品久久久久影视| 中文字幕在线播放不卡一区| 日韩三级中文字幕| 欧美视频一区在线观看| eeuss鲁片一区二区三区| 麻豆精品在线视频| 亚洲风情在线资源站| 亚洲欧美综合另类在线卡通| 欧美电影精品一区二区| 欧美色精品在线视频| 91免费观看在线| 成人午夜电影久久影院| 韩国成人福利片在线播放| 日韩电影免费在线看| 亚洲一区精品在线| 亚洲免费视频中文字幕| 国产精品久久久久久久久动漫| 26uuu亚洲综合色欧美| 欧美一区二区视频免费观看| 欧美男男青年gay1069videost| 97国产一区二区| 99这里只有精品| 成人三级在线视频| 国产99一区视频免费| 国产精品18久久久久久久久| 久久精品国产99国产| 精久久久久久久久久久| 久久精品99国产国产精| 久久精工是国产品牌吗| 免费在线看成人av| 激情图区综合网| 国产精华液一区二区三区| 国产自产v一区二区三区c| 国产精品一区二区三区乱码| 国产一区美女在线| 国产a级毛片一区| 成人免费视频国产在线观看| 成人综合婷婷国产精品久久蜜臀 | 一区二区三区中文在线观看| 亚洲蜜臀av乱码久久精品蜜桃| 国产精品成人在线观看| 中文字幕永久在线不卡| 亚洲精品视频一区二区| 一区二区三区欧美久久| 亚洲v日本v欧美v久久精品| 日韩高清不卡在线| 久久99精品国产91久久来源| 国产精品888| 91在线播放网址| 欧美性受极品xxxx喷水| 欧美一区二区三区日韩| 国产午夜一区二区三区| 亚洲欧美日韩久久| 午夜成人在线视频| 国产综合色产在线精品| 99久久精品国产网站| 欧美日韩成人在线一区| 久久嫩草精品久久久久| 亚洲色图欧洲色图| 日本午夜精品视频在线观看| 国产精品一区二区x88av| 99国内精品久久| 制服视频三区第一页精品| 久久免费电影网| 一区二区三区在线观看欧美| 麻豆久久一区二区| 色婷婷激情一区二区三区| 日韩欧美一二三四区| 成人欧美一区二区三区视频网页| 亚洲成人av一区二区三区| 国产剧情一区二区| 欧美色综合影院| 国产视频一区在线播放| 亚洲一区二区在线免费看| 国产乱码精品1区2区3区| 色婷婷av一区二区三区gif| 欧美精品一区二区在线观看| 亚洲欧美偷拍另类a∨色屁股| 日韩经典一区二区| 99久久精品国产精品久久| 日韩免费看网站| 一区二区高清视频在线观看| 国产一区二区在线视频| 欧美亚洲免费在线一区| 中文字幕精品一区二区精品绿巨人| 午夜视频久久久久久| 91在线观看免费视频| 久久网站热最新地址| 日韩精品五月天| 91丝袜美腿高跟国产极品老师| 精品91自产拍在线观看一区| 五月激情六月综合| 在线免费精品视频| 亚洲国产高清在线| 国产精品一区二区视频| 日韩欧美一级精品久久| 五月婷婷久久丁香| 欧美亚洲高清一区二区三区不卡| 欧美韩日一区二区三区| 精品在线一区二区三区| 欧美一区在线视频| 亚洲一级二级三级在线免费观看| 成人美女视频在线看| 久久天天做天天爱综合色| 麻豆91小视频| 欧美一卡2卡三卡4卡5免费| 亚洲一区二区三区国产| 一本一本久久a久久精品综合麻豆| 日本一区二区在线不卡| 国产毛片一区二区| 久久久国产一区二区三区四区小说| 蜜臀a∨国产成人精品| 欧美一区二区日韩一区二区| 日韩国产欧美一区二区三区| 欧美电影一区二区三区| 日本va欧美va精品发布| 欧美电影免费观看高清完整版 |