-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Switch to the Web Crypto API for generating SHA checksums #21522
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Submodule node_modules
updated
1242 files
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 |
---|---|---|
|
@@ -23,12 +23,19 @@ import React from "react"; | |
import { ClipboardCopy } from "@patternfly/react-core/dist/esm/components/ClipboardCopy/index.js"; | ||
import { Text, TextContent, TextVariants } from "@patternfly/react-core/dist/esm/components/Text/index.js"; | ||
|
||
import sha1 from "js-sha1"; | ||
import sha256 from "js-sha256"; | ||
import { useInit } from "hooks"; | ||
|
||
import stable_stringify from "json-stable-stringify-without-jsonify"; | ||
|
||
const _ = cockpit.gettext; | ||
|
||
async function digest(text, hash) { | ||
const encoder = new TextEncoder(); | ||
const data = encoder.encode(text); | ||
const digest = await window.crypto.subtle.digest(hash, data); | ||
return [...new Uint8Array(digest)]; | ||
} | ||
|
||
export function validate_url(url) { | ||
if (url.length === 0) | ||
return _("Address cannot be empty"); | ||
|
@@ -68,7 +75,7 @@ function jwk_b64_encode(bytes) { | |
.replace(/=+$/, ''); | ||
} | ||
|
||
function compute_thp(jwk) { | ||
async function compute_thp(jwk) { | ||
const REQUIRED_ATTRS = { | ||
RSA: ['kty', 'p', 'd', 'q', 'dp', 'dq', 'qi', 'oth'], | ||
EC: ['kty', 'crv', 'x', 'y'], | ||
|
@@ -83,10 +90,23 @@ function compute_thp(jwk) { | |
const req = REQUIRED_ATTRS[jwk.kty]; | ||
const norm = { }; | ||
req.forEach(k => { if (k in jwk) norm[k] = jwk[k]; }); | ||
return { | ||
sha256: jwk_b64_encode(sha256.digest(stable_stringify(norm))), | ||
sha1: jwk_b64_encode(sha1.digest(stable_stringify(norm))) | ||
}; | ||
|
||
const hashes = {}; | ||
try { | ||
const sha256 = jwk_b64_encode(await digest(stable_stringify(norm), "SHA-256")); | ||
hashes.sha256 = sha256; | ||
} catch (err) { | ||
console.warn("Unable to create a sha256 hash", err); | ||
} | ||
|
||
try { | ||
const sha1 = jwk_b64_encode(await digest(stable_stringify(norm), "SHA-1")); | ||
hashes.sha1 = sha1; | ||
} catch (err) { | ||
console.warn("Unable to create a sha1 hash", err); | ||
Comment on lines
+105
to
+106
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These 2 added lines are not executed by any test. |
||
} | ||
|
||
return hashes; | ||
} | ||
|
||
function compute_sigkey_thps(adv) { | ||
|
@@ -106,7 +126,15 @@ function compute_sigkey_thps(adv) { | |
export const TangKeyVerification = ({ url, adv }) => { | ||
const parsed = parse_url(url); | ||
const cmd = cockpit.format("ssh $0 tang-show-keys $1", parsed.hostname, parsed.port); | ||
const sigkey_thps = compute_sigkey_thps(tang_adv_payload(adv)); | ||
const [sigkey_thps, setSigKey] = React.useState(null); | ||
|
||
useInit(async () => { | ||
const sigkey = await Promise.all(compute_sigkey_thps(tang_adv_payload(adv))); | ||
setSigKey(sigkey); | ||
}); | ||
|
||
if (sigkey_thps === null) | ||
return null; | ||
|
||
return ( | ||
<TextContent> | ||
|
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These 2 added lines are not executed by any test.