feat: update ssh-verify.ts
This commit is contained in:
@@ -52,12 +52,12 @@
|
|||||||
},
|
},
|
||||||
"ssh-verify.ts": {
|
"ssh-verify.ts": {
|
||||||
"script_name": "ssh-verify.ts",
|
"script_name": "ssh-verify.ts",
|
||||||
"script_length": 2708,
|
"script_length": 2718,
|
||||||
"script_sha256": "c8ffa0e730db27046f4fdc2c7946e53eb3f4209f663374b60b64521957218a43",
|
"script_sha256": "03a9eec40f27821593eb4c323e29be1d7222f3d3922a0b6bdbdbcb257332db6c",
|
||||||
"script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/ssh-verify.ts",
|
"script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/ssh-verify.ts",
|
||||||
"single_script_file": true,
|
"single_script_file": true,
|
||||||
"publish_time": 1737272626141,
|
"publish_time": 1737272626141,
|
||||||
"update_time": 1737272626141
|
"update_time": 1737275173262
|
||||||
},
|
},
|
||||||
"wget.ts": {
|
"wget.ts": {
|
||||||
"script_name": "wget.ts",
|
"script_name": "wget.ts",
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
#!/usr/bin/env -S deno run --allow-env --allow-import --allow-read --allow-net
|
#!/usr/bin/env -S deno run --allow-env --allow-import --allow-read --allow-net
|
||||||
|
|
||||||
import { parseArgs } from "jsr:@std/cli/parse-args";
|
import { parseArgs } from "jsr:@std/cli/parse-args";
|
||||||
|
import {
|
||||||
|
log,
|
||||||
|
} from "https://hatter.ink/script/fetch/library/deno-commons-mod.ts?202401191623";
|
||||||
import {
|
import {
|
||||||
fetchKeys,
|
fetchKeys,
|
||||||
SshKey,
|
SshKey,
|
||||||
@@ -15,7 +18,7 @@ const flags = parseArgs(Deno.args, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (Deno.args.length === 0) {
|
if (Deno.args.length === 0) {
|
||||||
console.log("ssh-verify.ts --help for help");
|
log.info("ssh-verify.ts --help for help");
|
||||||
Deno.exit(1);
|
Deno.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -29,7 +32,7 @@ ssh-verify.ts --username <github-username> <filename>
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (flags._.length === 0) {
|
if (flags._.length === 0) {
|
||||||
console.log("Requires filename.");
|
log.error("Requires filename.");
|
||||||
Deno.exit(1);
|
Deno.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,15 +40,15 @@ const filename = flags._[0] as string;
|
|||||||
const sshSigFilename = `${filename}.sshsig`;
|
const sshSigFilename = `${filename}.sshsig`;
|
||||||
|
|
||||||
if (flags.debug) {
|
if (flags.debug) {
|
||||||
console.log(`SSH signature file: ${sshSigFilename}`);
|
log.debug(`SSH signature file: ${sshSigFilename}`);
|
||||||
}
|
}
|
||||||
const sshSignature = await SshSignature.parseFile(sshSigFilename);
|
const sshSignature = await SshSignature.parseFile(sshSigFilename);
|
||||||
|
|
||||||
const verifyResult = await sshSignature.verifyFile(filename);
|
const verifyResult = await sshSignature.verifyFile(filename);
|
||||||
|
|
||||||
if (!verifyResult) {
|
if (!verifyResult) {
|
||||||
console.log(
|
log.error(
|
||||||
`[ERROR] Verify ${filename}, signature: ${sshSigFilename} failed.`,
|
`Verify ${filename}, signature: ${sshSigFilename} failed.`,
|
||||||
);
|
);
|
||||||
Deno.exit(1);
|
Deno.exit(1);
|
||||||
}
|
}
|
||||||
@@ -54,19 +57,19 @@ const sshPublicKey = sshSignature.publicKey;
|
|||||||
const sshPublicKeyRawBase64 = sshSignature.publicKey.asRawBase64();
|
const sshPublicKeyRawBase64 = sshSignature.publicKey.asRawBase64();
|
||||||
const sshPublicKeySshFormat = sshPublicKey.toSshKeyFormat();
|
const sshPublicKeySshFormat = sshPublicKey.toSshKeyFormat();
|
||||||
|
|
||||||
console.log(`[SUCCESS] File ${filename} verify success.`);
|
log.success(`File ${filename} verify success.`);
|
||||||
console.log(`[SUCCESS] Signing SSH key: ${sshPublicKeySshFormat}`);
|
log.success(`Signing SSH key: ${sshPublicKeySshFormat}`);
|
||||||
|
|
||||||
if (flags.username) {
|
if (flags.username) {
|
||||||
let matches = false;
|
let matches = false;
|
||||||
try {
|
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);
|
const keys: Array<SshKey> = await fetchKeys(flags.username);
|
||||||
|
|
||||||
if (flags.debug) {
|
if (flags.debug) {
|
||||||
for (let i = 0; i < keys.length; i++) {
|
for (let i = 0; i < keys.length; i++) {
|
||||||
const key = keys[i];
|
const key = keys[i];
|
||||||
console.log(
|
log.debug(
|
||||||
`[DEBUG] Found SSH key: ${key.algorithm} ${key.material}`,
|
`[DEBUG] Found SSH key: ${key.algorithm} ${key.material}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -79,19 +82,19 @@ if (flags.username) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(
|
log.error(
|
||||||
`[ERROR] Fetch SSH keys for ${flags.username} failed: ${e}`,
|
`Fetch SSH keys for ${flags.username} failed: ${e}`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (matches) {
|
if (matches) {
|
||||||
console.log(
|
log.success(
|
||||||
`[SUCCESS] SSH key matches for GitHub user: ${flags.username} success.`,
|
`SSH key matches for GitHub user: ${flags.username} success.`,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
console.log(
|
log.error(
|
||||||
`[ERROR] SSH key NOT matched for GitHub user: ${flags.username}.`,
|
`SSH key NOT matched for GitHub user: ${flags.username}.`,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log("[WARN] GitHub user is not assigned.");
|
log.warn("GitHub user is not assigned.");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user