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.
improved Mozilla Observatory rating publication on github
- Loading branch information
Showing
12 changed files
with
300 additions
and
54 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
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,13 @@ | ||
#decrypt-error { | ||
display: none; | ||
} | ||
|
||
#password { | ||
display: inline; | ||
visibility: hidden; | ||
width: 25%; | ||
} | ||
|
||
#decrypt { | ||
visibility: hidden; | ||
} |
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,18 @@ | ||
#encrypt-error { | ||
display: none; | ||
} | ||
|
||
#share-secret-btn { | ||
margin-top: 0.5em; | ||
} | ||
|
||
#password { | ||
display: inline; | ||
margin-top: 0.5em; | ||
visibility: hidden; | ||
width: 25%; | ||
} | ||
|
||
#encrypt { | ||
visibility: hidden; | ||
} |
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,81 @@ | ||
// find decrypt button | ||
var decrypt_button = document.getElementById("decrypt"); | ||
if (null != decrypt_button) { | ||
// attach onClick event | ||
decrypt_button.addEventListener("click", function(){decrypt();}); | ||
} | ||
|
||
// find decrypt-locally checkbox | ||
var decrypt_locally_checkbox = document.getElementById("decrypt-locally"); | ||
if (null != decrypt_locally_checkbox) { | ||
// attach onClick event | ||
decrypt_locally_checkbox.addEventListener("click", function(){decrypt_locally();}); | ||
} | ||
|
||
// 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; | ||
} | ||
} |
Oops, something went wrong.