Skip to content

Commit bdf2fbd

Browse files
authored
Merge pull request #15 from msirringhaus/extensions
Implement webauthn-extensions.
2 parents 913d883 + 7c67e16 commit bdf2fbd

File tree

9 files changed

+492
-187
lines changed

9 files changed

+492
-187
lines changed

webext/add-on/background.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,39 @@ function serializeRequest(options) {
7878
cred.id = serializeBytes(cred.id);
7979
}
8080
}
81+
if (clone.publicKey.extensions && clone.publicKey.extensions.prf) {
82+
if (clone.publicKey.extensions.prf.eval) {
83+
clone.publicKey.extensions.prf.eval.first = serializeBytes(clone.publicKey.extensions.prf.eval.first);
84+
if (clone.publicKey.extensions.prf.eval.second) {
85+
clone.publicKey.extensions.prf.eval.second = serializeBytes(clone.publicKey.extensions.prf.eval.second);
86+
}
87+
}
88+
if (clone.publicKey.extensions.prf.evalByCredential) {
89+
const evalByCredential = clone.publicKey.extensions.prf.evalByCredential;
90+
91+
// Iterate over all credentialIDs, serialize the first/second bytebuffer and replace the original evalByCredential map
92+
const result = {};
93+
for (const credId in evalByCredentialData) {
94+
const prfValue = evalByCredentialData[credId];
95+
96+
if (prfValue && prfValue.first) {
97+
const newPrfValue = {
98+
first: serializeBytes(prfValue.first)
99+
};
100+
101+
if (prfValue.second) {
102+
newPrfValue.second = serializeBytes(prfValue.second);
103+
}
104+
result[credId] = newPrfValue;
105+
};
106+
}
107+
clone.publicKey.extensions.prf.evalByCredential = result;
108+
}
109+
110+
if (clone.publicKey.extensions && clone.publicKey.extensions.credBlob) {
111+
clone.publicKey.extensions.credBlob = serializeBytes(clone.publicKey.extensions.credBlob);
112+
}
113+
}
81114
return clone
82115
}
83116

webext/add-on/content.js

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ function endRequest(requestId, data, error) {
2929
request.resolve(data)
3030
}
3131
}
32+
3233
async function cloneCredentialResponse(credential) {
3334
try {
3435
const options = { alphabet: "base64url" }
@@ -82,13 +83,44 @@ async function cloneCredentialResponse(credential) {
8283
else {
8384
throw cloneInto(new Error("Unknown credential response type received"), window)
8485
}
86+
87+
// Unlike CreatePublicKey, for GetPublicKey, we have a lot of Byte arrays,
88+
// so we need a lot of deconstructions. So no: obj.clientExtensionResults = cloneInto(credential.clientExtensionResults, obj);
89+
const extensions = {}
90+
if (credential.clientExtensionResults) {
91+
if (credential.clientExtensionResults.hmac_get_secret) {
92+
extensions.hmac_get_secret = {}
93+
extensions.hmac_get_secret.output1 = Uint8Array.fromBase64(credential.clientExtensionResults.hmac_get_secret.output1, options);
94+
if (credential.clientExtensionResults.hmac_get_secret.output2) {
95+
extensions.hmac_get_secret.output2 = Uint8Array.fromBase64(credential.clientExtensionResults.hmac_get_secret.output2, options);
96+
}
97+
}
98+
99+
if (credential.clientExtensionResults.prf) {
100+
extensions.prf = {}
101+
if (credential.clientExtensionResults.prf.results) {
102+
extensions.prf.results = {}
103+
extensions.prf.results.first = Uint8Array.fromBase64(credential.clientExtensionResults.prf.results.first, options);
104+
if (credential.clientExtensionResults.prf.results.second) {
105+
extensions.prf.results.second = Uint8Array.fromBase64(credential.clientExtensionResults.prf.results.second, options);
106+
}
107+
}
108+
}
109+
110+
if (credential.clientExtensionResults.large_blob) {
111+
extensions.large_blob = {}
112+
if (credential.clientExtensionResults.large_blob.blob) {
113+
extensions.large_blob.blob = Uint8Array.fromBase64(credential.clientExtensionResults.large_blob.blob, options);
114+
}
115+
}
116+
}
85117
obj.response = cloneInto(response, obj, { cloneFunctions: true })
86-
obj.clientExtensionResults = new window.Object();
118+
obj.clientExtensionResults = extensions;
87119
obj.getClientExtensionResults = function() {
88-
// TODO
89-
return this.clientExtensionResults
120+
return this.clientExtensionResults;
90121
}
91122
obj.type = "public-key"
123+
92124
obj.toJSON = function() {
93125
json = new window.Object();
94126
json.id = this.id
@@ -115,8 +147,8 @@ async function cloneCredentialResponse(credential) {
115147
throw cloneInto(new Error("Unknown credential type received"), window)
116148
}
117149

118-
json.authenticatorAttachment = this.authenticatorAttachment
119-
json.clientExtensionResults = this.clientExtensionResults
150+
json.authenticatorAttachment = this.authenticatorAttachment;
151+
json.clientExtensionResults = this.clientExtensionResults;
120152
json.type = this.type
121153
return json
122154
}

webext/add-on/manifest.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
32
"description": "Linux WebAuthn Desktop Portal Shim",
43
"manifest_version": 3,
54
"name": "WebAuthn Portal",
@@ -20,7 +19,7 @@
2019
},
2120
"content_scripts": [
2221
{
23-
"matches": ["https://webauthn.io/*"],
22+
"matches": ["https://webauthn.io/*", "https://demo.yubico.com/*"],
2423
"js": ["content.js"],
2524
"run_at": "document_start"
2625
}
@@ -31,5 +30,4 @@
3130
},
3231

3332
"permissions": ["nativeMessaging"]
34-
3533
}

xyz-iinuwa-credential-manager-portal-gtk/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

xyz-iinuwa-credential-manager-portal-gtk/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ openssl = "0.10.72"
1616
ring = "0.17.14"
1717
serde = { version = "1.0.219", features = ["derive"] }
1818
serde_json = "1.0.140"
19+
# serde_cbor = "0.11.1"
1920
tracing = "0.1.41"
2021
tracing-subscriber = "0.3"
2122
zbus = "5.5.0"
22-
libwebauthn = { git = "https://github.com/linux-credentials/libwebauthn", rev = "24eb47113e2282ff31c53de3029928e914349559" }
23+
libwebauthn = { git = "https://github.com/linux-credentials/libwebauthn", rev = "dc23daed528f512f2bcb61fce9eb6b8ee74066e2" }
2324
async-trait = "0.1.88"
2425
tokio = { version = "1", features = ["rt-multi-thread"] }
2526

0 commit comments

Comments
 (0)