Skip to content

Commit d97079a

Browse files
committed
Conformance test server
1 parent f95305b commit d97079a

File tree

7 files changed

+1600
-0
lines changed

7 files changed

+1600
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ zig-out/
55
CLAUDE.md
66
copilot-instructions.md
77
codex.md
8+
**/.claude
9+

conformance/Conformance-Test-API.md

Lines changed: 537 additions & 0 deletions
Large diffs are not rendered by default.

conformance/README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# FIDO2 Conformance Test Server
2+
3+
This is a minimal implementation of a FIDO2 conformance test server that implements the required API for FIDO2 conformance testing. It uses the Passcay library for server-side WebAuthn operations.
4+
5+
It implements [FIDO2: Conformance testing server API](https://github.com/fido-alliance/conformance-test-tools-resources/blob/main/docs/FIDO2/Server/Conformance-Test-API.md)
6+
7+
## Overview
8+
9+
This project implements a complete HTTP server using Karl Seguin's http.zig library to create a FIDO2 conformance test server. It demonstrates how to use the Passcay library for FIDO2 operations and provides a working HTTP API that conforms to the FIDO2 conformance testing requirements.
10+
11+
The implementation supports both ES256 (ECDSA with P-256) and RS256 (RSA-PKCS1-v1_5 with SHA-256) signature algorithms for WebAuthn operations.
12+
13+
## Features
14+
15+
- Complete HTTP server implementation with all required FIDO2 endpoints
16+
- In-memory storage for user credentials and challenges
17+
- Support for both ES256 and RS256 verification
18+
- Built-in verification tests for both algorithms
19+
- Comprehensive error handling and JSON responses
20+
- Challenge generation and verification
21+
- Base64URL encoding utilities
22+
23+
## HTTP API Endpoints
24+
25+
The server implements the following endpoints required by the FIDO2 conformance test suite:
26+
27+
### Registration (Attestation)
28+
29+
- `POST /attestation/options` - Get options for WebAuthn credential creation
30+
- `POST /attestation/result` - Register a new credential with attestation
31+
32+
### Authentication (Assertion)
33+
34+
- `POST /assertion/options` - Get options for WebAuthn credential verification
35+
- `POST /assertion/result` - Verify an existing credential
36+
37+
## Building and Running
38+
39+
To build and run the server:
40+
41+
```bash
42+
# Navigate to the conformance directory
43+
cd conformance
44+
45+
# Build the server
46+
zig build
47+
48+
# Run the server
49+
zig build run
50+
```
51+
52+
The server will:
53+
1. Run verification tests for ES256 and RS256 to ensure the Passcay library is working correctly
54+
2. Start an HTTP server on port 8080 (configurable in main.zig)
55+
3. Accept requests on all the required FIDO2 endpoints
56+
57+
## Test Data
58+
59+
The implementation includes test data for both ES256 and RS256:
60+
61+
## Usage with Conformance Tools
62+
63+
The FIDO2 conformance test tool can be configured to use the following URLs:
64+
65+
- Registration:
66+
- Options URL: `http://localhost:8080/attestation/options`
67+
- Result URL: `http://localhost:8080/attestation/result`
68+
69+
- Authentication:
70+
- Options URL: `http://localhost:8080/assertion/options`
71+
- Result URL: `http://localhost:8080/assertion/result`
72+
73+
## Security Considerations
74+
75+
This implementation is intended for testing purposes only.

conformance/build.zig

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
const std = @import("std");
2+
3+
// Although this function looks imperative, note that its job is to
4+
// declaratively construct a build graph that will be executed by an external
5+
// runner.
6+
pub fn build(b: *std.Build) void {
7+
// Standard target options allows the person running `zig build` to choose
8+
// what target to build for. Here we do not override the defaults, which
9+
// means any target is allowed, and the default is native. Other options
10+
// for restricting supported target set are available.
11+
const target = b.standardTargetOptions(.{});
12+
13+
// Standard optimization options allow the person running `zig build` to select
14+
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. Here we do not
15+
// set a preferred release mode, allowing the user to decide how to optimize.
16+
const optimize = b.standardOptimizeOption(.{});
17+
18+
// Get the dependencies
19+
const passcay = b.dependency("passcay", .{
20+
.target = target,
21+
.optimize = optimize,
22+
});
23+
24+
const httpz = b.dependency("httpz", .{
25+
.target = target,
26+
.optimize = optimize,
27+
});
28+
29+
// This creates a "module", which represents a collection of source files alongside
30+
// some compilation options, such as optimization mode and linked system libraries.
31+
// Every executable or library we compile will be based on one or more modules.
32+
const lib_mod = b.createModule(.{
33+
// `root_source_file` is the Zig "entry point" of the module. If a module
34+
// only contains e.g. external object files, you can make this `null`.
35+
// In this case the main source file is merely a path, however, in more
36+
// complicated build scripts, this could be a generated file.
37+
.root_source_file = b.path("src/root.zig"),
38+
.target = target,
39+
.optimize = optimize,
40+
});
41+
42+
// We will also create a module for our other entry point, 'main.zig'.
43+
const exe_mod = b.createModule(.{
44+
// `root_source_file` is the Zig "entry point" of the module. If a module
45+
// only contains e.g. external object files, you can make this `null`.
46+
// In this case the main source file is merely a path, however, in more
47+
// complicated build scripts, this could be a generated file.
48+
.root_source_file = b.path("src/main.zig"),
49+
.target = target,
50+
.optimize = optimize,
51+
});
52+
53+
// Add dependencies to our exe module
54+
exe_mod.addImport("conformance_lib", lib_mod);
55+
exe_mod.addImport("passcay", passcay.module("passcay"));
56+
exe_mod.addImport("httpz", httpz.module("httpz"));
57+
58+
// Now, we will create a static library based on the module we created above.
59+
// This creates a `std.Build.Step.Compile`, which is the build step responsible
60+
// for actually invoking the compiler.
61+
const lib = b.addLibrary(.{
62+
.linkage = .static,
63+
.name = "conformance",
64+
.root_module = lib_mod,
65+
});
66+
67+
// This declares intent for the library to be installed into the standard
68+
// location when the user invokes the "install" step (the default step when
69+
// running `zig build`).
70+
b.installArtifact(lib);
71+
72+
// This creates another `std.Build.Step.Compile`, but this one builds an executable
73+
// rather than a static library.
74+
const exe = b.addExecutable(.{
75+
.name = "conformance-server",
76+
.root_module = exe_mod,
77+
});
78+
79+
// No external libraries needed
80+
81+
// This declares intent for the executable to be installed into the
82+
// standard location when the user invokes the "install" step (the default
83+
// step when running `zig build`).
84+
b.installArtifact(exe);
85+
86+
// This *creates* a Run step in the build graph, to be executed when another
87+
// step is evaluated that depends on it. The next line below will establish
88+
// such a dependency.
89+
const run_cmd = b.addRunArtifact(exe);
90+
91+
// By making the run step depend on the install step, it will be run from the
92+
// installation directory rather than directly from within the cache directory.
93+
// This is not necessary, however, if the application depends on other installed
94+
// files, this ensures they will be present and in the expected location.
95+
run_cmd.step.dependOn(b.getInstallStep());
96+
97+
// This allows the user to pass arguments to the application in the build
98+
// command itself, like this: `zig build run -- arg1 arg2 etc`
99+
if (b.args) |args| {
100+
run_cmd.addArgs(args);
101+
}
102+
103+
// This creates a build step. It will be visible in the `zig build --help` menu,
104+
// and can be selected like this: `zig build run`
105+
// This will evaluate the `run` step rather than the default, which is "install".
106+
const run_step = b.step("run", "Run the app");
107+
run_step.dependOn(&run_cmd.step);
108+
109+
// Creates a step for unit testing. This only builds the test executable
110+
// but does not run it.
111+
const lib_unit_tests = b.addTest(.{
112+
.root_module = lib_mod,
113+
});
114+
115+
const run_lib_unit_tests = b.addRunArtifact(lib_unit_tests);
116+
117+
const exe_unit_tests = b.addTest(.{
118+
.root_module = exe_mod,
119+
});
120+
121+
const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
122+
123+
// Similar to creating the run step earlier, this exposes a `test` step to
124+
// the `zig build --help` menu, providing a way for the user to request
125+
// running the unit tests.
126+
const test_step = b.step("test", "Run unit tests");
127+
test_step.dependOn(&run_lib_unit_tests.step);
128+
test_step.dependOn(&run_exe_unit_tests.step);
129+
}

conformance/build.zig.zon

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
.{
2+
// This is the default name used by packages depending on this one. For
3+
// example, when a user runs `zig fetch --save <url>`, this field is used
4+
// as the key in the `dependencies` table. Although the user can choose a
5+
// different name, most users will stick with this provided value.
6+
//
7+
// It is redundant to include "zig" in this name because it is already
8+
// within the Zig package namespace.
9+
.name = .conformance,
10+
11+
// This is a [Semantic Version](https://semver.org/).
12+
// In a future version of Zig it will be used for package deduplication.
13+
.version = "0.0.0",
14+
15+
// Together with name, this represents a globally unique package
16+
// identifier. This field is generated by the Zig toolchain when the
17+
// package is first created, and then *never changes*. This allows
18+
// unambiguous detection of one package being an updated version of
19+
// another.
20+
//
21+
// When forking a Zig project, this id should be regenerated (delete the
22+
// field and run `zig build`) if the upstream project is still maintained.
23+
// Otherwise, the fork is *hostile*, attempting to take control over the
24+
// original project's identity. Thus it is recommended to leave the comment
25+
// on the following line intact, so that it shows up in code reviews that
26+
// modify the field.
27+
.fingerprint = 0xe81515e7170e9611, // Changing this has security and trust implications.
28+
29+
// Tracks the earliest Zig version that the package considers to be a
30+
// supported use case.
31+
.minimum_zig_version = "0.14.0",
32+
33+
// This field is optional.
34+
// Each dependency must either provide a `url` and `hash`, or a `path`.
35+
// `zig build --fetch` can be used to fetch all dependencies of a package, recursively.
36+
// Once all dependencies are fetched, `zig build` no longer requires
37+
// internet connectivity.
38+
.dependencies = .{
39+
// Using passcay from parent directory
40+
.passcay = .{
41+
.path = "..",
42+
},
43+
// HTTP server library
44+
.httpz = .{
45+
.url = "https://github.com/karlseguin/http.zig/archive/37d7cb9819b804ade5f4b974b82f8dd0622225ed.tar.gz",
46+
.hash = "1220691d0180da6d113ea3c61239d37435c7a1d070ce3603ae6a6c853c3888cdf769",
47+
},
48+
},
49+
50+
// Specifies the set of files and directories that are included in this package.
51+
// Only files and directories listed here are included in the `hash` that
52+
// is computed for this package. Only files listed here will remain on disk
53+
// when using the zig package manager. As a rule of thumb, one should list
54+
// files required for compilation plus any license(s).
55+
// Paths are relative to the build root. Use the empty string (`""`) to refer to
56+
// the build root itself.
57+
// A directory listed here means that all files within, recursively, are included.
58+
.paths = .{
59+
"build.zig",
60+
"build.zig.zon",
61+
"src",
62+
// For example...
63+
//"LICENSE",
64+
//"README.md",
65+
},
66+
}

0 commit comments

Comments
 (0)