Permalink
Browse files

OpenSSL.X509.Revocation

darcs-hash:20070623073933-62b54-b308fa33b04ed466ba693d850a42f1360d8eebc7.gz
  • Loading branch information...
1 parent 36ab188 commit 6423c00c53bc29706f4bd9d6e1e8e97c2da750b0 @depressed-pho committed Jun 23, 2007
Showing with 372 additions and 86 deletions.
  1. +1 −0 .boring
  2. +1 −0 HsOpenSSL.cabal
  3. +1 −73 OpenSSL.hsc
  4. +2 −1 OpenSSL/EVP/Verify.hsc
  5. +52 −3 OpenSSL/PEM.hsc
  6. +2 −2 OpenSSL/X509/Request.hsc
  7. +274 −0 OpenSSL/X509/Revocation.hsc
  8. +20 −0 cbits/HsOpenSSL.c
  9. +6 −0 cbits/HsOpenSSL.h
  10. +13 −7 examples/HelloWorld.hs
View
@@ -76,6 +76,7 @@ _stub\.(c|h)$
^OpenSSL/X509\.hs$
^OpenSSL/X509/Name\.hs$
^OpenSSL/X509/Request\.hs$
+^OpenSSL/X509/Revocation\.hs$
^Setup$
^aclocal\.m4$
^configure$
View
@@ -35,6 +35,7 @@ Exposed-Modules:
OpenSSL.Stack
OpenSSL.Utils
OpenSSL.X509
+ OpenSSL.X509.Revocation
OpenSSL.X509.Name
OpenSSL.X509.Request
Extensions:
View
@@ -52,82 +52,10 @@
#include "HsOpenSSL.h"
module OpenSSL
- ( -- * Initialization
- withOpenSSL
-
- -- * Base64
- , encodeBase64
- , encodeBase64BS
- , encodeBase64LBS
- , decodeBase64
- , decodeBase64BS
- , decodeBase64LBS
-
- -- * Symmetric cipher
- , EvpCipher
- , CryptoMode(..)
- , getCipherByName
- , cipher
- , cipherBS
- , cipherLBS
-
- -- * Message digest
- , EvpMD
- , getDigestByName
- , digest
- , digestBS
- , digestLBS
-
- -- * Keypair
- , EvpPKey
-#ifndef OPENSSL_NO_RSA
- , newPKeyRSA
-#endif
-
- -- * Envelope decryption
- , open
- , openBS
- , openLBS
-
- -- * Envelope Encryption
- , seal
- , sealBS
- , sealLBS
-
- -- * Signing
- , sign
- , signBS
- , signLBS
-
- -- * Signature verification
- , verify
- , verifyBS
- , verifyLBS
-
- -- * PEM routines
- , PemPasswordRWState(..)
- , PemPasswordSupply(..)
- , writePKCS8PrivateKey
- , readPrivateKey
- , writePublicKey
- , readPublicKey
-
- -- * RSA public key cryptosystem
- , RSA
- , generateKey
+ ( withOpenSSL
)
where
-import OpenSSL.EVP.Base64
-import OpenSSL.EVP.Cipher
-import OpenSSL.EVP.Digest
-import OpenSSL.EVP.Open
-import OpenSSL.EVP.PKey
-import OpenSSL.EVP.Seal
-import OpenSSL.EVP.Sign
-import OpenSSL.EVP.Verify
-import OpenSSL.PEM
-import OpenSSL.RSA
import OpenSSL.SSL
View
@@ -12,6 +12,7 @@ import Data.ByteString as B
import Data.ByteString.Base
import qualified Data.ByteString.Char8 as B8
import qualified Data.ByteString.Lazy.Char8 as L8
+import Data.Typeable
import Foreign
import Foreign.C
import OpenSSL.EVP.Digest
@@ -20,7 +21,7 @@ import OpenSSL.Utils
data VerifyStatus = VerifySuccess
| VerifyFailure
- deriving (Show, Eq)
+ deriving (Show, Eq, Typeable)
foreign import ccall unsafe "EVP_VerifyFinal"
View
@@ -14,6 +14,9 @@ module OpenSSL.PEM
, writeX509Req
, readX509Req
+
+ , writeCRL
+ , readCRL
)
where
@@ -29,6 +32,7 @@ import OpenSSL.EVP.PKey
import OpenSSL.Utils
import OpenSSL.X509
import OpenSSL.X509.Request
+import OpenSSL.X509.Revocation
import Prelude hiding (catch)
import System.IO
@@ -208,7 +212,7 @@ readPublicKey pemStr
{- X.509 certificate --------------------------------------------------------- -}
-foreign import ccall safe "PEM_write_bio_X509_AUX"
+foreign import ccall unsafe "PEM_write_bio_X509_AUX"
_write_bio_X509_AUX :: Ptr BIO_
-> Ptr X509_
-> IO Int
@@ -253,12 +257,12 @@ readX509 pemStr
{- PKCS#10 certificate request ----------------------------------------------- -}
-foreign import ccall safe "PEM_write_bio_X509_REQ"
+foreign import ccall unsafe "PEM_write_bio_X509_REQ"
_write_bio_X509_REQ :: Ptr BIO_
-> Ptr X509_REQ
-> IO Int
-foreign import ccall safe "PEM_write_bio_X509_REQ_NEW"
+foreign import ccall unsafe "PEM_write_bio_X509_REQ_NEW"
_write_bio_X509_REQ_NEW :: Ptr BIO_
-> Ptr X509_REQ
-> IO Int
@@ -304,3 +308,48 @@ readX509Req' bio
readX509Req :: String -> IO X509Req
readX509Req pemStr
= newConstMem pemStr >>= readX509Req'
+
+
+{- Certificate Revocation List ----------------------------------------------- -}
+
+foreign import ccall unsafe "PEM_write_bio_X509_CRL"
+ _write_bio_X509_CRL :: Ptr BIO_
+ -> Ptr X509_CRL
+ -> IO Int
+
+foreign import ccall safe "PEM_read_bio_X509_CRL"
+ _read_bio_X509_CRL :: Ptr BIO_
+ -> Ptr (Ptr X509_CRL)
+ -> FunPtr PemPasswordCallback
+ -> Ptr ()
+ -> IO (Ptr X509_CRL)
+
+
+writeCRL' :: BIO -> CRL -> IO ()
+writeCRL' bio crl
+ = withForeignPtr bio $ \ bioPtr ->
+ withForeignPtr crl $ \ crlPtr ->
+ _write_bio_X509_CRL bioPtr crlPtr
+ >>= failIf (/= 1)
+ >> return ()
+
+
+writeCRL :: CRL -> IO String
+writeCRL crl
+ = do mem <- newMem
+ writeCRL' mem crl
+ bioRead mem
+
+
+readCRL' :: BIO -> IO CRL
+readCRL' bio
+ = withForeignPtr bio $ \ bioPtr ->
+ withCString "" $ \ passPtr ->
+ _read_bio_X509_CRL bioPtr nullPtr nullFunPtr (unsafeCoercePtr passPtr)
+ >>= failIfNull
+ >>= wrapCRL
+
+
+readCRL :: String -> IO CRL
+readCRL pemStr
+ = newConstMem pemStr >>= readCRL'
View
@@ -106,8 +106,8 @@ verifyX509Req req pkey
printX509Req :: X509Req -> IO String
printX509Req req
= do mem <- newMem
- withForeignPtr req $ \ reqPtr ->
- withForeignPtr mem $ \ memPtr ->
+ withForeignPtr mem $ \ memPtr ->
+ withForeignPtr req $ \ reqPtr ->
_print memPtr reqPtr
>>= failIf (/= 1)
bioRead mem
Oops, something went wrong.

0 comments on commit 6423c00

Please sign in to comment.