-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Merge branch 'release/v8.1.0'
- Loading branch information
Showing
23 changed files
with
801 additions
and
139 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,70 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>CloudproofJS in browser</title> | ||
<link rel="icon" href="data:,"> | ||
</head> | ||
<body> | ||
<p>This demo should work without any JS build.</p> | ||
|
||
<script src="node_modules/cloudproof_js/dist/umd/index.js"></script> | ||
<script> | ||
const { CoverCrypt } = window.cloudproof_js; | ||
|
||
(async () => { | ||
const { Policy, PolicyAxis, generateMasterKeys, generateUserSecretKey, encrypt, decrypt } = await CoverCrypt(); | ||
|
||
const policy = new Policy([ | ||
new PolicyAxis( | ||
"Security Level", | ||
[ | ||
{ name: "Low", isHybridized: false }, | ||
{ name: "Medium", isHybridized: false }, | ||
{ name: "High", isHybridized: true }, | ||
], | ||
true, | ||
), | ||
new PolicyAxis( | ||
"Department", | ||
[ | ||
{ name: "R&D", isHybridized: false }, | ||
{ name: "HR", isHybridized: false }, | ||
], | ||
false, | ||
), | ||
]); | ||
|
||
const masterKeys = generateMasterKeys(policy); | ||
console.log(masterKeys); | ||
|
||
const highSecretAllDepartmentsDecryptionKey = generateUserSecretKey(masterKeys.secretKey, "Security Level::High && Department::R&D && Department::HR", policy) | ||
const lowSecretHRDepartmentDecryptionKey = generateUserSecretKey(masterKeys.secretKey, "Security Level::Low && Department::HR", policy) | ||
|
||
const secret = encrypt(policy, masterKeys.publicKey, "Security Level::High && Department::HR", new TextEncoder().encode("My secret!")); | ||
console.log(secret); | ||
|
||
const decrypted = decrypt(highSecretAllDepartmentsDecryptionKey, secret); | ||
const decryptedMessage = new TextDecoder().decode(decrypted.plaintext); | ||
console.log(decryptedMessage); | ||
|
||
if (decryptedMessage !== "My secret!") { | ||
throw new Error("Incorrect decrypted message"); | ||
} | ||
|
||
try { | ||
decrypt(lowSecretHRDepartmentDecryptionKey, secret); | ||
} catch { | ||
// should fail | ||
} | ||
|
||
const element = document.createElement('div') | ||
element.id = "done" | ||
document.body.appendChild(element) | ||
})(); | ||
|
||
</script> | ||
</body> | ||
</html> |
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,14 @@ | ||
{ | ||
"name": "browser", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"devDependencies": { | ||
"cloudproof_js": "file:../.." | ||
} | ||
} |
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,51 @@ | ||
import { exit } from "process" | ||
import puppeteer from "puppeteer" | ||
|
||
const host = "http://localhost:8000" | ||
|
||
const browser = await puppeteer.launch({ | ||
headless: process.env.CI !== undefined, | ||
args: ["--no-sandbox"], | ||
}) | ||
const page = await browser.newPage() | ||
await page.setViewport({ | ||
width: 1920, | ||
height: 1080, | ||
}) | ||
page.on("pageerror", async (err) => { | ||
await reportError(page, `[PAGE ERROR] ${err.toString()}`) | ||
}) | ||
page.on("error", async (err) => { | ||
await reportError(page, `[PAGE ERROR] ${err.toString()}`) | ||
}) | ||
page.on("console", (msg) => { | ||
// This is an expected error when trying to decrypt something we don't have the correct rights | ||
if ( | ||
msg.text() !== | ||
"Failed to load resource: the server responded with a status of 422 (Unprocessable Entity)" | ||
) { | ||
console.log(`[PAGE LOG] ${msg.text()}`) | ||
} | ||
}) | ||
page.on("requestfailed", async (request) => | ||
console.log( | ||
`[PAGE HTTP ERROR] ${request.failure().errorText} ${request.url()}`, | ||
), | ||
) | ||
|
||
try { | ||
await page.goto(host) | ||
} catch { | ||
// In case of random error, try again. | ||
console.error("Cannot navigate to the example, trying again one time…") | ||
await page.goto(host) | ||
} | ||
|
||
await page.waitForSelector("#done", { timeout: 500 }) | ||
|
||
exit(0) | ||
|
||
async function reportError(page, message) { | ||
await page.screenshot({ path: "error.png", fullPage: true }) | ||
throw new Error(message) | ||
} |
Oops, something went wrong.