module Network.GnuTLS.GnuTLS
(
CipherAlgorithm(..), KxAlgorithm(..), ParamsType(..), CredentialsType(..),
MacAlgorithm(..), DigestAlgorithm(..), CompressionMethod(..), ConnectionEnd(..),
AlertLevel(..), AlertDescription(..), HandshakeDescription(..), CertificateStatus(..),
CertificateRequest(..), CloseRequest(..), Protocol(..),
CertificateType(..), X509CertificateFormat(..), PkAlgorithm(..), SignAlgorithm(..),
Session, DH, RSA, AnonymousServerCredentials, AnonymousClientCredentials,
Server, Client, Transport, CertificateCredentials,Datum(..),
SetPriority(..), setDefaultPriority, setDefaultExportPriority,
SetCredentials(..), Clear(..),
tlsClient, tlsServer,
priorities, credentials, dhPrimeBits, transport, handle, clientCert,
handshake, rehandshake, bye,
setMaxHandshakePacketLength,
serverWantedAuth, verifyPeer, isResumed,
getAlert, getCipher, getKx, getMac, getCompression, getCertificateType, getProtocol,
getCredentialsType,
getServerCredentialsType, getClientCredentialsType,
getPeersCertificatesRaw,
tlsSend, tlsSendString, tlsRecv, tlsRecvString, tlsCheckPending,
certificateCredentials, freeKeys, freeCas, freeCaNames, freeCrls,
certificateTrustFile, certificateCrlFile, certificateKeyFile,
anonymousServerCredentials, anonymousClientCredentials,
SetDHParams(..), CredParameter(..),
newDH, newRSA,cipherKeySize,cipherSuiteName,
version, gnutlsGlobalInit
) where
import Control.Concurrent
import Data.Bits((.&.), (.|.))
import Data.IORef(newIORef, readIORef)
import Foreign
import Foreign.C
import qualified Foreign.Concurrent as FC
import Foreign.Ptr
import System.IO
import System.IO.Unsafe
import Network.GnuTLS.Attributes
import Network.GnuTLS.Internals
import Network.GnuTLS.RefCount
data DH = DH (ForeignPtr ())! RefCount
data RSA = RSA (ForeignPtr ())! RefCount
data AnonymousServerCredentials = ASC (ForeignPtr ())! RefCount
data AnonymousClientCredentials = ACC (ForeignPtr ())! RefCount
data CertificateCredentials = CC (ForeignPtr ())! RefCount
data Server
data Client
type Transport = Ptr () -> Int -> Ptr CInt -> IO Int
withDH (DH fp _) = withForeignPtr fp
withRSA (RSA fp _) = withForeignPtr fp
withAnonymousServerCredentials (ASC fp _) = withForeignPtr fp
withAnonymousClientCredentials (ACC fp _) = withForeignPtr fp
withCertificateCredentials (CC fp _) = withForeignPtr fp
instance Show AlertDescription where
show a = unsafePerformIO $ gnutlsAlertGetName a
gnutlsAlertGetName :: AlertDescription -> IO (String)
gnutlsAlertGetName a1 =
let {a1' = enumCInt a1} in
gnutlsAlertGetName'_ a1' >>= \res ->
safePeekCString res >>= \res' ->
return (res')
instance Show CipherAlgorithm where
show a = unsafePerformIO $ gnutlsCipherGetName a
gnutlsCipherGetName :: CipherAlgorithm -> IO (String)
gnutlsCipherGetName a1 =
let {a1' = enumCInt a1} in
gnutlsCipherGetName'_ a1' >>= \res ->
safePeekCString res >>= \res' ->
return (res')
instance Show MacAlgorithm where
show a = unsafePerformIO $ gnutlsMacGetName a
gnutlsMacGetName :: MacAlgorithm -> IO (String)
gnutlsMacGetName a1 =
let {a1' = enumCInt a1} in
gnutlsMacGetName'_ a1' >>= \res ->
safePeekCString res >>= \res' ->
return (res')
instance Show CompressionMethod where
show a = unsafePerformIO $ gnutlsCompressionGetName a
gnutlsCompressionGetName :: CompressionMethod -> IO (String)
gnutlsCompressionGetName a1 =
let {a1' = enumCInt a1} in
gnutlsCompressionGetName'_ a1' >>= \res ->
safePeekCString res >>= \res' ->
return (res')
instance Show KxAlgorithm where
show a = unsafePerformIO $ gnutlsKxGetName a
gnutlsKxGetName :: KxAlgorithm -> IO (String)
gnutlsKxGetName a1 =
let {a1' = enumCInt a1} in
gnutlsKxGetName'_ a1' >>= \res ->
safePeekCString res >>= \res' ->
return (res')
instance Show CertificateType where
show a = unsafePerformIO $ gnutlsCertificateTypeGetName a
gnutlsCertificateTypeGetName :: CertificateType -> IO (String)
gnutlsCertificateTypeGetName a1 =
let {a1' = enumCInt a1} in
gnutlsCertificateTypeGetName'_ a1' >>= \res ->
safePeekCString res >>= \res' ->
return (res')
instance Show Protocol where
show a = unsafePerformIO $ gnutlsProtocolGetName a
gnutlsProtocolGetName :: Protocol -> IO (String)
gnutlsProtocolGetName a1 =
let {a1' = enumCInt a1} in
gnutlsProtocolGetName'_ a1' >>= \res ->
safePeekCString res >>= \res' ->
return (res')
instance Show PkAlgorithm where
show a = unsafePerformIO $ gnutlsPkAlgorithmGetName a
gnutlsPkAlgorithmGetName :: PkAlgorithm -> IO (String)
gnutlsPkAlgorithmGetName a1 =
let {a1' = enumCInt a1} in
gnutlsPkAlgorithmGetName'_ a1' >>= \res ->
safePeekCString res >>= \res' ->
return (res')
instance Show SignAlgorithm where
show a = unsafePerformIO $ gnutlsSignAlgorithmGetName a
gnutlsSignAlgorithmGetName :: SignAlgorithm -> IO (String)
gnutlsSignAlgorithmGetName a1 =
let {a1' = enumCInt a1} in
gnutlsSignAlgorithmGetName'_ a1' >>= \res ->
safePeekCString res >>= \res' ->
return (res')
setpwrap :: Enum e => (Ptr () -> Ptr CInt -> IO CInt) -> Session t -> [e] -> IO ()
setpwrap comp s x = do
withEnumList0 x $ \e -> do
withSession s $ \p -> do
comp p e >>= throwGnutlsIf
class SetPriority a where setPriority :: Session t -> [a] -> IO ()
instance SetPriority CipherAlgorithm where
setPriority = setpwrap gnutls_cipher_set_priority
instance SetPriority MacAlgorithm where
setPriority = setpwrap gnutls_mac_set_priority
instance SetPriority CompressionMethod where
setPriority = setpwrap gnutls_compression_set_priority
instance SetPriority KxAlgorithm where
setPriority = setpwrap gnutls_kx_set_priority
instance SetPriority Protocol where
setPriority = setpwrap gnutls_protocol_set_priority
instance SetPriority CertificateType where
setPriority = setpwrap gnutls_certificate_type_set_priority
setDefaultPriority :: Session t -> IO ()
setDefaultPriority a1 =
withSession a1 $ \a1' ->
setDefaultPriority'_ a1' >>= \res ->
return ()
setDefaultExportPriority :: Session t -> IO ()
setDefaultExportPriority a1 =
withSession a1 $ \a1' ->
setDefaultExportPriority'_ a1' >>= \res ->
return ()
class SetCredentials st a where setCredentials :: Session st -> a -> IO ()
instance SetCredentials st a => SetCredentials st (IO a) where
setCredentials s c = setCredentials s =<< c
instance SetCredentials Server AnonymousServerCredentials where
setCredentials s (ASC a rc) = setcred_ s CrdAnon (castForeignPtr a)
instance SetCredentials Client AnonymousClientCredentials where
setCredentials s (ACC a rc) = setcred_ s CrdAnon (castForeignPtr a)
instance SetCredentials t CertificateCredentials where
setCredentials s (CC a rc) = setcred_ s CrdCertificate (castForeignPtr a)
setcred_ :: Session t -> CredentialsType -> ForeignPtr a -> IO ()
setcred_ (Session sfp refc) ct fp = do
withForeignPtr sfp $ \sptr -> do
withForeignPtr fp $ \dptr -> do
gnutls_credentials_set sptr (enumCInt ct) (castPtr dptr) >>= throwGnutlsIf
addRefFinalizer refc (touchForeignPtr fp)
data Clear = Clear
instance SetCredentials t Clear where
setCredentials s _ = withSession s (\s -> gnutls_credentials_clear s >> return ())
tlsClient :: [AttrOp (Session Client)] -> IO (Session Client)
tlsClient p = do s <- newSession Client
set s p
return s
tlsServer :: [AttrOp (Session Server)] -> IO (Session Server)
tlsServer p = do s <- newSession Server
set s p
return s
newSession :: ConnectionEnd -> IO (Session t)
newSession ce = gnutlsGlobalInit >> alloca (\err -> do
let efun b l e = putStrLn "TLS pull/push functions not set" >> return 0
ef1 <- newStablePtr efun
ef2 <- newStablePtr efun
sp <- init_session_wrap (enumCInt ce) ef1 ef2 err
peek err >>= throwGnutlsIf
rc <- newRefCount (replace_transport_stable_ptrs sp stableNull stableNull >> gnutls_deinit sp)
ps <- FC.newForeignPtr sp (freeRef rc)
return $ Session ps rc)
stableNull = castPtrToStablePtr nullPtr
foreign import ccall unsafe "TLS.h gnutls_init" gnutls_init :: Ptr (Ptr ()) -> CInt -> IO CInt
foreign import ccall unsafe "TLS.h gnutls_deinit" gnutls_deinit :: Ptr () -> IO ()
foreign import ccall unsafe "TLS.h init_session_wrap"
init_session_wrap :: CInt -> StablePtr Transport -> StablePtr Transport -> Ptr CInt -> IO (Ptr ())
priorities :: SetPriority a => WriteAttr (Session t) [a]
priorities = writeAttr setPriority
credentials :: SetCredentials t a => WriteAttr (Session t) a
credentials = writeAttr setCredentials
dhPrimeBits :: ReadWriteAttr (Session t) Int Int
dhPrimeBits = newAttr get set
where get s = withSession s gnutls_dh_get_prime_bits >>= return . fromIntegral
set s v = withSession s (\sp -> gnutls_dh_set_prime_bits sp (fromIntegral v))
transport :: ReadWriteAttr (Session t) (Transport,Transport) (Transport,Transport)
transport = newAttr gnutls_transport_get_ptr2 set
where set s (a,b) = do a' <- newStablePtr a
b' <- newStablePtr b
withSession s $ \sp -> replace_transport_stable_ptrs sp a' b'
gnutls_transport_get_ptr2 :: Session t -> IO (Transport, Transport)
gnutls_transport_get_ptr2 a1 =
withSession a1 $ \a1' ->
alloca $ \a2' ->
alloca $ \a3' ->
gnutls_transport_get_ptr2'_ a1' a2' a3' >>= \res ->
ptrDeS a2'>>= \a2'' ->
ptrDeS a3'>>= \a3'' ->
return (a2'', a3'')
foreign import ccall "replace_transport_stable_ptrs"
replace_transport_stable_ptrs :: Ptr () -> StablePtr Transport -> StablePtr Transport -> IO ()
handle :: WriteAttr (Session t) Handle
handle = writeAttr ss
where rf hdl buf len err = (hGetBuf hdl buf (fromIntegral len)) `catch` ef err
sf hdl buf len err = (hPutBuf hdl buf (fromIntegral len) >> return len) `catch` ef err
ef err _ = do (Errno iv) <- getErrno; poke err iv; return (1)
ss (Session sfp sr) hdl = do rf' <- newStablePtr $ rf hdl
sf' <- newStablePtr $ sf hdl
hSetBuffering hdl NoBuffering
withForeignPtr sfp $ \p -> replace_transport_stable_ptrs p rf' sf'
addRefFinalizer sr (hClose hdl)
bye :: Session t -> CloseRequest -> IO (())
bye a1 a2 =
withSession a1 $ \a1' ->
let {a2' = enumCInt a2} in
bye'_ a1' a2' >>= \res ->
throwGnutlsIf res >>= \res' ->
return (res')
handshake :: Session t -> IO ()
handshake a1 =
withSession a1 $ \a1' ->
handshake'_ a1' >>= \res ->
throwGnutlsIf res >>= \res' ->
return (res')
rehandshake :: Session Server -> IO ()
rehandshake a1 =
withSession a1 $ \a1' ->
rehandshake'_ a1' >>= \res ->
throwGnutlsIf res >>= \res' ->
return (res')
setMaxHandshakePacketLength :: Session t -> Int -> IO ()
setMaxHandshakePacketLength a1 a2 =
withSession a1 $ \a1' ->
let {a2' = fromIntegral a2} in
setMaxHandshakePacketLength'_ a1' a2' >>= \res ->
return ()
clientCert :: WriteAttr (Session Server) CertificateRequest
clientCert = writeAttr p
where p s v = withSession s $ \sp -> gnutls_certificate_server_set_request sp (enumCInt v)
serverWantedAuth :: Session Client -> IO Bool
serverWantedAuth s = withSession s $ \sp -> do
iv <- gnutls_certificate_client_get_request_status sp
throwGnutlsIfNeg iv
return (iv /= 0)
verifyPeer :: Session t -> IO [CertificateStatus]
verifyPeer ses = do
withSession ses $ \sp -> do
alloca $ \stat -> do
gnutls_certificate_verify_peers2 sp stat >>= throwGnutlsIf
ci <- peekEnum stat
return $ filter (\e -> fromEnum e .&. ci /= 0) [CertInvalid, CertRevoked, CertSignerNotFound, CertSignerNotCa]
isResumed :: Session t -> IO (Bool)
isResumed a1 =
withSession a1 $ \a1' ->
isResumed'_ a1' >>= \res ->
let {res' = isNotZero res} in
return (res')
isNotZero :: CInt -> Bool
isNotZero 0 = False
isNotZero _ = True
getAlert :: Session t -> IO (AlertDescription)
getAlert a1 =
withSession a1 $ \a1' ->
getAlert'_ a1' >>= \res ->
let {res' = cintEnum res} in
return (res')
getCipher :: Session t -> IO (CipherAlgorithm)
getCipher a1 =
withSession a1 $ \a1' ->
getCipher'_ a1' >>= \res ->
let {res' = cintEnum res} in
return (res')
getKx :: Session t -> IO (KxAlgorithm)
getKx a1 =
withSession a1 $ \a1' ->
getKx'_ a1' >>= \res ->
let {res' = cintEnum res} in
return (res')
getMac :: Session t -> IO (MacAlgorithm)
getMac a1 =
withSession a1 $ \a1' ->
getMac'_ a1' >>= \res ->
let {res' = cintEnum res} in
return (res')
getCompression :: Session t -> IO (CompressionMethod)
getCompression a1 =
withSession a1 $ \a1' ->
getCompression'_ a1' >>= \res ->
let {res' = cintEnum res} in
return (res')
getCertificateType :: Session t -> IO (CertificateType)
getCertificateType a1 =
withSession a1 $ \a1' ->
getCertificateType'_ a1' >>= \res ->
let {res' = cintEnum res} in
return (res')
getProtocol :: Session t -> IO (Protocol)
getProtocol a1 =
withSession a1 $ \a1' ->
getProtocol'_ a1' >>= \res ->
let {res' = cintEnum res} in
return (res')
getCredentialsType :: Session t -> IO (CredentialsType)
getCredentialsType a1 =
withSession a1 $ \a1' ->
getCredentialsType'_ a1' >>= \res ->
let {res' = cintEnum res} in
return (res')
getServerCredentialsType :: Session t -> IO (CredentialsType)
getServerCredentialsType a1 =
withSession a1 $ \a1' ->
getServerCredentialsType'_ a1' >>= \res ->
let {res' = cintEnum res} in
return (res')
getClientCredentialsType :: Session t -> IO (CredentialsType)
getClientCredentialsType a1 =
withSession a1 $ \a1' ->
getClientCredentialsType'_ a1' >>= \res ->
let {res' = cintEnum res} in
return (res')
getPeersCertificatesRaw :: Session t -> IO [(Ptr CChar,Int)]
getPeersCertificatesRaw ses = do
withSession ses $ \sp ->
alloca $ \lenp -> do
res <- gnutls_certificate_get_peers sp lenp
if res == nullPtr
then return []
else do len <- peek lenp
peekDatumArray (fromIntegral len 1) res
tlsSend :: Session t -> Ptr a -> Int -> IO (Int)
tlsSend a1 a2 a3 =
withSession a1 $ \a1' ->
let {a2' = castPtr a2} in
let {a3' = fromIntegral a3} in
tlsSend'_ a1' a2' a3' >>= \res ->
throwGnutlsIfNeg res >>= \res' ->
return (res')
tlsSendString :: Session t -> String -> IO ()
tlsSendString ses str = withCStringLen str $ \(ptr,len) -> loop ptr len
where loop ptr len = do r <- tlsSend ses ptr len
case lenr of
x | x > 0 -> loop (plusPtr ptr r) x
| True -> return ()
tlsCheckPending :: Session t -> IO (Int)
tlsCheckPending a1 =
withSession a1 $ \a1' ->
tlsCheckPending'_ a1' >>= \res ->
let {res' = fromIntegral res} in
return (res')
tlsRecv :: Session t -> Ptr a -> Int -> IO (Int)
tlsRecv a1 a2 a3 =
withSession a1 $ \a1' ->
let {a2' = castPtr a2} in
let {a3' = fromIntegral a3} in
tlsRecv'_ a1' a2' a3' >>= \res ->
throwGnutlsIfNeg res >>= \res' ->
return (res')
tlsRecvString :: Session t -> IO String
tlsRecvString ses = allocaBytes 1024 $ \ptr -> do
r <- tlsRecv ses ptr 1024
peekCAStringLen (ptr,r)
anonymousServerCredentials :: IO AnonymousServerCredentials
anonymousServerCredentials = alloca $ \ptr -> do
gnutls_anon_allocate_server_credentials ptr >>= throwGnutlsIf
raw<- peek ptr
rc <- newRefCount $ gnutls_anon_free_server_credentials raw
fp <- FC.newForeignPtr raw $ freeRef rc
return $ ASC fp rc
foreign import ccall safe "TLS.h gnutls_anon_free_server_credentials"
gnutls_anon_free_server_credentials :: Ptr () -> IO ()
foreign import ccall safe "TLS.h gnutls_anon_allocate_server_credentials"
gnutls_anon_allocate_server_credentials :: Ptr (Ptr ()) -> IO CInt
class SetDHParams a where setDHParams :: a -> DH -> IO ()
instance SetDHParams AnonymousServerCredentials where
setDHParams asc@(ASC _ rc) dh@(DH _ refc) =
do gnutls_anon_set_server_dh_params asc dh
allocRef refc
addRefFinalizer rc $ freeRef refc
gnutls_anon_set_server_dh_params :: AnonymousServerCredentials -> DH -> IO ()
gnutls_anon_set_server_dh_params a1 a2 =
withAnonymousServerCredentials a1 $ \a1' ->
withDH a2 $ \a2' ->
gnutls_anon_set_server_dh_params'_ a1' a2' >>= \res ->
return ()
anonymousClientCredentials :: IO AnonymousClientCredentials
anonymousClientCredentials = alloca $ \ptr -> do
gnutls_anon_allocate_client_credentials ptr >>= throwGnutlsIf
raw<- peek ptr
rc <- newRefCount $ gnutls_anon_free_client_credentials raw
fp <- FC.newForeignPtr raw $ freeRef rc
return $ ACC fp rc
foreign import ccall safe "TLS.h gnutls_anon_free_client_credentials"
gnutls_anon_free_client_credentials :: Ptr () -> IO ()
foreign import ccall safe "TLS.h gnutls_anon_allocate_client_credentials"
gnutls_anon_allocate_client_credentials :: Ptr (Ptr ()) -> IO CInt
certificateCredentials :: IO CertificateCredentials
certificateCredentials = alloca $ \ptr -> do
gnutls_certificate_allocate_credentials ptr >>= throwGnutlsIf
raw<- peek ptr
rc <- newRefCount $ gnutls_certificate_free_credentials raw
fp <- FC.newForeignPtr raw $ freeRef rc
return $ CC fp rc
foreign import ccall safe "TLS.h gnutls_certificate_free_credentials"
gnutls_certificate_free_credentials :: Ptr () -> IO ()
foreign import ccall safe "TLS.h gnutls_certificate_allocate_credentials"
gnutls_certificate_allocate_credentials :: Ptr (Ptr ()) -> IO CInt
freeKeys :: CertificateCredentials -> IO ()
freeKeys a1 =
withCertificateCredentials a1 $ \a1' ->
freeKeys'_ a1' >>= \res ->
return ()
freeCas :: CertificateCredentials -> IO ()
freeCas a1 =
withCertificateCredentials a1 $ \a1' ->
freeCas'_ a1' >>= \res ->
return ()
freeCaNames :: CertificateCredentials -> IO ()
freeCaNames a1 =
withCertificateCredentials a1 $ \a1' ->
freeCaNames'_ a1' >>= \res ->
return ()
freeCrls :: CertificateCredentials -> IO ()
freeCrls a1 =
withCertificateCredentials a1 $ \a1' ->
freeCrls'_ a1' >>= \res ->
return ()
instance SetDHParams CertificateCredentials where
setDHParams cc@(CC _ rc) dh@(DH _ refc) =
do gnutls_certificate_set_dh_params cc dh
allocRef refc
addRefFinalizer rc $ freeRef refc
gnutls_certificate_set_dh_params :: CertificateCredentials -> DH -> IO ()
gnutls_certificate_set_dh_params a1 a2 =
withCertificateCredentials a1 $ \a1' ->
withDH a2 $ \a2' ->
gnutls_certificate_set_dh_params'_ a1' a2' >>= \res ->
return ()
certificateTrustFile :: CertificateCredentials -> FilePath -> X509CertificateFormat -> IO (Int)
certificateTrustFile a1 a2 a3 =
withCertificateCredentials a1 $ \a1' ->
withCAString a2 $ \a2' ->
let {a3' = enumCInt a3} in
certificateTrustFile'_ a1' a2' a3' >>= \res ->
throwGnutlsIfNeg res >>= \res' ->
return (res')
certificateCrlFile :: CertificateCredentials -> FilePath -> X509CertificateFormat -> IO (Int)
certificateCrlFile a1 a2 a3 =
withCertificateCredentials a1 $ \a1' ->
withCAString a2 $ \a2' ->
let {a3' = enumCInt a3} in
certificateCrlFile'_ a1' a2' a3' >>= \res ->
throwGnutlsIfNeg res >>= \res' ->
return (res')
certificateKeyFile :: CertificateCredentials -> FilePath -> FilePath -> X509CertificateFormat -> IO (Int)
certificateKeyFile a1 a2 a3 a4 =
withCertificateCredentials a1 $ \a1' ->
withCAString a2 $ \a2' ->
withCAString a3 $ \a3' ->
let {a4' = enumCInt a4} in
certificateKeyFile'_ a1' a2' a3' a4' >>= \res ->
throwGnutlsIfNeg res >>= \res' ->
return (res')
class CredParameter a where
generate :: a -> Int -> IO ()
newDH :: IO DH
newDH = alloca $ \ptr -> do
gnutls_dh_params_init ptr >>= throwGnutlsIf
raw<- peek ptr
rc <- newRefCount (gnutls_dh_params_deinit raw)
fp <- FC.newForeignPtr raw (freeRef rc)
return $ DH fp rc
foreign import ccall safe "TLS.h gnutls_dh_params_deinit" gnutls_dh_params_deinit :: Ptr () -> IO ()
foreign import ccall safe "TLS.h gnutls_dh_params_init" gnutls_dh_params_init :: Ptr (Ptr ()) -> IO CInt
instance CredParameter DH where
generate a i = withDH a (\ap -> gnutls_dh_params_generate2 ap (fromIntegral i) >>= throwGnutlsIf)
newRSA :: IO RSA
newRSA = alloca $ \ptr -> do
gnutls_rsa_params_init ptr >>= throwGnutlsIf
raw<- peek ptr
rc <- newRefCount (gnutls_rsa_params_deinit raw)
fp <- FC.newForeignPtr raw (freeRef rc)
return $ RSA fp rc
foreign import ccall safe "TLS.h gnutls_rsa_params_deinit" gnutls_rsa_params_deinit :: Ptr () -> IO ()
foreign import ccall safe "TLS.h gnutls_rsa_params_init" gnutls_rsa_params_init :: Ptr (Ptr ()) -> IO CInt
instance CredParameter RSA where
generate a i = withRSA a (\ap -> gnutls_rsa_params_generate2 ap (fromIntegral i) >>= throwGnutlsIf)
cipherKeySize :: CipherAlgorithm -> Int
cipherKeySize a1 =
let {a1' = enumCInt a1} in
let {res = cipherKeySize'_ a1'} in
let {res' = fromIntegral res} in
(res')
cipherSuiteName :: KxAlgorithm -> CipherAlgorithm -> MacAlgorithm -> String
cipherSuiteName a1 a2 a3 =
unsafePerformIO $
let {a1' = enumCInt a1} in
let {a2' = enumCInt a2} in
let {a3' = enumCInt a3} in
let {res = cipherSuiteName'_ a1' a2' a3'} in
safePeekCString res >>= \res' ->
return (res')
version = unsafePerformIO $ gnutls_check_version nullPtr >>= safePeekCString
gnutlsGlobalInitIORef = unsafePerformIO $ do
gcry_init_helper
gnutls_global_init >>= throwGnutlsIf
newIORef ()
gnutlsGlobalInit = readIORef gnutlsGlobalInitIORef
foreign import ccall unsafe "gcry_init_helper" gcry_init_helper :: IO ()
foreign import ccall unsafe "Network/GnuTLS/GnuTLS.chs.h gnutls_alert_get_name"
gnutlsAlertGetName'_ :: (CInt -> (IO (Ptr CChar)))
foreign import ccall unsafe "Network/GnuTLS/GnuTLS.chs.h gnutls_cipher_get_name"
gnutlsCipherGetName'_ :: (CInt -> (IO (Ptr CChar)))
foreign import ccall unsafe "Network/GnuTLS/GnuTLS.chs.h gnutls_mac_get_name"
gnutlsMacGetName'_ :: (CInt -> (IO (Ptr CChar)))
foreign import ccall unsafe "Network/GnuTLS/GnuTLS.chs.h gnutls_compression_get_name"
gnutlsCompressionGetName'_ :: (CInt -> (IO (Ptr CChar)))
foreign import ccall unsafe "Network/GnuTLS/GnuTLS.chs.h gnutls_kx_get_name"
gnutlsKxGetName'_ :: (CInt -> (IO (Ptr CChar)))
foreign import ccall unsafe "Network/GnuTLS/GnuTLS.chs.h gnutls_certificate_type_get_name"
gnutlsCertificateTypeGetName'_ :: (CInt -> (IO (Ptr CChar)))
foreign import ccall unsafe "Network/GnuTLS/GnuTLS.chs.h gnutls_protocol_get_name"
gnutlsProtocolGetName'_ :: (CInt -> (IO (Ptr CChar)))
foreign import ccall unsafe "Network/GnuTLS/GnuTLS.chs.h gnutls_pk_algorithm_get_name"
gnutlsPkAlgorithmGetName'_ :: (CInt -> (IO (Ptr CChar)))
foreign import ccall unsafe "Network/GnuTLS/GnuTLS.chs.h gnutls_sign_algorithm_get_name"
gnutlsSignAlgorithmGetName'_ :: (CInt -> (IO (Ptr CChar)))
foreign import ccall unsafe "Network/GnuTLS/GnuTLS.chs.h gnutls_cipher_set_priority"
gnutls_cipher_set_priority :: ((Ptr ()) -> ((Ptr CInt) -> (IO CInt)))
foreign import ccall unsafe "Network/GnuTLS/GnuTLS.chs.h gnutls_mac_set_priority"
gnutls_mac_set_priority :: ((Ptr ()) -> ((Ptr CInt) -> (IO CInt)))
foreign import ccall unsafe "Network/GnuTLS/GnuTLS.chs.h gnutls_compression_set_priority"
gnutls_compression_set_priority :: ((Ptr ()) -> ((Ptr CInt) -> (IO CInt)))
foreign import ccall unsafe "Network/GnuTLS/GnuTLS.chs.h gnutls_kx_set_priority"
gnutls_kx_set_priority :: ((Ptr ()) -> ((Ptr CInt) -> (IO CInt)))
foreign import ccall unsafe "Network/GnuTLS/GnuTLS.chs.h gnutls_protocol_set_priority"
gnutls_protocol_set_priority :: ((Ptr ()) -> ((Ptr CInt) -> (IO CInt)))
foreign import ccall unsafe "Network/GnuTLS/GnuTLS.chs.h gnutls_certificate_type_set_priority"
gnutls_certificate_type_set_priority :: ((Ptr ()) -> ((Ptr CInt) -> (IO CInt)))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_set_default_priority"
setDefaultPriority'_ :: ((Ptr ()) -> (IO CInt))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_set_default_export_priority"
setDefaultExportPriority'_ :: ((Ptr ()) -> (IO CInt))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_credentials_set"
gnutls_credentials_set :: ((Ptr ()) -> (CInt -> ((Ptr ()) -> (IO CInt))))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_credentials_clear"
gnutls_credentials_clear :: ((Ptr ()) -> (IO ()))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_dh_get_prime_bits"
gnutls_dh_get_prime_bits :: ((Ptr ()) -> (IO CInt))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_dh_set_prime_bits"
gnutls_dh_set_prime_bits :: ((Ptr ()) -> (CUInt -> (IO ())))
foreign import ccall unsafe "Network/GnuTLS/GnuTLS.chs.h gnutls_transport_get_ptr2"
gnutls_transport_get_ptr2'_ :: ((Ptr ()) -> ((Ptr (Ptr ())) -> ((Ptr (Ptr ())) -> (IO ()))))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_bye"
bye'_ :: ((Ptr ()) -> (CInt -> (IO CInt)))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_handshake"
handshake'_ :: ((Ptr ()) -> (IO CInt))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_rehandshake"
rehandshake'_ :: ((Ptr ()) -> (IO CInt))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_handshake_set_max_packet_length"
setMaxHandshakePacketLength'_ :: ((Ptr ()) -> (CUInt -> (IO ())))
foreign import ccall unsafe "Network/GnuTLS/GnuTLS.chs.h gnutls_certificate_server_set_request"
gnutls_certificate_server_set_request :: ((Ptr ()) -> (CInt -> (IO ())))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_certificate_client_get_request_status"
gnutls_certificate_client_get_request_status :: ((Ptr ()) -> (IO CInt))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_certificate_verify_peers2"
gnutls_certificate_verify_peers2 :: ((Ptr ()) -> ((Ptr CUInt) -> (IO CInt)))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_session_is_resumed"
isResumed'_ :: ((Ptr ()) -> (IO CInt))
foreign import ccall unsafe "Network/GnuTLS/GnuTLS.chs.h gnutls_alert_get"
getAlert'_ :: ((Ptr ()) -> (IO CInt))
foreign import ccall unsafe "Network/GnuTLS/GnuTLS.chs.h gnutls_cipher_get"
getCipher'_ :: ((Ptr ()) -> (IO CInt))
foreign import ccall unsafe "Network/GnuTLS/GnuTLS.chs.h gnutls_kx_get"
getKx'_ :: ((Ptr ()) -> (IO CInt))
foreign import ccall unsafe "Network/GnuTLS/GnuTLS.chs.h gnutls_mac_get"
getMac'_ :: ((Ptr ()) -> (IO CInt))
foreign import ccall unsafe "Network/GnuTLS/GnuTLS.chs.h gnutls_compression_get"
getCompression'_ :: ((Ptr ()) -> (IO CInt))
foreign import ccall unsafe "Network/GnuTLS/GnuTLS.chs.h gnutls_certificate_type_get"
getCertificateType'_ :: ((Ptr ()) -> (IO CInt))
foreign import ccall unsafe "Network/GnuTLS/GnuTLS.chs.h gnutls_protocol_get_version"
getProtocol'_ :: ((Ptr ()) -> (IO CInt))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_auth_get_type"
getCredentialsType'_ :: ((Ptr ()) -> (IO CInt))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_auth_server_get_type"
getServerCredentialsType'_ :: ((Ptr ()) -> (IO CInt))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_auth_client_get_type"
getClientCredentialsType'_ :: ((Ptr ()) -> (IO CInt))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_certificate_get_peers"
gnutls_certificate_get_peers :: ((Ptr ()) -> ((Ptr CUInt) -> (IO (Ptr ()))))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_record_send"
tlsSend'_ :: ((Ptr ()) -> ((Ptr ()) -> (CUInt -> (IO CInt))))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_record_check_pending"
tlsCheckPending'_ :: ((Ptr ()) -> (IO CUInt))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_record_recv"
tlsRecv'_ :: ((Ptr ()) -> ((Ptr ()) -> (CUInt -> (IO CInt))))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_anon_set_server_dh_params"
gnutls_anon_set_server_dh_params'_ :: ((Ptr ()) -> ((Ptr ()) -> (IO ())))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_certificate_free_keys"
freeKeys'_ :: ((Ptr ()) -> (IO ()))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_certificate_free_cas"
freeCas'_ :: ((Ptr ()) -> (IO ()))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_certificate_free_ca_names"
freeCaNames'_ :: ((Ptr ()) -> (IO ()))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_certificate_free_crls"
freeCrls'_ :: ((Ptr ()) -> (IO ()))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_certificate_set_dh_params"
gnutls_certificate_set_dh_params'_ :: ((Ptr ()) -> ((Ptr ()) -> (IO ())))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_certificate_set_x509_trust_file"
certificateTrustFile'_ :: ((Ptr ()) -> ((Ptr CChar) -> (CInt -> (IO CInt))))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_certificate_set_x509_crl_file"
certificateCrlFile'_ :: ((Ptr ()) -> ((Ptr CChar) -> (CInt -> (IO CInt))))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_certificate_set_x509_key_file"
certificateKeyFile'_ :: ((Ptr ()) -> ((Ptr CChar) -> ((Ptr CChar) -> (CInt -> (IO CInt)))))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_dh_params_generate2"
gnutls_dh_params_generate2 :: ((Ptr ()) -> (CUInt -> (IO CInt)))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_rsa_params_generate2"
gnutls_rsa_params_generate2 :: ((Ptr ()) -> (CUInt -> (IO CInt)))
foreign import ccall unsafe "Network/GnuTLS/GnuTLS.chs.h gnutls_cipher_get_key_size"
cipherKeySize'_ :: (CInt -> CUInt)
foreign import ccall unsafe "Network/GnuTLS/GnuTLS.chs.h gnutls_cipher_suite_get_name"
cipherSuiteName'_ :: (CInt -> (CInt -> (CInt -> (Ptr CChar))))
foreign import ccall safe "Network/GnuTLS/GnuTLS.chs.h gnutls_check_version"
gnutls_check_version :: ((Ptr CChar) -> (IO (Ptr CChar)))
foreign import ccall unsafe "Network/GnuTLS/GnuTLS.chs.h gnutls_global_init"
gnutls_global_init :: (IO CInt)