Last active
February 17, 2019 18:29
-
-
Save stevenleeg/ab23fa17d5479673b04e27cdf41e74db to your computer and use it in GitHub Desktop.
Standard Notes authentication in ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
resp = HTTP.use(:auto_inflate).get("#{BASE_URL}/auth/params?email=#{EMAIL}") | |
auth_params = JSON.parse(resp.body.to_s) | |
salt = Digest::SHA256.hexdigest([ | |
EMAIL, | |
"SF", | |
auth_params["version"], | |
auth_params["pw_cost"], | |
auth_params["pw_nonce"], | |
].join(":")) | |
pbk = PBKDF2.new( | |
password: PASSWORD, | |
salt: salt, | |
iterations: auth_params["pw_cost"], | |
hash_function: OpenSSL::Digest::SHA512, | |
key_length: 768, | |
) | |
credentials = pbk.hex_string | |
split_length = credentials.length / 3 | |
puts split_length | |
pw = credentials[0...split_length] | |
mk = credentials[split_length...split_length*2] | |
ak = credentials[split_length*2...split_length*3] | |
params = {email: EMAIL, password: pw} | |
resp = HTTP.use(:auto_inflate) | |
.post("#{BASE_URL}/auth/sign_in", params: params) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment