feat: update deno-sshsig-mod.ts
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import {crypto} from "jsr:@std/crypto";
|
import {crypto} from "jsr:@std/crypto";
|
||||||
import {decodeBase64} from "jsr:@std/encoding/base64";
|
import {decodeBase64} from "jsr:@std/encoding/base64";
|
||||||
import {encodeBase64Url} from "jsr:@std/encoding/base64url";
|
import {encodeBase64Url} from "jsr:@std/encoding/base64url";
|
||||||
import {decodeHex, encodeHex} from "jsr:@std/encoding/hex";
|
import {encodeHex} from "jsr:@std/encoding/hex";
|
||||||
|
|
||||||
// Reference:
|
// Reference:
|
||||||
// * https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.sshsig
|
// * https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.sshsig
|
||||||
@@ -284,7 +284,7 @@ class SshPublicKey {
|
|||||||
} else if (this.algorithm === "nistp384") {
|
} else if (this.algorithm === "nistp384") {
|
||||||
coordinateLength = 384 / 8;
|
coordinateLength = 384 / 8;
|
||||||
} else {
|
} else {
|
||||||
throw `Not supported alrogithm: ${this.algorithm}`;
|
throw `Not supported algorithm: ${this.algorithm}`;
|
||||||
}
|
}
|
||||||
const x = this.publicKeyPoint.slice(1, coordinateLength + 1);
|
const x = this.publicKeyPoint.slice(1, coordinateLength + 1);
|
||||||
const y = this.publicKeyPoint.slice(coordinateLength + 1, coordinateLength + 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 file = await Deno.open(filename, {read: true});
|
||||||
const readableStream = file.readable;
|
const readableStream = file.readable;
|
||||||
const fileHashBuffer = await crypto.subtle.digest(hashAlgorithm, readableStream);
|
const fileHashBuffer = await crypto.subtle.digest(hashAlgorithm, readableStream);
|
||||||
|
console.log("XXXXX", encodeHex(fileHashBuffer));
|
||||||
return new Uint8Array(fileHashBuffer);
|
return new Uint8Array(fileHashBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -358,21 +359,25 @@ AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAABJAAAAIQDD7MAiklQEsY3Dq3Zy25Zz
|
|||||||
const sshSignature = SshSignature.parse(parsePem(TEST_SIG));
|
const sshSignature = SshSignature.parse(parsePem(TEST_SIG));
|
||||||
console.log(sshSignature);
|
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();
|
const publicKey = await sshSignature.publicKey.importJwk();
|
||||||
console.log(publicKey);
|
console.log(publicKey);
|
||||||
console.log(encodeHex(sshSignature.signature.toDer()));
|
console.log("signature:", encodeHex(sshSignature.signature.toDer()));
|
||||||
|
|
||||||
// crypto.subtle.verify(
|
const signature = sshSignature.signature.toDer();
|
||||||
// {
|
|
||||||
// name: "ECDSA",
|
const file = "/Users/hatterjiang/temp/sigstore-tests/hello.txt";
|
||||||
// hash: { name: "SHA-256" },
|
const encoded = await sshSignature.calculateSignatureData(file);
|
||||||
// },
|
console.log("encoded:", encodeHex(encoded));
|
||||||
// publicKey,
|
|
||||||
// signature,
|
const r: boolean = await crypto.subtle.verify(
|
||||||
// encoded,
|
{
|
||||||
// );
|
name: "ECDSA",
|
||||||
|
hash: {name: "SHA-256"},
|
||||||
|
},
|
||||||
|
publicKey,
|
||||||
|
signature,
|
||||||
|
encoded,
|
||||||
|
);
|
||||||
|
|
||||||
|
console.log(r);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user