Skip to content

Instantly share code, notes, and snippets.

@stevenleeg
Last active February 17, 2019 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevenleeg/ab23fa17d5479673b04e27cdf41e74db to your computer and use it in GitHub Desktop.
Save stevenleeg/ab23fa17d5479673b04e27cdf41e74db to your computer and use it in GitHub Desktop.
Standard Notes authentication in ruby
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