feat: update deno-sshsig-mod.ts

This commit is contained in:
2025-01-11 16:59:59 +08:00
parent 9fc3613cf5
commit 85dbc76755

View File

@@ -1,7 +1,7 @@
import {crypto} from "jsr:@std/crypto";
import {decodeBase64} from "jsr:@std/encoding/base64";
import {encodeBase64Url} from "jsr:@std/encoding/base64url";
import {decodeHex, encodeHex} from "jsr:@std/encoding/hex";
import {encodeHex} from "jsr:@std/encoding/hex";
// Reference:
// * https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.sshsig
@@ -284,7 +284,7 @@ class SshPublicKey {
} else if (this.algorithm === "nistp384") {
coordinateLength = 384 / 8;
} else {
throw `Not supported alrogithm: ${this.algorithm}`;
throw `Not supported algorithm: ${this.algorithm}`;
}
const x = this.publicKeyPoint.slice(1, coordinateLength + 1);
const y = this.publicKeyPoint.slice(coordinateLength + 1, coordinateLength + coordinateLength + 1);
@@ -343,6 +343,7 @@ async function digestFile(filename: string, algorithm: string): Promise<Uint8Arr
const file = await Deno.open(filename, {read: true});
const readableStream = file.readable;
const fileHashBuffer = await crypto.subtle.digest(hashAlgorithm, readableStream);
console.log("XXXXX", encodeHex(fileHashBuffer));
return new Uint8Array(fileHashBuffer);
}
@@ -358,21 +359,25 @@ AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAABJAAAAIQDD7MAiklQEsY3Dq3Zy25Zz
const sshSignature = SshSignature.parse(parsePem(TEST_SIG));
console.log(sshSignature);
const file = "/Users/hatterjiang/temp/sigstore-tests/hello.txt";
const sig = await sshSignature.calculateSignatureData(file);
console.log(encodeHex(sig));
const publicKey = await sshSignature.publicKey.importJwk();
console.log(publicKey);
console.log(encodeHex(sshSignature.signature.toDer()));
console.log("signature:", encodeHex(sshSignature.signature.toDer()));
// crypto.subtle.verify(
// {
// name: "ECDSA",
// hash: { name: "SHA-256" },
// },
// publicKey,
// signature,
// encoded,
// );
const signature = sshSignature.signature.toDer();
const file = "/Users/hatterjiang/temp/sigstore-tests/hello.txt";
const encoded = await sshSignature.calculateSignatureData(file);
console.log("encoded:", encodeHex(encoded));
const r: boolean = await crypto.subtle.verify(
{
name: "ECDSA",
hash: {name: "SHA-256"},
},
publicKey,
signature,
encoded,
);
console.log(r);