companion,website: make encryption shorter + enable onedrive on website example

This commit is contained in:
ifedapoolarewaju 2020-01-21 13:14:17 +01:00
parent 78003c2f5b
commit 61edba36b3
No known key found for this signature in database
GPG key ID: FF050AA4EEBCE82E
3 changed files with 9 additions and 14 deletions

View file

@ -123,11 +123,11 @@ function createIv () {
}
function urlEncode (unencoded) {
return unencoded.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, ',')
return unencoded.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '~')
}
function urlDecode (encoded) {
encoded = encoded.replace(/-/g, '+').replace(/_/g, '/').replace(/,/g, '=')
encoded = encoded.replace(/-/g, '+').replace(/_/g, '/').replace(/~/g, '=')
return encoded
}
@ -141,10 +141,10 @@ function urlDecode (encoded) {
module.exports.encrypt = (input, secret) => {
const iv = createIv()
const cipher = crypto.createCipheriv('aes256', createSecret(secret), iv)
let encrypted = iv.toString('hex')
encrypted += urlEncode(cipher.update(input, 'utf8', 'base64'))
encrypted += urlEncode(cipher.final('base64'))
return encrypted
let encrypted = cipher.update(input, 'utf8', 'base64')
encrypted += cipher.final('base64')
// add iv to encrypted string to use for decryption
return iv.toString('hex') + urlEncode(encrypted)
}
/**
@ -161,8 +161,9 @@ module.exports.decrypt = (encrypted, secret) => {
}
const iv = Buffer.from(encrypted.slice(0, 32), 'hex')
const encryptionWithoutIv = encrypted.slice(32)
const decipher = crypto.createDecipheriv('aes256', createSecret(secret), iv)
let decrypted = decipher.update(urlDecode(encrypted.slice(32)), 'base64', 'utf8')
let decrypted = decipher.update(urlDecode(encryptionWithoutIv), 'base64', 'utf8')
decrypted += decipher.final('utf8')
return decrypted
}

View file

@ -98,7 +98,7 @@ describe('test authentication', () => {
.expect(200)
.expect((res) => {
const authToken = res.header['set-cookie'][0].split(';')[0].split('uppyAuthToken--google=')[1]
expect(decodeURIComponent(authToken)).toEqual(token)
expect(authToken).toEqual(token)
const body = `
<!DOCTYPE html>
<html>

View file

@ -108,11 +108,5 @@
facebookCheckbox.style.display = 'inline-block'
}
const onedriveCheckbox = document.getElementById('onedrive-checkbox')
onedriveCheckbox.style.display = 'none'
if (document.location.hash === '#enable-onedrive') {
onedriveCheckbox.style.display = 'inline-block'
}
toggleModalBtn()
</script>