Skip to content

Commit

Permalink
feat: update zig and public key decode
Browse files Browse the repository at this point in the history
  • Loading branch information
speed2exe committed Nov 18, 2023
1 parent df1f92d commit 2293c3b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integrations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
run: |
# curl -L https://ziglang.org/download/ > page.xml
# ZIG_VERSION=$(cat page.xml | tidy -html 2> /dev/null | grep zig-linux-x86_64 | head -n 1 | cut -d '-' -f 4,5 | cut -d '.' -f 1,2,3,4)
ZIG_VERSION=0.12.0-dev.1390+94cee4fb2
ZIG_VERSION=0.12.0-dev.1642+5f8641401
echo "zig version: $ZIG_VERSION"
wget https://ziglang.org/builds/zig-linux-x86_64-$ZIG_VERSION.tar.xz
tar xf zig-linux-x86_64-$ZIG_VERSION.tar.xz
Expand Down
7 changes: 2 additions & 5 deletions src/auth.zig
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ pub const caching_sha2_password_full_authentication_start = 0x04;

pub const DecodedPublicKey = struct {
allocated: []const u8,
value: struct {
modulus: []const u8,
exponent: []const u8,
},
value: std.crypto.Certificate.rsa.PublicKey,

pub fn deinit(d: *const DecodedPublicKey, allocator: std.mem.Allocator) void {
allocator.free(d.allocated);
Expand Down Expand Up @@ -86,7 +83,7 @@ pub fn decodePublicKey(encoded_bytes: []const u8, allocator: std.mem.Allocator)
};

const pk_decoded = try std.crypto.Certificate.rsa.PublicKey.parseDer(bitstring);
decoded_pk.value = .{ .modulus = pk_decoded.modulus, .exponent = pk_decoded.exponent };
decoded_pk.value = try std.crypto.Certificate.rsa.PublicKey.fromBytes(pk_decoded.exponent, pk_decoded.modulus);
return decoded_pk;
}

Expand Down
13 changes: 8 additions & 5 deletions src/conn.zig
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,21 @@ pub const Conn = struct {
auth.caching_sha2_password_full_authentication_start => {
// Full Authentication start

// TODO: support TLS
// // if TLS, send password as plain text
// try conn.sendBytesAsPacket(config.password);

// Request public key from server
try conn.sendBytesAsPacket(&[_]u8{auth.caching_sha2_password_public_key_request});
const pk_packet = try conn.readPacket(allocator);
defer pk_packet.deinit(allocator);

// Decode public key
const pub_key = try auth.decodePublicKey(pk_packet.payload, allocator);
defer pub_key.deinit(allocator);

// TODO: support TLS
// // if TLS, send password as plain text
// try conn.sendBytesAsPacket(config.password);
// Encrypt password with public key
// TODO
const auth_resp = try generate_auth_response(.sha256_password, &auth_data, config.password);
try conn.sendBytesAsPacket(auth_resp.get());

Expand All @@ -236,8 +241,6 @@ pub const Conn = struct {
else => return packet.asError(conn.client_capabilities),
}
}

// Server ack
}

fn sendPacketUsingSmallPacketWriter(conn: *Conn, packet: anytype) !void {
Expand Down

0 comments on commit 2293c3b

Please sign in to comment.