Skip to content

Commit

Permalink
fix: Update the algorithm to calculate nonce (#1295)
Browse files Browse the repository at this point in the history
Signed-off-by: Sheng Chen <sheche@microsoft.com>
  • Loading branch information
jdneo authored Mar 6, 2024
1 parent b8c464e commit 3792c57
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 27 deletions.
36 changes: 27 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@
"@types/fs-extra": "^9.0.13",
"@types/lodash": "^4.14.186",
"@types/minimatch": "^3.0.5",
"@types/node": "^16.11.65",
"@types/node": "18.x",
"@types/path-exists": "^3.0.0",
"@types/react": "^17.0.50",
"@types/react-dom": "^16.9.16",
Expand Down
11 changes: 1 addition & 10 deletions src/beginner-tips/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import * as path from "path";
import * as vscode from "vscode";
import { sendInfo } from "vscode-extension-telemetry-wrapper";
import { webviewCmdLinkHandler } from "../utils";
import { getNonce, webviewCmdLinkHandler } from "../utils";

const WEBVIEW_ID = "java.gettingStarted";
const WEBVIEW_TITLE = "Tips for Beginners";
Expand Down Expand Up @@ -127,12 +127,3 @@ class BeginnerTipsPage {
</html>`;
}
}

function getNonce() {
let text = "";
const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (let i = 0; i < 32; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
}
2 changes: 1 addition & 1 deletion src/utils/adoptiumApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export async function latestCompatibleAsset(featureVersion: string, jvmImpl: str
os = "linux";
}

let arch = process.arch;
let arch = process.arch as string;
if (arch === "arm64") {
arch = "aarch64";
}
Expand Down
11 changes: 5 additions & 6 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

import * as crypto from "crypto";
import * as vscode from "vscode";
import { readFile as fsReadFile } from "fs";
import * as util from "util";
Expand Down Expand Up @@ -79,10 +80,8 @@ export function isInsiders() {
}

export function getNonce() {
let text = "";
const possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (let i = 0; i < 32; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
let array = new Uint32Array(16);
array = crypto.getRandomValues(array);
const buffer = Buffer.from(array);
return buffer.toString('base64');
}

0 comments on commit 3792c57

Please sign in to comment.