2

The trouble I am facing is hard to debug as it doesn't offer much of an explanation in the stack trace. What I am trying to do is retrieve an oAuth token using a key and a secret provided to me. When using postman it works just fine meaning the issue cannot be external. When I try it in Clojure it fails.

See sample code below.

(let [options {:keepalive 10000
               :timeout 10000                 
               :query-params {:grant_type "client_credentials"}
               :headers {"Authorization" (str "Basic "  (-> (str (:key config/oAuth) ":" (:secret config/oAuth)) .getBytes b64/encode String. ))}
               }]             
  @(http/get "https://my-path.com/oauth/v1/generate" options))

the result I get is

    1. Unhandled java.io.IOException
   An existing connection was forcibly closed by the remote host
     SocketDispatcher.java:   -2  sun.nio.ch.SocketDispatcher/read0
     SocketDispatcher.java:   43  sun.nio.ch.SocketDispatcher/read
               IOUtil.java:  223  sun.nio.ch.IOUtil/readIntoNativeBuffer
               IOUtil.java:  197  sun.nio.ch.IOUtil/read
    SocketChannelImpl.java:  379  sun.nio.ch.SocketChannelImpl/read
         HttpsRequest.java:   93  org.httpkit.client.HttpsRequest/doHandshake
           HttpClient.java:  133  org.httpkit.client.HttpClient/doRead
           HttpClient.java:  377  org.httpkit.client.HttpClient/run
               Thread.java:  745  java.lang.Thread/run
IOException java.io.IOException: An existing connection was forcibly closed by the remote host

Below is the curl request sample generates

curl -X GET 'https://my-path.com/oauth/v1/generate' -H 'authorization: Basic Nasjdbajksdkasjdkey:secret==' -H 'cache-control: no-cache' -H 'postman-token: f2af6f4a-f197-20df-f9be-a5a9a7525e57'

I have obviously changed any sensitive information. Now the strange thing is that when I run that curl request it doesn't work despite postman returning expected results. See curl error below

* Adding handle: conn: 0x1328a58
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x1328a58) send_pipe: 1, recv_pipe: 0
* About to connect() to my-path.com port 443 (#0)
*   Trying xxx.xxx.xxx.xxx...
* Connected to my-path.com (xxx.xxx.xxx.xxx) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: E:\Git\bin\curl-ca-bundle.crt
  CApath: none
* SSLv3, TLS handshake, Client hello (1):
* Unknown SSL protocol error in connection to my-path.com:443
* Closing connection 0
curl: (35) Unknown SSL protocol error in connection to my-path.com:443

Why does it work on postman but not for the exact curl request postman generated?

Why does it not work for my Clojure app, any assistance will be greatly appreciated.

sqwale
  • 554
  • 3
  • 24
  • Try to run `curl` with `--verbose` to get more details. – Piotrek Bzdyl Oct 19 '17 at 07:40
  • Just edited to add more context – sqwale Oct 19 '17 at 08:23
  • I am not sure what might be the issue. Does Postman offer a log with more details of the request (e.g. the actual remote IP address etc.)? Does Postman have a client certificate setup which is not provided to curl? – Piotrek Bzdyl Oct 19 '17 at 08:37
  • Also I would check what could be the cause of "Unknown SSL protocol error in connection" error, for example http://blog.techstacks.com/2010/03/3-common-causes-of-unknown-ssl-protocol-errors-with-curl.html. – Piotrek Bzdyl Oct 19 '17 at 08:38
  • Most likely some setting or a default in postman make it work. `my-path.com` gives me errors too. And if this is just a dummy-name (why not use `example.com` instead then?), then make sure, that it actually runs httpS there and not just http. – cfrick Oct 19 '17 at 12:16
  • Considering the `Unknown SSL protocol error`, you'd better use `openssl s_client -connect my-path.com:443` to gain a better insight in the TLS support of the server. – user2609980 Oct 20 '17 at 13:57
  • It looks like `http-kit` requires a reverse proxy to support https ([docs](http://www.http-kit.org/migration.html)). – nrako Oct 20 '17 at 17:14

0 Answers0