Browse Source

split auth in auth (takes mechanism list) and simpleAuth (defaults to Scram and DigestMd5)

swap authzic and authcid parameters in DigestMd5
master
Philipp Balzarek 14 years ago
parent
commit
684646e3db
  1. 36
      source/Network/Xmpp.hs
  2. 6
      source/Network/Xmpp/Sasl/Mechanisms/DigestMd5.hs

36
source/Network/Xmpp.hs

@ -170,15 +170,29 @@ import Control.Monad.Error
connect :: HostName -> Text -> XmppConMonad (Either StreamError ()) connect :: HostName -> Text -> XmppConMonad (Either StreamError ())
connect address hostname = xmppRawConnect address hostname >> xmppStartStream connect address hostname = xmppRawConnect address hostname >> xmppStartStream
-- | Authenticate to the server using the first matching method and bind a
-- resource.
auth :: [SaslHandler]
-> Maybe Text
-> XmppConMonad (Either AuthError Jid)
auth mechanisms resource = runErrorT $ do
ErrorT $ xmppSasl mechanisms
jid <- lift $ xmppBind resource
lift $ xmppStartSession
return jid
-- | Authenticate to the server with the given username and password -- | Authenticate to the server with the given username and password
-- and bind a resource -- and bind a resource.
auth :: Text.Text -- ^ The username --
-> Text.Text -- ^ The password -- Prefers SCRAM-SHA1 over DIGEST-MD5.
-> Maybe Text -- ^ The desired resource or 'Nothing' to let the server simpleAuth :: Text.Text -- ^ The username
-- assign one -> Text.Text -- ^ The password
-> XmppConMonad (Either AuthError Jid) -> Maybe Text -- ^ The desired resource or 'Nothing' to let the
auth username passwd resource = runErrorT $ do -- server assign one
ErrorT $ xmppSasl [scramSha1 username Nothing passwd] -> XmppConMonad (Either AuthError Jid)
jid <- lift $ xmppBind resource simpleAuth username passwd resource = flip auth resource $
lift $ xmppStartSession [ -- TODO: scramSha1Plus
return jid scramSha1 username Nothing passwd
, digestMd5 username Nothing passwd
]

6
source/Network/Xmpp/Sasl/Mechanisms/DigestMd5.hs

@ -128,10 +128,10 @@ xmppDigestMd5 authcid authzid password = do
ha2 = hash ["AUTHENTICATE", digestURI] ha2 = hash ["AUTHENTICATE", digestURI]
in hash [ha1, nonce, nc, cnonce, qop, ha2] in hash [ha1, nonce, nc, cnonce, qop, ha2]
digestMd5 :: Maybe Text -- Authorization identity (authzid) digestMd5 :: Text -- Authorization identity (authzid)
-> Text -- Authentication identity (authzid) -> Maybe Text -- Authentication identity (authzid)
-> Text -- Password (authzid) -> Text -- Password (authzid)
-> SaslHandler -> SaslHandler
digestMd5 authzid authcid password = ( "DIGEST-MD5" digestMd5 authcid authzid password = ( "DIGEST-MD5"
, xmppDigestMd5 authcid authzid password , xmppDigestMd5 authcid authzid password
) )
Loading…
Cancel
Save