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) {...@@ -2557,12 +2557,12 @@ pub const Signature = union(enum) {
2557 const sigformat = try sigfixed.readSlice(try sigfixed.readInt(u32, .big));2557 const sigformat = try sigfixed.readSlice(try sigfixed.readInt(u32, .big));
2558 var pkfixed: nio.FixedBufferStream([]const u8) = .init(publickey);2558 var pkfixed: nio.FixedBufferStream([]const u8) = .init(publickey);
2559 const pkformat = try pkfixed.readSlice(try pkfixed.readInt(u32, .big));2559 const pkformat = try pkfixed.readSlice(try pkfixed.readInt(u32, .big));
2560 _ = pkformat;
25612560
2562 if (std.mem.eql(u8, sigformat, "ssh-rsa")) {2561 if (std.mem.eql(u8, sigformat, "ssh-rsa")) {
2563 // intentionally skipped, rsa with sha12562 // intentionally skipped, rsa with sha1
2564 }2563 }
2565 if (std.mem.eql(u8, sigformat, "rsa-sha2-256")) blk: {2564 if (std.mem.eql(u8, sigformat, "rsa-sha2-256")) blk: {
2565 if (!(std.mem.eql(u8, pkformat, "ssh-rsa"))) break :blk;
2566 const ns = std.crypto.Certificate.rsa;2566 const ns = std.crypto.Certificate.rsa;
2567 const pk_e_len = pkfixed.readInt(u32, .big) catch break :blk;2567 const pk_e_len = pkfixed.readInt(u32, .big) catch break :blk;
2568 var pk_e = pkfixed.readSlice(pk_e_len) catch break :blk;2568 var pk_e = pkfixed.readSlice(pk_e_len) catch break :blk;
...@@ -2576,6 +2576,7 @@ pub const Signature = union(enum) {...@@ -2576,6 +2576,7 @@ pub const Signature = union(enum) {
2576 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;2576 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;
2577 }2577 }
2578 if (std.mem.eql(u8, sigformat, "rsa-sha2-512")) blk: {2578 if (std.mem.eql(u8, sigformat, "rsa-sha2-512")) blk: {
2579 if (!(std.mem.eql(u8, pkformat, "ssh-rsa"))) break :blk;
2579 const ns = std.crypto.Certificate.rsa;2580 const ns = std.crypto.Certificate.rsa;
2580 const pk_e_len = pkfixed.readInt(u32, .big) catch break :blk;2581 const pk_e_len = pkfixed.readInt(u32, .big) catch break :blk;
2581 var pk_e = pkfixed.readSlice(pk_e_len) catch break :blk;2582 var pk_e = pkfixed.readSlice(pk_e_len) catch break :blk;
...@@ -2589,6 +2590,7 @@ pub const Signature = union(enum) {...@@ -2589,6 +2590,7 @@ pub const Signature = union(enum) {
2589 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;2590 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;
2590 }2591 }
2591 if (std.mem.eql(u8, sigformat, "ssh-ed25519")) blk: {2592 if (std.mem.eql(u8, sigformat, "ssh-ed25519")) blk: {
2593 if (!(std.mem.eql(u8, pkformat, "ssh-ed25519"))) break :blk;
2592 const ed = std.crypto.sign.Ed25519;2594 const ed = std.crypto.sign.Ed25519;
2593 const pk_len = pkfixed.readInt(u32, .big) catch break :blk;2595 const pk_len = pkfixed.readInt(u32, .big) catch break :blk;
2594 if (pk_len != ed.PublicKey.encoded_length) break :blk;2596 if (pk_len != ed.PublicKey.encoded_length) break :blk;
...@@ -2601,6 +2603,7 @@ pub const Signature = union(enum) {...@@ -2601,6 +2603,7 @@ pub const Signature = union(enum) {
2601 valid = if (sig.verifyStrict(signed_data.items, pk)) true else |_| false;2603 valid = if (sig.verifyStrict(signed_data.items, pk)) true else |_| false;
2602 }2604 }
2603 if (std.mem.eql(u8, sigformat, "ecdsa-sha2-nistp256")) blk: {2605 if (std.mem.eql(u8, sigformat, "ecdsa-sha2-nistp256")) blk: {
2606 if (!(std.mem.eql(u8, pkformat, "ecdsa-sha2-nistp256"))) break :blk;
2604 const C = std.crypto.ecc.P256;2607 const C = std.crypto.ecc.P256;
2605 const H = std.crypto.hash.sha2.Sha256;2608 const H = std.crypto.hash.sha2.Sha256;
2606 const ns = std.crypto.sign.ecdsa.Ecdsa(C, H);2609 const ns = std.crypto.sign.ecdsa.Ecdsa(C, H);
...@@ -2624,6 +2627,7 @@ pub const Signature = union(enum) {...@@ -2624,6 +2627,7 @@ pub const Signature = union(enum) {
2624 valid = if (sig.verify(signed_data.items, pk)) true else |_| false;2627 valid = if (sig.verify(signed_data.items, pk)) true else |_| false;
2625 }2628 }
2626 if (std.mem.eql(u8, sigformat, "ecdsa-sha2-nistp384")) blk: {2629 if (std.mem.eql(u8, sigformat, "ecdsa-sha2-nistp384")) blk: {
2630 if (!(std.mem.eql(u8, pkformat, "ecdsa-sha2-nistp384"))) break :blk;
2627 const C = std.crypto.ecc.P384;2631 const C = std.crypto.ecc.P384;
2628 const H = std.crypto.hash.sha2.Sha384;2632 const H = std.crypto.hash.sha2.Sha384;
2629 const ns = std.crypto.sign.ecdsa.Ecdsa(C, H);2633 const ns = std.crypto.sign.ecdsa.Ecdsa(C, H);