Move parsing username, password and algorithm to the only place that uses it and
add comments (sasl.scram)
This commit is contained in:
parent
bffd43648d
commit
efbbe4c3db
1 changed files with 10 additions and 2 deletions
|
@ -64,19 +64,26 @@ class Module(ModuleManager.BaseModule):
|
||||||
auth_text = "+"
|
auth_text = "+"
|
||||||
|
|
||||||
elif mechanism.startswith("SCRAM-"):
|
elif mechanism.startswith("SCRAM-"):
|
||||||
algo = mechanism.split("SCRAM-", 1)[1].replace("-", "")
|
|
||||||
sasl_username, sasl_password = sasl["args"].split(":", 1)
|
|
||||||
if event["message"] == "+":
|
if event["message"] == "+":
|
||||||
# start SCRAM handshake
|
# start SCRAM handshake
|
||||||
|
|
||||||
|
# create SCRAM helper
|
||||||
|
sasl_username, sasl_password = sasl["args"].split(":", 1)
|
||||||
|
algo = mechanism.split("SCRAM-", 1)[1].replace("-", "")
|
||||||
event["server"]._scram = scram.SCRAM(
|
event["server"]._scram = scram.SCRAM(
|
||||||
algo, sasl_username, sasl_password)
|
algo, sasl_username, sasl_password)
|
||||||
|
|
||||||
|
# generate client-first-message
|
||||||
auth_text = event["server"]._scram.client_first()
|
auth_text = event["server"]._scram.client_first()
|
||||||
else:
|
else:
|
||||||
current_scram = event["server"]._scram
|
current_scram = event["server"]._scram
|
||||||
data = base64.b64decode(event["message"])
|
data = base64.b64decode(event["message"])
|
||||||
if current_scram.state == scram.SCRAMState.ClientFirst:
|
if current_scram.state == scram.SCRAMState.ClientFirst:
|
||||||
|
# use server-first-message to generate client-final-message
|
||||||
auth_text = current_scram.server_first(data)
|
auth_text = current_scram.server_first(data)
|
||||||
elif current_scram.state == scram.SCRAMState.ClientFinal:
|
elif current_scram.state == scram.SCRAMState.ClientFinal:
|
||||||
|
# use server-final-message to check server proof
|
||||||
verified = current_scram.server_final(data)
|
verified = current_scram.server_final(data)
|
||||||
del event["server"]._scram
|
del event["server"]._scram
|
||||||
|
|
||||||
|
@ -84,6 +91,7 @@ class Module(ModuleManager.BaseModule):
|
||||||
auth_text = "+"
|
auth_text = "+"
|
||||||
else:
|
else:
|
||||||
if current_scram.state == scram.SCRAMState.VerifyFailed:
|
if current_scram.state == scram.SCRAMState.VerifyFailed:
|
||||||
|
# server gave a bad verification so we should panic
|
||||||
event["server"].disconnect()
|
event["server"].disconnect()
|
||||||
raise ValueError("Server SCRAM verification failed")
|
raise ValueError("Server SCRAM verification failed")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue