호출-정지 방법 - 자체 서명된 인증서 무시
이 질문에 대해 묻고 답한 것처럼 보이지만, 지금까지 제가 접하는 모든 해결책은 도움이 되지 않습니다.사용 정보를 얻기 위해 REST API를 실행하기 위해 PowerShell 스크립트를 작성하고 있습니다.서버와 통신하기만 하면 스크립트가 즉시 중단됩니다.테스트를 위해 매우 단순한 명령을 수행하고 있습니다.
Invoke-RestMethod 'https://server:4443/login'
다음 오류와 함께 반환됩니다.
Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a send.
저는 URL google.com 을 사용하여 동일한 명령을 실행할 수 있으며 유효한 반환을 받기 때문에 명령이 일반적으로 작동한다는 것을 알고 있습니다.
서버 자체에서 컬에 해당하는 것을 실행하면 예상대로 완료됩니다.다음은 curl 명령의 자세한 출력에 대한 일부입니다.
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server key exchange (12):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using TLSv1.0 / DHE-RSA-AES256-SHA
* Server certificate:
* subject: CN=localhost
* start date: 2016-03-22 21:48:57 GMT
* expire date: 2026-03-20 21:48:57 GMT
* issuer: CN=localhost
* SSL certificate verify result: self signed certificate (18), continuing anyway.
PowerShell이 반환하는 일반적인 오류를 검색한 결과 이 문제는 자체 서명된 인증서 문제라고 생각합니다.
시도해 봤습니다.
[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
기타 유사한 방법(복잡한 기능)을 사용하여 인증서 문제를 무시할 수 있습니다.
도움이 될 경우를 대비해 PowerShell 5를 실행하고 있습니다.
PowerShell 코드는 괜찮지만 Invoke-Rest Method는 처음 시도하는 거라서 뭔가 누락된 것 같습니다.어떤 식으로든 이해해 주시면 감사하겠습니다.
이는 invoke-rest 메서드/webrequest를 사용하는 이후 버전의 파워셸에서도 작동합니다.핸들러를 네이티브 .net으로 구현하여 런스페이스가 필요하지 않습니다.
if (-not("dummy" -as [type])) {
add-type -TypeDefinition @"
using System;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
public static class Dummy {
public static bool ReturnTrue(object sender,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors sslPolicyErrors) { return true; }
public static RemoteCertificateValidationCallback GetDelegate() {
return new RemoteCertificateValidationCallback(Dummy.ReturnTrue);
}
}
"@
}
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = [dummy]::GetDelegate()
이게 도움이 되길 바랍니다.
@x0n 응답 후에도 여전히 문제가 있는 경우 요청/다시 시작하기 전에 추가하십시오.
[System.Net.ServicePointManager]::SecurityProtocol =[System.Net.SecurityProtocolType]::Tls12
작업 스크립트:
if (-not ([System.Management.Automation.PSTypeName]'ServerCertificateValidationCallback').Type)
{
$certCallback = @"
using System;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
public class ServerCertificateValidationCallback
{
public static void Ignore()
{
if(ServicePointManager.ServerCertificateValidationCallback ==null)
{
ServicePointManager.ServerCertificateValidationCallback +=
delegate
(
Object obj,
X509Certificate certificate,
X509Chain chain,
SslPolicyErrors errors
)
{
return true;
};
}
}
}
"@
Add-Type $certCallback
}
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;
[ServerCertificateValidationCallback]::Ignore()
Invoke-WebRequest https://*YOUR URI*
이것이 오래된 것이라는 것을 알지만, 실제로 확인하지 않고 이 질문을 받았을 때 여전히 나왔습니다.구글 먼저 하죠?
사용해 보십시오.
invoke-restMethod -SkipCertificateCheck -uri 'https://server:4443/login' -etc..etc..etc..
구글을 통해 여기서 구했습니다: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-restmethod?view=powershell-6
저도 비슷한 문제가 있었고 제 PS 버전은 5.1이었고, 처음에 사용했습니다.[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12
하지만 아래에 있는 것들은Powershell6
아래 링크의 인증서 정책을 사용하십시오. https://gist.github.com/rchaganti/aae721ebccd25eaab0b8b3dd67ad4b9b
그것은 매력적으로 작동합니다.라비 샤간티 덕분에.
저는 지금 이 같은 문제와 오랫동안 싸우고 있습니다.저는 이 스레드에 이미 게시된 것과 같은 스크립트의 여러 변형을 시도했습니다.테스트 환경이 아닌 워크스테이션에서 동일한 스크립트를 사용하여 실행함으로써 작동한다는 사실에 놀랐습니다.
결국 상승된 자격 증명(관리자 권한으로 실행)을 사용하여 테스트 환경에서 스크립트를 실행하면 SSL/TLS 오류 없이 작동한다는 것을 알게 되었습니다.
언급URL : https://stackoverflow.com/questions/36456104/invoke-restmethod-ignore-self-signed-certs
'sourcecode' 카테고리의 다른 글
구조 포인터 내부의 포인터 참조 취소 (0) | 2023.08.16 |
---|---|
Spring @값 주석은 항상 null로 평가합니까? (0) | 2023.08.16 |
복사 구현 시 모범 사례구역 포함: (0) | 2023.08.11 |
PySpark를 사용하여 CSV 파일 로드 (0) | 2023.08.11 |
ASP를 수정하는 방법.NET 오류 "'nnn.aspx' 파일이 사전 컴파일되지 않았으므로 요청할 수 없습니다."? (0) | 2023.08.11 |