Skip to content

Instantly share code, notes, and snippets.

@dpwiz
Last active December 15, 2015 12:39
Show Gist options
  • Save dpwiz/5261576 to your computer and use it in GitHub Desktop.
Save dpwiz/5261576 to your computer and use it in GitHub Desktop.
http-conduit with client certificate example
module Main where
import Network.TLS (PrivateKey)
import Network.TLS.Extra as TLS
import Network.HTTP.Conduit
import Data.Certificate.X509 (X509)
import qualified Data.ByteString.Lazy.Char8 as LBS
import System.Environment (getArgs)
import GW.PaySafeCard
import Private
main :: IO ()
main = do
(confName:args) <- getArgs
let conf = case confName of
"test" -> testConf
_ -> error "unknown conf"
certs <- loadClientCerts "test.pem" "test.key"
req <- parseUrl (pscURL conf)
let req' = req { clientCertificates = certs }
Response _ _ _ lbs <- withManager $ httpLbs req'
LBS.putStrLn lbs
loadClientCerts :: FilePath -> FilePath -> IO [(X509, Maybe PrivateKey)]
loadClientCerts certPath keyPath = do
cert <- TLS.fileReadCertificate certPath
pkey <- TLS.fileReadPrivateKey keyPath
return [(cert, Just pkey)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment