╭─────────────╮ │scroll to top│ ╰─────────────╯ ╭ serve_ssh.zig ────────────────────────────────────────────────╮ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ╰───────────────────────────────────────────────────────────────╯
╭────╮ ╭ clone ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╮ │http│ ssh │ │ ╰────╯ ╰ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ╯
607 user_id: *const [evt.event_id_size]u8, 608 ) !evt.CommitAuthor { 609 const user = (try evt.User.readById(evt.AdminDB, evt.admin_repo_opts.hash, moment, arena, user_id)) orelse unreachable; 610 return .{ .name = user.event.name, .email = user.event.email }; 611 } 612 613 // the authorized_keys line of a pubkey blob: its type, then the blob in base64 614 fn authorizedKeyLine(allocator: std.mem.Allocator, blob: []const u8) ![]const u8 { 615 var reader = std.Io.Reader.fixed(blob); 616 const key_type = try ssh.takeString(&reader, 64); 617 const encoder = std.base64.standard.Encoder; 618 const line = try allocator.alloc(u8, key_type.len + 1 + encoder.calcSize(blob.len)); 619 @memcpy(line[0..key_type.len], key_type); 620 line[key_type.len] = ' '; 621 _ = encoder.encode(line[key_type.len + 1 ..], blob); 622 return line; 623 } 624 625 fn writeError(sess: *ssh.SessionCtx, comptime msg: []const u8) !void { 626 const body = "ERR haxy ssh: " ++ msg; 627 var packet: [body.len + 4]u8 = undefined; 628 const line = try std.fmt.bufPrint(&packet, "{x:0>4}{s}", .{ packet.len, body }); 629 try sess.writeBytes(line); 630 try sess.exit(1); 631 } 632 633 test "parseGitCommand rejects malformed input" { 634 const allocator = std.testing.allocator; 635 try std.testing.expectError(error.InvalidCommand, parseGitCommand(allocator, "git-upload-pack")); 636 try std.testing.expectError(error.UnsupportedService, parseGitCommand(allocator, "ls -la")); 637 try std.testing.expectError(error.UnsupportedService, parseGitCommand(allocator, "git-fake-pack 'repo'")); 638 } 639 640 test "parseGitCommand happy paths" { 641 const allocator = std.testing.allocator; 642 643 { 644 const parsed = try parseGitCommand(allocator, "git-upload-pack 'some-repo'"); 645 defer parsed.deinit(allocator); 646 try std.testing.expectEqual(GitService.upload_pack, parsed.service); 647 try std.testing.expectEqualStrings("some-repo", parsed.dir); 648 } 649 { 650 const parsed = try parseGitCommand(allocator, "git-receive-pack 'user/proj'"); 651 defer parsed.deinit(allocator); 652 try std.testing.expectEqual(GitService.receive_pack, parsed.service); 653 try std.testing.expectEqualStrings("user/proj", parsed.dir); 654 } 655 { 656 const parsed = try parseGitCommand(allocator, "git-upload-pack repo"); 657 defer parsed.deinit(allocator); 658 try std.testing.expectEqual(GitService.upload_pack, parsed.service); 659 try std.testing.expectEqualStrings("repo", parsed.dir); 660 } 661 } 662