on master help sign in
New version of certificate
5a66b93Michael Snoyman
warp-tls/Network/Wai/Handler/WarpTLS.hs+18−17
@@ -17,10 +17,12 @@ import qualified Data.Conduit.List as CL
17import Control.Exception (bracket, handle, SomeException)
17import Control.Exception (bracket, handle, SomeException)
18import qualified Network.TLS.Extra as TLSExtra
18import qualified Network.TLS.Extra as TLSExtra
19import qualified Data.Certificate.X509 as X509
19import qualified Data.Certificate.X509 as X509
20−import qualified Data.Certificate.PEM as PEM
21import qualified Data.ByteString as B
20import qualified Data.ByteString as B
22import qualified Data.Certificate.KeyRSA as KeyRSA
21import qualified Data.Certificate.KeyRSA as KeyRSA
23import Data.Conduit.Network (bindPort)
22import Data.Conduit.Network (bindPort)
23+import Data.Either (rights)
24+import Control.Applicative ((<$>))
25+import qualified Data.PEM as PEM
24
26
25data TLSSettings = TLSSettings
27data TLSSettings = TLSSettings
26 { certFile :: FilePath
28 { certFile :: FilePath
@@ -75,22 +77,21 @@ ciphers =
75
77
76readCertificate :: FilePath -> IO X509.X509
78readCertificate :: FilePath -> IO X509.X509
77readCertificate filepath = do
79readCertificate filepath = do
78− content <- B.readFile filepath
80+ certs <- rights . parseCerts . PEM.pemParseBS <$> B.readFile filepath
79− certdata <-
81+ case certs of
80− case PEM.parsePEMCert content of
81− Nothing -> error "no valid certificate section"
82+ [] -> error "no valid certificate found"
82− Just x -> return x
83+ (x:_) -> return x
83− case X509.decodeCertificate $ L.fromChunks [certdata] of
84+ where parseCerts (Right pems) = map (X509.decodeCertificate . L.fromChunks . (:[]) . PEM.pemContent)
85+ $ filter (flip elem ["CERTIFICATE", "TRUSTED CERTIFICATE"] . PEM.pemName) pems
84− Left err -> error ("cannot decode certificate: " ++ err)
86+ parseCerts (Left err) = error $ "cannot parse PEM file: " ++ err
85− Right x -> return x
86
87
87readPrivateKey :: FilePath -> IO TLS.PrivateKey
88readPrivateKey :: FilePath -> IO TLS.PrivateKey
88readPrivateKey filepath = do
89readPrivateKey filepath = do
89− content <- B.readFile filepath
90+ pk <- rights . parseKey . PEM.pemParseBS <$> B.readFile filepath
90− pkdata <-
91+ case pk of
91− case PEM.parsePEMKeyRSA content of
92− Nothing -> error "no valid RSA key section"
92+ [] -> error "no valid RSA key found"
93− Just x -> return (L.fromChunks [x])
93+ (x:_) -> return x
94− case KeyRSA.decodePrivate pkdata of
94+
95+ where parseKey (Right pems) = map (fmap (TLS.PrivRSA . snd) . KeyRSA.decodePrivate . L.fromChunks . (:[]) . PEM.pemContent)
96+ $ filter ((== "RSA PRIVATE KEY") . PEM.pemName) pems
95− Left err -> error ("cannot decode key: " ++ err)
97+ parseKey (Left err) = error $ "Cannot parse PEM file: " ++ err
96− Right (_pub, x) -> return $ TLS.PrivRSA x
warp-tls/warp-tls.cabal+3−2
@@ -1,5 +1,5 @@
1Name: warp-tls
1Name: warp-tls
2−Version: 1.2.0.1
2+Version: 1.2.0.2
3Synopsis: SSL support for Warp via the TLS package
3Synopsis: SSL support for Warp via the TLS package
4License: MIT
4License: MIT
5License-file: LICENSE
5License-file: LICENSE
@@ -20,7 +20,8 @@ Library
20 , transformers >= 0.2 && < 0.4
20 , transformers >= 0.2 && < 0.4
21 , conduit >= 0.4 && < 0.5
21 , conduit >= 0.4 && < 0.5
22 , network-conduit >= 0.4 && < 0.5
22 , network-conduit >= 0.4 && < 0.5
23− , certificate >= 1.1 && < 1.2
23+ , certificate >= 1.2 && < 1.3
24+ , pem >= 0.1 && < 0.2
24 , cryptocipher >= 0.3 && < 0.4
25 , cryptocipher >= 0.3 && < 0.4
25 , tls-extra >= 0.4.3 && < 0.5
26 , tls-extra >= 0.4.3 && < 0.5
26 , tls >= 0.9 && < 0.10
27 , tls >= 0.9 && < 0.10