feat: update ssh-verify.ts

This commit is contained in:
2025-01-19 16:26:34 +08:00
parent 4d61625252
commit 27111b421f
2 changed files with 22 additions and 19 deletions

View File

@@ -52,12 +52,12 @@
},
"ssh-verify.ts": {
"script_name": "ssh-verify.ts",
"script_length": 2708,
"script_sha256": "c8ffa0e730db27046f4fdc2c7946e53eb3f4209f663374b60b64521957218a43",
"script_length": 2718,
"script_sha256": "03a9eec40f27821593eb4c323e29be1d7222f3d3922a0b6bdbdbcb257332db6c",
"script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/ssh-verify.ts",
"single_script_file": true,
"publish_time": 1737272626141,
"update_time": 1737272626141
"update_time": 1737275173262
},
"wget.ts": {
"script_name": "wget.ts",

View File

@@ -1,6 +1,9 @@
#!/usr/bin/env -S deno run --allow-env --allow-import --allow-read --allow-net
import { parseArgs } from "jsr:@std/cli/parse-args";
import {
log,
} from "https://hatter.ink/script/fetch/library/deno-commons-mod.ts?202401191623";
import {
fetchKeys,
SshKey,
@@ -15,7 +18,7 @@ const flags = parseArgs(Deno.args, {
});
if (Deno.args.length === 0) {
console.log("ssh-verify.ts --help for help");
log.info("ssh-verify.ts --help for help");
Deno.exit(1);
}
@@ -29,7 +32,7 @@ ssh-verify.ts --username <github-username> <filename>
}
if (flags._.length === 0) {
console.log("Requires filename.");
log.error("Requires filename.");
Deno.exit(1);
}
@@ -37,15 +40,15 @@ const filename = flags._[0] as string;
const sshSigFilename = `${filename}.sshsig`;
if (flags.debug) {
console.log(`SSH signature file: ${sshSigFilename}`);
log.debug(`SSH signature file: ${sshSigFilename}`);
}
const sshSignature = await SshSignature.parseFile(sshSigFilename);
const verifyResult = await sshSignature.verifyFile(filename);
if (!verifyResult) {
console.log(
`[ERROR] Verify ${filename}, signature: ${sshSigFilename} failed.`,
log.error(
`Verify ${filename}, signature: ${sshSigFilename} failed.`,
);
Deno.exit(1);
}
@@ -54,19 +57,19 @@ const sshPublicKey = sshSignature.publicKey;
const sshPublicKeyRawBase64 = sshSignature.publicKey.asRawBase64();
const sshPublicKeySshFormat = sshPublicKey.toSshKeyFormat();
console.log(`[SUCCESS] File ${filename} verify success.`);
console.log(`[SUCCESS] Signing SSH key: ${sshPublicKeySshFormat}`);
log.success(`File ${filename} verify success.`);
log.success(`Signing SSH key: ${sshPublicKeySshFormat}`);
if (flags.username) {
let matches = false;
try {
console.log(`[INFO] Fetch SSH keys for user: ${flags.username}`);
log.info(`Fetch SSH keys for user: ${flags.username}`);
const keys: Array<SshKey> = await fetchKeys(flags.username);
if (flags.debug) {
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
console.log(
log.debug(
`[DEBUG] Found SSH key: ${key.algorithm} ${key.material}`,
);
}
@@ -79,19 +82,19 @@ if (flags.username) {
}
}
} catch (e) {
console.error(
`[ERROR] Fetch SSH keys for ${flags.username} failed: ${e}`,
log.error(
`Fetch SSH keys for ${flags.username} failed: ${e}`,
);
}
if (matches) {
console.log(
`[SUCCESS] SSH key matches for GitHub user: ${flags.username} success.`,
log.success(
`SSH key matches for GitHub user: ${flags.username} success.`,
);
} else {
console.log(
`[ERROR] SSH key NOT matched for GitHub user: ${flags.username}.`,
log.error(
`SSH key NOT matched for GitHub user: ${flags.username}.`,
);
}
} else {
console.log("[WARN] GitHub user is not assigned.");
log.warn("GitHub user is not assigned.");
}