Skip to content

Commit 16be38a

Browse files
feat(psl): add DAFSA-format Public Suffix List reader (#215)
- Split psl.rs into psl/{mod,dat,dafsa,system} - DafsaFilePublicSuffixList: native libpsl .dafsa reader with BadMagic / BadHeader / Truncated / UnsupportedVersion errors - SystemPublicSuffixList::auto() probes DAFSA then DAT, picking whichever the distro ships - Hoist registrable_domain to a default trait method derived from public_suffix - CI installs publicsuffix and exercises the gated system-file PSL test
1 parent 4b677e6 commit 16be38a

10 files changed

Lines changed: 656 additions & 99 deletions

File tree

.github/workflows/rust.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
- name: Update apt cache
1515
run: sudo apt-get update
1616
- name: Install system dependencies
17-
run: sudo apt-get install libudev-dev libdbus-1-dev libsodium-dev libnfc-dev libpcsclite-dev
17+
run: sudo apt-get install libudev-dev libdbus-1-dev libsodium-dev libnfc-dev libpcsclite-dev publicsuffix
1818
- name: Clippy
1919
run: cargo clippy --workspace --all-targets --all-features -- -D warnings
2020
- name: Check formatting
@@ -27,5 +27,7 @@ jobs:
2727
run: cargo build -p libwebauthn --examples --features nfc-backend-libnfc
2828
- name: Run tests
2929
run: cargo test --workspace --verbose
30+
env:
31+
LIBWEBAUTHN_PSL_SYSTEM_TEST: "1"
3032
- name: Verify libwebauthn publishes cleanly
3133
run: cargo publish --dry-run -p libwebauthn

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ _Looking for the D-Bus API proposal?_ Check out [credentialsd][credentialsd].
4040

4141
## Runtime requirements
4242

43-
Validating the relying party ID against the calling origin requires the [Public Suffix List][psl]. The built-in loader reads it from the standard system path. The `publicsuffix` package on Debian/Ubuntu or `publicsuffix-list` on Fedora and Arch installs it there, but these are not always present on minimal installs. Install explicitly if needed. Callers wiring their own list don't need a system package.
43+
Validating the relying party ID against the calling origin requires the [Public Suffix List][psl]. The built-in `SystemPublicSuffixList::auto()` loader reads it from the standard system path, probing the binary `.dafsa` format first and falling back to the text `.dat` format. The `publicsuffix` package on Debian/Ubuntu ships both. On Fedora the binary `.dafsa` file is shipped by `publicsuffix-list-dafsa` (a transitive dependency of `libpsl`, so usually already installed), while the text `.dat` file requires the optional `publicsuffix-list` package. On Arch only the text `.dat` format is packaged. Callers wiring their own list don't need a system package.
4444

4545
## Transports
4646

libwebauthn/examples/ceremony/webauthn_cable.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use qrcode::QrCode;
1212
use tokio::time::sleep;
1313

1414
use libwebauthn::ops::webauthn::{
15-
DatFilePublicSuffixList, GetAssertionRequest, JsonFormat, MakeCredentialRequest, RequestOrigin,
15+
GetAssertionRequest, JsonFormat, MakeCredentialRequest, RequestOrigin, SystemPublicSuffixList,
1616
WebAuthnIDL as _, WebAuthnIDLResponse as _,
1717
};
1818
use libwebauthn::transport::{Channel as _, Device};
@@ -66,8 +66,8 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
6666

6767
let device_info_store = Arc::new(EphemeralDeviceInfoStore::default());
6868
let request_origin: RequestOrigin = "https://example.org".try_into().expect("Invalid origin");
69-
let psl = DatFilePublicSuffixList::from_system_file().expect(
70-
"PSL not available; install the publicsuffix-list package or pass an explicit path",
69+
let psl = SystemPublicSuffixList::auto().expect(
70+
"PSL not available; install the publicsuffix-list (or publicsuffix-list-dafsa) package, or pass an explicit path",
7171
);
7272

7373
{

libwebauthn/examples/ceremony/webauthn_hid.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::error::Error;
22
use std::time::Duration;
33

44
use libwebauthn::ops::webauthn::{
5-
DatFilePublicSuffixList, GetAssertionRequest, JsonFormat, MakeCredentialRequest, RequestOrigin,
5+
GetAssertionRequest, JsonFormat, MakeCredentialRequest, RequestOrigin, SystemPublicSuffixList,
66
WebAuthnIDL as _, WebAuthnIDLResponse as _,
77
};
88
use libwebauthn::proto::ctap2::Ctap2PublicKeyCredentialDescriptor;
@@ -29,8 +29,8 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
2929

3030
let request_origin: RequestOrigin =
3131
"https://example.org".try_into().expect("Invalid origin");
32-
let psl = DatFilePublicSuffixList::from_system_file().expect(
33-
"PSL not available; install the publicsuffix-list package or pass an explicit path",
32+
let psl = SystemPublicSuffixList::auto().expect(
33+
"PSL not available; install the publicsuffix-list (or publicsuffix-list-dafsa) package, or pass an explicit path",
3434
);
3535
let request_json = r#"
3636
{

libwebauthn/examples/ceremony/webauthn_nfc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::error::Error;
22

33
use libwebauthn::ops::webauthn::{
4-
DatFilePublicSuffixList, GetAssertionRequest, JsonFormat, MakeCredentialRequest, RequestOrigin,
4+
GetAssertionRequest, JsonFormat, MakeCredentialRequest, RequestOrigin, SystemPublicSuffixList,
55
WebAuthnIDL as _, WebAuthnIDLResponse as _,
66
};
77
use libwebauthn::transport::nfc::{get_nfc_device, is_nfc_available};
@@ -27,8 +27,8 @@ pub async fn main() -> Result<(), Box<dyn Error>> {
2727
let mut channel = device.channel().await?;
2828

2929
let request_origin: RequestOrigin = "https://example.org".try_into().expect("Invalid origin");
30-
let psl = DatFilePublicSuffixList::from_system_file().expect(
31-
"PSL not available; install the publicsuffix-list package or pass an explicit path",
30+
let psl = SystemPublicSuffixList::auto().expect(
31+
"PSL not available; install the publicsuffix-list (or publicsuffix-list-dafsa) package, or pass an explicit path",
3232
);
3333
let make_credentials_request = MakeCredentialRequest::from_json(
3434
&request_origin,

libwebauthn/src/ops/webauthn/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ pub use make_credential::{
3131
MakeCredentialsResponseExtensions, MakeCredentialsResponseUnsignedExtensions,
3232
ResidentKeyRequirement,
3333
};
34-
pub use psl::{DatFileLoadError, DatFilePublicSuffixList, PublicSuffixList, SYSTEM_PSL_PATH};
34+
pub use psl::{
35+
DafsaFileLoadError, DafsaFilePublicSuffixList, DatFileLoadError, DatFilePublicSuffixList,
36+
PublicSuffixList, SystemLoadError, SystemPublicSuffixList, SYSTEM_PSL_DAFSA_PATH,
37+
SYSTEM_PSL_PATH,
38+
};
3539
use serde::Deserialize;
3640

3741
#[derive(Debug, Clone, Copy, Deserialize, PartialEq)]

0 commit comments

Comments
 (0)