handoff: the native challenge hashes the verifier string (align with the Swift client)
Human
Prompt
Coordinator: align with the Swift client — verifier challenge = SHA-256 of the verifier STRING.
From this commit's own message. The prompt ledger has no entries for it — which is what a squashed, rebased or amended commit looks like, and what every commit looks like in a repo without a ledger.
Summary
challenge = base64url(SHA-256(the verifier's 43 ASCII characters)), the S256 convention rastrillo/native's /native/exchange already uses and the one the Swift client (rastrillo/native native/oficina-id-slice-a a1039a1) implements; the nonce derivation from the challenge is unchanged. New test vector.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+17
−13
handoff/native.go+10 −7handoff/native_test.go+7 −6
CI cancelled — superseded by a newer push — run details
diff --git a/handoff/native.go b/handoff/native.go| index 3b7f26d..889eb6a 100644 |
| --- a/handoff/native.go |
| +++ b/handoff/native.go |
| @@ -19,22 +19,25 @@ import ( |
| // On the wire every value is unpadded base64url: |
| // |
| // verifier = 32 random bytes (43 characters) |
| -// challenge = SHA-256(verifier bytes) (43 characters) |
| -// nonce = SHA-256("oficina-id/native/v1" || 0x00 || challenge bytes)[:16] |
| +// challenge = SHA-256(the verifier's 43 ASCII characters) |
| +// (43 characters) |
| +// nonce = SHA-256("oficina-id/native/v1" || 0x00 || challenge's 32 bytes)[:16] |
| // (22 characters) |
| // |
| -// The nonce is cut to 16 bytes because an assertion nonce is exactly that |
| -// (rastrillo assertion: 22 characters of 16 bytes). |
| +// The challenge hashes the verifier string, not its decoded bytes: that is |
| +// the S256 convention rastrillo/native's /native/exchange already uses, and |
| +// the one the Swift client implements. The nonce is cut to 16 bytes because |
| +// an assertion nonce is exactly that (rastrillo assertion: 22 characters of |
| +// 16 bytes). |
| const nativeNonceContext = "oficina-id/native/v1\x00" |
| // NativeChallenge is the challenge for a native verifier, or false unless |
| // the verifier is the canonical encoding of exactly 32 bytes. |
| func NativeChallenge(verifier string) (string, bool) { |
| - raw, ok := decode32(verifier) |
| - if !ok { |
| + if _, ok := decode32(verifier); !ok { |
| return "", false |
| } |
| - sum := sha256.Sum256(raw) |
| + sum := sha256.Sum256([]byte(verifier)) |
| return base64.RawURLEncoding.EncodeToString(sum[:]), true |
| } |
diff --git a/handoff/native_test.go b/handoff/native_test.go| index 1ca2513..7f57c29 100644 |
| --- a/handoff/native_test.go |
| +++ b/handoff/native_test.go |
| @@ -6,15 +6,16 @@ import ( |
| ) |
| // A fixed vector, so Home's assert, every instance and the Swift client can |
| -// each check their derivation against the same bytes (verifier = 0x00..0x1f). |
| +// each check their derivation against the same bytes (verifier = the |
| +// encoding of 0x00..0x1f; the challenge hashes that 43-character string). |
| func TestNativeNonceVector(t *testing.T) { |
| const verifier = "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8" |
| challenge, ok := NativeChallenge(verifier) |
| - if !ok || challenge != "Yw3NKWbEM2aRElRIu7JbT_QSpJxzLbLIq8G4WBvXEN0" { |
| + if !ok || challenge != "6oZqdX5MOLq_qBJ8vppAnT4fk6AP8UiP9zX8-Rev_9A" { |
| t.Fatalf("challenge %q %v", challenge, ok) |
| } |
| nonce, ok := NativeNonce(challenge) |
| - if !ok || nonce != "cU9jQRCTNby9G46AOrt78A" || !ValidNonce(nonce) { |
| + if !ok || nonce != "ZVVVj2zbBfhkAIwAOKNylg" || !ValidNonce(nonce) { |
| t.Fatalf("nonce %q %v", nonce, ok) |
| } |
| } |
| @@ -39,9 +40,9 @@ func TestNativeDerivationRefusesNonCanonicalInput(t *testing.T) { |
| func TestVerifyConsumesNothing(t *testing.T) { |
| f := fresh(t) |
| - token := f.token(t, "cU9jQRCTNby9G46AOrt78A") |
| + token := f.token(t, "ZVVVj2zbBfhkAIwAOKNylg") |
| for range 2 { |
| - if c, err := f.s.Verify(token, f.now); err != nil || c.Nonce != "cU9jQRCTNby9G46AOrt78A" { |
| + if c, err := f.s.Verify(token, f.now); err != nil || c.Nonce != "ZVVVj2zbBfhkAIwAOKNylg" { |
| t.Fatal(c, err) |
| } |
| } |
| @@ -56,7 +57,7 @@ func TestVerifyConsumesNothing(t *testing.T) { |
| func TestReserveOnceAcrossRestart(t *testing.T) { |
| f := fresh(t) |
| ctx := context.Background() |
| - token := f.token(t, "cU9jQRCTNby9G46AOrt78A") |
| + token := f.token(t, "ZVVVj2zbBfhkAIwAOKNylg") |
| if c, err := f.s.Reserve(ctx, token, f.now); err != nil || c.Subject != "person_123" { |
| t.Fatal(c, err) |
| } |