Browse Source

minor formatting and documentation additions

master
Jon Kristensen 14 years ago
parent
commit
48c60f8e9b
  1. 26
      src/Network/XMPP/TLS.hs

26
src/Network/XMPP/TLS.hs

@ -18,12 +18,11 @@ import Network.XMPP.Stream
import Network.XMPP.Types import Network.XMPP.Types
starttlsE :: Element starttlsE :: Element
starttlsE = starttlsE = Element "{urn:ietf:params:xml:ns:xmpp-tls}starttls" [] []
Element "{urn:ietf:params:xml:ns:xmpp-tls}starttls" [] []
exampleParams :: TLS.TLSParams exampleParams :: TLS.TLSParams
exampleParams = TLS.defaultParams exampleParams = TLS.defaultParams
{pConnectVersion = TLS.TLS10 { pConnectVersion = TLS.TLS10
, pAllowedVersions = [TLS.SSL3, TLS.TLS10, TLS.TLS11] , pAllowedVersions = [TLS.SSL3, TLS.TLS10, TLS.TLS11]
, pCiphers = [TLS.cipher_AES128_SHA1] , pCiphers = [TLS.cipher_AES128_SHA1]
, pCompressions = [TLS.nullCompression] , pCompressions = [TLS.nullCompression]
@ -31,7 +30,7 @@ exampleParams = TLS.defaultParams
, pUseSecureRenegotiation = False -- No renegotiation , pUseSecureRenegotiation = False -- No renegotiation
, pCertificates = [] -- TODO , pCertificates = [] -- TODO
, pLogging = TLS.defaultLogging -- TODO , pLogging = TLS.defaultLogging -- TODO
, onCertificatesRecv = \ _certificate -> , onCertificatesRecv = \_certificate ->
return TLS.CertificateUsageAccept return TLS.CertificateUsageAccept
} }
@ -40,14 +39,16 @@ data XMPPTLSError = TLSError TLSError
| TLSNoServerSupport | TLSNoServerSupport
| TLSNoConnection | TLSNoConnection
| TLSStreamError StreamError | TLSStreamError StreamError
| XMPPTLSError -- General instance used for the Error instance
deriving (Show, Eq, Typeable) deriving (Show, Eq, Typeable)
instance Error XMPPTLSError where instance Error XMPPTLSError where
noMsg = TLSNoConnection -- TODO: What should we choose here? noMsg = XMPPTLSError
-- Pushes "<starttls/>, waits for "<proceed/>", performs the TLS handshake, and
-- restarts the stream. May throw errors.
startTLS :: TLS.TLSParams -> XMPPConMonad (Either XMPPTLSError ()) startTLS :: TLS.TLSParams -> XMPPConMonad (Either XMPPTLSError ())
startTLS params = Ex.handle (return . Left . TLSError) startTLS params = Ex.handle (return . Left . TLSError) . runErrorT $ do
. runErrorT $ do
features <- lift $ gets sFeatures features <- lift $ gets sFeatures
handle' <- lift $ gets sConHandle handle' <- lift $ gets sConHandle
handle <- maybe (throwError TLSNoConnection) return handle' handle <- maybe (throwError TLSNoConnection) return handle'
@ -56,13 +57,13 @@ startTLS params = Ex.handle (return . Left . TLSError)
answer <- lift $ pullElement answer <- lift $ pullElement
case answer of case answer of
Element "{urn:ietf:params:xml:ns:xmpp-tls}proceed" [] [] -> return () Element "{urn:ietf:params:xml:ns:xmpp-tls}proceed" [] [] -> return ()
Element "{urn:ietf:params:xml:ns:xmpp-tls}failure" _ _ Element "{urn:ietf:params:xml:ns:xmpp-tls}failure" _ _ ->
-> lift . Ex.throwIO $ StreamConnectionError lift . Ex.throwIO $ StreamConnectionError
-- TODO: find something more suitable -- TODO: find something more suitable
e -> lift . Ex.throwIO . StreamXMLError e -> lift . Ex.throwIO . StreamXMLError $
$ "Unexpected element: " ++ ppElement e "Unexpected element: " ++ ppElement e
(raw, _snk, psh, ctx) <- lift $ TLS.tlsinit params handle (raw, _snk, psh, ctx) <- lift $ TLS.tlsinit params handle
lift $ modify (\x -> x lift $ modify ( \x -> x
{ sRawSrc = raw { sRawSrc = raw
-- , sConSrc = -- Note: this momentarily leaves us in an -- , sConSrc = -- Note: this momentarily leaves us in an
-- inconsistent state -- inconsistent state
@ -72,4 +73,3 @@ startTLS params = Ex.handle (return . Left . TLSError)
either (lift . Ex.throwIO) return =<< lift xmppRestartStream either (lift . Ex.throwIO) return =<< lift xmppRestartStream
modify (\s -> s{sConnectionState = XmppConnectionSecured}) modify (\s -> s{sConnectionState = XmppConnectionSecured})
return () return ()

Loading…
Cancel
Save