module System.X509.Unix
( getSystemCertificateStore
) where
import System.Environment (getEnv)
import Data.X509.CertificateStore
import Control.Applicative ((<$>))
import qualified Control.Exception as E
import Data.Maybe (catMaybes)
import Data.Monoid (mconcat)
defaultSystemPaths :: [FilePath]
defaultSystemPaths :: [FilePath]
defaultSystemPaths =
[ FilePath
"/etc/ssl/certs/"
, FilePath
"/system/etc/security/cacerts/"
, FilePath
"/usr/local/share/certs/"
, FilePath
"/etc/ssl/cert.pem"
]
envPathOverride :: String
envPathOverride :: FilePath
envPathOverride = FilePath
"SYSTEM_CERTIFICATE_PATH"
getSystemCertificateStore :: IO CertificateStore
getSystemCertificateStore :: IO CertificateStore
getSystemCertificateStore = forall a. Monoid a => [a] -> a
mconcat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. [Maybe a] -> [a]
catMaybes forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (IO [FilePath]
getSystemPaths forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
mapM FilePath -> IO (Maybe CertificateStore)
readCertificateStore)
getSystemPaths :: IO [FilePath]
getSystemPaths :: IO [FilePath]
getSystemPaths = forall e a. Exception e => IO a -> (e -> IO a) -> IO a
E.catch ((forall a. a -> [a] -> [a]
:[]) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FilePath -> IO FilePath
getEnv FilePath
envPathOverride) IOException -> IO [FilePath]
inDefault
where
inDefault :: E.IOException -> IO [FilePath]
inDefault :: IOException -> IO [FilePath]
inDefault IOException
_ = forall (m :: * -> *) a. Monad m => a -> m a
return [FilePath]
defaultSystemPaths