snoyberg / http-client

An HTTP client engine, intended as a base layer for more user-friendly packages.
280 stars 194 forks source link

TlsExceptionHostPort (HandshakeFailed (Error_Protocol ("expecting server hello, got alert : [(AlertLevel_Fatal,HandshakeFailure)]",True,HandshakeFailure))) #182

Closed nineonine closed 8 years ago

nineonine commented 8 years ago

Im trying to establish secured connection with https://www.discogs.com

here is my code

{-# LANGUAGE OverloadedStrings #-}

module Main where

import Data.ByteString.Lazy (ByteString)
import Network.HTTP.Client
import Network.HTTP.Client.TLS

discogstls :: String -> IO ByteString
discogstls s = do
    initReq <- parseUrl s
    man <- newManager tlsManagerSettings
    let req = initReq { requestHeaders = [("User-Agent","dummytesting")] } 
    resp <- httpLbs req man
    return $ responseBody resp

then I'm testing it in ghci and getting an error

λ: discogstls "https://api.discogs.com/users/chemik_ck?token=LeOmytEjqpOGESAqxfbVuazqjJkUMSZAEyFtIjSm"
*** Exception: TlsExceptionHostPort (HandshakeFailed (Error_Protocol ("expecting server hello, got alert : [(AlertLevel_Fatal,HandshakeFailure)]",True,HandshakeFailure))) "api.discogs.com" 443

according to discogs.com API documentation, I can send token either in URL params or in headers - i tried both - nothing worked.

Then I googled that issue related to some troubles with tls package. However, after that I used some tls debugging tools (tls-simpleclient from hs-tls) and I had no problems establishing connection with the host.

I tried everything - I updated all the necessary packages and nothing helped.

There was the same issue but , it was openSSL related and according to that thread Discogs switched to tls completely.

Am I doing something wrong ?

thanks

nineonine commented 8 years ago

this is definitely something discogs specific and not related to this library. closing it

nineonine commented 8 years ago

I tried it with Wreq and got the same Exception *** Exception: TlsExceptionHostPort (HandshakeFailed (Error_Protocol ("expecting server hello, got alert : [(AlertLevel_Fatal,HandshakeFailure)]",True,HandshakeFailure))) "api.discogs.com" 443 _Interesting to notice: _ I got that Exception first time I tried to do authorised request (passing token as Url param) however doing unauthorized requests was possible ! (and I used defaultManagerSettings for that, not tlsManagerSettings. After I updated http-client, http-client-tls, tls , it became impossible to request anything (using defaultManagerSettings stopped working as well).

nineonine commented 8 years ago

should I address this issue in tls library ? maybe @vincenthz could help ? ^_^

might be helpful : https://www.ssllabs.com/ssltest/analyze.html?d=discogs.com&latest

nineonine commented 8 years ago

all good now . This was my first experience with cabal hell :)

eikeon commented 8 years ago

@nineonine What what the issue... think I'm in that same cabal hell now

nineonine commented 8 years ago

@eikeon in my case this scenario worked

ghc-pkg list

There were 2 versions of tls listed there. I unregistered the older package doing

ghc-pkg unregister --force <necessary package>

eikeon commented 8 years ago

@nineonine Thank you. ( In my case it looks like I need to install an older version for now: https://github.com/vincenthz/hs-tls/issues/145#issuecomment-218035708 )