Skip to content

Commit 078c092

Browse files
authored
Merge pull request haskell-github#410 from phadej/issue-402-operational-sample
Resolve haskell-github#402: Use openssl in operational sample
2 parents c6d2fb0 + 87a88ac commit 078c092

2 files changed

Lines changed: 37 additions & 22 deletions

File tree

samples/Operational/Operational.hs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ import Common
77
import Prelude ()
88

99
import Control.Monad.Operational
10-
import Control.Monad.Trans.Except (ExceptT (..), runExceptT)
11-
import Network.HTTP.Client (Manager, newManager)
12-
import Network.HTTP.Client.TLS (tlsManagerSettings)
10+
import Control.Monad.Trans.Except (ExceptT (..), runExceptT)
11+
import Network.HTTP.Client (Manager, newManager, ManagerSettings)
12+
import Network.HTTP.Client.OpenSSL (opensslManagerSettings, withOpenSSL)
1313

14-
import qualified GitHub as GH
14+
import qualified GitHub as GH
15+
import qualified OpenSSL.Session as SSL
16+
import qualified OpenSSL.X509.SystemStore as SSL
1517

1618
data R a where
1719
R :: FromJSON a => GH.Request 'GH.RA a -> R a
@@ -29,7 +31,7 @@ githubRequest :: FromJSON a => GH.Request 'GH.RA a -> GithubMonad a
2931
githubRequest = singleton . R
3032

3133
main :: IO ()
32-
main = do
34+
main = withOpenSSL $ do
3335
manager <- newManager tlsManagerSettings
3436
auth' <- getAuth
3537
case auth' of
@@ -39,3 +41,14 @@ main = do
3941
repo <- githubRequest $ GH.repositoryR "phadej" "github"
4042
githubRequest $ GH.ownerInfoForR (GH.simpleOwnerLogin . GH.repoOwner $ repo)
4143
print owner
44+
45+
tlsManagerSettings :: ManagerSettings
46+
tlsManagerSettings = opensslManagerSettings $ do
47+
ctx <- SSL.context
48+
SSL.contextAddOption ctx SSL.SSL_OP_NO_SSLv2
49+
SSL.contextAddOption ctx SSL.SSL_OP_NO_SSLv3
50+
SSL.contextAddOption ctx SSL.SSL_OP_NO_TLSv1
51+
SSL.contextSetCiphers ctx "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256"
52+
SSL.contextLoadSystemCerts ctx
53+
SSL.contextSetVerificationMode ctx $ SSL.VerifyPeer True True Nothing
54+
return ctx

samples/github-samples.cabal

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,25 @@ library
2929
exposed-modules: Common
3030
default-language: Haskell2010
3131

32-
-- executable github-operational
33-
-- main-is: Operational.hs
34-
-- hs-source-dirs:
35-
-- Operational
36-
-- ghc-options: -Wall
37-
-- build-depends:
38-
-- base <5
39-
-- , base-compat-batteries
40-
-- , github
41-
-- , text
42-
-- , github-samples
43-
-- , http-client
44-
-- , http-client-tls
45-
-- , operational
46-
-- , transformers
47-
-- , transformers-compat
48-
-- default-language: Haskell2010
32+
executable github-operational
33+
main-is: Operational.hs
34+
hs-source-dirs: Operational
35+
ghc-options: -Wall -threaded
36+
build-depends:
37+
, base >=0 && <5
38+
, base-compat-batteries
39+
, github
40+
, github-samples
41+
, HsOpenSSL
42+
, HsOpenSSL-x509-system
43+
, http-client
44+
, http-client-openssl
45+
, operational
46+
, text
47+
, transformers
48+
, transformers-compat
49+
50+
default-language: Haskell2010
4951

5052
common deps
5153
default-language: Haskell2010

0 commit comments

Comments
 (0)