mirror of
https://github.com/sbrow/envr.git
synced 2026-08-26 18:03:32 -04:00
Compare commits
3 Commits
f2a98bc782
...
7ffc38171c
| Author | SHA1 | Date | |
|---|---|---|---|
| 7ffc38171c | |||
| 8b9a9789ab | |||
| 6244a6c8ce |
@@ -16,11 +16,7 @@
|
|||||||
|
|
||||||
8. Add tests for untested commands.
|
8. Add tests for untested commands.
|
||||||
|
|
||||||
9. Update `read_wire_string` to use a slice.
|
9. Audit ssh.odin for places where `#no_bounds_check` would be appropriate.
|
||||||
|
|
||||||
10. Consider getting rid of color global.
|
|
||||||
|
|
||||||
11. `write_flags_table` should never return false.
|
|
||||||
|
|
||||||
## Double-check AI output
|
## Double-check AI output
|
||||||
|
|
||||||
|
|||||||
@@ -206,10 +206,9 @@ write_command_help :: proc(name: string, w: io.Writer) -> bool {
|
|||||||
tbl: table.Table
|
tbl: table.Table
|
||||||
table.init(&tbl, context.temp_allocator, context.temp_allocator)
|
table.init(&tbl, context.temp_allocator, context.temp_allocator)
|
||||||
table.padding(&tbl, 2, 0)
|
table.padding(&tbl, 2, 0)
|
||||||
if write_flags_table(&tbl, info.flags) {
|
write_flags_table(&tbl, info.flags)
|
||||||
fmt.wprintf(w, "\n", flush = false)
|
fmt.wprintf(w, "\n", flush = false)
|
||||||
write_borderless_table(w, &tbl)
|
write_borderless_table(w, &tbl)
|
||||||
}
|
|
||||||
table_reset(&tbl)
|
table_reset(&tbl)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@@ -267,8 +266,7 @@ flag_field_info :: proc(
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
write_flags_table :: proc(tbl: ^table.Table, flags: bit_set[Flag_Type]) -> (has_rows: bool) {
|
write_flags_table :: proc(tbl: ^table.Table, flags: bit_set[Flag_Type]) {
|
||||||
if flags == {} do return false
|
|
||||||
table.caption(tbl, "Flags:")
|
table.caption(tbl, "Flags:")
|
||||||
for ft in Flag_Type {
|
for ft in Flag_Type {
|
||||||
if ft not_in flags do continue
|
if ft not_in flags do continue
|
||||||
@@ -285,7 +283,6 @@ write_flags_table :: proc(tbl: ^table.Table, flags: bit_set[Flag_Type]) -> (has_
|
|||||||
table.row(tbl, colorize(.Flag, names, tbl.format_allocator), desc)
|
table.row(tbl, colorize(.Flag, names, tbl.format_allocator), desc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
find_command :: proc(name: string) -> (CommandInfo, bool) {
|
find_command :: proc(name: string) -> (CommandInfo, bool) {
|
||||||
@@ -365,9 +362,8 @@ at before, restore your backup with:
|
|||||||
write_borderless_table(w, &tbl)
|
write_borderless_table(w, &tbl)
|
||||||
table_reset(&tbl)
|
table_reset(&tbl)
|
||||||
|
|
||||||
if write_flags_table(&tbl, GLOBAL_FLAGS) {
|
write_flags_table(&tbl, GLOBAL_FLAGS)
|
||||||
write_borderless_table(w, &tbl)
|
write_borderless_table(w, &tbl)
|
||||||
}
|
|
||||||
table_reset(&tbl)
|
table_reset(&tbl)
|
||||||
|
|
||||||
fmt.wprintf(
|
fmt.wprintf(
|
||||||
|
|||||||
@@ -35,18 +35,18 @@ parse_ssh_public_key :: proc(pub_path: string) -> (pub: [32]u8, ok: bool) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
offset := 0
|
rest := decoded
|
||||||
key_type, type_ok := read_wire_string(decoded, &offset)
|
key_type, type_ok := read_wire_string(&rest)
|
||||||
if !type_ok || key_type != SSH_ED25519 {
|
if !type_ok || string(key_type) != SSH_ED25519 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
pk_data, pk_ok := read_wire_string(decoded, &offset)
|
pk_data, pk_ok := read_wire_string(&rest)
|
||||||
if !pk_ok || len(pk_data) != 32 {
|
if !pk_ok || len(pk_data) != 32 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
mem.copy_non_overlapping(&pub[0], raw_data(pk_data), 32)
|
mem.copy_non_overlapping(&pub[0], &pk_data[0], 32)
|
||||||
|
|
||||||
ok = true
|
ok = true
|
||||||
return
|
return
|
||||||
@@ -91,81 +91,63 @@ parse_ssh_private_key :: proc(priv_path: string) -> (kp: Ed25519Keypair, ok: boo
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
offset := len(magic)
|
rest := decoded[len(magic):]
|
||||||
|
|
||||||
ciphername, cipher_ok := read_wire_string(decoded, &offset)
|
ciphername, cipher_ok := read_wire_string(&rest)
|
||||||
if !cipher_ok || ciphername != "none" {
|
if !cipher_ok || string(ciphername) != "none" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
kdfname, kdf_ok := read_wire_string(decoded, &offset)
|
kdfname, kdf_ok := read_wire_string(&rest)
|
||||||
if !kdf_ok || kdfname != "none" {
|
if !kdf_ok || string(kdfname) != "none" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, opts_ok := read_wire_string(decoded, &offset)
|
_, opts_ok := read_wire_string(&rest)
|
||||||
if !opts_ok {
|
if !opts_ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if offset + 4 > len(decoded) {
|
num_keys, nkeys_ok := read_wire_u32(&rest)
|
||||||
|
if !nkeys_ok || num_keys != 1 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
num_keys := endian.get_u32(decoded[offset:offset + 4], .Big) or_return
|
_, pub_blob_ok := read_wire_string(&rest)
|
||||||
offset += 4
|
|
||||||
|
|
||||||
if num_keys != 1 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
_, pub_blob_ok := read_wire_string(decoded, &offset)
|
|
||||||
if !pub_blob_ok {
|
if !pub_blob_ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
priv_blob, priv_blob_ok := read_wire_string(decoded, &offset)
|
priv_blob, priv_blob_ok := read_wire_string(&rest)
|
||||||
if !priv_blob_ok {
|
if !priv_blob_ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
inner_offset := 0
|
inner := priv_blob
|
||||||
if inner_offset + 8 > len(priv_blob) {
|
|
||||||
|
check1, c1_ok := read_wire_u32(&inner)
|
||||||
|
check2, c2_ok := read_wire_u32(&inner)
|
||||||
|
if !c1_ok || !c2_ok || check1 != check2 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
check1 := endian.get_u32(
|
priv_type, type_ok := read_wire_string(&inner)
|
||||||
transmute([]u8)(priv_blob)[inner_offset:inner_offset + 4],
|
if !type_ok || string(priv_type) != SSH_ED25519 {
|
||||||
.Big,
|
|
||||||
) or_return
|
|
||||||
inner_offset += 4
|
|
||||||
check2 := endian.get_u32(
|
|
||||||
transmute([]u8)(priv_blob)[inner_offset:inner_offset + 4],
|
|
||||||
.Big,
|
|
||||||
) or_return
|
|
||||||
inner_offset += 4
|
|
||||||
|
|
||||||
if check1 != check2 {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
priv_type, type_ok := read_wire_string(transmute([]u8)priv_blob, &inner_offset)
|
pub_wire, pub_ok := read_wire_string(&inner)
|
||||||
if !type_ok || priv_type != SSH_ED25519 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
pub_wire, pub_ok := read_wire_string(transmute([]u8)priv_blob, &inner_offset)
|
|
||||||
if !pub_ok || len(pub_wire) != 32 {
|
if !pub_ok || len(pub_wire) != 32 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
mem.copy_non_overlapping(&kp.Public[0], raw_data(pub_wire), 32)
|
mem.copy_non_overlapping(&kp.Public[0], &pub_wire[0], 32)
|
||||||
|
|
||||||
priv_wire, priv_ok := read_wire_string(transmute([]u8)priv_blob, &inner_offset)
|
priv_wire, priv_ok := read_wire_string(&inner)
|
||||||
if !priv_ok || len(priv_wire) != 64 {
|
if !priv_ok || len(priv_wire) != 64 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
mem.copy_non_overlapping(&kp.Private[0], raw_data(priv_wire), 32)
|
mem.copy_non_overlapping(&kp.Private[0], &priv_wire[0], 32)
|
||||||
|
|
||||||
ok = true
|
ok = true
|
||||||
return
|
return
|
||||||
@@ -182,19 +164,22 @@ is_ed25519_key :: proc(
|
|||||||
return ok, nil
|
return ok, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
read_wire_string :: proc(data: []u8, offset: ^int) -> (s: string, ok: bool) {
|
read_wire_string :: proc(data: ^[]u8) -> (s: []u8, ok: bool) {
|
||||||
if offset^ + 4 > len(data) {
|
if len(data^) < 4 do return
|
||||||
return
|
length := endian.get_u32(data^[:4], .Big) or_return
|
||||||
}
|
data^ = data^[4:]
|
||||||
length := endian.get_u32(data[offset^:offset^ + 4], .Big) or_return
|
|
||||||
offset^ += 4
|
|
||||||
|
|
||||||
if offset^ + int(length) > len(data) {
|
if len(data^) < int(length) do return
|
||||||
return
|
s = data^[:int(length)]
|
||||||
}
|
data^ = data^[int(length):]
|
||||||
|
ok = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
s = string(data[offset^:offset^ + int(length)])
|
read_wire_u32 :: proc(data: ^[]u8) -> (v: u32, ok: bool) {
|
||||||
offset^ += int(length)
|
if len(data^) < 4 do return
|
||||||
|
v = endian.get_u32(data^[:4], .Big) or_return
|
||||||
|
data^ = data^[4:]
|
||||||
ok = true
|
ok = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-6
@@ -52,15 +52,15 @@ test_private_key_pub_matches_public_key :: proc(t: ^testing.T) {
|
|||||||
@(test)
|
@(test)
|
||||||
test_read_wire_string :: proc(t: ^testing.T) {
|
test_read_wire_string :: proc(t: ^testing.T) {
|
||||||
data := []u8{0, 0, 0, 5, u8('h'), u8('e'), u8('l'), u8('l'), u8('o'), 0, 0, 0, 0}
|
data := []u8{0, 0, 0, 5, u8('h'), u8('e'), u8('l'), u8('l'), u8('o'), 0, 0, 0, 0}
|
||||||
offset := 0
|
|
||||||
|
|
||||||
s, ok := read_wire_string(data, &offset)
|
buf := data
|
||||||
|
s, ok := read_wire_string(&buf)
|
||||||
testing.expect(t, ok, "expected read_wire_string to succeed")
|
testing.expect(t, ok, "expected read_wire_string to succeed")
|
||||||
testing.expect_value(t, s, "hello")
|
testing.expect_value(t, string(s), "hello")
|
||||||
testing.expect_value(t, offset, 9)
|
testing.expect_value(t, len(data) - len(buf), 9)
|
||||||
|
|
||||||
s2, ok2 := read_wire_string(data, &offset)
|
s2, ok2 := read_wire_string(&buf)
|
||||||
testing.expect(t, ok2, "expected second read to succeed")
|
testing.expect(t, ok2, "expected second read to succeed")
|
||||||
testing.expect_value(t, s2, "")
|
testing.expect_value(t, len(s2), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user