Bind passkey answers to their request and keep Google out of the key's page

A late passkey answer now counts only for the request that asked, and a copy
is sealed only for the account the passkey was made for. Browsers open Google
in its own window and run none of its code beside the account key, so Google
is offered only on the Entity site, which serves the page it returns to. PRF
buffers are cleared where the runtime allows.
This commit is contained in:
waozi committed 2026-11-01 20:50:25 -03:00
1 parent 1815ffd325
commit 298a5413fa
6 files changed
+212 -113

No files matched your search

+5 -3
View File
@@ -164,9 +164,11 @@ lost password.
Use the same Cloud project as Drive above.
1. In [Clients](https://console.cloud.google.com/auth/clients), create a **Web
application** client. Add `https://entity.waozi.xyz` and `https://waozi.xyz`
under Authorized JavaScript origins. Copy its client ID; it is not a secret.
See [Google's client ID guide](https://developers.google.com/identity/gsi/web/guides/get-google-api-clientid).
application** client. Add `https://entity.waozi.xyz/google-signin.html` under
Authorized redirect URIs. Copy its client ID; it is not a secret. Browsers offer
Google only on the Entity site: no Google script runs beside the account key,
so Google's page opens in its own window. See
[Google's OpenID Connect guide](https://developers.google.com/identity/openid-connect/openid-connect).
2. Keep the Android OAuth clients from Drive step 4, one per package and signing
certificate pair. Sign in with Google needs them too.
3. In [Data Access](https://console.cloud.google.com/auth/scopes) add only
@@ -48,6 +48,8 @@ public final class SignInBridge {
private static final Object lock = new Object();
private static String answer = "{\"status\":\"cancelled\"}";
private static CancellationSignal cancellation;
// A result counts only for the operation that asked; cancelling ends it.
private static long generation;
private SignInBridge() {
}
@@ -90,8 +92,17 @@ public final class SignInBridge {
}
}
private static void finish(String value) {
private static long currentOperation() {
synchronized (lock) {
return generation;
}
}
private static void finish(long operation, String value) {
synchronized (lock) {
if (operation != generation) {
return;
}
answer = value;
cancellation = null;
}
@@ -99,6 +110,7 @@ public final class SignInBridge {
private static CancellationSignal begin() {
synchronized (lock) {
generation++;
answer = status("pending");
cancellation = new CancellationSignal();
return cancellation;
@@ -107,6 +119,7 @@ public final class SignInBridge {
private static void cancel() {
synchronized (lock) {
generation++;
if (cancellation != null) {
cancellation.cancel();
}
@@ -232,7 +245,9 @@ public final class SignInBridge {
JSONObject output = new JSONObject();
output.put("status", "ok");
output.put("credential", credential);
output.put("prf", hex(decode(first)));
byte[] value = decode(first);
output.put("prf", hex(value));
java.util.Arrays.fill(value, (byte) 0);
JSONObject inner = response.optJSONObject("response");
String handle = inner == null ? "" : inner.optString("userHandle", "");
if (!handle.isEmpty()) {
@@ -267,55 +282,56 @@ public final class SignInBridge {
return status("error");
}
CancellationSignal signal = begin();
final long operation = currentOperation();
CredentialManager.create(activity).createCredentialAsync(activity, new CreatePublicKeyCredentialRequest(requestJson),
signal, mainExecutor(activity), new CredentialManagerCallback<CreateCredentialResponse, CreateCredentialException>() {
@Override
public void onResult(CreateCredentialResponse result) {
created(activity, result);
created(activity, operation, result);
}
@Override
public void onError(CreateCredentialException error) {
finish(createFailure(error));
finish(operation, createFailure(error));
}
});
return status("pending");
}
private static void created(Activity activity, CreateCredentialResponse result) {
private static void created(Activity activity, long operation, CreateCredentialResponse result) {
if (!(result instanceof CreatePublicKeyCredentialResponse)) {
finish(status("error"));
finish(operation, status("error"));
return;
}
String responseJson = ((CreatePublicKeyCredentialResponse) result).getRegistrationResponseJson();
try {
String read = passkeyAnswer(responseJson);
if (!read.contains("no_prf")) {
finish(read);
finish(operation, read);
return;
}
if (!prfEnabled(responseJson)) {
finish(read);
finish(operation, read);
return;
}
read(activity, new JSONObject(responseJson).getString("rawId"));
read(activity, operation, new JSONObject(responseJson).getString("rawId"));
} catch (JSONException | NoSuchAlgorithmException error) {
finish(status("error"));
finish(operation, status("error"));
}
}
private static String get(Activity activity) {
begin();
read(activity, "");
read(activity, currentOperation(), "");
return status("pending");
}
private static void read(Activity activity, String credentialId) {
private static void read(Activity activity, long operation, String credentialId) {
final String requestJson;
try {
requestJson = getRequest(credentialId);
} catch (JSONException error) {
finish(status("error"));
finish(operation, status("error"));
return;
}
CancellationSignal signal;
@@ -331,19 +347,19 @@ public final class SignInBridge {
public void onResult(GetCredentialResponse result) {
Credential credential = result.getCredential();
if (!(credential instanceof PublicKeyCredential)) {
finish(status("error"));
finish(operation, status("error"));
return;
}
try {
finish(passkeyAnswer(((PublicKeyCredential) credential).getAuthenticationResponseJson()));
finish(operation, passkeyAnswer(((PublicKeyCredential) credential).getAuthenticationResponseJson()));
} catch (JSONException | NoSuchAlgorithmException error) {
finish(status("error"));
finish(operation, status("error"));
}
}
@Override
public void onError(GetCredentialException error) {
finish(getFailure(error));
finish(operation, getFailure(error));
}
});
}
@@ -357,6 +373,7 @@ public final class SignInBridge {
.addCredentialOption(option.build())
.build();
CancellationSignal signal = begin();
final long operation = currentOperation();
CredentialManager.create(activity).getCredentialAsync(activity, request, signal, mainExecutor(activity),
new CredentialManagerCallback<GetCredentialResponse, GetCredentialException>() {
@Override
@@ -365,7 +382,7 @@ public final class SignInBridge {
if (!(credential instanceof CustomCredential) ||
!GoogleIdTokenCredential.TYPE_GOOGLE_ID_TOKEN_CREDENTIAL.equals(credential.getType()) &&
!GoogleIdTokenCredential.TYPE_GOOGLE_ID_TOKEN_SIWG_CREDENTIAL.equals(credential.getType())) {
finish(status("error"));
finish(operation, status("error"));
return;
}
try {
@@ -373,15 +390,15 @@ public final class SignInBridge {
JSONObject output = new JSONObject();
output.put("status", "ok");
output.put("token", token);
finish(output.toString());
finish(operation, output.toString());
} catch (JSONException error) {
finish(status("error"));
finish(operation, status("error"));
}
}
@Override
public void onError(GetCredentialException error) {
finish(getFailure(error));
finish(operation, getFailure(error));
}
});
return status("pending");
+7
View File
@@ -99,6 +99,7 @@ ManagementProvider :: struct {
sign_in_message: [160]u8
passkey_keys: RecoveryKeys
passkey_credential: [65]u8
passkey_account: [65]u8
passkey_count: s32
passkeys: [MANAGEMENT_PASSKEY_LIMIT]ManagementPasskey
google_client: [256]u8
@@ -790,6 +791,7 @@ ProviderMethodsPump :: (provider: *ManagementProvider) {
ProviderPasskeyForget :: (provider: *ManagementProvider) {
RecoveryKeysClear(*provider.passkey_keys)
provider.passkey_credential = .{}
provider.passkey_account = .{}
}
ProviderBridgeFinish :: (provider: *ManagementProvider, result: string, message: string) {
@@ -816,6 +818,7 @@ ProviderPasskeyStart :: (provider: *ManagementProvider, adding: bool) {
state := ProviderState(provider)
name := TextUntilNul(state.alias[:])
if name == "" { name = TextUntilNul(state.public_id[:]) }
unused CopyCString(TextUntilNul(state.public_id[:]), provider.passkey_account[:])
started = PasskeyBridgeCreate(TextUntilNul(state.public_id[:]), name)
provider.bridge_operation = 1
} else {
@@ -862,6 +865,10 @@ ProviderPasskeyUpload :: (provider: *ManagementProvider, answer: *SignInAnswer)
ProviderBridgeFinish(provider, "error", "No account is signed in on this device")
return
}
if !SignInSameAccount(TextUntilNul(provider.passkey_account[:]), TextUntilNul(recovery.keys.public_id[:])) {
ProviderBridgeFinish(provider, "error", "The account changed while adding this passkey. Add it again.")
return
}
wrapper: [ACCOUNT_EXPORT_ENCRYPTED_TEXT_SIZE]u8
defer { SecureWipe(*wrapper[0], wrapper.count) }
label: [64]u8
+148 -89
View File
@@ -161,6 +161,11 @@ SignInPasskeyList :: (reply: string, output: []ManagementPasskey) -> s32 {
return kept
}
// A passkey made for one account never seals another that signed in meanwhile.
SignInSameAccount :: (expected: string, current: string) -> bool {
return expected != "" && expected == current
}
// A plain name for the list of passkeys, so a person can tell them apart.
SignInDeviceLabel :: (output: []u8) -> string {
name := "Passkey"
@@ -176,20 +181,25 @@ SignInDeviceLabel :: (output: []u8) -> string {
#if #defined(PLATFORM_WEB) {
bridge_answer: SignInAnswer;
bridge_pending: bool;
// A callback counts only for the request that made it; finishing ends it.
bridge_generation: s32;
// 1 waits for a new passkey, 2 for a passkey's PRF value.
bridge_step: s32;
bridge_abort: s32;
bridge_account: [65]u8;
bridge_overlay: s32;
bridge_google_client: [160]u8;
bridge_google_nonce: [65]u8;
bridge_google_ready: bool;
bridge_google_state: [33]u8;
bridge_google_url: [1200]u8;
bridge_channel: s32;
BridgeFinish :: (status: string) {
unused CopyCString(status, bridge_answer.status[:])
bridge_pending = false
bridge_step = 0
bridge_generation += 1
BridgeOverlayClose()
BridgeChannelClose()
if bridge_abort != 0 { WebRelease(bridge_abort); bridge_abort = 0 }
}
@@ -257,9 +267,10 @@ SignInDeviceLabel :: (output: []u8) -> string {
data: [64]u8
count := WebCopyOut(bytes, cast(*void)*data[0], cast(s32)data.count)
if count <= 0 || count != limit { return 0 }
if BytesToHex(*data[0], cast(s64)count, *output[0], output.count) == 0 { return 0 }
written := BytesToHex(*data[0], cast(s64)count, *output[0], output.count)
SecureWipe(*data[0], data.count)
return count
unused WebCall1(bytes, WebName("fill"), WebNumber(0.0))
return ifx written == 0 then 0 else count
}
// The credential is named by its SHA-256, so its length does not matter.
@@ -335,12 +346,11 @@ SignInDeviceLabel :: (output: []u8) -> string {
}
BridgeResolved :: (context: s32, first: s32, second: s32, third: s32) {
unused context
unused second
unused third
scope := WebScope()
defer WebEnd(scope)
if !bridge_pending { return }
if !bridge_pending || context != bridge_generation { return }
if first == 0 || WebTypeOf(first) != WebTypeObject { BridgeFinish("cancelled"); return }
if !BridgeCredentialHash(first) { BridgeFinish("error"); return }
if BridgePrfValue(first) {
@@ -358,12 +368,11 @@ SignInDeviceLabel :: (output: []u8) -> string {
}
BridgeRejected :: (context: s32, first: s32, second: s32, third: s32) {
unused context
unused second
unused third
scope := WebScope()
defer WebEnd(scope)
if !bridge_pending { return }
if !bridge_pending || context != bridge_generation { return }
name: [40]u8
handle := WebAsObject(WebGet(first, WebName("name")))
if handle != 0 && !WebFailed() { unused WebCopyString(handle, name[:]) }
@@ -385,8 +394,8 @@ SignInDeviceLabel :: (output: []u8) -> string {
if bridge_abort != 0 { WebSet(wrapper, WebName("signal"), WebGet(bridge_abort, WebName("signal"))) }
promise := WebAsObject(WebCall1(credentials, WebName(method), WebObject(wrapper)))
if promise == 0 || WebFailed() { return false }
resolved := WebFunction(BridgeResolved, 0)
rejected := WebFunction(BridgeRejected, 0)
resolved := WebFunction(BridgeResolved, bridge_generation)
rejected := WebFunction(BridgeRejected, bridge_generation)
unused WebCall2(promise, WebName("then"), WebObject(resolved), WebObject(rejected))
return !WebFailed()
}
@@ -398,96 +407,137 @@ SignInDeviceLabel :: (output: []u8) -> string {
bridge_overlay = 0
}
BridgeGoogleToken :: (context: s32, first: s32, second: s32, third: s32) {
unused context
BridgeChannelClose :: () {
if bridge_channel == 0 { return }
unused WebCall0(bridge_channel, WebName("close"))
WebRelease(bridge_channel)
bridge_channel = 0
}
// Only the Entity site serves the page Google returns to.
BridgeGoogleHosted :: () -> bool {
location := WebGetObject(WebGlobal, WebName("location"))
if location == 0 || WebFailed() { return false }
handle := WebAsObject(WebGet(location, WebName("hostname")))
if handle == 0 || WebFailed() { return false }
host: [256]u8
length := WebCopyString(handle, host[:])
if length <= 0 || length >= cast(s32)host.count { return false }
name := TextUntilNul(host[:])
return name == "entity.waozi.xyz" || name == "localhost"
}
BridgeUrlAppend :: (value: string, at: *s64, encode: bool) -> bool {
digits := "0123456789ABCDEF"
for byte: value {
plain := !encode || (byte >= #char "a" && byte <= #char "z") || (byte >= #char "A" && byte <= #char "Z") ||
(byte >= #char "0" && byte <= #char "9") || byte == #char "-" || byte == #char "." || byte == #char "_" || byte == #char "~"
if at.* + 4 >= cast(s64)bridge_google_url.count { return false }
if plain {
bridge_google_url[at.*] = byte
at.* += 1
} else {
bridge_google_url[at.*] = #char "%"
bridge_google_url[at.* + 1] = digits[cast(s64)(byte >> 4)]
bridge_google_url[at.* + 2] = digits[cast(s64)(byte & cast(u8)15)]
at.* += 3
}
}
bridge_google_url[at.*] = cast(u8)0
return true
}
// Google's own page in its own window: no Google code runs beside the key.
BridgeGoogleAddress :: (nonce: string) -> bool {
location := WebGetObject(WebGlobal, WebName("location"))
if location == 0 || WebFailed() { return false }
handle := WebAsObject(WebGet(location, WebName("origin")))
if handle == 0 || WebFailed() { return false }
origin: [256]u8
length := WebCopyString(handle, origin[:])
if length <= 0 || length >= cast(s32)origin.count { return false }
at: s64 = 0
return BridgeUrlAppend("https://accounts.google.com/o/oauth2/v2/auth?response_type=id_token&scope=openid&prompt=select_account&client_id=", *at, false) &&
BridgeUrlAppend(TextUntilNul(bridge_google_client[:]), *at, true) &&
BridgeUrlAppend("&redirect_uri=", *at, false) &&
BridgeUrlAppend(TextUntilNul(origin[:]), *at, true) &&
BridgeUrlAppend("/google-signin.html", *at, true) &&
BridgeUrlAppend("&state=", *at, false) &&
BridgeUrlAppend(TextUntilNul(bridge_google_state[:]), *at, true) &&
BridgeUrlAppend("&nonce=", *at, false) &&
BridgeUrlAppend(nonce, *at, true)
}
BridgeGoogleMessage :: (context: s32, first: s32, second: s32, third: s32) {
unused second
unused third
scope := WebScope()
defer WebEnd(scope)
if !bridge_pending { return }
handle := WebAsObject(WebGet(first, WebName("credential")))
if !bridge_pending || context != bridge_generation { return }
data := WebAsObject(WebGet(first, WebName("data")))
if data == 0 || WebFailed() { return }
state: [33]u8
state_handle := WebAsObject(WebGet(data, WebName("state")))
if state_handle == 0 || WebFailed() { return }
length := WebCopyString(state_handle, state[:])
// Another tab's sign-in has another state: it is not an answer to this one.
if length != 32 || TextUntilNul(state[:]) != TextUntilNul(bridge_google_state[:]) { return }
handle := WebAsObject(WebGet(data, WebName("id_token")))
if handle == 0 || WebFailed() { BridgeFinish("error"); return }
length := WebCopyString(handle, bridge_answer.token[:])
if length <= 0 || length >= cast(s32)bridge_answer.token.count { BridgeFinish("error"); return }
length = WebCopyString(handle, bridge_answer.token[:])
if length <= 0 || length >= cast(s32)bridge_answer.token.count {
bridge_answer.token = .{}
BridgeFinish("cancelled")
return
}
BridgeFinish("ok")
}
BridgeGoogleCancel :: (context: s32, first: s32, second: s32, third: s32) {
unused context
unused first
unused second
unused third
if bridge_pending { BridgeFinish("cancelled") }
if bridge_pending && context == bridge_generation { BridgeFinish("cancelled") }
}
BridgeGoogleFailed :: (context: s32, first: s32, second: s32, third: s32) {
unused context
unused first
unused second
unused third
if bridge_pending { BridgeFinish("error") }
}
// Google's button has to be Google's own element, over the canvas.
BridgeGoogleShow :: () {
document := WebGetObject(WebGlobal, WebName("document"))
google := WebGetObject(WebGlobal, WebName("google"))
if document == 0 || google == 0 || WebFailed() { BridgeFinish("unsupported"); return }
accounts := WebGetObject(google, WebName("accounts"))
identity := WebGetObject(accounts, WebName("id"))
if identity == 0 || WebFailed() { BridgeFinish("unsupported"); return }
settings := WebNewObject()
WebSet(settings, WebName("client_id"), WebText(TextUntilNul(bridge_google_client[:])))
WebSet(settings, WebName("callback"), WebObject(WebFunction(BridgeGoogleToken, 0)))
WebSet(settings, WebName("auto_select"), WebBool(false))
if bridge_google_nonce[0] != cast(u8)0 {
WebSet(settings, WebName("nonce"), WebText(TextUntilNul(bridge_google_nonce[:])))
}
unused WebCall1(identity, WebName("initialize"), WebObject(settings))
BridgeOverlayClose()
overlay := WebAsObject(WebCall1(document, WebName("createElement"), WebText("div")))
style := WebGetObject(overlay, WebName("style"))
WebSet(style, WebName("cssText"), WebText("position:fixed;inset:0;z-index:1000;display:grid;place-content:center;gap:16px;background:rgba(0,0,0,.55);padding:24px"))
holder := WebAsObject(WebCall1(document, WebName("createElement"), WebText("div")))
unused WebCall1(overlay, WebName("append"), WebObject(holder))
cancel := WebAsObject(WebCall1(document, WebName("createElement"), WebText("button")))
WebSet(cancel, WebName("type"), WebText("button"))
WebSet(cancel, WebName("textContent"), WebText("Cancel"))
WebSet(WebGetObject(cancel, WebName("style")), WebName("cssText"), WebText("padding:12px;border:0;border-radius:8px;font:16px system-ui,sans-serif;cursor:pointer"))
WebSet(cancel, WebName("onclick"), WebObject(WebFunction(BridgeGoogleCancel, 0)))
unused WebCall1(overlay, WebName("append"), WebObject(cancel))
unused WebCall1(WebGetObject(document, WebName("body")), WebName("append"), WebObject(overlay))
bridge_overlay = WebKeep(overlay)
button := WebNewObject()
WebSet(button, WebName("theme"), WebText("outline"))
WebSet(button, WebName("size"), WebText("large"))
WebSet(button, WebName("text"), WebText("signin_with"))
unused WebCall2(identity, WebName("renderButton"), WebObject(holder), WebObject(button))
if WebFailed() { BridgeFinish("error") }
}
BridgeGoogleLoaded :: (context: s32, first: s32, second: s32, third: s32) {
unused context
// Opening the window must come from this click, or browsers block it.
BridgeGoogleOpen :: (context: s32, first: s32, second: s32, third: s32) {
unused first
unused second
unused third
scope := WebScope()
defer WebEnd(scope)
bridge_google_ready = true
if bridge_pending { BridgeGoogleShow() }
if !bridge_pending || context != bridge_generation { return }
opened := WebAsObject(WebCall3(WebGlobal, WebName("open"), WebText(TextUntilNul(bridge_google_url[:])), WebText("waozi-google"), WebText("popup,width=480,height=640")))
if opened == 0 || WebFailed() { BridgeFinish("unsupported") }
}
BridgeGoogleLoad :: () -> bool {
// Google's script loads only once someone chooses Google.
if bridge_google_ready { BridgeGoogleShow(); return true }
BridgeGoogleShow :: () -> bool {
document := WebGetObject(WebGlobal, WebName("document"))
if document == 0 || WebFailed() { return false }
script := WebAsObject(WebCall1(document, WebName("createElement"), WebText("script")))
if script == 0 || WebFailed() { return false }
WebSet(script, WebName("src"), WebText("https://accounts.google.com/gsi/client"))
WebSet(script, WebName("onload"), WebObject(WebFunction(BridgeGoogleLoaded, 0)))
WebSet(script, WebName("onerror"), WebObject(WebFunction(BridgeGoogleFailed, 0)))
unused WebCall1(WebGetObject(document, WebName("head")), WebName("append"), WebObject(script))
constructor := WebGetObject(WebGlobal, WebName("BroadcastChannel"))
if document == 0 || constructor == 0 || WebFailed() { return false }
channel := WebNew1(constructor, WebText("waozi-google-signin"))
if channel == 0 || WebFailed() { return false }
bridge_channel = WebKeep(channel)
WebSet(bridge_channel, WebName("onmessage"), WebObject(WebFunction(BridgeGoogleMessage, bridge_generation)))
BridgeOverlayClose()
overlay := WebAsObject(WebCall1(document, WebName("createElement"), WebText("div")))
WebSet(WebGetObject(overlay, WebName("style")), WebName("cssText"), WebText("position:fixed;inset:0;z-index:1000;display:grid;place-content:center;gap:16px;background:rgba(0,0,0,.55);padding:24px"))
look := "padding:12px 20px;border:0;border-radius:8px;font:16px system-ui,sans-serif;cursor:pointer"
open_button := WebAsObject(WebCall1(document, WebName("createElement"), WebText("button")))
WebSet(open_button, WebName("type"), WebText("button"))
WebSet(open_button, WebName("textContent"), WebText("Continue with Google"))
WebSet(WebGetObject(open_button, WebName("style")), WebName("cssText"), WebText(look))
WebSet(open_button, WebName("onclick"), WebObject(WebFunction(BridgeGoogleOpen, bridge_generation)))
unused WebCall1(overlay, WebName("append"), WebObject(open_button))
cancel := WebAsObject(WebCall1(document, WebName("createElement"), WebText("button")))
WebSet(cancel, WebName("type"), WebText("button"))
WebSet(cancel, WebName("textContent"), WebText("Cancel"))
WebSet(WebGetObject(cancel, WebName("style")), WebName("cssText"), WebText(look))
WebSet(cancel, WebName("onclick"), WebObject(WebFunction(BridgeGoogleCancel, bridge_generation)))
unused WebCall1(overlay, WebName("append"), WebObject(cancel))
unused WebCall1(WebGetObject(document, WebName("body")), WebName("append"), WebObject(overlay))
bridge_overlay = WebKeep(overlay)
return !WebFailed()
}
}
@@ -582,11 +632,13 @@ PasskeyBridgeAvailable :: () -> bool {
return false
}
// Google needs its script (web) or the Play adapter (Android), and a client ID
// Google needs the Entity site (web) or the Play adapter (Android), and a client ID
// the node gave, so nothing offers Google before the owner has set it up.
GoogleBridgeAvailable :: () -> bool {
#if #defined(PLATFORM_WEB) {
return true
scope := WebScope()
defer WebEnd(scope)
return BridgeGoogleHosted()
}
#if #defined(ANDROID_BUILD) && #defined(GOOGLE_PLAY) {
output: [32]u8
@@ -634,6 +686,7 @@ PasskeyBridgeCreate :: (account: string, name: string) -> bool {
WebSet(options, WebName("timeout"), WebNumber(120000.0))
WebSet(options, WebName("extensions"), WebObject(BridgePrfExtension()))
bridge_answer = SignInAnswer.{}
bridge_generation += 1
bridge_pending = true
bridge_step = 1
if !BridgeRequest(credentials, "create", options) {
@@ -674,6 +727,7 @@ PasskeyBridgeGet :: () -> bool {
WebSet(options, WebName("timeout"), WebNumber(120000.0))
WebSet(options, WebName("extensions"), WebObject(BridgePrfExtension()))
bridge_answer = SignInAnswer.{}
bridge_generation += 1
bridge_pending = true
bridge_step = 2
if !BridgeRequest(credentials, "get", options) {
@@ -695,11 +749,20 @@ GoogleBridgeStart :: (client: string, nonce: string) -> bool {
#if #defined(PLATFORM_WEB) {
scope := WebScope()
defer WebEnd(scope)
if bridge_pending || !CopyCString(client, bridge_google_client[:]) || !CopyCString(nonce, bridge_google_nonce[:]) { return false }
if bridge_pending || !CopyCString(client, bridge_google_client[:]) { return false }
// The redirect form requires a nonce even when nothing is bound to it.
random: [16]u8
fresh_nonce: [33]u8
unused SecureRandom(*random[0], random.count)
if BytesToHex(*random[0], 16, *fresh_nonce[0], fresh_nonce.count) == 0 { return false }
unused SecureRandom(*random[0], random.count)
if BytesToHex(*random[0], 16, *bridge_google_state[0], bridge_google_state.count) == 0 { return false }
if !BridgeGoogleAddress(ifx nonce == "" then TextUntilNul(fresh_nonce[:]) else nonce) { return false }
bridge_answer = SignInAnswer.{}
bridge_generation += 1
bridge_pending = true
if !BridgeGoogleLoad() {
bridge_pending = false
if !BridgeGoogleShow() {
BridgeFinish("unsupported")
return false
}
return true
@@ -766,12 +829,8 @@ SignInBridgeForget :: () {
scope := WebScope()
defer WebEnd(scope)
bridge_google_client[0] = cast(u8)0
bridge_google_nonce[0] = cast(u8)0
google := WebGetObject(WebGlobal, WebName("google"))
if google == 0 || WebFailed() { return }
accounts := WebGetObject(google, WebName("accounts"))
identity := WebGetObject(accounts, WebName("id"))
if identity != 0 && !WebFailed() { unused WebCall0(identity, WebName("disableAutoSelect")) }
bridge_google_state[0] = cast(u8)0
bridge_google_url[0] = cast(u8)0
}
#if #defined(ANDROID_BUILD) && #defined(GOOGLE_PLAY) {
output: [64]u8
+2
View File
@@ -121,6 +121,8 @@ main :: () -> s32 {
if PasskeyOpenReply(TextUntilNul(reply[:]), other_id, CREDENTIAL_A, *keys_a, *wrong) { return 33 }
if !ReplyFor(other_id, text, reply[:]) { return 34 }
if PasskeyOpenReply(TextUntilNul(reply[:]), other_id, CREDENTIAL_A, *keys_a, *wrong) { return 35 }
// A late passkey answer cannot seal an account that signed in meanwhile.
if !SignInSameAccount(public_id, public_id) || SignInSameAccount(public_id, other_id) || SignInSameAccount("", "") { return 62 }
// Without a platform to ask, nothing is offered and nothing pretends.
if PasskeyBridgeAvailable() || GoogleBridgeAvailable() { return 40 }
if PasskeyBridgeCreate(public_id, "name") || PasskeyBridgeGet() || GoogleBridgeStart("client", "") { return 41 }
+12
View File
@@ -0,0 +1,12 @@
<!doctype html>
<meta charset="utf-8">
<title>Waozi</title>
<!-- Hands Google's answer to the page that asked; it runs nothing from anywhere else. -->
<script>
const answer = new URLSearchParams(location.hash.slice(1));
history.replaceState(null, '', location.pathname);
const channel = new BroadcastChannel('waozi-google-signin');
channel.postMessage({state: answer.get('state') || '', id_token: answer.get('id_token') || ''});
channel.close();
close();
</script>