keybase / keybase/keybase-issues

Login from javascript using crypto_scrypt and CryptoJS not working

Open
#1,500 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
899
Forks
40
PR merge metrics
No merged PRs in 30d

Description

The following code is my best shot at implementing a logon to keybase from javascript. I have proxied the calls via php as CORS is not enabled for the getsalt or the login calls.

The login call returns code 202 - failed to purpack.unpack

The trickiest part seems to be using CryptoJS to do the Hmac - which expects word arrays. This means converting the base64 encoded login_session to a word array and also converting the last 32 bytes of the pwh - which is a uint8array to a word array.

Has anyone got this working?

```
$.ajax({
data:{requrl:'https://keybase.io/_/api/1.0/getsalt.json?'+queryString+'&csrf_token='+xsrf},
url:"php/proxy.php",
async:false,
dataType:"json",
success:function(data) {
document.dataCache['salt'] = data;
$('#salt').html(data.salt);

var secretpassphrase="blahblahblah";

var scrypt = scrypt_module_factory(67108864);
var pwh=scrypt.crypto_scrypt(scrypt.encode_utf8(secretpassphrase),
scrypt.encode_utf8(data.salt),
Math.pow(2,15), 8, 1, 224);

var pwh_short=new Uint8Array(32);
var j=0;
for (var i=192;i<224;i++){
pwh_short[j]=pwh[i];
j++;
}

var hmac_pwh = CryptoJS.HmacSHA256(CryptoJS.enc.Base64.parse(data.login_session),CryptoJS.enc.u8array.parse(pwh_short));

var login_data = {
url:'https://keybase.io/_/api/1.0/login.json',
email_or_username: document.dataCache.data.them.basics.username,
hmac_pwh:CryptoJS.enc.Hex.stringify(hmac_pwh),
login_session:data.login_session
}

$.ajax({
data:login_data,
url:"php/proxy_post.php",
async:false,
dataType:"json",
success:function(data) {
document.dataCache['login_result']=data;
}
});

},
error:function(xhr, ajaxOptions, thrownError) {
//alert(xhr.statusText);
}
});
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Begin with the JavaScript flow in the issue and the mentioned php/proxy.php and php/proxy_post.php calls; reproduce the getsalt and login requests against the listed Keybase endpoints. Check the CryptoJS HMAC inputs and the returned “failed to purpack.unpack” response. Done means the login request completes without that error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, php
Domain
api, authentication
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.