vincenthz/hs-certificate — pull request #16 by swtw7466 (2012-11-22 12:46:24+00:00)
Title: getSystemCertificateStore throws an exception when crt files cannot be read

# The problem

[ghci] Prelude System.Certificate.X509> getSystemCertificateStore
[ghci] *** Exception: /etc/ssl/certs/localhost.crt: openBinaryFile: permission denied (Permission denied)

# Why

% ls -l /etc/ssl/certs/
-rw-r--r--. 1 root root 571450 Apr 8 2010 ca-bundle.crt
-rw-r--r--. 1 root root 651083 Apr 8 2010 ca-bundle.trust.crt
-rw------- 1 root root 1192 Aug 24 19:01 localhost.crt

So our administrator doesn't want the file to be read by everyone.

# Solution

Check whether crt files are readable:

listDirectoryCerts path = (map (path ) . filter isCert <$> getDirectoryContents path)
>>= filterM doesFileExist
+ >>= filterM (liftM readable . getPermissions)