Quantcast
Channel: Security forum
Viewing all articles
Browse latest Browse all 12072

IIS Client Certificate Mapping Authentication

$
0
0

Hi all,

I am trying to programmatically add onetoone client certificate authentication to the applicationhost.config file.

After referring to these two documents(thread1thread2), I am sure that it is possible to implement it with different languages.  And for some kind of reason I have to develop it with C++. While translating the code sample in thread1, 

I found that there is not any kind of "add" or "create new" method for IAppHostPropertyCollection class, which make it impossible for me to add property to the new element I create.

Below is the code snippet FYI.

IAppHostWritableAdminManager        * pWMgr       = NULL;
	IAppHostConfigManager               * pCfgMgr     = NULL;
	IAppHostConfigFile                  * pCfgFile    = NULL; 
	IAppHostSectionGroup                * pRtSctnGrp  = NULL;
	IAppHostSectionGroup                * pSctnGrp    = NULL;
	IAppHostSectionDefinitionCollection * pSctnDefCol = NULL;
	IAppHostSectionDefinition           * pSctnDef    = NULL;

	IAppHostElement *pAuth = NULL;
	IAppHostElementCollection *pAuthColection = NULL;
	IAppHostChildElementCollection *pChildColection = NULL;
	IAppHostElement *pOneToOne = NULL;
	IAppHostElementCollection *pOneToOneCollection = NULL;
	IAppHostElement *pNewElement = NULL;
	IAppHostPropertyCollection *propertyCollection = NULL;
	IAppHostProperty *pProperty = NULL;

	BSTR bstrConfigCommitPath = SysAllocString(L"MACHINE/WEBROOT/APPHOST/Default Web Site");
	BSTR bstrSctnGrpName      = SysAllocString(L"mySectionGroup");
	BSTR bstrSctnName         = SysAllocString(L"myNewSection");
	BSTR bstrDeny             = SysAllocString(L"Deny");
	BSTR bstrAppHostOnly      = SysAllocString(L"appHostOnly");

	BSTR bstrAuthName = SysAllocString(L"system.webServer/security/authentication/iisClientCertificateMappingAuthentication");
	BSTR bstrOnetoOne = SysAllocString(L"oneToOneMappings");
	BSTR bstrAuthPath = SysAllocString(L"Default Web Site");
	BSTR bstrAdd = SysAllocString(L"add");

	BSTR bstrUsername = SysAllocString(L"name");
	BSTR bstrUsernameVal = SysAllocString(L"jinqiu.tao@emacle.com");

	// Initialize
	hr = CoInitializeEx( NULL, COINIT_MULTITHREADED );

	// Create
	hr = CoCreateInstance( __uuidof( AppHostWritableAdminManager ), NULL, 
		CLSCTX_INPROC_SERVER,
		__uuidof( IAppHostWritableAdminManager ), (void**) &pWMgr );

	pWMgr -> put_CommitPath ( bstrConfigCommitPath );

	// Get an IAppHostConfigManager
	hr = pWMgr -> get_ConfigManager ( &pCfgMgr );

	// Get an IAppHostConfigFile
	hr = pCfgMgr -> GetConfigFile ( bstrConfigCommitPath, &pCfgFile );

	//get section
	hr = pCfgFile->GetAdminSection(bstrAuthName, bstrConfigCommitPath, &pAuth);
	BSTR bstrName;
	hr = pAuth->get_Name(&bstrName);

	_tprintf(_T("Name : %s\n"), bstrName);

	hr = pAuth->get_ChildElements(&pChildColection);

	VARIANT vtPropertyName;
	vtPropertyName.vt = VT_BSTR;
	vtPropertyName.bstrVal = bstrOnetoOne;

	hr = pChildColection->get_Item(vtPropertyName, &pOneToOne);
	hr = pOneToOne->get_Name(&bstrName);
	_tprintf(_T("Name : %s\n"), bstrName);

	hr = pOneToOne->get_Collection(&pOneToOneCollection);

	hr = pOneToOneCollection->CreateNewElement(bstrAdd, &pNewElement);

	
	hr = pNewElement->get_Properties(&propertyCollection);

	vtPropertyName.vt = VT_BSTR;
	vtPropertyName.bstrVal = bstrUsername;
	hr = propertyCollection->get_Item(vtPropertyName, &pProperty);

     As you see, I can get the propertyCollection object, but not able to add property to the new element.

What I want to do is just add a record to the onetoonemappings part.

<location path="Default Web Site"><system.webServer><security><access sslFlags="None" /><authentication><anonymousAuthentication enabled="true" /><iisClientCertificateMappingAuthentication enabled="true" oneToOneCertificateMappingsEnabled="true"><oneToOneMappings><add userName="yonggui.yu@emacle.com" password="[enc:AesProvider:4QEVwn3c530VH5sdwCl+Sm8G2eJesNEs4SaL6U5LrXg=:enc]" certificate="MIIFOjCCBCKgAwIBAgIKOAVSKwAAAAAAbDANBgkqhkiG9w0BAQUFADBLMRMwEQYKCZImiZPyLGQBGRYDY29tMRkwFwYKCZImiZPyLGQB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TAXgRV5b25nZ3VpLnl1QGVtYWNsZS5jb20wgegGA1UdIASB4DCB3TCB2gYNKwYBBAGCm1EBAQEBAjCByDApBggrBgEFBQcCARYdaHR0cDovL3d3dy53b3NpZ24uY29tL3BvbGljeS8wgZoGCCsGAQUFBwICMIGNMCgWIVdvU2lnbiBlQ29tbWVyY2UgU2VydmljZXMgTGltaXRlZDADAgEBGmFMaW1pdGVkIExpYWJpbGl0eSwgc2VlIHRoZSBXb1NpZ24gQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkgUG9saWN5IGF0IGh0dHA6Ly93d3cud29zaWduLmNvbS9wb2xpY3kvMDQGA1UdHwQtMCswKaAnoCWGI2h0dHA6Ly9jcmxzLndvc2lnbi5jb20vY2xpZW50LTEuY3JsMHsGCCsGAQUFBwEBBG8wbTAzBggrBgEFBQcwAYYnaHR0cDovL29jc3Aud29zaWduLmNvbS9jbGFzczEvY2xpZW50L2NhMDYGCCsGAQUFBzAChipodHRwOi8vYWlhLndvc2lnbi5jb20vY2xhc3MxLmNsaWVudC5jYS5jZXIwIQYDVR0SBBowGIYWaHR0cDovL3d3dy53b3NpZ24uY29tLzANBgkqhkiG9w0BAQUFAAOCAQEAb9981A/6ll+E3s5v1uyUwmlwv0ez0b5nhqzsSeU66f1AIAWhlVawtqJ0I75WQXFUEAV6dIve5JDr2XxQ8udY+KmNHKmdbqTbOGzG/NW+dGxKGDn2IcYhWVK/7S6TfkaRBzR7t68nbd0x9ZFCsyocO03tx5/gj0fHI6bC7rgStgbso3kCrJAMbbP8N9nxb0v6Yl52cCKrlQNogfnwcoYJlyvrReFBenxYeXLt/drivHVFGMvYe058D6xIBDs1qskyroIPM/f3HXGcoCJogm7yO5YzSJu4whHvtux2zMgNlp8pWmxcsIoVnnaZolFv8/V9GGXITIatqEGcxK91EBybKA==" /></oneToOneMappings></iisClientCertificateMappingAuthentication></authentication></security></system.webServer></location>

I hope that I have made it clear enough. If you guys need any kind of additional information, please do not hesitate to inform me.

Looking forward for your help.

Best Regards,

Jordan


Viewing all articles
Browse latest Browse all 12072

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>