Commit e05f4205 authored by Aral Balkan's avatar Aral Balkan
Browse files

Update private token paths to match latest server protocol

parent 952db29b
......@@ -8,41 +8,38 @@ import sealedBox from 'tweetnacl-sealedbox-js'
nacl.sealedBox = sealedBox
export async function authenticate (passphrase) {
// Get the encrypted private socket path fragment.
const privateSocketURL = `https://${window.location.hostname}/private-socket`
const privateSocketResponse = await fetch(privateSocketURL)
const privateSocket = await privateSocketResponse.json()
const encryptedPrivateSocketPathFragment = privateSocket.encryptedPrivateSocketPathFragment
// Get the encrypted private token.
const privateTokenURL = `https://${window.location.hostname}/private-token`
const privateTokenResponse = await fetch(privateTokenURL)
const privateTokenResponseJson = await privateTokenResponse.json()
const encryptedPrivateToken = privateTokenResponseJson.encryptedPrivateToken
const productionHostnameResponse = await fetch(`https://${window.location.hostname}/hostname`)
const productionHostname = (await productionHostnameResponse.json()).hostname
console.log('Production hostname: ', productionHostname)
// Regenerate the private key.
// Regenerate the keys.
const blake2bHashOfHostnameAsSalt = blake.blake2bHex(productionHostname)
const keys = await generateKeys(blake2bHashOfHostnameAsSalt, passphrase)
const publicKeyAsHex = toHex(keys.publicKey)
console.log('public key', publicKeyAsHex)
console.log('Public key: ', publicKeyAsHex)
const sealedBoxOpenResult =, keys.publicKey, keys.secretKey)
// Open the sealed box to get the token.
console.log('encryptedPrivateToken', encryptedPrivateToken)
const sealedBoxOpenResult =, keys.publicKey, keys.secretKey)
if (sealedBoxOpenResult === null) {
console.log('Error: could not decrypt the private token.')
return null
// OK, signed in.
const secretPath = naclUtil.encodeUTF8(sealedBoxOpenResult)
console.log('secretPath', secretPath)
return secretPath
const privateToken = naclUtil.encodeUTF8(sealedBoxOpenResult)
console.log('Unencrypted private token: ', privateToken)
return privateToken
function generateKeys(blake2bHashOfHostnameAsSalt, passphrase){
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment