Докер Linux: System.Security.Authentication.AuthenticationException: удаленный сертификат недействителен в соответствии с процедурой проверки - PullRequest
0 голосов
/ 10 сентября 2018

Следующий код (.Net core 2.1) прекрасно работает в Visual Studio в Windows.

ServicePointManager.ServerCertificateValidationCallback <- fun _ _ _ _ -> true
use request = new HttpRequestMessage(RequestUri = uri, Method = httpMethod)
use client = new HttpClient(handler)
let! response = client.SendAsync(request) |> Async.AwaitTask

Однако при работе в контейнере Linux возникла следующая ошибка. Кажется, сертификат выдан в соответствии с вопросом Удаленный сертификат недействителен в соответствии с процедурой проверки . Это способ найти и установить сертификат конкретного веб-сайта и установить его в Docker-контейнере?

$ docker run crawlers:latest gmac 201808 System.AggregateException: One or more errors occurred. (The SSL connection could not be established, see inner exception.) ---> System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure. at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, ExceptionDispatchInfo exception) at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.PartialFrameCallback(AsyncProtocolRequest asyncRequest) --- End of stack trace from previous location where exception was thrown --- at System.Net.Security.SslState.ThrowIfExceptional() at System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult) at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result) at System.Net.Security.SslStream.EndAuthenticateAsClient(IAsyncResult asyncResult) at System.Net.Security.SslStream.<>c.b__47_1(IAsyncResult iar) at System.Threading.Tasks.TaskFactory<code>1.FromAsyncCoreLogic(IAsyncResult iar, Func 2 endFunction, Действие 1 endAction, Task 1 обещание, логическое значение требует синхронизации) --- Конец стека трассировки от предыдущего местоположения, где было сгенерировано исключение --- в System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore (Поток потока, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken) --- Конец внутренней трассировки стека исключений --- в System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore (Поток потока, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken) в System.Threading.Tasks.ValueTask 1.get_Result() at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Threading.Tasks.ValueTask 1.get_Result () в System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync (ValueTask 1 creationTask) at System.Threading.Tasks.ValueTask 1.get_Result () в System.Net.Http.HttpConnectionPool.SendWithRetryAsync (запрос HttpRequestMessage, логическое значение doRequestAuth, CancellationToken cancellationToken) в System.Net.Http.RedirectHandler.SendAsync (запрос HttpRequestMessage, CancellationToken cancellationToken) в System.Net.Http.DecompressionHandler.SendAsync (запрос HttpRequestMessage, CancellationToken cancellationToken) at System.Net.Http.HttpClient.FinishSendAsyncBuffered (Задача 1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts) --- End of inner exception stack trace --- ---> (Inner Exception #0) System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure. at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, ExceptionDispatchInfo exception) at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.ProcessReceivedBlob(Byte[] buffer, Int32 count, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) at System.Net.Security.SslState.PartialFrameCallback(AsyncProtocolRequest asyncRequest) --- End of stack trace from previous location where exception was thrown --- at System.Net.Security.SslState.ThrowIfExceptional() at System.Net.Security.SslState.InternalEndProcessAuthentication(LazyAsyncResult lazyResult) at System.Net.Security.SslState.EndProcessAuthentication(IAsyncResult result) at System.Net.Security.SslStream.EndAuthenticateAsClient(IAsyncResult asyncResult) at System.Net.Security.SslStream.<>c.<AuthenticateAsClientAsync>b__47_1(IAsyncResult iar) at System.Threading.Tasks.TaskFactory 1.FromAsyncCoreLogic (IAsyncResult iar, Func 2 endFunction, Action 1 endAction, Задача 1 promise, Boolean requiresSynchronization) --- End of stack trace from previous location where exception was thrown --- at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken) --- End of inner exception stack trace --- at System.Net.Http.ConnectHelper.EstablishSslConnectionAsyncCore(Stream stream, SslClientAuthenticationOptions sslOptions, CancellationToken cancellationToken) at System.Threading.Tasks.ValueTask 1.get_Result () в System.Net.Http.HttpConnectionPool.CreateConnectionAsync (запрос HttpRequestMessage, CancellationToken cancellationToken) в System.Threading.Tasks.ValueTask 1.get_Result() at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask 1 creationTask) в System.Threading.Tasks.ValueTask 1.get_Result() at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken) at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.DecompressionHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task 1 sendTask, запрос HttpRequestMessage, CancellationTokenSource cts, Boolean disposeCts)

1 Ответ

0 голосов
/ 10 сентября 2018

Вам потребуется установить соответствующий сертификат CA в доверенный корень образа Docker.

Добавьте следующие строки в ваш файл Docker, предполагая, что сертификат CA называется mycert.crt

RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/*
COPY ./mycert.crt /usr/local/share/ca-certificates/mycert.crt
RUN update-ca-certificates

Пожалуйста, убедитесь, что формат сертификата такой:

enter image description here

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...