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 =
[ "/etc/ssl/certs/"
, "/system/etc/security/cacerts/"
, "/usr/local/share/certs/"
, "/etc/ssl/cert.pem"
]
envPathOverride :: String
envPathOverride = "SYSTEM_CERTIFICATE_PATH"
getSystemCertificateStore :: IO CertificateStore
getSystemCertificateStore = mconcat . catMaybes <$> (getSystemPaths >>= mapM readCertificateStore)
getSystemPaths :: IO [FilePath]
getSystemPaths = E.catch ((:[]) <$> getEnv envPathOverride) inDefault
where
inDefault :: E.IOException -> IO [FilePath]
inDefault _ = return defaultSystemPaths