ASPNET_REGIIS를 사용하여 사용자 정의 구성 섹션을 암호화 할 수 있습니까?
-
16-09-2019 - |
문제
사용자 정의 구성 섹션이있는 웹 응용 프로그램이 있습니다. 이 섹션에는 내가 암호화하고 싶은 정보가 포함되어 있습니다 (직접하기보다는 aspnet_regiis를 사용하기를 바랐습니다).
web.config :
<?xml version="1.0"?>
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<configSections>
<section name="MyCustomSection"
type="MyNamespace.MyCustomSectionHandler, MyAssembly"/>
</configSections>
<configProtectedData>
<providers>
<clear />
<add name="DataProtectionConfigurationProvider"
type="System.Configuration.RsaProtectedConfigurationProvider, System.Configuration, Version=2.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a,
processorArchitecture=MSIL"
keyContainerName="MyKeyContainer"
useMachineContainer="true" />
</providers>
</configProtectedData>
<MyCustomSection>
<blah name="blah1">
<blahChild name="blah1Child1" />
</blah>
</MyCustomSection>
구성 핸들러는 암호화하기 전에 훌륭하게 작동합니다. 내가 암호화하려고 할 때 :
aspnet_regiis -pef "mycustomsection"c : inetpub wwwroot mywebsite -prov dataprotectionconfigurationprovider
오류가 발생합니다.
암호화 구성 섹션 ... 오류가 발생했습니다. myCustomsection에 대한 구성 섹션 핸들러를 생성 : 파일 또는 어셈블리 'myAsSembly'또는 그 종속성 중 하나를로드 할 수 없습니다. 시스템이 지정된 파일을 찾을 수 없습니다. (C : inetpub wwwroot mywebsite web.config line 5)
공급자가 구성된 유무에 관계없이 시도했습니다. 섹션 그룹이 있거나없는. 미리 웹 사이트를 시작한 것과 함께. 등록을 위해 GAC에 조립을 일시적으로 배치하려고 시도했습니다. 나는 또한 내 로그 4NET 섹션을 시도하여 운이 좋지 않은 내 것이 아닌 것을 시도했습니다. 명령 프롬프트를 관리자로 실행합니다. 어떤 아이디어? 아니면 ASPNET_REGIIS가 사용자 정의 섹션에 사용될 수 없습니까?
보기 후 마지막 샷 MSDN 기술적으로 2.0에서 이상 사용되지 않았기 때문에 iconfigurationsectionhandler를 구현하기보다는 핸들러가 구성에서 상속되도록 변경하고있었습니다 (ASPNET_REGIIS 버전과 관련된 것이기를 바랍니다). 거기에도 운이 없습니다.
어떤 아이디어라도 알려주세요. 감사!
해결책
aspnet_regiis
어셈블리를 바인딩 할 수 있어야합니다. 정상적인 .NET 바인딩 규칙이 적용됩니다.
나는 호출 된 디렉토리를 만들어 이것을 돌아옵니다 aspnet_regiis_bin
같은 디렉토리에서 aspnet_regiis.exe
그리고 aspnet_regiis.exe.config
파일 aspnet_regiis_bin
이와 같은 개인 경로로 :
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="aspnet_regiis_bin"/>
</assemblyBinding>
</runtime>
</configuration>
그런 다음 사용자 정의 구성 섹션을 다음으로 정의하는 어셈블리를 복사합니다. aspnet_regiis_bin
~하도록 하다 aspnet_regiis
그들을 찾을 수 있습니다.
이 절차는 어셈블리의 이름이 강하거나 GAC에서 강력해야하지만 프레임 워크 디렉토리에서 엉망이 필요합니다.
다른 팁
구성 요소의 내용을 일시적으로 주석으로하는 해결 방법을 사용하고 있습니다.
<configSection>
<!--
<section name="CustomSection" type="" />
-->
</configSection>
그런 다음 암호화를 사용하여 실행할 수 있습니다 aspnet_regiis -pef
평소와 같이. 이 후에는 무의미한 상태에서 섹션을 실행하고 사이트가 실행될 준비가되었습니다.
이것은 전체 해킹이지만, 사용자 정의 섹션을 정의하고 조정하는 어셈블리를 강력하게 명명하지 않고 그것을 할 수있는 또 다른 방법이 있는지 잘 모르겠습니다 (작동하지 않았지만 확실하지 않더라도 확실하지 않습니다. 왜 그렇지 않은지). aspnet_regiis는 <drive> : windows microsoft.net framework <bersion> 폴더 (WinXP)에서 실행되므로 구성 섹션을 관련 프레임 워크 <버전> 폴더로 정의하는 DLL을 복사 할 수 있습니다. 작동해야합니다.
기록을 위해, 나는 이것을 위해 이것을하기 위해 약간의 유지 보수 페이지로 끝났습니다.
var currentConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration("~/");
// Unprotect
ConfigurationSection section = currentConfig.GetSection("MyCustomSection");
if (section.SectionInformation.IsProtected)
{
section.SectionInformation.UnprotectSection();
currentConfig.Save();
}
// Protect
if (!section.SectionInformation.IsProtected)
{
section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
currentConfig.Save();
}
경고 : 프로세스는 수정중인 구성 파일에 대한 쓰기 액세스가 필요합니다. 누가 이것을 실행할 수 있는지 승인 할 수있는 방법을 원할 것입니다. 당신은 일반적으로 저장하면 웹 사이트를 다시 시작하십시오.
올바른 것으로 표시된 대답은 정확합니다. 주석을 추가하고 싶었지만 주석 (샘플 구성 항목)이 너무 길기 때문에 할 수 없었습니다.
섹션 이름은 어셈블리의 전체 이름을 사용해야합니다. 런타임 어셈블리 자격은 aspnet_regiis.exe에서 작동하지 않습니다.
이것은 작동합니다 :
<configSections>
<section name="securityConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Security.Configuration.SecuritySettings, Microsoft.Practices.EnterpriseLibrary.Security, Version=5.0.414.0, Culture=neutral, PublicKeyToken=9c844884b2afcb9e" />
</configSections>
그러나 이것은 작동하지 않습니다.
<configSections>
<section name="securityConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Security.Configuration.SecuritySettings, Microsoft.Practices.EnterpriseLibrary.Security" />
</configSections>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<qualifyAssembly partialName="Microsoft.Practices.EnterpriseLibrary.Security" fullName="Microsoft.Practices.EnterpriseLibrary.Security, Version=5.0.414.0, Culture=neutral, PublicKeyToken=9c844884b2afcb9e" />
</assemblyBinding>
</runtime>