cURL이 Windows에서 인증서를 제대로 확인할 수 없는 이유는 무엇입니까?

cURL이 Windows에서 인증서를 제대로 확인할 수 없는 이유는 무엇입니까?

URL 을 검색하기 위해 Windows에서 Curl을 사용하려고 하면 https무서운 "연결 오류(60)"가 발생합니다.

여기에 이미지 설명을 입력하세요

정확한 오류 메시지는 다음과 같습니다.

컬: (60) SSL 인증서 문제입니다. CA 인증서가 올바른지 확인하세요. 세부 정보:
오류:14090086:SSL 루틴:SSL3_GET_SERVER_CERTIFICATE:인증서 확인 실패
자세한 내용은 여기를 참조하세요.http://curl.haxx.se/docs/sslcerts.html

이 문제를 해결하는 방법은 무엇입니까?

답변1

이유는 모르겠지만 이 정보를 한 곳에서 모두 찾을 수 없었습니다.

  1. SSL 인식 버전의 Curl을 다운로드하거나 SSL 인식 버전을 직접 구축하세요.

  2. 에서http://curl.haxx.se/docs/caextract.html, cacert.pem 파일을 다운로드합니다.

  3. 컬.exe와 .pem 파일을 동일한 디렉터리에 배치합니다.

  4. cacert.pem파일 이름을 다음으로 바꿉니다 .curl-ca-bundle.crt

  5. 컬.exe를 다시 실행하세요!


편집하다:

문제를 해결하는 다른 방법이 있습니다. 이 특별한 방법은 Curl 제조사가 제작한 cacert에 의존합니다. 이는 원하는 것이 아닐 수 있으며, 특히 SSL 사이트에서 사용하는 인증서에 대해 잘 알려지지 않은 인증 기관(예: 회사에만 알려진 기관)이 있는 경우에는 작동하지 않을 수 있습니다. . 이 경우 자신만의 파일을 생성하고 싶을 것입니다 curl-ca-bundle.crt. certreq.exe 및 openssl.exe를 사용하여 IE/Windows 저장소에서 해당 인증서를 내보낸 다음 각각 pem-format으로 변환할 수 있습니다.

답변2

ca-cert.crtWindows 인증 저장소(CurrentUser 또는 LocalMachine)에 설치된 CA 인증서를 기반으로 파일을 작성할 수 있는 PowerShell 스크립트를 만들었습니다 . 다음과 같이 스크립트를 실행하세요.

CreateCaCert.ps1 -StoreLocation CurrentUser | Out-File -Encoding utf8 curl-ca-cert.crt

curl-ca-cert.crt이렇게 하면 와 동일한 디렉토리에 저장되어야 하는 파일이 생성되며 curl.exeWindows 응용 프로그램에서와 동일한 사이트의 유효성을 검사할 수 있어야 합니다. 이 파일은 에서도 사용할 수 있습니다 git.

"공식" 스크립트는 다음에서 찾을 수 있습니다.GitHub, 그러나 참고용으로 초기 버전이 여기에 나열되어 있습니다.

[CmdletBinding()]
Param(
    [ValidateSet(
        [System.Security.Cryptography.X509Certificates.StoreLocation]::CurrentUser,
        [System.Security.Cryptography.X509Certificates.StoreLocation]::LocalMachine)]
    [string]
    $StoreLocation = [System.Security.Cryptography.X509Certificates.StoreLocation]::CurrentUser
)

$maxLineLength = 77

# Open the store
$store = New-Object System.Security.Cryptography.X509Certificates.X509Store ([System.Security.Cryptography.X509Certificates.StoreName]::Root, $StoreLocation)
$store.Open([System.Security.Cryptography.X509Certificates.OpenFlags]::ReadOnly);

# Write header
Write-Output "# Root certificates ($StoreLocation) generated at $(Get-Date)"

# Write all certificates
Foreach ($certificate in $store.Certificates)
{
    # Start with an empty line
    Write-Output ""

    # Convert the certificate to a BASE64 encoded string
    $certString = [Convert]::ToBase64String($certificate.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Cert));

    # Write the actual certificate
    Write-Output "# Friendly name: $($certificate.FriendlyName)"
    Write-Output "# Issuer:        $($certificate.Issuer)"
    Write-Output "# Expiration:    $($certificate.GetExpirationDateString())"
    Write-Output "# Serial:        $($certificate.SerialNumber)"
    Write-Output "# Thumbprint:    $($certificate.Thumbprint)"
    Write-Output "-----BEGIN CERTIFICATE-----"
    For ($i = 0; $i -lt $certString.Length; $i += $maxLineLength)
    {
        Write-Output $certString.Substring($i, [Math]::Min($maxLineLength, $certString.Length - $i))
    }
    Write-Output "-----END CERTIFICATE-----"
}

답변3

실제로 Typheous/Ruby에서도 동일한 문제가 발생했습니다. 솔루션은cacert.pemC:\Windows\System32(또는 Windows가 있는 위치)에 저장합니다. 그 후 전역 환경 변수를 설정합니다.여기에 설명된 것처럼여기서 "변수 이름"은 있어야 CURL_CA_BUNDLE하고 "변수 값"은 파일 경로여야 합니다 %SystemRoot%\System32\cacert.pem.

새로운 CMD 세션을 시작할 때 이제 Typheous/Libcurl을 사용하여 SSL 연결을 인증할 수 있습니다. Windows 8.1에서 성공적으로 시도했습니다.

관련 정보