util/sasl/scram.lua

changeset 407
c99db5172309
parent 390
7f535a1d5827
child 453
e60c776b7760
equal deleted inserted replaced
406:3c732f1d990c 407:c99db5172309
64 64
65 local cbind_input = gs2_header .. cbind_data; 65 local cbind_input = gs2_header .. cbind_data;
66 local channel_binding = "c=" .. base64(cbind_input); 66 local channel_binding = "c=" .. base64(cbind_input);
67 local client_final_message_without_proof = channel_binding .. "," .. nonce; 67 local client_final_message_without_proof = channel_binding .. "," .. nonce;
68 68
69 local SaltedPassword = Hi(Normalize(stream.password), salt, i); 69 local SaltedPassword;
70 local ClientKey = HMAC(SaltedPassword, "Client Key"); 70 local ClientKey;
71 local ServerKey;
72
73 if stream.client_key and stream.server_key then
74 ClientKey = stream.client_key;
75 ServerKey = stream.server_key;
76 else
77 if stream.salted_password then
78 SaltedPassword = stream.salted_password;
79 elseif stream.password then
80 SaltedPassword = Hi(Normalize(stream.password), salt, i);
81 end
82 ServerKey = HMAC(SaltedPassword, "Server Key");
83 ClientKey = HMAC(SaltedPassword, "Client Key");
84 end
85
71 local StoredKey = H(ClientKey); 86 local StoredKey = H(ClientKey);
72 local AuthMessage = client_first_message_bare .. "," .. server_first_message .. "," .. client_final_message_without_proof; 87 local AuthMessage = client_first_message_bare .. "," .. server_first_message .. "," .. client_final_message_without_proof;
73 local ClientSignature = HMAC(StoredKey, AuthMessage); 88 local ClientSignature = HMAC(StoredKey, AuthMessage);
74 local ClientProof = XOR(ClientKey, ClientSignature); 89 local ClientProof = XOR(ClientKey, ClientSignature);
75 local ServerKey = HMAC(SaltedPassword, "Server Key");
76 local ServerSignature = HMAC(ServerKey, AuthMessage); 90 local ServerSignature = HMAC(ServerKey, AuthMessage);
77 91
78 local proof = "p=" .. base64(ClientProof); 92 local proof = "p=" .. base64(ClientProof);
79 local client_final_message = client_final_message_without_proof .. "," .. proof; 93 local client_final_message = client_final_message_without_proof .. "," .. proof;
80 94

mercurial