authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-07-17 12:45:46 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-07-17 12:45:46 -07:00
log3d9e5c82192c59497d4038e7ffe82a65007d129e
treef7d8691d15b57385551652f75da8a54d6e946a6a
parentcd2f528fc410738c7951e6f0cb4b4a4a1cd7f1cb
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

Signature: ssh: validate pkformat


1 files changed, 5 insertions(+), 1 deletions(-)

git.zig+5-1
......@@ -2557,12 +2557,12 @@ pub const Signature = union(enum) {
25572557 const sigformat = try sigfixed.readSlice(try sigfixed.readInt(u32, .big));
25582558 var pkfixed: nio.FixedBufferStream([]const u8) = .init(publickey);
25592559 const pkformat = try pkfixed.readSlice(try pkfixed.readInt(u32, .big));
2560 _ = pkformat;
25612560
25622561 if (std.mem.eql(u8, sigformat, "ssh-rsa")) {
25632562 // intentionally skipped, rsa with sha1
25642563 }
25652564 if (std.mem.eql(u8, sigformat, "rsa-sha2-256")) blk: {
2565 if (!(std.mem.eql(u8, pkformat, "ssh-rsa"))) break :blk;
25662566 const ns = std.crypto.Certificate.rsa;
25672567 const pk_e_len = pkfixed.readInt(u32, .big) catch break :blk;
25682568 var pk_e = pkfixed.readSlice(pk_e_len) catch break :blk;
......@@ -2576,6 +2576,7 @@ pub const Signature = union(enum) {
25762576 valid = if (pgp_rsa_verify(pk_n.len, sig, signed_data.items, pk, .sha2_256)) true else |err| if (err == error.unrecognized) null else false;
25772577 }
25782578 if (std.mem.eql(u8, sigformat, "rsa-sha2-512")) blk: {
2579 if (!(std.mem.eql(u8, pkformat, "ssh-rsa"))) break :blk;
25792580 const ns = std.crypto.Certificate.rsa;
25802581 const pk_e_len = pkfixed.readInt(u32, .big) catch break :blk;
25812582 var pk_e = pkfixed.readSlice(pk_e_len) catch break :blk;
......@@ -2589,6 +2590,7 @@ pub const Signature = union(enum) {
25892590 valid = if (pgp_rsa_verify(pk_n.len, sig, signed_data.items, pk, .sha2_512)) true else |err| if (err == error.unrecognized) null else false;
25902591 }
25912592 if (std.mem.eql(u8, sigformat, "ssh-ed25519")) blk: {
2593 if (!(std.mem.eql(u8, pkformat, "ssh-ed25519"))) break :blk;
25922594 const ed = std.crypto.sign.Ed25519;
25932595 const pk_len = pkfixed.readInt(u32, .big) catch break :blk;
25942596 if (pk_len != ed.PublicKey.encoded_length) break :blk;
......@@ -2601,6 +2603,7 @@ pub const Signature = union(enum) {
26012603 valid = if (sig.verifyStrict(signed_data.items, pk)) true else |_| false;
26022604 }
26032605 if (std.mem.eql(u8, sigformat, "ecdsa-sha2-nistp256")) blk: {
2606 if (!(std.mem.eql(u8, pkformat, "ecdsa-sha2-nistp256"))) break :blk;
26042607 const C = std.crypto.ecc.P256;
26052608 const H = std.crypto.hash.sha2.Sha256;
26062609 const ns = std.crypto.sign.ecdsa.Ecdsa(C, H);
......@@ -2624,6 +2627,7 @@ pub const Signature = union(enum) {
26242627 valid = if (sig.verify(signed_data.items, pk)) true else |_| false;
26252628 }
26262629 if (std.mem.eql(u8, sigformat, "ecdsa-sha2-nistp384")) blk: {
2630 if (!(std.mem.eql(u8, pkformat, "ecdsa-sha2-nistp384"))) break :blk;
26272631 const C = std.crypto.ecc.P384;
26282632 const H = std.crypto.hash.sha2.Sha384;
26292633 const ns = std.crypto.sign.ecdsa.Ecdsa(C, H);