Azure 웹사이트의 사이트에서 X509 Certificate 2 처리가 실패함
Azure Web 사이트(호스트 서비스 아님)에 사이트를 가지고 있으며, 거기서 개인 키를 사용하여 .pfx 증명서를 처리해야 합니다.
var x509Certificate2 = new X509Certificate2(certificate, password);
하지만 나는 다음과 같은 예외에 직면했다.
System.Security.Cryptography.CryptographicException: The system cannot find the file specified.
at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)
at System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromBlob(Byte[] rawData, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx)
at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[] rawData, Object password, X509KeyStorageFlags keyStorageFlags)
at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(Byte[] rawData, String password, X509KeyStorageFlags keyStorageFlags)
at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData, String password, X509KeyStorageFlags keyStorageFlags)
기사 http://blog.tylerdoerksen.com/2013/08/23/pfx-certificate-files-and-windows-azure-websites/에서는 기본적으로 사용자 로컬디렉토리를 사용하여 키를 저장하기 때문에 이 문제가 발생한다는 것을 알게 되었습니다.그러나 Azure 웹사이트에는 로컬 사용자 프로필 디렉토리가 없습니다.같은 기사에서 저자는 다음을 사용할 것을 제안합니다.X509KeyStorageFlags.MachineKeySet
플래그를 설정합니다.
var x509Certificate2 = new X509Certificate2(certificate, password, X509KeyStorageFlags.MachineKeySet);
하지만 이제 다른 예외가 있습니다.
System.Security.Cryptography.CryptographicException: Access denied.
at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)
at System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromBlob(Byte[] rawData, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx)
at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[] rawData, Object password, X509KeyStorageFlags keyStorageFlags)
at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(Byte[] rawData, String password, X509KeyStorageFlags keyStorageFlags)
at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData, String password, X509KeyStorageFlags keyStorageFlags)
왜 이런 일이 일어나는지, 어떻게 고쳐야 하는지 제가 이해할 수 있도록 도와줄 사람 있나요?
회피책을 찾으셨다고 생각합니다만, 다른 사람이 이 문제에 어려움을 겪고 있다면, 저는 다른 SO 질문에서 이에 대한 답을 찾았습니다.
PKCS#12 바이트 어레이에서 X509 Certificate2를 구축하는 방법 Cryptographic Exception()시스템에서 지정된 파일을 찾을 수 없습니다."?
매직은 X509KeyStorageFlags 스토리지 플래그를 지정하는 것입니다.예:
var myCertificae = new X509Certificate2(
certificateData,
securePasswordString,
X509KeyStorageFlags.MachineKeySet |
X509KeyStorageFlags.PersistKeySet |
X509KeyStorageFlags.Exportable);
Azure Web 사이트에서는 증명서 스토어에 증명서를 설치할 수 있게 되었습니다.시도해 봤어?
자세한 내용은 이쪽:http://azure.microsoft.com/blog/2014/10/27/using-certificates-in-azure-websites-applications/
Azure Web 사이트는 공유 환경에서 실행됩니다.증명서 컨스트럭터가 인스턴스에서 임시 정보를 생성하려고 시도하고 있으며, 이 정보를 생성할 수 있는 권한이 없는 것으로 가정합니다.
상위 컨텍스트에서 실행하고 이 작업을 수행하려면 호스트 서비스로 업그레이드해야 할 수 있습니다.
그리고 비밀번호가 맞는지 확인하셨나요?패스워드가 필요 없는 경우는, 적어도 문자열을 건네주셔야 합니다.생성자에 대해 비어 있습니다.NULL 값을 전달해도 이 예외가 발생합니다.
똑같은 문제가 있어서 고치느라 몇 시간이나 고생했어요.당신이 언급한 마지막 스택콜은 LoadCertFromFile 함수에 대한 것이지만 당신의 경우(그리고 나의 경우) 그것은 LoadCertFromBlob입니다.
그래서 LoadCertFromBlob을 찾아보니 다음과 같습니다.
X509 Certificate2가 BLOB에서 작성되지 않는 이유는 무엇입니까?
해결책은 IIS에서 응용 프로그램 풀 ID를 "ApplicationPoolIdentity"에서 "LocalService"로 변경하여 증명서가 올바른 로컬 폴더에 로드되도록 하는 것이었습니다.
Azure 웹 사이트 / 웹 앱 / 모바일 앱 - SSL 인증서 가져오기를 허용하는 앱 서비스 플랜을 사용해야 하므로 무료 또는 공유가 되지 않아야 합니다.SSL 인증서뿐만 아니라 코드 서명 인증서 예제에도 가져와 signtool 또는 PowerShell에서 사용할 수 있습니다.
https://vmplace.eu/에서 이 방법을 사용했습니다.
무료 플랜 또는 공유 플랜을 사용하려고 하면 오류가 발생합니다.따라서 이 플랜의 Azure에는 다른 버전의 가 있습니다.NET 프레임워크
이 프로젝트도 참조할 수 있습니다.https://github.com/onovotny/SignService
mvpbuzz.
저는 공문서의 지시에 따라 이 문제를 해결했습니다.이전에는 이것이 옵션이었는지는 잘 모르겠지만, 현재는 옵션이 되었습니다.또, 사용/실장도입이 용이했습니다.
먼저 Azure App Service에 .pfx 증명서를 업로드하고 입력하라는 메시지가 뜨면 비밀번호를 입력했습니다.지문을 복사했다.
그런 다음 Azure Console 내에서 다음 명령을 실행했습니다(지문 하나만 추가).이는 앱이 인증서에 액세스할 수 있도록 하기 때문에 중요합니다.
az webapp config appsettings set --name <app-name> --resource-group <resource-group-name> --settings WEBSITE_LOAD_CERTIFICATES=<comma-separated-certificate-thumbprints>
- 다음 방법을 사용하여 이전에 업로드한 .pfx 증명서를 앱에 로드했습니다.
public X509Certificate2 GetAzureCertificate(string thumbprint, bool validOnly)
{
using (var certStore = new X509Store(StoreName.My, StoreLocation.CurrentUser))
{
certStore.Open(OpenFlags.ReadOnly);
var certCollection = certStore.Certificates.Find(X509FindType.FindByThumbprint, thumbprint, validOnly);
var cert = certCollection.OfType<X509Certificate2>().FirstOrDefault();
if (cert == null)
{
throw new Exception($"Cert not found. Total cert count : {certStore.Certificates.Count}.");
}
return cert;
}
}
언급URL : https://stackoverflow.com/questions/18959418/site-in-azure-websites-fails-processing-of-x509certificate2
'programing' 카테고리의 다른 글
UITable View 아래에 추가 구분 기호 제거 (0) | 2023.04.22 |
---|---|
배리언트 배열에 범위를 할당하는 데 문제가 발생하는 이유 (0) | 2023.04.22 |
Excel 선택과 활성화 (0) | 2023.04.22 |
최대 길이 UITextField (0) | 2023.04.22 |
차트의 반복 호출.SetSourceData 오류 1004 발생 (0) | 2023.04.22 |