Last active
December 15, 2015 12:39
-
-
Save dpwiz/5261576 to your computer and use it in GitHub Desktop.
http-conduit with client certificate example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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