Skip to content

Commit

Permalink
Merge pull request #4 from luite/master
Browse files Browse the repository at this point in the history
Fix certificate on OS X
  • Loading branch information
vincenthz committed Mar 31, 2012
2 parents dc3d583 + 2980775 commit 959f6d1
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions System/Certificate/X509/MacOS.hs
Expand Up @@ -11,10 +11,13 @@ import Control.Applicative
import Data.Either
import Data.Maybe

keyChain :: String
keyChain = "/System/Library/Keychains/SystemRootCertificates.keychain"

findCertificate :: (X509 -> Bool) -> IO (Maybe X509)
findCertificate f = do
(_, h, _, ph) <- runInteractiveCommand "security find-certificate -pa"
waitForProcess ph
pems <- parsePEMs <$> hGetContents h
(_, Just hout, _, ph) <- createProcess (proc "security" ["find-certificate", "-pa", keyChain]) { std_out = CreatePipe }
pems <- parsePEMs <$> hGetContents hout
_ <- waitForProcess ph
let targets = rights $ map (decodeCertificate . LBS.fromChunks . pure . snd) $ filter ((=="CERTIFICATE") . fst) pems
return $ listToMaybe $ filter f targets

0 comments on commit 959f6d1

Please sign in to comment.