Skip to content

Commit 36411a4

Browse files
committed
Reintroduce dropped functions and bump to 0.1.7.0
Due to an oversight the two functions introduced in 6039cd2 and released as part of the (retroactively deprecated) 0.1.6.0 release were lost in the 0.1.6.1 release. This merge-commit tries to rectify the situation by finally reintroducing them in a PVP-gnostic way by tagging a new 0.1.7.0 release and treating 0.1.6.0 as if it didn't exist (by deprecation on Hackage).
2 parents 59d4e48 + 6039cd2 commit 36411a4

File tree

4 files changed

+69
-14
lines changed

4 files changed

+69
-14
lines changed

CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
See also http://pvp.haskell.org/faq
22

3+
### 0.1.7.0
4+
5+
* New function `voidContextSSL` for creating a _void_ SSL Context which rejects any TLS handshake attempts
6+
* New function `contextSetCASystemStore` exposing functionality embedded in `baselineContextSSL`
7+
8+
NB: These functions were originally introduced in the retroactively deprecated 0.1.6.0 release but due to an oversight were dropped again in 0.1.6.1 inadvertently. This minor release reintroduces them in a PVP-compliant way.
9+
310
#### 0.1.6.4
411

512
* Depend on `directory` rather than `system-fileio` ([PR #18](https://github.com/haskell-hvr/http-io-streams/pull/18)).
@@ -26,9 +33,12 @@ Tested with GHC 7.4 - 9.6.
2633
#### 0.1.6.1
2734

2835
* Build with GHC 9.2 and `ghc-prim-0.8` (via `base-4.16`).
36+
* Accidentally removed function `voidContextSSL` and `contextSetCASystemStore` introduced in 0.1.6.0
2937

30-
### 0.1.6.0
38+
### 0.1.6.0 **deprecated**
3139

40+
* New function `voidContextSSL` for creating a _void_ SSL Context which rejects any TLS handshake attempts
41+
* New function `contextSetCASystemStore` exposing functionality embedded in `baselineContextSSL`
3242
* New function `openConnectionAddress''` supporting supplying local `SSLContext`s as well as modifying the `SSL` connection before initiating the client SSL handshake.
3343
* New function `openConnectionSSL'` which allows to customize the SSL connection _before_ a client SSL handshake is attempted.
3444
* New convenience function `getContextSSL` function allowing to retrieve global `SSLContext`.

http-io-streams.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cabal-version: 2.2
22
name: http-io-streams
3-
version: 0.1.6.4
3+
version: 0.1.7.0
44

55
synopsis: HTTP and WebSocket client based on io-streams
66
description:

http-streams/lib/Network/Http/Client.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ module Network.Http.Client (
177177
openConnectionSSL,
178178
openConnectionSSL',
179179
baselineContextSSL,
180+
voidContextSSL,
181+
contextSetCASystemStore,
180182
modifyContextSSL,
181183
getContextSSL,
182184
establishConnection,

http-streams/lib/Network/Http/Inconvenience.hs

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ module Network.Http.Inconvenience (
2828
encodedFormBody,
2929
put,
3030
baselineContextSSL,
31+
voidContextSSL,
32+
contextSetCASystemStore,
3133
concatHandler',
3234
TooManyRedirects(..),
3335
HttpClientError(..),
@@ -402,6 +404,7 @@ connectionAddressFromURI u = fmap addxinfo $
402404
-- you are encouraged to install the system
403405
-- certificates somewhere and create your own 'SSLContext'.
404406
--
407+
-- See also 'contextSetCASystemStore'
405408
{-
406409
We would like to turn certificate verification on for everyone, but
407410
this has proved contingent on leveraging platform specific mechanisms
@@ -412,26 +415,66 @@ baselineContextSSL :: IO SSLContext
412415
baselineContextSSL = withOpenSSL $ do
413416
ctx <- SSL.context
414417
SSL.contextSetDefaultCiphers ctx
418+
419+
caSet <- contextSetCASystemStore ctx
420+
if caSet
421+
then SSL.contextSetVerificationMode ctx (SSL.VerifyPeer True True Nothing)
422+
else SSL.contextSetVerificationMode ctx SSL.VerifyNone
423+
424+
return ctx
425+
426+
-- | Construct a /void/ 'SSL.Context' in a configuration which uses
427+
-- the @HIGH@ cipher-suite and rejects /any/ presented server
428+
-- certificate.
429+
--
430+
-- This is mostly useful for testing purposes or intentionally
431+
-- thwarting any attempt to connect to @https://@ uris.
432+
--
433+
-- @since 0.1.6.0
434+
voidContextSSL :: IO SSLContext
435+
voidContextSSL = do
436+
ctx <- SSL.context
437+
SSL.contextSetCiphers ctx "HIGH"
438+
SSL.contextSetVerificationMode ctx (SSL.VerifyPeer True True (Just (\_ _ -> return False)))
439+
return ctx
440+
441+
-- | Configure system-wide certificate store based on OS-specific heuristics.
442+
--
443+
-- This function returns 'True' if the 'SSLContext' was configured; or
444+
-- 'False' if the location couldn't be termined for the current OS.
445+
--
446+
-- This function is used by 'baselineContextSSL' but in contrast does
447+
-- *not* invoke 'SSL.contextSetDefaultCiphers' nor
448+
-- 'SSL.contextSetVerificationMode'. See source-code for details on
449+
-- the heuristic used to determine the location of the system
450+
-- certificate store.
451+
--
452+
-- @since 0.1.6.0
453+
contextSetCASystemStore :: SSLContext -> IO Bool
454+
contextSetCASystemStore ctx = do
415455
#if defined(darwin_HOST_OS)
416-
SSL.contextSetVerificationMode ctx SSL.VerifyNone
456+
return False
417457
#elif defined(mingw32_HOST_OS)
418-
SSL.contextSetVerificationMode ctx SSL.VerifyNone
458+
return False
419459
#elif defined(freebsd_HOST_OS)
420460
SSL.contextSetCAFile ctx "/usr/local/etc/ssl/cert.pem"
421-
SSL.contextSetVerificationMode ctx $ SSL.VerifyPeer True True Nothing
461+
return True
422462
#elif defined(openbsd_HOST_OS)
423463
SSL.contextSetCAFile ctx "/etc/ssl/cert.pem"
424-
SSL.contextSetVerificationMode ctx $ SSL.VerifyPeer True True Nothing
464+
return True
425465
#else
426-
fedora <- doesDirectoryExist "/etc/pki/tls"
427-
if fedora
428-
then do
429-
SSL.contextSetCAFile ctx "/etc/pki/tls/certs/ca-bundle.crt"
430-
else do
431-
SSL.contextSetCADirectory ctx "/etc/ssl/certs"
432-
SSL.contextSetVerificationMode ctx $ SSL.VerifyPeer True True Nothing
466+
hasFedoraEtcPkiTls <- doesDirectoryExist "/etc/pki/tls"
467+
if hasFedoraEtcPkiTls
468+
then do
469+
SSL.contextSetCAFile ctx "/etc/pki/tls/certs/ca-bundle.crt"
470+
return True
471+
else do
472+
-- Setting this as fallback effectively will cause systems to
473+
-- either fail to verify any certificates (if peer
474+
-- verification is enabled) if the folder doesn't exist.
475+
SSL.contextSetCADirectory ctx "/etc/ssl/certs"
476+
return True
433477
#endif
434-
return ctx
435478

436479

437480
parseURL :: URL -> URI

0 commit comments

Comments
 (0)