UNPKG

@sexycoders/libauth.js

Version:

A full service for asymetric passwordless authentication.

48 lines (44 loc) 1.66 kB
function handshake(system) { //if(typeof window.system == 'undefined') //{ //var auth_page="http://localhost:56082/login.html"; //window.location.replace(auth_page); //} //var system=window.system; //if(system.KEY_SET!=1) //MOVE(system.auth_page); var seed=Math.floor(Math.random()*1000000000)+1; //var signature=Sign(seed,user.rsa); var signature=Sign(seed,system.pRSA); var json_send=new Object(); json_send.command="request_handshake"; json_send.user=new Object(); json_send.user.id=system.user; json_send.user.seed=seed; json_send.user.sign=btoa(signature); console.log("Json Is: "+JSON.stringify(json_send)); var send=btoa(JSON.stringify(json_send)); $.ajax({ type: 'POST', headers: {"Access-Control-Allow-Origin":"localhost:56083"}, url: window.system.auth_server, data: send, success: function(response) { var data=JSON.parse(atob(response)); console.log("server response: "+JSON.stringify(data)); if(data.message=="connection_refused") { MOVE(window.system.auth_page,false); return 1; } var privateKey=forge.pki.privateKeyFromPem(system.pRSA); var decrypted = privateKey.decrypt(atob(data.hash),"RSAES-PKCS1-V1_5"); system.hash=decrypted; console.log(decrypted); }, async:false }); }