Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The SSL connection could not be established #920

Closed
jonny-xhl opened this issue Jun 12, 2019 · 14 comments · Fixed by #1377
Closed

The SSL connection could not be established #920

jonny-xhl opened this issue Jun 12, 2019 · 14 comments · Fixed by #1377
Assignees
Labels
bug Identified as a potential bug merged Issue has been merged to dev and is waiting for the next release Websockets Ocelot feature: Websockets

Comments

@jonny-xhl
Copy link

I local debug is ok,but publish to IIS is error.
Don't use ocelot is ok,when I use upstream to get is error.

My logs details

warn: Ocelot.Requester.Middleware.HttpRequesterMiddleware[0]
      requestId: 0HLNESHAE1B8L:00000003, previousRequestId: no previous request id, message: Error making http request, 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.<AuthenticateAsClientAsync>b__47_1(IAsyncResult iar)
         at System.Threading.Tasks.TaskFactory`1.FromAsyncCoreLogic(IAsyncResult iar, Func`2 endFunction, Action`1 endAction, Task`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()
         at System.Net.Http.HttpConnectionPool.CreateConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
         at System.Threading.Tasks.ValueTask`1.get_Result()
         at System.Net.Http.HttpConnectionPool.WaitForCreatedConnectionAsync(ValueTask`1 creationTask)
         at System.Threading.Tasks.ValueTask`1.get_Result()
         at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
         at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
         at Ocelot.Requester.HttpClientHttpRequester.GetResponse(DownstreamContext context)

ocelot.json

{
  "ReRoutes": [
    //identityserver4  token
    {

      "DownstreamPathTemplate": "/connect/token",
      "DownstreamScheme": "https",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": "5001"
        }
      ],
      "UpstreamPathTemplate": "/auth/token",
      "UpstreamHttpMethod": ["Post"],
      "UseServiceDiscovery": true,
      "DangerousAcceptAnyServerCertificateValidator": false
    },
    // API:Service1
    {
      "AuthenticationOptions": {
        "AuthenticationProviderKey": "service1Identity",
        "AllowedScopes": []
      },
      "DownstreamPathTemplate": "/api/{url}",
      "DownstreamScheme": "https",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": "5011"
        }
      ],
      "UpstreamPathTemplate": "/Service1/{url}",
      "UpstreamHttpMethod": [ "Get", "Post" ],
      "UseServiceDiscovery": true,
      "DangerousAcceptAnyServerCertificateValidator": false
    },
    // API:Service2
    {
      "AuthenticationOptions": {
        "AuthenticationProviderKey": "service2Idnetity",
        "AllowedScopes": []
      },
      "DownstreamPathTemplate": "/api/{url}",
      "DownstreamScheme": "https",
      "DownstreamHostAndPorts": [
        {
          "Host": "localhost",
          "Port": "5021"
        }
      ],
      "UpstreamPathTemplate": "/Service2/{url}",
      "UpstreamHttpMethod": [ "Get", "Post" ],
      "UseServiceDiscovery": true,
      "DangerousAcceptAnyServerCertificateValidator": false
    }
  ],
  "GlobalConfiguration": {
    "ServiceDiscoveryProvider": {
      "Host": "192.168.1.186",
      "Port": 8500,
      "Type": "Consul"
    },
    "RateLimitOptions": {
      "ClientIdHeader": "client_id",
      "QuotaExceededMessage": "Too Many Requests!!!",
      "DisableRateLimitHeaders": false
    }
  }
}
@yuft
Copy link

yuft commented Jun 12, 2019

it clearly says 'The remote certificate is invalid according to the validation procedure'.

Did you check if SSL certificate is valid or not?

E.g. open a endpoint with Chrome and see what Chrome says. https://localhost:5001

@jonny-xhl
Copy link
Author

I open a endpoint with Chrome is not an effective secure connection,but I can get data by clicking on Continue Link.

@yuft
Copy link

yuft commented Jun 12, 2019

see #309 #325 ,

set DangerousAcceptAnyServerCertificateValidator in ReRoute config and this will ignore SSL errors, false by default.

@jonny-xhl
Copy link
Author

see #309 #325 ,

set DangerousAcceptAnyServerCertificateValidator in ReRoute config and this will ignore SSL errors, false by default.

I set DangerousAcceptAnyServerCertificateValidator false,but also error.

@jonny-xhl
Copy link
Author

see #309 understand it.
The code is in the company and will only be tested tomorrow.

@v2codes
Copy link

v2codes commented May 22, 2020

maybe you need to set DangerousAcceptAnyServerCertificateValidator = true,if you want to ignore SSL validation

@naruto1227
Copy link

Is there an answer to this question?

@naruto1227
Copy link

微信图片_20200722174716

@nemanjapyr
Copy link

have you managed to get around this issue yet?

i seem to be running into the same issue and using DangerousAcceptAnyServerCertificateValidator = true doesn't resolve it either.

@naruto1227
Copy link

I also set DangerousAcceptAnyServerCertificateValidator = true, but it has no effect

@57575
Copy link

57575 commented Jun 13, 2021

try modify your downStreamScheme to "http"

@harshwd
Copy link

harshwd commented Dec 8, 2022

I am having same issue, any resolution?

image

@ahmedtolba1984
Copy link

@harshwd
Did you solve the issue as we currently face the same issue with the same stacktrace?

@raman-m
Copy link
Member

raman-m commented Sep 25, 2023

@raman-m raman-m self-assigned this Sep 25, 2023
@raman-m raman-m added bug Identified as a potential bug Websockets Ocelot feature: Websockets labels Sep 25, 2023
raman-m added a commit that referenced this issue Sep 28, 2023
…tificateValidator (#1377)

* Fix/1375 fix DownstreamRoute DangerousAcceptAnyServerCertificateValidator does not work

* Fix the exception when RoundRobin services is empty

* Fix build errors

* IDE0063 'using' statement can be simplified

* IDE0051 Private member 'StreamCopyBufferSize' is unused

* Use nameof() in string interpolations

* @RaynaldM code review

* Code review. Refactor method

* Organize folders for WebSockets feature

* Add unit tests class for WebSockets feature

* Refactor middleware to make it suitable for unit testing

* Add unit test

* Review current acceptance tests for WebSockets

* Review

---------

Co-authored-by: raman-m <[email protected]>
@raman-m raman-m added the merged Issue has been merged to dev and is waiting for the next release label Sep 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Identified as a potential bug merged Issue has been merged to dev and is waiting for the next release Websockets Ocelot feature: Websockets
Projects
None yet
9 participants