This repository has been archived by the owner on Mar 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
integrity-checking feature publication on github
- Loading branch information
Showing
12 changed files
with
185 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// find copy-to-clipboard button | ||
var copy_to_clipboard = document.getElementById("copy-to-clipboard"); | ||
|
||
if (null != copy_to_clipboard) { | ||
// check if we're confronted with a Safari browser | ||
if ((-1 != navigator.userAgent.indexOf("Safari")) && | ||
(-1 == navigator.userAgent.indexOf("Android")) && | ||
(-1 == navigator.userAgent.indexOf("Chrome"))) { | ||
// hide copy-to-clipboard button, because it is not supported | ||
copy_to_clipboard.style.display = "none"; | ||
} else { | ||
// initialize clipboard feature | ||
var clipboard = new Clipboard('.btn'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// action happening on local decryption | ||
function decrypt() { | ||
var result = decrypt_secret(document.getElementById("secret").innerHTML, | ||
document.getElementById("password").value); | ||
|
||
if (null != result) { | ||
document.getElementById("secret").innerHTML = html_entities(result); | ||
|
||
document.getElementById("decrypt").disabled = true; | ||
document.getElementById("decrypt-locally").disabled = true; | ||
|
||
document.getElementById("password").readOnly = "readonly"; | ||
|
||
document.getElementById("decrypt-error").style.display = "none"; | ||
} else { | ||
document.getElementById("decrypt-error").style.display = "block"; | ||
} | ||
} | ||
|
||
// show/hide local decryption | ||
function decrypt_locally(checkbox) { | ||
if (document.getElementById("decrypt-locally").checked) { | ||
document.getElementById("decrypt").style.visibility = "visible"; | ||
document.getElementById("password").style.visibility = "visible"; | ||
} else { | ||
document.getElementById("decrypt").style.visibility = "hidden"; | ||
document.getElementById("password").style.visibility = "hidden"; | ||
} | ||
} | ||
|
||
// prevent code injection through locally decrypted secret | ||
function html_entities(content) { | ||
return content.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"); | ||
} | ||
|
||
function decrypt_secret(concatSecret, password) { | ||
// these variables configure the PBKDF2 call | ||
var outputLength = 32; | ||
var workFactor = 1024; | ||
|
||
// split concatenation of Base64-encoded salt and Base64-encoded encrypted secret | ||
var base64Salt = concatSecret.substring(0, 44); | ||
var base64Secret = concatSecret.substring(44); | ||
|
||
// retrieve plain salt from Base64-encoded salt | ||
var salt = (new buffer.SlowBuffer(base64Salt, "base64")).toArrayBuffer(); | ||
|
||
// retrieve plain secret from Base64-encoded encrypted secret | ||
var secret = (new buffer.SlowBuffer(base64Secret, "base64")).toArrayBuffer(); | ||
|
||
// derive decryption key | ||
var pbkdf2Key = asmCrypto.PBKDF2_HMAC_SHA256.bytes(password, salt, workFactor, outputLength); | ||
|
||
try { | ||
// decrypt secret with derived decryption key | ||
var aesResult = asmCrypto.AES_GCM.decrypt(secret, pbkdf2Key, new Uint8Array(12)); | ||
} catch(err) { | ||
var aesResult = null; | ||
} | ||
|
||
if (null != aesResult) { | ||
// return UTF-8-encoded decrypted secret | ||
return (new buffer.SlowBuffer(aesResult)).toString("utf-8"); | ||
} else { | ||
return aesResult; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// action happening on local encryption | ||
function encrypt() { | ||
var result = encrypt_secret(document.getElementById("secret").value, | ||
document.getElementById("password").value); | ||
|
||
if (null != result) { | ||
document.getElementById("secret").value = result; | ||
|
||
document.getElementById("share-secret-btn").disabled = false; | ||
|
||
document.getElementById("encrypt").disabled = true; | ||
document.getElementById("encrypt-locally").disabled = true; | ||
|
||
document.getElementById("password").readOnly = "readonly"; | ||
document.getElementById("secret").readOnly = "readonly"; | ||
|
||
document.getElementById("encrypt-error").style.display = "none"; | ||
} else { | ||
document.getElementById("encrypt-error").style.display = "block"; | ||
} | ||
} | ||
|
||
// show/hide local encryption | ||
function encrypt_locally(checkbox) { | ||
if (document.getElementById("encrypt-locally").checked) { | ||
document.getElementById("share-secret-btn").disabled = true; | ||
|
||
document.getElementById("encrypt").style.visibility = "visible"; | ||
document.getElementById("password").style.visibility = "visible"; | ||
} else { | ||
document.getElementById("share-secret-btn").disabled = false; | ||
|
||
document.getElementById("encrypt").style.visibility = "hidden"; | ||
document.getElementById("password").style.visibility = "hidden"; | ||
} | ||
} | ||
|
||
function encrypt_secret(secret, password) { | ||
// these variables configure the PBKDF2 call | ||
var outputLength = 32; | ||
var workFactor = 1024; | ||
|
||
// disable asmCrypto warning | ||
asmCrypto.random.skipSystemRNGWarning = true; | ||
|
||
// retrieve salt from PRNG | ||
var salt = new Uint8Array(32); | ||
asmCrypto.getRandomValues(salt); | ||
|
||
// derive encryption key | ||
var pbkdf2Key = asmCrypto.PBKDF2_HMAC_SHA256.bytes(password, salt, workFactor, outputLength); | ||
|
||
try { | ||
// encrypt secret with derived encryption key | ||
var aesResult = asmCrypto.AES_GCM.encrypt(secret, pbkdf2Key, new Uint8Array(12)); | ||
} catch (err) { | ||
var aesResult = null; | ||
} | ||
|
||
if (null != aesResult) { | ||
// create Base64-encoded salt | ||
var base64Salt = (new buffer.SlowBuffer(salt)).toString("base64"); | ||
|
||
// create Base64-encoded encrypted secret | ||
var base64Secret = (new buffer.SlowBuffer(aesResult)).toString("base64"); | ||
|
||
// return concatenation of Base64-encoded salt and Base64-encoded encrypted secret | ||
return (base64Salt + base64Secret); | ||
} else { | ||
return aesResult; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.