diff --git a/ChangeLog b/ChangeLog
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2016-10-06  Vladimir Shabanov  <vshabanoff@gmail.com>
+
+	* HsOpenSSL.cabal (Version): Bump version to 0.11.2.3
+
+	* HsOpenSSL.cabal, Setup.hs:
+	Automatic detection of Homebrew or MacPorts OpenSSL on macOS
+	with helpful (I hope ;) error messages (phonohawk#41).
+	Previous approach caused ld warning 'directory not found',
+	wasn't informative when OpenSSL is not installed and could
+	potentially prevent linking with OpenSSL from another source.
+
+	* HsOpenSSL.cabal: Bump Cabal-Version to 1.12 (bundled with GHC 7.2.2).
+
+	* OpenSSL/Session.hsc: Exposed OpenSSL.Session internal types,
+	by Eric Mertens @glguy (#10).
+
 2016-10-05  Vladimir Shabanov  <vshabanoff@gmail.com>
 
 	* HsOpenSSL.cabal (Version): Bump version to 0.11.2.2
diff --git a/HsOpenSSL.cabal b/HsOpenSSL.cabal
--- a/HsOpenSSL.cabal
+++ b/HsOpenSSL.cabal
@@ -12,7 +12,7 @@
     <http://hackage.haskell.org/package/tls>, which is a pure Haskell
     implementation of SSL.
     .
-Version:       0.11.2.2
+Version:       0.11.2.3
 License:       PublicDomain
 License-File:  COPYING
 Author:        Adam Langley, Mikhail Vorozhtsov, PHO, Taru Karttunen
@@ -21,10 +21,10 @@
 Homepage:      https://github.com/vshabanov/HsOpenSSL
 Bug-Reports:   https://github.com/vshabanov/HsOpenSSL/issues
 Category:      Cryptography
-Cabal-Version: >= 1.10
+Cabal-Version: >= 1.12
 Tested-With:
     GHC==8.0.2, GHC==7.10.3, GHC==7.8.4, GHC==7.6.3, GHC==7.4.2, GHC==7.2.2
-Build-Type:    Simple
+Build-Type:    Custom
 Extra-Source-Files:
     AUTHORS
     ChangeLog
@@ -45,10 +45,22 @@
 
 Flag fast-bignum
     Description:
-        Enable fast moving of bignums between OpenSSL and GMP (GHC Only).
+        Enable fast moving of bignums between OpenSSL and GMP (GHC only).
     Default:
         True
 
+Flag homebrew-openssl
+    Description:
+        Use Homebrew version of OpenSSL (macOS only).
+    Default:
+        False
+
+Flag macports-openssl
+    Description:
+        Use MacPorts version of OpenSSL (macOS only).
+    Default:
+        False
+
 Library
     Build-Depends:
         base       >= 4.4 && < 5,
@@ -66,11 +78,13 @@
         else
             Build-Depends: ghc-prim, integer
 
-    if os(darwin)
-        Include-Dirs: /usr/local/opt/openssl/include /opt/local/include
-        Extra-Lib-Dirs: /usr/local/opt/openssl/lib /opt/local/lib
-        -- /usr/local for Homebrew
-        -- /opt/local for MacPorts
+    if os(darwin) && flag(homebrew-openssl)
+        Include-Dirs: /usr/local/opt/openssl/include
+        Extra-Lib-Dirs: /usr/local/opt/openssl/lib
+
+    if os(darwin) && flag(macports-openssl)
+        Include-Dirs: /opt/local/include
+        Extra-Lib-Dirs: /opt/local/lib
 
     if os(mingw32)
         Extra-Libraries: eay32 ssl32
diff --git a/OpenSSL/Session.hsc b/OpenSSL/Session.hsc
--- a/OpenSSL/Session.hsc
+++ b/OpenSSL/Session.hsc
@@ -67,6 +67,13 @@
   , SomeSSLException
   , ConnectionAbruptlyTerminated
   , ProtocolError(..)
+
+    -- * Direct access to OpenSSL objects
+  , SSLContext_
+  , withContext
+  , SSL_
+  , withSSL
+
   ) where
 
 #include "openssl/ssl.h"
@@ -376,6 +383,7 @@
 fdConnection :: SSLContext -> Fd -> IO SSL
 fdConnection context fd = connection' context fd Nothing
 
+-- | Run continuation with exclusive access to the underlying SSL object.
 withSSL :: SSL -> (Ptr SSL_ -> IO a) -> IO a
 withSSL = withMVar . sslMVar
 
diff --git a/Setup.hs b/Setup.hs
--- a/Setup.hs
+++ b/Setup.hs
@@ -1,4 +1,91 @@
 #!/usr/bin/env runghc
 
+{-# LANGUAGE TupleSections #-}
+
 import Distribution.Simple
-main = defaultMain
+import Distribution.Simple.Setup (ConfigFlags(..), toFlag)
+import Distribution.Simple.LocalBuildInfo (localPkgDescr)
+import Distribution.PackageDescription (FlagName(..))
+import Distribution.Verbosity (silent)
+import System.Info (os)
+import qualified Control.Exception as E (tryJust, throw)
+import System.IO.Error (isUserError)
+import Control.Monad (forM)
+import Data.List
+
+-- On macOS we're checking whether OpenSSL library is avaiable
+-- and if not, we're trying to find Homebrew or MacPorts OpenSSL installations.
+--
+-- Method is dumb -- set homebrew-openssl or macports-openssl flag and try
+-- to configure and check C libs.
+--
+-- If no or multiple libraries are found we display error message
+-- with instructions.
+
+main
+    | os == "darwin" =
+        defaultMainWithHooks simpleUserHooks { confHook = conf }
+    | otherwise =
+        defaultMain
+
+flags = ["homebrew-openssl", "macports-openssl"]
+
+conf descr cfg = do
+    c <- tryConfig descr cfg
+    case c of
+        Right lbi -> return lbi -- library was found
+        Left e
+            | configConfigurationsFlags cfg
+              `intersect` [(FlagName f, True) | f <- flags] /= [] ->
+                E.throw e
+                -- flag was set but library still wasn't found
+            | otherwise -> do
+                r <- forM flags $ \ f ->
+                    fmap (f,) $ tryConfig descr $
+                    setFlag f cfg { configVerbosity = toFlag silent }
+                    -- TODO: configure is a long operation
+                    -- while checkForeignDeps is fast.
+                    -- Perhaps there is a way to configure once
+                    -- and only apply flags to result and check.
+                    -- However, additional `configure`s happen only on macOS
+                    -- and only when library wasn't found.
+                case [(f,r) | (f, Right r) <- r] of
+                    [(_,lbi)] ->
+                        return lbi -- library was found
+                    [] ->
+                        fail notFound
+                    fs ->
+                        fail $ multipleFound fs
+
+multipleFound fs =
+    "Multiple OpenSSL libraries were found,\n\
+    \use " ++ intercalate " or " ["'-f " ++ f ++ "'" | (f,_) <- fs] ++ "\n\
+    \to specify location of installed OpenSSL library."
+
+notFound =
+    "Can't find OpenSSL library,\n\
+    \install it via 'brew install openssl' or 'port install openssl'\n\
+    \or use --extra-include-dirs= and --extra-lib-dirs=\n\
+    \to specify location of installed OpenSSL library."
+
+setFlag f c = c { configConfigurationsFlags = go (configConfigurationsFlags c) }
+    where go [] = []
+          go (x@(FlagName n, _):xs)
+              | n == f = (FlagName f, True) : xs
+              | otherwise = x : go xs
+
+tryConfig descr flags =
+    E.tryJust ue $ checkedConfigure descr flags
+    where ue e | isUserError e = Just e
+               | otherwise = Nothing
+
+checkedConfigure descr flags = do
+    lbi <- confHook simpleUserHooks descr flags
+    -- confHook simpleUserHooks == Distribution.Simple.Configure.configure
+
+    -- Testing whether C lib and header dependencies are working
+    postConf simpleUserHooks [] flags (localPkgDescr lbi) lbi
+    -- postConf simpleUserHooks ~==
+    --   Distribution.Simple.Configure.checkForeignDeps
+
+    return lbi
