diff --git a/HsOpenSSL.cabal b/HsOpenSSL.cabal index f1cb58d..91e3335 100644 --- a/HsOpenSSL.cabal +++ b/HsOpenSSL.cabal @@ -37,6 +37,10 @@ Library else build-depends: base < 3, time >= 1.1.1 + --PkgConfig-Depends: openssl >= 0.9.7l + -- We really should use this instead of the configure script but + -- Cabal 1.2.2.0 can't handle the weird version scheme of OpenSSL. + Exposed-Modules: OpenSSL OpenSSL.BN @@ -70,7 +74,7 @@ Library Extensions: ForeignFunctionInterface, EmptyDataDecls, MagicHash ghc-options: - -O2 -fwarn-unused-imports -fglasgow-exts + -Wall -fglasgow-exts C-Sources: cbits/HsOpenSSL.c Include-Dirs: diff --git a/Makefile b/Makefile index 37eefef..be23ab2 100644 --- a/Makefile +++ b/Makefile @@ -1,15 +1,15 @@ CABAL_FILE = HsOpenSSL.cabal GHC = ghc -build: .setup-config Setup +build: dist/setup-config Setup ./Setup build run: build @echo ".:.:. Let's go .:.:." $(MAKE) -C examples run -.setup-config: $(CABAL_FILE) configure Setup - ./Setup configure -p +dist/setup-config: $(CABAL_FILE) configure Setup + ./Setup configure -p -O --enable-split-objs configure: aclocal.m4 configure.ac autoconf @@ -26,7 +26,7 @@ clean: $(MAKE) -C examples clean doc: .setup-config Setup - ./Setup haddock + ./Setup haddock --hyperlink-source --hscolour-css=../hscolour/hscolour.css install: build sudo ./Setup install diff --git a/OpenSSL/ASN1.hsc b/OpenSSL/ASN1.hsc index 79354f6..ec29963 100644 --- a/OpenSSL/ASN1.hsc +++ b/OpenSSL/ASN1.hsc @@ -157,6 +157,6 @@ allocaASN1Time m withASN1Time :: UTCTime -> (Ptr ASN1_TIME -> IO a) -> IO a withASN1Time utc m = allocaASN1Time $ \ time -> - do _ASN1_TIME_set time (fromIntegral $ round $ utcTimeToPOSIXSeconds utc) + do _ASN1_TIME_set time (fromIntegral $ (round $ utcTimeToPOSIXSeconds utc :: Integer)) >>= failIfNull m time \ No newline at end of file diff --git a/OpenSSL/BN.hsc b/OpenSSL/BN.hsc index 77a156a..86baab0 100644 --- a/OpenSSL/BN.hsc +++ b/OpenSSL/BN.hsc @@ -41,7 +41,7 @@ module OpenSSL.BN ) where -import Control.Exception +import Control.Exception hiding (try) import Foreign import qualified Data.ByteString as BS import OpenSSL.Utils @@ -172,7 +172,7 @@ bnToInteger bn = do if negative == 0 then return $ S## i else return $ 0 - (S## i) - otherwise -> do + _ -> do let (I## nlimbsi) = fromIntegral nlimbs (I## limbsize) = (#size unsigned long) (MBA arr) <- newByteArray (nlimbsi *## limbsize) @@ -290,7 +290,7 @@ foreign import ccall unsafe "BN_mod_exp" _mod_exp :: Ptr BIGNUM -> Ptr BIGNUM -> Ptr BIGNUM -> Ptr BIGNUM -> BNCtx -> IO (Ptr BIGNUM) type BNCtx = Ptr BNCTX -data BNCTX = BNCTX +data BNCTX foreign import ccall unsafe "BN_CTX_new" _BN_ctx_new :: IO BNCtx diff --git a/OpenSSL/Cipher.hsc b/OpenSSL/Cipher.hsc index 931718e..20ad9c9 100644 --- a/OpenSSL/Cipher.hsc +++ b/OpenSSL/Cipher.hsc @@ -29,6 +29,7 @@ import OpenSSL.Utils data Mode = Encrypt | Decrypt deriving (Eq, Show) +modeToInt :: Num a => Mode -> a modeToInt Encrypt = 1 modeToInt Decrypt = 0 @@ -71,7 +72,7 @@ newAESCtx mode key iv = do when (BS.length iv /= 16) $ fail "Bad AES128 iv length" ctx <- mallocForeignPtrBytes (#size AES_KEY) withForeignPtr ctx $ \ctxPtr -> - BS.useAsCStringLen key (\(ptr, len) -> + BS.useAsCStringLen key (\(ptr, _) -> case mode of Encrypt -> _AES_set_encrypt_key ptr (fromIntegral keyLen) ctxPtr >>= failIf (/= 0) Decrypt -> _AES_set_decrypt_key ptr (fromIntegral keyLen) ctxPtr >>= failIf (/= 0)) @@ -80,7 +81,7 @@ newAESCtx mode key iv = do nref <- newIORef 0 withForeignPtr ecounter (\ecptr -> _memset ecptr 0 16) withForeignPtr ivbytes $ \ivPtr -> - BS.useAsCStringLen iv $ \(ptr, len) -> + BS.useAsCStringLen iv $ \(ptr, _) -> do _memcpy ivPtr ptr 16 return $ AESCtx ctx ivbytes ecounter nref mode @@ -102,6 +103,7 @@ aesCBC (AESCtx ctx iv _ _ mode) input = do aesCTR :: AESCtx -- ^ context -> BS.ByteString -- ^ input, any number of bytes -> IO BS.ByteString +aesCTR (AESCtx _ _ _ _ Decrypt) _ = fail "the context mode must be Encrypt" aesCTR (AESCtx ctx iv ecounter nref Encrypt) input = do withForeignPtr ctx $ \ctxPtr -> withForeignPtr iv $ \ivPtr -> diff --git a/OpenSSL/EVP/Base64.hsc b/OpenSSL/EVP/Base64.hsc index 6364b75..3a42d48 100644 --- a/OpenSSL/EVP/Base64.hsc +++ b/OpenSSL/EVP/Base64.hsc @@ -15,7 +15,7 @@ module OpenSSL.EVP.Base64 ) where -import Control.Exception +import Control.Exception hiding (block) import Data.ByteString.Internal (createAndTrim) import Data.ByteString.Unsafe (unsafeUseAsCStringLen) import qualified Data.ByteString.Lazy.Internal as L8Internal @@ -32,12 +32,13 @@ import Foreign.C -- -- デコード時: 分割のアルゴリズムは同じだが最低バイト数が 4。 nextBlock :: Int -> ([B8.ByteString], L8.ByteString) -> ([B8.ByteString], L8.ByteString) -nextBlock _ (xs, L8Internal.Empty ) = (xs, L8Internal.Empty) -nextBlock minLen (xs, src) = if foldl' (+) 0 (map B8.length xs) >= minLen then - (xs, src) - else - case src of - L8Internal.Chunk y ys -> nextBlock minLen (xs ++ [y], ys) +nextBlock minLen (xs, src) + = if foldl' (+) 0 (map B8.length xs) >= minLen then + (xs, src) + else + case src of + L8Internal.Empty -> (xs, src) + L8Internal.Chunk y ys -> nextBlock minLen (xs ++ [y], ys) {- encode -------------------------------------------------------------------- -} diff --git a/OpenSSL/EVP/Cipher.hsc b/OpenSSL/EVP/Cipher.hsc index b07cdca..40e04cf 100644 --- a/OpenSSL/EVP/Cipher.hsc +++ b/OpenSSL/EVP/Cipher.hsc @@ -62,7 +62,7 @@ foreign import ccall unsafe "HsOpenSSL_EVP_CIPHER_iv_length" withCipherPtr :: Cipher -> (Ptr EVP_CIPHER -> IO a) -> IO a -withCipherPtr (Cipher cipher) f = f cipher +withCipherPtr (Cipher cipherPtr) f = f cipherPtr -- |@'getCipherByName' name@ returns a symmetric cipher algorithm -- whose name is @name@. If no algorithms are found, the result is @@ -83,7 +83,7 @@ getCipherNames = getObjNames CipherMethodType True cipherIvLength :: Cipher -> Int -cipherIvLength (Cipher cipher) = _iv_length cipher +cipherIvLength (Cipher cipherPtr) = _iv_length cipherPtr {- EVP_CIPHER_CTX ------------------------------------------------------------ -} diff --git a/OpenSSL/EVP/Digest.hsc b/OpenSSL/EVP/Digest.hsc index 7a4cc95..ea950cc 100644 --- a/OpenSSL/EVP/Digest.hsc +++ b/OpenSSL/EVP/Digest.hsc @@ -30,7 +30,6 @@ module OpenSSL.EVP.Digest where import Control.Monad -import Data.ByteString (packCStringLen) import Data.ByteString.Unsafe (unsafeUseAsCStringLen) import qualified Data.ByteString.Char8 as B8 import qualified Data.ByteString.Lazy.Char8 as L8 @@ -51,9 +50,6 @@ data EVP_MD foreign import ccall unsafe "EVP_get_digestbyname" _get_digestbyname :: CString -> IO (Ptr EVP_MD) -foreign import ccall unsafe "HsOpenSSL_EVP_MD_size" - mdSize :: Ptr EVP_MD -> Int - withMDPtr :: Digest -> (Ptr EVP_MD -> IO a) -> IO a withMDPtr (Digest mdPtr) f = f mdPtr @@ -128,11 +124,6 @@ digestUpdateBS ctx bs _DigestUpdate ctxPtr buf (fromIntegral len) >>= failIf (/= 1) >> return () -digestUpdateLBS :: DigestCtx -> L8.ByteString -> IO () -digestUpdateLBS ctx lbs - = mapM_ (digestUpdateBS ctx) $ L8.toChunks lbs - - digestFinal :: DigestCtx -> IO String digestFinal ctx = withDigestCtxPtr ctx $ \ ctxPtr -> @@ -196,4 +187,4 @@ hmacBS (Digest md) key input = unsafeUseAsCStringLen input $ \(inputdata, inputlen) -> do _HMAC md keydata (fromIntegral keylen) inputdata (fromIntegral inputlen) bufPtr bufLenPtr bufLen <- liftM fromIntegral $ peek bufLenPtr - packCStringLen (bufPtr, bufLen) + B8.packCStringLen (bufPtr, bufLen) diff --git a/OpenSSL/EVP/PKey.hsc b/OpenSSL/EVP/PKey.hsc index 7286247..d9f331e 100644 --- a/OpenSSL/EVP/PKey.hsc +++ b/OpenSSL/EVP/PKey.hsc @@ -29,7 +29,7 @@ module OpenSSL.EVP.PKey import Foreign import OpenSSL.DSA -import OpenSSL.EVP.Digest +import OpenSSL.EVP.Digest hiding (digest) import OpenSSL.RSA import OpenSSL.Utils diff --git a/OpenSSL/EVP/Seal.hsc b/OpenSSL/EVP/Seal.hsc index e2620c9..b1f0b40 100644 --- a/OpenSSL/EVP/Seal.hsc +++ b/OpenSSL/EVP/Seal.hsc @@ -15,7 +15,7 @@ import qualified Data.ByteString.Char8 as B8 import qualified Data.ByteString.Lazy.Char8 as L8 import Foreign import Foreign.C -import OpenSSL.EVP.Cipher +import OpenSSL.EVP.Cipher hiding (cipher) import OpenSSL.EVP.PKey import OpenSSL.Utils diff --git a/OpenSSL/PEM.hsc b/OpenSSL/PEM.hsc index e222c5e..f3003c7 100644 --- a/OpenSSL/PEM.hsc +++ b/OpenSSL/PEM.hsc @@ -35,12 +35,12 @@ module OpenSSL.PEM ) where -import Control.Exception +import Control.Exception hiding (try) import Control.Monad import Foreign import Foreign.C import OpenSSL.BIO -import OpenSSL.EVP.Cipher +import OpenSSL.EVP.Cipher hiding (cipher) import OpenSSL.EVP.PKey import OpenSSL.PKCS7 import OpenSSL.Utils @@ -92,6 +92,7 @@ foreign import ccall "wrapper" rwflagToState :: Int -> PemPasswordRWState rwflagToState 0 = PwRead rwflagToState 1 = PwWrite +rwflagToState _ = undefined callPasswordCB :: PemPasswordCallback -> PemPasswordCallback' diff --git a/OpenSSL/PKCS7.hsc b/OpenSSL/PKCS7.hsc index 1da05ce..cc39adc 100644 --- a/OpenSSL/PKCS7.hsc +++ b/OpenSSL/PKCS7.hsc @@ -33,7 +33,7 @@ import Data.Typeable import Foreign import Foreign.C import OpenSSL.BIO -import OpenSSL.EVP.Cipher +import OpenSSL.EVP.Cipher hiding (cipher) import OpenSSL.EVP.PKey import OpenSSL.Stack import OpenSSL.Utils diff --git a/OpenSSL/Utils.hs b/OpenSSL/Utils.hs index eb14a49..3ddc6e5 100644 --- a/OpenSSL/Utils.hs +++ b/OpenSSL/Utils.hs @@ -51,6 +51,7 @@ toHex = reverse . map hexByte . unfoldr step where hexByte 13 = 'd' hexByte 14 = 'e' hexByte 15 = 'f' + hexByte _ = undefined -- | Convert a hex string to an integer fromHex :: (Bits i) => String -> i @@ -79,3 +80,4 @@ fromHex = foldl step 0 where byteHex 'D' = 13 byteHex 'E' = 14 byteHex 'F' = 15 + byteHex _ = undefined diff --git a/OpenSSL/X509.hsc b/OpenSSL/X509.hsc index 64244dc..61e2804 100644 --- a/OpenSSL/X509.hsc +++ b/OpenSSL/X509.hsc @@ -56,7 +56,7 @@ import Foreign import Foreign.C import OpenSSL.ASN1 import OpenSSL.BIO -import OpenSSL.EVP.Digest +import OpenSSL.EVP.Digest hiding (digest) import OpenSSL.EVP.PKey import OpenSSL.EVP.Verify import OpenSSL.Utils diff --git a/OpenSSL/X509/Request.hsc b/OpenSSL/X509/Request.hsc index f11049c..2b804b8 100644 --- a/OpenSSL/X509/Request.hsc +++ b/OpenSSL/X509/Request.hsc @@ -37,7 +37,7 @@ import Control.Monad import Foreign import Foreign.C import OpenSSL.BIO -import OpenSSL.EVP.Digest +import OpenSSL.EVP.Digest hiding (digest) import OpenSSL.EVP.PKey import OpenSSL.EVP.Verify import OpenSSL.Utils diff --git a/OpenSSL/X509/Revocation.hsc b/OpenSSL/X509/Revocation.hsc index c26c749..89cf307 100644 --- a/OpenSSL/X509/Revocation.hsc +++ b/OpenSSL/X509/Revocation.hsc @@ -49,7 +49,7 @@ import Foreign import Foreign.C import OpenSSL.ASN1 import OpenSSL.BIO -import OpenSSL.EVP.Digest +import OpenSSL.EVP.Digest hiding (digest) import OpenSSL.EVP.PKey import OpenSSL.EVP.Verify import OpenSSL.Stack