.Net에서 웹 서비스를 호출 할 때 유효하지 않은 SSL 인증서 오류 우회
아직 유효한 SSL 인증서가없는 새 SharePoint를 설정하고 있습니다. 설정에 대한 일부 메타 데이터를 검색하기 위해 Lists 웹 서비스를 호출하고 싶습니다. 그러나 이렇게하려고하면 예외가 발생합니다.
기본 연결이 닫혔습니다. SSL / TLS 보안 채널에 대한 신뢰 관계를 설정할 수 없습니다.
중첩 된 예외에는 오류 메시지가 포함됩니다.
유효성 검사 절차에 따라 원격 인증서가 유효하지 않습니다.
이는 임시 인증서를 사용하고 있기 때문에 정확합니다.
내 질문은 : .Net 웹 서비스 클라이언트 ( SoapHttpClientProtocol )에 이러한 오류를 무시하도록 어떻게 알릴 수 있습니까?
이 문제에 직면했을 때 사용한 접근 방식은 임시 인증서의 서명자를 해당 컴퓨터의 신뢰할 수있는 기관 목록에 추가하는 것이 었습니다.
저는 일반적으로 CACERT로 생성 된 인증서로 테스트를 수행하고이를 신뢰할 수있는 기관 목록에 추가하면 원활하게 작동했습니다.
이렇게하면 응용 프로그램에 사용자 지정 코드를 추가 할 필요가 없으며 응용 프로그램이 배포 될 때 발생할 일을 올바르게 시뮬레이션 할 수 있습니다. 따라서 이것이 프로그래밍 방식으로 검사를 해제하는 데 탁월한 솔루션이라고 생각합니다.
또는 인증 오류를 무시하는 콜백 대리인을 등록 할 수 있습니다.
...
ServicePointManager.ServerCertificateValidationCallback = MyCertHandler;
...
static bool MyCertHandler(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors error)
{
// Ignore errors
return true;
}
Jason S의 대답처럼 :
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
나는 이것을 내 Main에 넣고 코드 줄을 호출하기 전에 내 app.config
보고 테스트합니다 (ConfigurationManager.AppSettings["IgnoreSSLCertificates"] == "True")
.
이 방법으로 해결했습니다.
해당 오류를 일으키는 SSL 웹 서비스를 호출하기 직전에 다음을 호출하십시오.
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
/// <summary>
/// solution for exception
/// System.Net.WebException:
/// The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
/// </summary>
public static void BypassCertificateError()
{
ServicePointManager.ServerCertificateValidationCallback +=
delegate(
Object sender1,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{
return true;
};
}
DownloadString을 사용하여 동일한 오류가 발생했습니다. 이 페이지의 제안으로 아래와 같이 작동하도록 만들 수있었습니다.
System.Net.WebClient client = new System.Net.WebClient();
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
string sHttpResonse = client.DownloadString(sUrl);
ServicePointManager.ServerCertificateValidationCallback +=
(mender, certificate, chain, sslPolicyErrors) => true;
invaild ssl을 우회합니다. 웹 서비스 생성자에 작성하십시오.
초보자를 위해 별도의 cs 파일에서 부분 서비스 클래스를 확장하고 "imanabidi"에서 제공 한 코드를 추가하여 통합 할 수 있습니다.
Simon Johnsons 게시물을 더 확장하려면-이상적으로는 프로덕션에서 보게 될 조건을 시뮬레이션하는 솔루션을 원하고 코드를 수정해도 그렇게되지 않으며 배포하기 전에 코드를 제거하는 것을 잊으면 위험 할 수 있습니다.
You will need a self-signed certificate of some sort. If you're using IIS Express you will have one of these already, you'll just have to find it. Open Firefox or whatever browser you like and go to your dev website. You should be able to view the certificate information from the URL bar and depending on your browser you should be able to export the certificate to a file.
Next, open MMC.exe, and add the Certificate snap-in. Import your certificate file into the Trusted Root Certificate Authorities store and that's all you should need. It's important to make sure it goes into that store and not some other store like 'Personal'. If you're unfamiliar with MMC or certificates, there are numerous websites with information how to do this.
Now, your computer as a whole will implicitly trust any certificates that it has generated itself and you won't need to add code to handle this specially. When you move to production it will continue to work provided you have a proper valid certificate installed there. Don't do this on a production server - that would be bad and it won't work for any other clients other than those on the server itself.
'program tip' 카테고리의 다른 글
Tensorflow 백엔드가있는 Keras가 CPU 또는 GPU를 마음대로 사용하도록 강요받을 수 있습니까? (0) | 2020.09.13 |
---|---|
Bootstrap 4의 .pull-left 및 .pull-right 클래스는 어떻게 되었습니까? (0) | 2020.09.13 |
PHP에서 날짜 시간을 ISO 8601로 변환하는 방법 (0) | 2020.09.13 |
디렉토리의 폴더 목록 가져 오기 (0) | 2020.09.13 |
해시에서 하위 해시를 어떻게 추출합니까? (0) | 2020.09.13 |