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. 30
      source/Network/Xmpp.hs
  2. 6
      source/Network/Xmpp/Sasl/Mechanisms/DigestMd5.hs

30
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 with the given username and password
-- and bind a resource -- | Authenticate to the server using the first matching method and bind a
auth :: Text.Text -- ^ The username -- resource.
-> Text.Text -- ^ The password auth :: [SaslHandler]
-> Maybe Text -- ^ The desired resource or 'Nothing' to let the server -> Maybe Text
-- assign one
-> XmppConMonad (Either AuthError Jid) -> XmppConMonad (Either AuthError Jid)
auth username passwd resource = runErrorT $ do auth mechanisms resource = runErrorT $ do
ErrorT $ xmppSasl [scramSha1 username Nothing passwd] ErrorT $ xmppSasl mechanisms
jid <- lift $ xmppBind resource jid <- lift $ xmppBind resource
lift $ xmppStartSession lift $ xmppStartSession
return jid return jid
-- | Authenticate to the server with the given username and password
-- and bind a resource.
--
-- Prefers SCRAM-SHA1 over DIGEST-MD5.
simpleAuth :: Text.Text -- ^ The username
-> Text.Text -- ^ The password
-> Maybe Text -- ^ The desired resource or 'Nothing' to let the
-- server assign one
-> XmppConMonad (Either AuthError Jid)
simpleAuth username passwd resource = flip auth resource $
[ -- TODO: scramSha1Plus
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