Skip to content

Commit

Permalink
added new param to read_first callback. This allows to pass a hash in…
Browse files Browse the repository at this point in the history
…stead of a rpId.
  • Loading branch information
r4gus committed Oct 17, 2024
1 parent 9777056 commit cb1aba4
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions example/authenticator.zig
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,12 @@ pub fn my_up(
pub fn my_read_first(
id: ?dt.ABS64B,
rp: ?dt.ABS128T,
hash: ?[32]u8,
) CallbackError!Credential {
// The hash is mostly relevant for credential management
// because the client will only send a SHA256(rpId).
_ = hash;

std.log.info("my_first_read: {s}, {s}", .{
if (id) |uid| uid.get() else "n.a.",
if (rp) |rpid| rpid.get() else "n.a.",
Expand Down
1 change: 1 addition & 0 deletions lib/ctap/auth/Callbacks.zig
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ pub const UvCallback = ?*const fn (
pub const ReadFirstCallback = *const fn (
id: ?dt.ABS64B,
rp: ?dt.ABS128T,
hash: ?[32]u8,
) CallbackError!fido.ctap.authenticator.Credential;

/// This function can be called multiple times after calling the ReadFirstCallback to obtain the remaining credentials.
Expand Down
4 changes: 2 additions & 2 deletions lib/ctap/commands/authenticator/authenticatorGetAssertion.zig
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ pub fn authenticatorGetAssertion(
// ++++++++++++++++++++++++++++++++++++++++++++++++
var selected_credential: ?fido.ctap.authenticator.Credential = null;
var total_credentials: usize = 0;
var credential = auth.callbacks.read_first(null, gap.rpId) catch {
var credential = auth.callbacks.read_first(null, gap.rpId, null) catch {
return fido.ctap.StatusCodes.ctap2_err_no_credentials;
};

Expand Down Expand Up @@ -215,7 +215,7 @@ pub fn authenticatorGetAssertion(

// We previously iterated over all credentials, now we have to get back to the
// first one, so we can iterate over the remaining ones using getNextAssertion.
credential = auth.callbacks.read_first(null, gap.rpId) catch {
credential = auth.callbacks.read_first(null, gap.rpId, null) catch {
return fido.ctap.StatusCodes.ctap2_err_no_credentials;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ pub fn authenticatorMakeCredential(

if (mcp.excludeList) |ecllist| {
for (ecllist.get()) |item| {
const cred = auth.callbacks.read_first(item.id, null) catch {
const cred = auth.callbacks.read_first(item.id, null, null) catch {
continue;
};
// If the credential was created by this authenticator: Return.
Expand Down Expand Up @@ -392,7 +392,7 @@ pub fn authenticatorMakeCredential(
std.log.info("MakeCredential: creating resident key", .{});
entry.discoverable = true;

var credential = auth.callbacks.read_first(null, mcp.rp.id) catch {
var credential = auth.callbacks.read_first(null, mcp.rp.id, null) catch {
break :outer;
};

Expand Down

0 comments on commit cb1aba4

Please sign in to comment.