Skip to content

Instantly share code, notes, and snippets.

@adamldoyle
Created March 18, 2014 00:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save adamldoyle/9611324 to your computer and use it in GitHub Desktop.
Save adamldoyle/9611324 to your computer and use it in GitHub Desktop.
import base64
import binascii
import hashlib
import hmac
import requests
import scrypt
def hex2bin(hex):
return bin(int(hex, 16))[2:]
logN = 15
r = 8
p = 1
name = 'name'
password = 'password'
salt_response = requests.get('https://keybase.io/_/api/1.0/getsalt.json', params={'email_or_username': name}).json()
salt = salt_response['salt']
csrf_token = salt_response['csrf_token']
login_session = salt_response['login_session']
pwh = scrypt.hash(password, hex2bin(salt), 1 << logN, r, p, 128)[96:128]
hmac_pwh = hmac.new(pwh, base64.b64decode(login_session), hashlib.sha512).hexdigest()
login_response = requests.post('https://keybase.io/_/api/1.0/login.json', params={'email_or_username': name, 'csrf_token': csrf_token, 'hmac_pwh': hmac_pwh, 'login_session': login_session})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment