Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #4 from mvv/evp-refactoring

EVP refactoring
  • Loading branch information...
commit e9ed30afae7c151e828990aef2a556e17f43a98f 2 parents 0d599fb + b2c35c8
PHO phonohawk authored
1  HsOpenSSL.cabal
@@ -87,6 +87,7 @@ Library
87 87 OpenSSL.Stack
88 88 OpenSSL.Utils
89 89 OpenSSL.X509.Name
  90 + OpenSSL.EVP.Internal
90 91 OpenSSL.DH.Internal
91 92 Extensions:
92 93 ForeignFunctionInterface, EmptyDataDecls, MagicHash,
4 OpenSSL/DH.hsc
@@ -17,7 +17,11 @@ import Data.ByteString (ByteString)
17 17 import qualified Data.ByteString.Internal as BS
18 18 import Control.Applicative ((<$>))
19 19 import Foreign.Ptr (Ptr, nullPtr)
  20 +#if __GLASGOW_HASKELL__ >= 703
  21 +import Foreign.C.Types (CInt(..))
  22 +#else
20 23 import Foreign.C.Types (CInt)
  24 +#endif
21 25 import Foreign.Marshal.Alloc (alloca)
22 26 import OpenSSL.BN
23 27 import OpenSSL.DH.Internal
129 OpenSSL/EVP/Cipher.hsc
@@ -8,24 +8,11 @@
8 8
9 9 module OpenSSL.EVP.Cipher
10 10 ( Cipher
11   - , EVP_CIPHER -- private
12   - , withCipherPtr -- private
13   -
14 11 , getCipherByName
15 12 , getCipherNames
16 13
17   - , cipherIvLength -- private
18   -
19   - , CipherCtx -- private
20   - , EVP_CIPHER_CTX -- private
21   - , newCtx -- private
22   - , withCipherCtxPtr -- private
23   -
24 14 , CryptoMode(..)
25 15
26   - , cipherStrictly -- private
27   - , cipherLazily -- private
28   -
29 16 , cipher
30 17 , cipherBS
31 18 , cipherLBS
@@ -33,39 +20,18 @@ module OpenSSL.EVP.Cipher
33 20 )
34 21 where
35 22
36   -import Control.Exception(bracket_)
37   -import Control.Monad
38   -import Data.ByteString.Internal (createAndTrim)
39 23 import Data.ByteString.Unsafe (unsafeUseAsCStringLen)
40 24 import qualified Data.ByteString.Char8 as B8
41 25 import qualified Data.ByteString.Lazy.Char8 as L8
42   -import qualified Data.ByteString.Lazy.Internal as L8Internal
43 26 import Foreign
44 27 import Foreign.C
45 28 import OpenSSL.Objects
46 29 import OpenSSL.Utils
47   -import System.IO.Unsafe
48   -
49   -
50   -{- EVP_CIPHER ---------------------------------------------------------------- -}
51   -
52   --- |@Cipher@ is an opaque object that represents an algorithm of
53   --- symmetric cipher.
54   -newtype Cipher = Cipher (Ptr EVP_CIPHER)
55   -data EVP_CIPHER
56   -
  30 +import OpenSSL.EVP.Internal
57 31
58 32 foreign import ccall unsafe "EVP_get_cipherbyname"
59 33 _get_cipherbyname :: CString -> IO (Ptr EVP_CIPHER)
60 34
61   -
62   -foreign import ccall unsafe "HsOpenSSL_EVP_CIPHER_iv_length"
63   - _iv_length :: Ptr EVP_CIPHER -> CInt
64   -
65   -
66   -withCipherPtr :: Cipher -> (Ptr EVP_CIPHER -> IO a) -> IO a
67   -withCipherPtr (Cipher cipherPtr) f = f cipherPtr
68   -
69 35 -- |@'getCipherByName' name@ returns a symmetric cipher algorithm
70 36 -- whose name is @name@. If no algorithms are found, the result is
71 37 -- @Nothing@.
@@ -83,65 +49,21 @@ getCipherByName name
83 49 getCipherNames :: IO [String]
84 50 getCipherNames = getObjNames CipherMethodType True
85 51
86   -
87   -cipherIvLength :: Cipher -> Int
88   -cipherIvLength (Cipher cipherPtr) = fromIntegral $ _iv_length cipherPtr
89   -
90   -
91   -{- EVP_CIPHER_CTX ------------------------------------------------------------ -}
92   -
93   -newtype CipherCtx = CipherCtx (ForeignPtr EVP_CIPHER_CTX)
94   -data EVP_CIPHER_CTX
95   -
96   -
97   -foreign import ccall unsafe "EVP_CIPHER_CTX_init"
98   - _ctx_init :: Ptr EVP_CIPHER_CTX -> IO ()
99   -
100   -foreign import ccall unsafe "&EVP_CIPHER_CTX_cleanup"
101   - _ctx_cleanup :: FunPtr (Ptr EVP_CIPHER_CTX -> IO ())
102   -
103   -foreign import ccall unsafe "EVP_CIPHER_CTX_cleanup"
104   - _ctx_cleanup' :: Ptr EVP_CIPHER_CTX -> IO ()
105   -
106   -foreign import ccall unsafe "HsOpenSSL_EVP_CIPHER_CTX_block_size"
107   - _ctx_block_size :: Ptr EVP_CIPHER_CTX -> CInt
108   -
109   -
110   -newCtx :: IO CipherCtx
111   -newCtx = do ctx <- mallocForeignPtrBytes (#size EVP_CIPHER_CTX)
112   - withForeignPtr ctx _ctx_init
113   - addForeignPtrFinalizer _ctx_cleanup ctx
114   - return $ CipherCtx ctx
115   -
116   -
117   -withCipherCtxPtr :: CipherCtx -> (Ptr EVP_CIPHER_CTX -> IO a) -> IO a
118   -withCipherCtxPtr (CipherCtx ctx) = withForeignPtr ctx
119   -
120   -
121 52 {- encrypt/decrypt ----------------------------------------------------------- -}
122 53
123 54 -- |@CryptoMode@ represents instruction to 'cipher' and such like.
124 55 data CryptoMode = Encrypt | Decrypt
125 56
126   -
127   -foreign import ccall unsafe "EVP_CipherInit"
128   - _CipherInit :: Ptr EVP_CIPHER_CTX -> Ptr EVP_CIPHER -> CString -> CString -> CInt -> IO CInt
129   -
130   -foreign import ccall unsafe "EVP_CipherUpdate"
131   - _CipherUpdate :: Ptr EVP_CIPHER_CTX -> Ptr CChar -> Ptr CInt -> Ptr CChar -> CInt -> IO CInt
132   -
133   -foreign import ccall unsafe "EVP_CipherFinal"
134   - _CipherFinal :: Ptr EVP_CIPHER_CTX -> Ptr CChar -> Ptr CInt -> IO CInt
135   -
136   -
137 57 cryptoModeToInt :: CryptoMode -> CInt
138 58 cryptoModeToInt Encrypt = 1
139 59 cryptoModeToInt Decrypt = 0
140 60
  61 +foreign import ccall unsafe "EVP_CipherInit"
  62 + _CipherInit :: Ptr EVP_CIPHER_CTX -> Ptr EVP_CIPHER -> CString -> CString -> CInt -> IO CInt
141 63
142 64 cipherInit :: Cipher -> String -> String -> CryptoMode -> IO CipherCtx
143 65 cipherInit (Cipher c) key iv mode
144   - = do ctx <- newCtx
  66 + = do ctx <- newCipherCtx
145 67 withCipherCtxPtr ctx $ \ ctxPtr ->
146 68 withCString key $ \ keyPtr ->
147 69 withCString iv $ \ ivPtr ->
@@ -157,8 +79,7 @@ cipherStrictLBS :: Cipher -- ^ Cipher
157 79 -> L8.ByteString -- ^ Input
158 80 -> IO L8.ByteString
159 81 cipherStrictLBS (Cipher c) key iv mode input =
160   - allocaBytes (#size EVP_CIPHER_CTX) $ \cptr ->
161   - bracket_ (_ctx_init cptr) (_ctx_cleanup' cptr) $
  82 + withNewCipherCtxPtr $ \cptr ->
162 83 unsafeUseAsCStringLen key $ \(keyp,_) ->
163 84 unsafeUseAsCStringLen iv $ \(ivp, _) -> do
164 85 failIf_ (/= 1) =<< _CipherInit cptr c keyp ivp (cryptoModeToInt mode)
@@ -167,26 +88,6 @@ cipherStrictLBS (Cipher c) key iv mode input =
167 88 rf <- cipherFinalBS cc
168 89 return $ L8.fromChunks (rr++[rf])
169 90
170   -cipherUpdateBS :: CipherCtx -> B8.ByteString -> IO B8.ByteString
171   -cipherUpdateBS ctx inBS
172   - = withCipherCtxPtr ctx $ \ ctxPtr ->
173   - unsafeUseAsCStringLen inBS $ \ (inBuf, inLen) ->
174   - createAndTrim (inLen + fromIntegral (_ctx_block_size ctxPtr) - 1) $ \ outBuf ->
175   - alloca $ \ outLenPtr ->
176   - _CipherUpdate ctxPtr (castPtr outBuf) outLenPtr inBuf (fromIntegral inLen)
177   - >>= failIf (/= 1)
178   - >> liftM fromIntegral (peek outLenPtr)
179   -
180   -
181   -cipherFinalBS :: CipherCtx -> IO B8.ByteString
182   -cipherFinalBS ctx
183   - = withCipherCtxPtr ctx $ \ ctxPtr ->
184   - createAndTrim (fromIntegral $ _ctx_block_size ctxPtr) $ \ outBuf ->
185   - alloca $ \ outLenPtr ->
186   - _CipherFinal ctxPtr (castPtr outBuf) outLenPtr
187   - >>= failIf (/= 1)
188   - >> liftM fromIntegral (peek outLenPtr)
189   -
190 91 -- |@'cipher'@ lazilly encrypts or decrypts a stream of data. The
191 92 -- input string doesn't necessarily have to be finite.
192 93 cipher :: Cipher -- ^ algorithm to use
@@ -199,7 +100,7 @@ cipher :: Cipher -- ^ algorithm to use
199 100 -- U+00FF.
200 101 -> IO String -- ^ the result string
201 102 cipher c key iv mode input
202   - = liftM L8.unpack $ cipherLBS c key iv mode $ L8.pack input
  103 + = fmap L8.unpack $ cipherLBS c key iv mode $ L8.pack input
203 104
204 105 -- |@'cipherBS'@ strictly encrypts or decrypts a chunk of data.
205 106 cipherBS :: Cipher -- ^ algorithm to use
@@ -224,21 +125,3 @@ cipherLBS c key iv mode input
224 125 = do ctx <- cipherInit c key iv mode
225 126 cipherLazily ctx input
226 127
227   -
228   -cipherStrictly :: CipherCtx -> B8.ByteString -> IO B8.ByteString
229   -cipherStrictly ctx input
230   - = do output' <- cipherUpdateBS ctx input
231   - output'' <- cipherFinalBS ctx
232   - return $ B8.append output' output''
233   -
234   -
235   -cipherLazily :: CipherCtx -> L8.ByteString -> IO L8.ByteString
236   -
237   -cipherLazily ctx (L8Internal.Empty) =
238   - cipherFinalBS ctx >>= \ bs -> (return . L8.fromChunks) [bs]
239   -
240   -cipherLazily ctx (L8Internal.Chunk x xs) = do
241   - y <- cipherUpdateBS ctx x
242   - ys <- unsafeInterleaveIO $
243   - cipherLazily ctx xs
244   - return $ L8Internal.Chunk y ys
137 OpenSSL/EVP/Digest.hsc
@@ -8,19 +8,9 @@
8 8
9 9 module OpenSSL.EVP.Digest
10 10 ( Digest
11   - , EVP_MD -- private
12   - , withMDPtr -- private
13   -
14 11 , getDigestByName
15 12 , getDigestNames
16 13
17   - , DigestCtx -- private
18   - , EVP_MD_CTX -- private
19   - , withDigestCtxPtr -- private
20   -
21   - , digestStrictly -- private
22   - , digestLazily -- private
23   -
24 14 , digest
25 15 , digestBS
26 16 , digestBS'
@@ -31,32 +21,19 @@ module OpenSSL.EVP.Digest
31 21 )
32 22 where
33 23
34   -import Control.Monad
35   -import Data.ByteString.Internal (createAndTrim, create)
  24 +import Data.ByteString.Internal (create)
36 25 import Data.ByteString.Unsafe (unsafeUseAsCStringLen)
37 26 import qualified Data.ByteString.Char8 as B8
38 27 import qualified Data.ByteString.Lazy.Char8 as L8
  28 +import Control.Applicative ((<$>))
39 29 import Foreign
40 30 import Foreign.C
  31 +import OpenSSL.EVP.Internal
41 32 import OpenSSL.Objects
42   -import OpenSSL.Utils
43   -
44   -
45   -{- EVP_MD -------------------------------------------------------------------- -}
46   -
47   --- |@Digest@ is an opaque object that represents an algorithm of
48   --- message digest.
49   -newtype Digest = Digest (Ptr EVP_MD)
50   -data EVP_MD
51   -
52 33
53 34 foreign import ccall unsafe "EVP_get_digestbyname"
54 35 _get_digestbyname :: CString -> IO (Ptr EVP_MD)
55 36
56   -
57   -withMDPtr :: Digest -> (Ptr EVP_MD -> IO a) -> IO a
58   -withMDPtr (Digest mdPtr) f = f mdPtr
59   -
60 37 -- |@'getDigestByName' name@ returns a message digest algorithm whose
61 38 -- name is @name@. If no algorithms are found, the result is
62 39 -- @Nothing@.
@@ -74,89 +51,8 @@ getDigestByName name
74 51 getDigestNames :: IO [String]
75 52 getDigestNames = getObjNames MDMethodType True
76 53
77   -
78   -{- EVP_MD_CTX ---------------------------------------------------------------- -}
79   -
80   -newtype DigestCtx = DigestCtx (ForeignPtr EVP_MD_CTX)
81   -data EVP_MD_CTX
82   -
83   -
84   -foreign import ccall unsafe "EVP_MD_CTX_init"
85   - _ctx_init :: Ptr EVP_MD_CTX -> IO ()
86   -
87   -foreign import ccall unsafe "&EVP_MD_CTX_cleanup"
88   - _ctx_cleanup :: FunPtr (Ptr EVP_MD_CTX -> IO ())
89   -
90   -
91   -newCtx :: IO DigestCtx
92   -newCtx = do ctx <- mallocForeignPtrBytes (#size EVP_MD_CTX)
93   - withForeignPtr ctx _ctx_init
94   - addForeignPtrFinalizer _ctx_cleanup ctx
95   - return $ DigestCtx ctx
96   -
97   -
98   -withDigestCtxPtr :: DigestCtx -> (Ptr EVP_MD_CTX -> IO a) -> IO a
99   -withDigestCtxPtr (DigestCtx ctx) = withForeignPtr ctx
100   -
101   -
102 54 {- digest -------------------------------------------------------------------- -}
103 55
104   -foreign import ccall unsafe "EVP_DigestInit"
105   - _DigestInit :: Ptr EVP_MD_CTX -> Ptr EVP_MD -> IO CInt
106   -
107   -foreign import ccall unsafe "EVP_DigestUpdate"
108   - _DigestUpdate :: Ptr EVP_MD_CTX -> Ptr CChar -> CSize -> IO CInt
109   -
110   -foreign import ccall unsafe "EVP_DigestFinal"
111   - _DigestFinal :: Ptr EVP_MD_CTX -> Ptr CChar -> Ptr CUInt -> IO CInt
112   -
113   -
114   -digestInit :: Digest -> IO DigestCtx
115   -digestInit (Digest md)
116   - = do ctx <- newCtx
117   - withDigestCtxPtr ctx $ \ ctxPtr ->
118   - _DigestInit ctxPtr md >>= failIf_ (/= 1)
119   - return ctx
120   -
121   -
122   -digestUpdateBS :: DigestCtx -> B8.ByteString -> IO ()
123   -digestUpdateBS ctx bs
124   - = withDigestCtxPtr ctx $ \ ctxPtr ->
125   - unsafeUseAsCStringLen bs $ \ (buf, len) ->
126   - _DigestUpdate ctxPtr buf (fromIntegral len) >>= failIf (/= 1) >> return ()
127   -
128   -
129   -digestFinal :: DigestCtx -> IO String
130   -digestFinal ctx
131   - = withDigestCtxPtr ctx $ \ ctxPtr ->
132   - allocaArray (#const EVP_MAX_MD_SIZE) $ \ bufPtr ->
133   - alloca $ \ bufLenPtr ->
134   - do _DigestFinal ctxPtr bufPtr bufLenPtr >>= failIf_ (/= 1)
135   - bufLen <- liftM fromIntegral $ peek bufLenPtr
136   - peekCStringLen (bufPtr, bufLen)
137   -
138   -digestFinalBS :: DigestCtx -> IO B8.ByteString
139   -digestFinalBS ctx =
140   - withDigestCtxPtr ctx $ \ctxPtr ->
141   - createAndTrim (#const EVP_MAX_MD_SIZE) $ \bufPtr ->
142   - alloca $ \bufLenPtr ->
143   - do _DigestFinal ctxPtr (castPtr bufPtr) bufLenPtr >>= failIf_ (/= 1)
144   - liftM fromIntegral $ peek bufLenPtr
145   -
146   -
147   -digestStrictly :: Digest -> B8.ByteString -> IO DigestCtx
148   -digestStrictly md input
149   - = do ctx <- digestInit md
150   - digestUpdateBS ctx input
151   - return ctx
152   -
153   -
154   -digestLazily :: Digest -> L8.ByteString -> IO DigestCtx
155   -digestLazily md lbs
156   - = do ctx <- digestInit md
157   - mapM_ (digestUpdateBS ctx) $ L8.toChunks lbs
158   - return ctx
159   -
160 56 -- |@'digest'@ digests a stream of data. The string must
161 57 -- not contain any letters which aren't in the range of U+0000 -
162 58 -- U+00FF.
@@ -167,19 +63,16 @@ digest md input
167 63 -- |@'digestBS'@ digests a chunk of data.
168 64 digestBS :: Digest -> B8.ByteString -> String
169 65 digestBS md input
170   - = unsafePerformIO
171   - (digestStrictly md input >>= digestFinal)
  66 + = unsafePerformIO $ digestStrictly md input >>= digestFinal
172 67
173 68 digestBS' :: Digest -> B8.ByteString -> B8.ByteString
174 69 digestBS' md input
175   - = unsafePerformIO
176   - (digestStrictly md input >>= digestFinalBS)
  70 + = unsafePerformIO $ digestStrictly md input >>= digestFinalBS
177 71
178 72 -- |@'digestLBS'@ digests a stream of data.
179 73 digestLBS :: Digest -> L8.ByteString -> String
180 74 digestLBS md input
181   - = unsafePerformIO
182   - (digestLazily md input >>= digestFinal)
  75 + = unsafePerformIO $ digestLazily md input >>= digestFinal
183 76
184 77 {- HMAC ---------------------------------------------------------------------- -}
185 78
@@ -197,9 +90,11 @@ hmacBS (Digest md) key input =
197 90 allocaArray (#const EVP_MAX_MD_SIZE) $ \bufPtr ->
198 91 alloca $ \bufLenPtr ->
199 92 unsafeUseAsCStringLen key $ \(keydata, keylen) ->
200   - unsafeUseAsCStringLen input $ \(inputdata, inputlen) ->
201   - do _HMAC md keydata (fromIntegral keylen) inputdata (fromIntegral inputlen) bufPtr bufLenPtr
202   - bufLen <- liftM fromIntegral $ peek bufLenPtr
  93 + unsafeUseAsCStringLen input $ \(inputdata, inputlen) -> do
  94 + _HMAC md
  95 + keydata (fromIntegral keylen) inputdata (fromIntegral inputlen)
  96 + bufPtr bufLenPtr
  97 + bufLen <- fromIntegral <$> peek bufLenPtr
203 98 B8.packCStringLen (bufPtr, bufLen)
204 99
205 100 -- | Calculate a PKCS5-PBKDF2 SHA1-HMAC suitable for password hashing.
@@ -219,7 +114,9 @@ pkcs5_pbkdf2_hmac_sha1 pass salt iter dkeylen =
219 114 (fromIntegral iter) (fromIntegral dkeylen) (castPtr dkeydata)
220 115 >> return ()
221 116
222   -foreign import ccall unsafe "PKCS5_PBKDF2_HMAC_SHA1" _PKCS5_PBKDF2_HMAC_SHA1 :: Ptr CChar -> CInt
223   - -> Ptr CChar -> CInt
224   - -> CInt -> CInt -> Ptr CChar
225   - -> IO CInt
  117 +foreign import ccall unsafe "PKCS5_PBKDF2_HMAC_SHA1"
  118 + _PKCS5_PBKDF2_HMAC_SHA1 :: Ptr CChar -> CInt
  119 + -> Ptr CChar -> CInt
  120 + -> CInt -> CInt -> Ptr CChar
  121 + -> IO CInt
  122 +
307 OpenSSL/EVP/Internal.hsc
... ... @@ -0,0 +1,307 @@
  1 +
  2 +module OpenSSL.EVP.Internal (
  3 + Cipher(..),
  4 + EVP_CIPHER,
  5 + withCipherPtr,
  6 +
  7 + cipherIvLength,
  8 +
  9 + CipherCtx(..),
  10 + EVP_CIPHER_CTX,
  11 + newCipherCtx,
  12 + withCipherCtxPtr,
  13 + withNewCipherCtxPtr,
  14 +
  15 + cipherUpdateBS,
  16 + cipherFinalBS,
  17 + cipherStrictly,
  18 + cipherLazily,
  19 +
  20 + Digest(..),
  21 + EVP_MD,
  22 + withMDPtr,
  23 +
  24 + DigestCtx(..),
  25 + EVP_MD_CTX,
  26 + withDigestCtxPtr,
  27 +
  28 + digestUpdateBS,
  29 + digestFinalBS,
  30 + digestFinal,
  31 + digestStrictly,
  32 + digestLazily,
  33 +
  34 + VaguePKey(..),
  35 + EVP_PKEY,
  36 + PKey(..),
  37 + createPKey,
  38 + wrapPKeyPtr,
  39 + withPKeyPtr,
  40 + withPKeyPtr',
  41 + unsafePKeyToPtr,
  42 + touchPKey
  43 + ) where
  44 +
  45 +#include "HsOpenSSL.h"
  46 +
  47 +import qualified Data.ByteString.Internal as B8
  48 +import qualified Data.ByteString.Unsafe as B8
  49 +import qualified Data.ByteString.Char8 as B8
  50 +import qualified Data.ByteString.Lazy.Char8 as L8
  51 +import qualified Data.ByteString.Lazy.Internal as L8
  52 +import Control.Applicative ((<$>))
  53 +import Control.Exception (mask, mask_, bracket_, onException)
  54 +import Foreign.C.Types (CChar)
  55 +#if __GLASGOW_HASKELL__ >= 703
  56 +import Foreign.C.Types (CInt(..), CUInt(..), CSize(..))
  57 +#else
  58 +import Foreign.C.Types (CInt, CUInt, CSize)
  59 +#endif
  60 +import Foreign.Ptr (Ptr, castPtr, FunPtr)
  61 +import Foreign.C.String (peekCStringLen)
  62 +import Foreign.ForeignPtr (
  63 + ForeignPtr, newForeignPtr, withForeignPtr, addForeignPtrFinalizer,
  64 + mallocForeignPtrBytes, touchForeignPtr, unsafeForeignPtrToPtr)
  65 +import Foreign.Storable (Storable(..))
  66 +import Foreign.Marshal.Alloc (alloca, allocaBytes)
  67 +import Foreign.Marshal.Array (allocaArray)
  68 +import System.IO.Unsafe (unsafeInterleaveIO)
  69 +import OpenSSL.Utils
  70 +
  71 +{- EVP_CIPHER ---------------------------------------------------------------- -}
  72 +
  73 +-- |@Cipher@ is an opaque object that represents an algorithm of
  74 +-- symmetric cipher.
  75 +newtype Cipher = Cipher (Ptr EVP_CIPHER)
  76 +data EVP_CIPHER
  77 +
  78 +withCipherPtr :: Cipher -> (Ptr EVP_CIPHER -> IO a) -> IO a
  79 +withCipherPtr (Cipher cipherPtr) f = f cipherPtr
  80 +
  81 +foreign import ccall unsafe "HsOpenSSL_EVP_CIPHER_iv_length"
  82 + _iv_length :: Ptr EVP_CIPHER -> CInt
  83 +
  84 +cipherIvLength :: Cipher -> Int
  85 +cipherIvLength (Cipher cipherPtr) = fromIntegral $ _iv_length cipherPtr
  86 +
  87 +{- EVP_CIPHER_CTX ------------------------------------------------------------ -}
  88 +
  89 +newtype CipherCtx = CipherCtx (ForeignPtr EVP_CIPHER_CTX)
  90 +data EVP_CIPHER_CTX
  91 +
  92 +foreign import ccall unsafe "EVP_CIPHER_CTX_init"
  93 + _cipher_ctx_init :: Ptr EVP_CIPHER_CTX -> IO ()
  94 +
  95 +foreign import ccall unsafe "&EVP_CIPHER_CTX_cleanup"
  96 + _cipher_ctx_cleanup :: FunPtr (Ptr EVP_CIPHER_CTX -> IO ())
  97 +
  98 +foreign import ccall unsafe "EVP_CIPHER_CTX_cleanup"
  99 + _cipher_ctx_cleanup' :: Ptr EVP_CIPHER_CTX -> IO ()
  100 +
  101 +foreign import ccall unsafe "HsOpenSSL_EVP_CIPHER_CTX_block_size"
  102 + _cipher_ctx_block_size :: Ptr EVP_CIPHER_CTX -> CInt
  103 +
  104 +newCipherCtx :: IO CipherCtx
  105 +newCipherCtx = do
  106 + ctx <- mallocForeignPtrBytes (#size EVP_CIPHER_CTX)
  107 + mask_ $ do
  108 + withForeignPtr ctx _cipher_ctx_init
  109 + addForeignPtrFinalizer _cipher_ctx_cleanup ctx
  110 + return $ CipherCtx ctx
  111 +
  112 +withCipherCtxPtr :: CipherCtx -> (Ptr EVP_CIPHER_CTX -> IO a) -> IO a
  113 +withCipherCtxPtr (CipherCtx ctx) = withForeignPtr ctx
  114 +
  115 +withNewCipherCtxPtr :: (Ptr EVP_CIPHER_CTX -> IO a) -> IO a
  116 +withNewCipherCtxPtr f =
  117 + allocaBytes (#size EVP_CIPHER_CTX) $ \ptr ->
  118 + bracket_ (_cipher_ctx_init ptr) (_cipher_ctx_cleanup' ptr) (f ptr)
  119 +
  120 +{- encrypt/decrypt ----------------------------------------------------------- -}
  121 +
  122 +foreign import ccall unsafe "EVP_CipherUpdate"
  123 + _CipherUpdate :: Ptr EVP_CIPHER_CTX -> Ptr CChar -> Ptr CInt
  124 + -> Ptr CChar -> CInt -> IO CInt
  125 +
  126 +cipherUpdateBS :: CipherCtx -> B8.ByteString -> IO B8.ByteString
  127 +cipherUpdateBS ctx inBS =
  128 + withCipherCtxPtr ctx $ \ctxPtr ->
  129 + B8.unsafeUseAsCStringLen inBS $ \(inBuf, inLen) ->
  130 + let len = inLen + fromIntegral (_cipher_ctx_block_size ctxPtr) - 1 in
  131 + B8.createAndTrim len $ \outBuf ->
  132 + alloca $ \outLenPtr ->
  133 + _CipherUpdate ctxPtr (castPtr outBuf) outLenPtr inBuf
  134 + (fromIntegral inLen)
  135 + >>= failIf (/= 1)
  136 + >> fromIntegral <$> peek outLenPtr
  137 +
  138 +foreign import ccall unsafe "EVP_CipherFinal"
  139 + _CipherFinal :: Ptr EVP_CIPHER_CTX -> Ptr CChar -> Ptr CInt -> IO CInt
  140 +
  141 +cipherFinalBS :: CipherCtx -> IO B8.ByteString
  142 +cipherFinalBS ctx =
  143 + withCipherCtxPtr ctx $ \ctxPtr ->
  144 + let len = fromIntegral $ _cipher_ctx_block_size ctxPtr in
  145 + B8.createAndTrim len $ \outBuf ->
  146 + alloca $ \outLenPtr ->
  147 + _CipherFinal ctxPtr (castPtr outBuf) outLenPtr
  148 + >>= failIf (/= 1)
  149 + >> fromIntegral <$> peek outLenPtr
  150 +
  151 +cipherStrictly :: CipherCtx -> B8.ByteString -> IO B8.ByteString
  152 +cipherStrictly ctx input = do
  153 + output' <- cipherUpdateBS ctx input
  154 + output'' <- cipherFinalBS ctx
  155 + return $ B8.append output' output''
  156 +
  157 +cipherLazily :: CipherCtx -> L8.ByteString -> IO L8.ByteString
  158 +cipherLazily ctx (L8.Empty) =
  159 + cipherFinalBS ctx >>= return . L8.fromChunks . return
  160 +cipherLazily ctx (L8.Chunk x xs) = do
  161 + y <- cipherUpdateBS ctx x
  162 + ys <- unsafeInterleaveIO $ cipherLazily ctx xs
  163 + return $ L8.Chunk y ys
  164 +
  165 +{- EVP_MD -------------------------------------------------------------------- -}
  166 +
  167 +-- |@Digest@ is an opaque object that represents an algorithm of
  168 +-- message digest.
  169 +newtype Digest = Digest (Ptr EVP_MD)
  170 +data EVP_MD
  171 +
  172 +withMDPtr :: Digest -> (Ptr EVP_MD -> IO a) -> IO a
  173 +withMDPtr (Digest mdPtr) f = f mdPtr
  174 +
  175 +{- EVP_MD_CTX ---------------------------------------------------------------- -}
  176 +
  177 +newtype DigestCtx = DigestCtx (ForeignPtr EVP_MD_CTX)
  178 +data EVP_MD_CTX
  179 +
  180 +foreign import ccall unsafe "EVP_MD_CTX_init"
  181 + _md_ctx_init :: Ptr EVP_MD_CTX -> IO ()
  182 +
  183 +foreign import ccall unsafe "&EVP_MD_CTX_cleanup"
  184 + _md_ctx_cleanup :: FunPtr (Ptr EVP_MD_CTX -> IO ())
  185 +
  186 +newDigestCtx :: IO DigestCtx
  187 +newDigestCtx = do
  188 + ctx <- mallocForeignPtrBytes (#size EVP_MD_CTX)
  189 + mask_ $ do
  190 + withForeignPtr ctx _md_ctx_init
  191 + addForeignPtrFinalizer _md_ctx_cleanup ctx
  192 + return $ DigestCtx ctx
  193 +
  194 +withDigestCtxPtr :: DigestCtx -> (Ptr EVP_MD_CTX -> IO a) -> IO a
  195 +withDigestCtxPtr (DigestCtx ctx) = withForeignPtr ctx
  196 +
  197 +{- digest -------------------------------------------------------------------- -}
  198 +
  199 +foreign import ccall unsafe "EVP_DigestInit"
  200 + _DigestInit :: Ptr EVP_MD_CTX -> Ptr EVP_MD -> IO CInt
  201 +
  202 +digestInit :: Digest -> IO DigestCtx
  203 +digestInit (Digest md) = do
  204 + ctx <- newDigestCtx
  205 + withDigestCtxPtr ctx $ \ctxPtr ->
  206 + _DigestInit ctxPtr md
  207 + >>= failIf_ (/= 1)
  208 + >> return ctx
  209 +
  210 +foreign import ccall unsafe "EVP_DigestUpdate"
  211 + _DigestUpdate :: Ptr EVP_MD_CTX -> Ptr CChar -> CSize -> IO CInt
  212 +
  213 +digestUpdateBS :: DigestCtx -> B8.ByteString -> IO ()
  214 +digestUpdateBS ctx bs =
  215 + withDigestCtxPtr ctx $ \ctxPtr ->
  216 + B8.unsafeUseAsCStringLen bs $ \(buf, len) ->
  217 + _DigestUpdate ctxPtr buf (fromIntegral len)
  218 + >>= failIf (/= 1)
  219 + >> return ()
  220 +
  221 +foreign import ccall unsafe "EVP_DigestFinal"
  222 + _DigestFinal :: Ptr EVP_MD_CTX -> Ptr CChar -> Ptr CUInt -> IO CInt
  223 +
  224 +digestFinalBS :: DigestCtx -> IO B8.ByteString
  225 +digestFinalBS ctx =
  226 + withDigestCtxPtr ctx $ \ctxPtr ->
  227 + B8.createAndTrim (#const EVP_MAX_MD_SIZE) $ \bufPtr ->
  228 + alloca $ \bufLenPtr -> do
  229 + _DigestFinal ctxPtr (castPtr bufPtr) bufLenPtr >>= failIf_ (/= 1)
  230 + fromIntegral <$> peek bufLenPtr
  231 +
  232 +digestFinal :: DigestCtx -> IO String
  233 +digestFinal ctx =
  234 + withDigestCtxPtr ctx $ \ctxPtr ->
  235 + allocaArray (#const EVP_MAX_MD_SIZE) $ \bufPtr ->
  236 + alloca $ \bufLenPtr -> do
  237 + _DigestFinal ctxPtr bufPtr bufLenPtr >>= failIf_ (/= 1)
  238 + bufLen <- fromIntegral <$> peek bufLenPtr
  239 + peekCStringLen (bufPtr, bufLen)
  240 +
  241 +digestStrictly :: Digest -> B8.ByteString -> IO DigestCtx
  242 +digestStrictly md input = do
  243 + ctx <- digestInit md
  244 + digestUpdateBS ctx input
  245 + return ctx
  246 +
  247 +digestLazily :: Digest -> L8.ByteString -> IO DigestCtx
  248 +digestLazily md lbs = do
  249 + ctx <- digestInit md
  250 + mapM_ (digestUpdateBS ctx) $ L8.toChunks lbs
  251 + return ctx
  252 +
  253 +{- EVP_PKEY ------------------------------------------------------------------ -}
  254 +
  255 +-- VaguePKey is a ForeignPtr to EVP_PKEY, that is either public key or
  256 +-- a ker pair. We can't tell which at compile time.
  257 +newtype VaguePKey = VaguePKey (ForeignPtr EVP_PKEY)
  258 +data EVP_PKEY
  259 +
  260 +-- Instances of class PKey can be converted back and forth to
  261 +-- VaguePKey.
  262 +class PKey k where
  263 + -- Wrap the key (i.g. RSA) into EVP_PKEY.
  264 + toPKey :: k -> IO VaguePKey
  265 +
  266 + -- Extract the concrete key from the EVP_PKEY. Returns Nothing if
  267 + -- the type mismatches.
  268 + fromPKey :: VaguePKey -> IO (Maybe k)
  269 +
  270 + -- Do the same as EVP_PKEY_size().
  271 + pkeySize :: k -> Int
  272 +
  273 + -- Return the default digesting algorithm for the key.
  274 + pkeyDefaultMD :: k -> IO Digest
  275 +
  276 +foreign import ccall unsafe "EVP_PKEY_new"
  277 + _pkey_new :: IO (Ptr EVP_PKEY)
  278 +
  279 +foreign import ccall unsafe "&EVP_PKEY_free"
  280 + _pkey_free :: FunPtr (Ptr EVP_PKEY -> IO ())
  281 +
  282 +foreign import ccall unsafe "EVP_PKEY_free"
  283 + _pkey_free' :: Ptr EVP_PKEY -> IO ()
  284 +
  285 +wrapPKeyPtr :: Ptr EVP_PKEY -> IO VaguePKey
  286 +wrapPKeyPtr = fmap VaguePKey . newForeignPtr _pkey_free
  287 +
  288 +createPKey :: (Ptr EVP_PKEY -> IO a) -> IO VaguePKey
  289 +createPKey f = mask $ \restore -> do
  290 + ptr <- _pkey_new >>= failIfNull
  291 + (restore $ f ptr >> return ()) `onException` _pkey_free' ptr
  292 + wrapPKeyPtr ptr
  293 +
  294 +withPKeyPtr :: VaguePKey -> (Ptr EVP_PKEY -> IO a) -> IO a
  295 +withPKeyPtr (VaguePKey pkey) = withForeignPtr pkey
  296 +
  297 +withPKeyPtr' :: PKey k => k -> (Ptr EVP_PKEY -> IO a) -> IO a
  298 +withPKeyPtr' k f = do
  299 + pk <- toPKey k
  300 + withPKeyPtr pk f
  301 +
  302 +unsafePKeyToPtr :: VaguePKey -> Ptr EVP_PKEY
  303 +unsafePKeyToPtr (VaguePKey pkey) = unsafeForeignPtrToPtr pkey
  304 +
  305 +touchPKey :: VaguePKey -> IO ()
  306 +touchPKey (VaguePKey pkey) = touchForeignPtr pkey
  307 +
3  OpenSSL/EVP/Open.hsc
@@ -16,6 +16,7 @@ import Foreign
16 16 import Foreign.C
17 17 import OpenSSL.EVP.Cipher hiding (cipher)
18 18 import OpenSSL.EVP.PKey
  19 +import OpenSSL.EVP.Internal
19 20 import OpenSSL.Utils
20 21
21 22
@@ -31,7 +32,7 @@ foreign import ccall unsafe "EVP_OpenInit"
31 32
32 33 openInit :: KeyPair key => Cipher -> String -> String -> key -> IO CipherCtx
33 34 openInit cipher encKey iv pkey
34   - = do ctx <- newCtx
  35 + = do ctx <- newCipherCtx
35 36 withCipherCtxPtr ctx $ \ ctxPtr ->
36 37 withCStringLen encKey $ \ (encKeyPtr, encKeyLen) ->
37 38 withCString iv $ \ ivPtr ->
83 OpenSSL/EVP/PKey.hsc
... ... @@ -1,5 +1,6 @@
1 1 {- -*- haskell -*- -}
2 2
  3 +{-# OPTIONS_GHC -fno-warn-orphans #-}
3 4 {-# OPTIONS_HADDOCK prune #-}
4 5
5 6 -- |An interface to asymmetric cipher keypair.
@@ -7,21 +8,12 @@
7 8 #include "HsOpenSSL.h"
8 9
9 10 module OpenSSL.EVP.PKey
10   - ( PublicKey(..)
  11 + ( PKey
  12 + , PublicKey(..)
11 13 , KeyPair(..)
12 14 , SomePublicKey
13 15 , SomeKeyPair
14   -
15   - -- private
16   - , PKey(..)
17   - , EVP_PKEY
18   - , withPKeyPtr
19   - , withPKeyPtr'
20   - , wrapPKeyPtr
21   - , unsafePKeyToPtr
22   - , touchPKey
23   - )
24   - where
  16 + ) where
25 17
26 18 import Data.Typeable
27 19 import Data.Maybe
@@ -29,30 +21,10 @@ import Foreign
29 21 import Foreign.C
30 22 import OpenSSL.DSA
31 23 import OpenSSL.EVP.Digest hiding (digest)
  24 +import OpenSSL.EVP.Internal
32 25 import OpenSSL.RSA
33 26 import OpenSSL.Utils
34 27
35   --- VaguePKey is a ForeignPtr to EVP_PKEY, that is either public key or
36   --- a ker pair. We can't tell which at compile time.
37   -newtype VaguePKey = VaguePKey (ForeignPtr EVP_PKEY)
38   -data EVP_PKEY
39   -
40   --- Instances of class PKey can be converted back and forth to
41   --- VaguePKey.
42   -class PKey k where
43   - -- Wrap the key (i.g. RSA) into EVP_PKEY.
44   - toPKey :: k -> IO VaguePKey
45   -
46   - -- Extract the concrete key from the EVP_PKEY. Returns Nothing if
47   - -- the type mismatches.
48   - fromPKey :: VaguePKey -> IO (Maybe k)
49   -
50   - -- Do the same as EVP_PKEY_size().
51   - pkeySize :: k -> Int
52   -
53   - -- Return the default digesting algorithm for the key.
54   - pkeyDefaultMD :: k -> IO Digest
55   -
56 28 -- |Instances of this class has at least public portion of a
57 29 -- keypair. They might or might not have the private key.
58 30 class (Eq k, Typeable k, PKey k) => PublicKey k where
@@ -175,35 +147,6 @@ instance PKey SomeKeyPair where
175 147 = withConcreteKeyPair pk (return . Just . SomeKeyPair)
176 148
177 149
178   -foreign import ccall unsafe "EVP_PKEY_new"
179   - _pkey_new :: IO (Ptr EVP_PKEY)
180   -
181   -foreign import ccall unsafe "&EVP_PKEY_free"
182   - _pkey_free :: FunPtr (Ptr EVP_PKEY -> IO ())
183   -
184   -
185   -wrapPKeyPtr :: Ptr EVP_PKEY -> IO VaguePKey
186   -wrapPKeyPtr
187   - = fmap VaguePKey . newForeignPtr _pkey_free
188   -
189   -
190   -withPKeyPtr' :: PKey k => k -> (Ptr EVP_PKEY -> IO a) -> IO a
191   -withPKeyPtr' k f = do pk <- toPKey k
192   - withPKeyPtr pk f
193   -
194   -
195   -withPKeyPtr :: VaguePKey -> (Ptr EVP_PKEY -> IO a) -> IO a
196   -withPKeyPtr (VaguePKey pkey) = withForeignPtr pkey
197   -
198   -
199   -unsafePKeyToPtr :: VaguePKey -> Ptr EVP_PKEY
200   -unsafePKeyToPtr (VaguePKey pkey) = unsafeForeignPtrToPtr pkey
201   -
202   -
203   -touchPKey :: VaguePKey -> IO ()
204   -touchPKey (VaguePKey pkey) = touchForeignPtr pkey
205   -
206   -
207 150 #ifndef OPENSSL_NO_RSA
208 151 -- The resulting Ptr RSA must be freed by caller.
209 152 foreign import ccall unsafe "EVP_PKEY_get1_RSA"
@@ -215,10 +158,9 @@ foreign import ccall unsafe "EVP_PKEY_set1_RSA"
215 158
216 159 rsaToPKey :: RSAKey k => k -> IO VaguePKey
217 160 rsaToPKey rsa
218   - = withRSAPtr rsa $ \ rsaPtr ->
219   - do pkeyPtr <- _pkey_new >>= failIfNull
220   - _set1_RSA pkeyPtr rsaPtr >>= failIf_ (/= 1)
221   - wrapPKeyPtr pkeyPtr
  161 + = withRSAPtr rsa $ \rsaPtr ->
  162 + createPKey $ \pkeyPtr ->
  163 + _set1_RSA pkeyPtr rsaPtr >>= failIf_ (/= 1)
222 164
223 165 rsaFromPKey :: RSAKey k => VaguePKey -> IO (Maybe k)
224 166 rsaFromPKey pk
@@ -255,10 +197,9 @@ foreign import ccall unsafe "EVP_PKEY_set1_DSA"
255 197
256 198 dsaToPKey :: DSAKey k => k -> IO VaguePKey
257 199 dsaToPKey dsa
258   - = withDSAPtr dsa $ \ dsaPtr ->
259   - do pkeyPtr <- _pkey_new >>= failIfNull
260   - _set1_DSA pkeyPtr dsaPtr >>= failIf_ (/= 1)
261   - wrapPKeyPtr pkeyPtr
  200 + = withDSAPtr dsa $ \dsaPtr ->
  201 + createPKey $ \pkeyPtr ->
  202 + _set1_DSA pkeyPtr dsaPtr >>= failIf_ (/= 1)
262 203
263 204 dsaFromPKey :: DSAKey k => VaguePKey -> IO (Maybe k)
264 205 dsaFromPKey pk
@@ -283,4 +224,4 @@ instance PKey DSAKeyPair where
283 224 fromPKey = dsaFromPKey
284 225 pkeySize = dsaSize
285 226 pkeyDefaultMD _ = return . fromJust =<< getDigestByName "dss1"
286   -#endif
  227 +#endif
3  OpenSSL/EVP/Seal.hsc
@@ -16,6 +16,7 @@ import Foreign
16 16 import Foreign.C
17 17 import OpenSSL.EVP.Cipher hiding (cipher)
18 18 import OpenSSL.EVP.PKey
  19 +import OpenSSL.EVP.Internal
19 20 import OpenSSL.Utils
20 21
21 22
@@ -36,7 +37,7 @@ sealInit _ []
36 37 = fail "sealInit: at least one public key is required"
37 38
38 39 sealInit cipher pubKeys
39   - = do ctx <- newCtx
  40 + = do ctx <- newCipherCtx
40 41
41 42 -- Allocate a list of buffers to write encrypted symmetric
42 43 -- keys. Each keys will be at most pkeySize bytes long.
29 OpenSSL/EVP/Sign.hsc
@@ -7,35 +7,33 @@ module OpenSSL.EVP.Sign
7 7 ( sign
8 8 , signBS
9 9 , signLBS
10   - , signFinal -- private
11 10 )
12 11 where
13 12
14   -import Control.Monad
15 13 import qualified Data.ByteString.Char8 as B8
16 14 import qualified Data.ByteString.Internal as B8
17 15 import qualified Data.ByteString.Lazy.Char8 as L8
  16 +import Control.Applicative ((<$>))
18 17 import Foreign
19 18 import Foreign.C
20 19 import OpenSSL.EVP.Digest
21 20 import OpenSSL.EVP.PKey
  21 +import OpenSSL.EVP.Internal
22 22 import OpenSSL.Utils
23 23
24   -
25 24 foreign import ccall unsafe "EVP_SignFinal"
26   - _SignFinal :: Ptr EVP_MD_CTX -> Ptr Word8 -> Ptr CUInt -> Ptr EVP_PKEY -> IO CInt
27   -
  25 + _SignFinal :: Ptr EVP_MD_CTX -> Ptr Word8 -> Ptr CUInt
  26 + -> Ptr EVP_PKEY -> IO CInt
28 27
29 28 signFinal :: KeyPair k => DigestCtx -> k -> IO B8.ByteString
30   -signFinal ctx k
31   - = do let maxLen = pkeySize k
32   - withDigestCtxPtr ctx $ \ ctxPtr ->
33   - withPKeyPtr' k $ \ pkeyPtr ->
34   - B8.createAndTrim maxLen $ \ bufPtr ->
35   - alloca $ \ bufLenPtr ->
36   - do failIf_ (/= 1) =<< _SignFinal ctxPtr bufPtr bufLenPtr pkeyPtr
37   - liftM fromIntegral $ peek bufLenPtr
38   -
  29 +signFinal ctx k = do
  30 + let maxLen = pkeySize k
  31 + withDigestCtxPtr ctx $ \ ctxPtr ->
  32 + withPKeyPtr' k $ \ pkeyPtr ->
  33 + B8.createAndTrim maxLen $ \ bufPtr ->
  34 + alloca $ \ bufLenPtr -> do
  35 + failIf_ (/= 1) =<< _SignFinal ctxPtr bufPtr bufLenPtr pkeyPtr
  36 + fromIntegral <$> peek bufLenPtr
39 37
40 38 -- |@'sign'@ generates a signature from a stream of data. The string
41 39 -- must not contain any letters which aren't in the range of U+0000 -
@@ -46,7 +44,7 @@ sign :: KeyPair key =>
46 44 -> String -- ^ input string
47 45 -> IO String -- ^ the result signature
48 46 sign md pkey input
49   - = liftM L8.unpack $ signLBS md pkey $ L8.pack input
  47 + = fmap L8.unpack $ signLBS md pkey $ L8.pack input
50 48
51 49 -- |@'signBS'@ generates a signature from a chunk of data.
52 50 signBS :: KeyPair key =>
@@ -68,3 +66,4 @@ signLBS md pkey input
68 66 = do ctx <- digestLazily md input
69 67 sig <- signFinal ctx pkey
70 68 return $ L8.fromChunks [sig]
  69 +
1  OpenSSL/EVP/Verify.hsc
@@ -18,6 +18,7 @@ import Foreign
18 18 import Foreign.C
19 19 import OpenSSL.EVP.Digest
20 20 import OpenSSL.EVP.PKey
  21 +import OpenSSL.EVP.Internal
21 22 import OpenSSL.Utils
22 23
23 24 -- |@'VerifyStatus'@ represents a result of verification.
1  OpenSSL/PEM.hsc
@@ -48,6 +48,7 @@ import Foreign.C
48 48 import OpenSSL.BIO
49 49 import OpenSSL.EVP.Cipher hiding (cipher)
50 50 import OpenSSL.EVP.PKey
  51 +import OpenSSL.EVP.Internal
51 52 import OpenSSL.DH.Internal
52 53 import OpenSSL.PKCS7
53 54 import OpenSSL.Utils
1  OpenSSL/PKCS7.hsc
@@ -35,6 +35,7 @@ import Foreign.C
35 35 import OpenSSL.BIO
36 36 import OpenSSL.EVP.Cipher hiding (cipher)
37 37 import OpenSSL.EVP.PKey
  38 +import OpenSSL.EVP.Internal
38 39 import OpenSSL.Stack
39 40 import OpenSSL.Utils
40 41 import OpenSSL.X509
1  OpenSSL/Session.hsc
@@ -85,6 +85,7 @@ import System.Posix.Types (Fd(..))
85 85 import Network.Socket (Socket(..))
86 86
87 87 import OpenSSL.EVP.PKey
  88 +import OpenSSL.EVP.Internal
88 89 import OpenSSL.Utils
89 90 import OpenSSL.X509 (X509, X509_, wrapX509, withX509Ptr)
90 91 import OpenSSL.X509.Store
3  OpenSSL/X509.hsc
@@ -60,6 +60,7 @@ import OpenSSL.BIO
60 60 import OpenSSL.EVP.Digest hiding (digest)
61 61 import OpenSSL.EVP.PKey
62 62 import OpenSSL.EVP.Verify
  63 +import OpenSSL.EVP.Internal
63 64 import OpenSSL.Utils
64 65 import OpenSSL.Stack
65 66 import OpenSSL.X509.Name
@@ -374,4 +375,4 @@ getSubjectEmail x509
374 375 do st <- _get1_email x509Ptr
375 376 list <- mapStack peekCString st
376 377 _email_free st
377   - return list
  378 + return list
3  OpenSSL/X509/Request.hsc
@@ -41,6 +41,7 @@ import OpenSSL.BIO
41 41 import OpenSSL.EVP.Digest hiding (digest)
42 42 import OpenSSL.EVP.PKey
43 43 import OpenSSL.EVP.Verify
  44 +import OpenSSL.EVP.Internal
44 45 import OpenSSL.Utils
45 46 import OpenSSL.X509 (X509)
46 47 import qualified OpenSSL.X509 as Cert
@@ -251,4 +252,4 @@ makeX509FromReq req caCert
251 252 Cert.setSubjectName cert =<< getSubjectName req False
252 253 Cert.setPublicKey cert =<< getPublicKey req
253 254
254   - return cert
  255 + return cert
1  OpenSSL/X509/Revocation.hsc
@@ -55,6 +55,7 @@ import OpenSSL.BIO
55 55 import OpenSSL.EVP.Digest hiding (digest)
56 56 import OpenSSL.EVP.PKey
57 57 import OpenSSL.EVP.Verify
  58 +import OpenSSL.EVP.Internal
58 59 import OpenSSL.Stack
59 60 import OpenSSL.Utils
60 61 import OpenSSL.X509.Name

0 comments on commit e9ed30a

Please sign in to comment.
Something went wrong with that request. Please try again.