Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
aba7676
refactor(server): split keygo-server into lib and bin
OffRange Nov 9, 2026
04ce2e4
feat(api): add keygo-api with ErrorCode and ApiError
OffRange Nov 9, 2026
0e094e0
refactor(server): share ids, usernames and device types through keygo…
OffRange Nov 9, 2026
0c35462
refactor(server): share tokens and key bundles through keygo-api
OffRange Nov 9, 2026
85f0193
fix(api): use the defined server gate for token minting
OffRange Nov 9, 2026
2c1a841
refactor(server): move auth and device DTOs to keygo-api
OffRange Nov 9, 2026
0e68db4
test(api): pin request and response json
OffRange Nov 9, 2026
aac738e
feat(client): add SyncClient over Transport, DpopKey and TokenStore
OffRange Nov 9, 2026
d6dcade
feat(client): sign DPoP proofs and answer nonce challenges
OffRange Nov 9, 2026
739cae2
feat(client): refresh access tokens and manage devices
OffRange Nov 9, 2026
a38d977
fix(client): report a logout that could not clear the token
OffRange Nov 9, 2026
e420a2e
test(e2e): drive SyncClient against the router
OffRange Nov 9, 2026
7283750
feat(uniffi): export SyncClient and its foreign traits
OffRange Nov 9, 2026
89f5536
fix(uniffi): report a failing DPoP public key as a SyncError
OffRange Nov 9, 2026
a4203ee
feat(sync): add OkHttp transport and FakeSyncClient
OffRange Nov 9, 2026
dbbf1ef
fix(client): build the crate's tests without the server feature
OffRange Nov 9, 2026
28ce90a
fix(client): keep a rotated token the store refused
OffRange Nov 9, 2026
48a410c
test(client): pin every path of a token the store refused
OffRange Nov 9, 2026
894c231
build(uniffi): give the tokio runtime a worker pool
OffRange Nov 10, 2026
dbb2c0d
refactor(api): declare the fixed endpoints in a table
OffRange Nov 10, 2026
e25ba50
test: share request helpers in the wire, server and e2e tests
OffRange Nov 10, 2026
1697ebf
refactor(sync): let DpopKey::public_key fail, make save borrow
OffRange Nov 10, 2026
d592d42
refactor(client): simplify the request pipeline
OffRange Nov 10, 2026
86f3f98
refactor(uniffi): remove sync binding boilerplate
OffRange Nov 10, 2026
f6de20e
refactor(sync): simplify OkHttpTransport
OffRange Nov 10, 2026
1ac26a7
docs: trim comments on the sync API and test fixtures
OffRange Nov 10, 2026
cff175c
refactor(client): add better url parsing
OffRange Nov 10, 2026
bf0410e
refactor: drop DpopKey indirection
OffRange Nov 10, 2026
a153aea
refactor: fold exchange and exchange_unlocked
OffRange Nov 10, 2026
a296a36
refactor: simplify rust client
OffRange Nov 10, 2026
df52475
refactor: rename exchange and send_signed
OffRange Nov 10, 2026
acace29
feat(client): implement sync client registration
OffRange Nov 10, 2026
ab6db0f
feat(client): implement sync client login
OffRange Nov 12, 2026
b6f109f
refactor(core): rename ServerKek to OpaqueKek
OffRange Nov 13, 2026
425a986
refactor(core): make retagging a sealed blob explicit
OffRange Nov 13, 2026
38d9cc6
fix(client): zeroize response bodies
OffRange Nov 13, 2026
f74f79e
fix(client): treat an empty register password as invalid credentials
OffRange Nov 13, 2026
69f98ac
refactor(uniffi): rename SyncError::Locked to VaultLocked
OffRange Nov 13, 2026
b9743dc
feat(client): report an account mismatch as its own error
OffRange Nov 13, 2026
865f802
fix(client): keep the session when registration fails
OffRange Nov 13, 2026
7716b74
fix(client): keep the previous session when login fails
OffRange Nov 13, 2026
061bd3c
fix(client): reclaim the device on login and end the old session
OffRange Nov 13, 2026
6d513bb
docs(uniffi): document register and login
OffRange Nov 13, 2026
b916a8d
test: cover sync login and the server-wrapped ARK
OffRange Nov 13, 2026
486eaf3
refactor: reintroduce glob import
OffRange Nov 14, 2026
810b6e6
refactor: drop Sealed<[u8]>
OffRange Nov 14, 2026
880238a
fix(client): rename send_singed to send_signed
OffRange Nov 14, 2026
7834268
docs(client): shorten the sync client docs
OffRange Nov 14, 2026
2f5bb8e
refactor: rename ark_session
OffRange Nov 14, 2026
51b98a2
refactor: rename message to reason
OffRange Nov 14, 2026
d8a620a
chore: fix formatting
OffRange Nov 14, 2026
b6b114f
fix(security): map AccountMismatch session error
OffRange Nov 14, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ jobs:
grep -q 'keygo-core feature "crypto"' <<<"$client"
server=$(cargo tree -p keygo-server -e features)
if grep -E 'keygo-client|keygo-core feature "crypto"' <<<"$server"; then exit 1; fi
- name: keygo-client cannot mint server ids or tokens
run: |
server=$(cargo tree -p keygo-server -e features)
grep -q 'keygo-api feature "server"' <<<"$server"
client=$(cargo tree -p keygo-client -e features)
if grep 'keygo-api feature "server"' <<<"$client"; then exit 1; fi

# Rust-native tests (no NDK). Runs in parallel with android-test once lint passes.
rust-test:
Expand Down
8 changes: 6 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Android password manager using Clean Architecture per module:
| `:core:identity` | Key wrapping, auth data, proto schemas (`core/identity/src/main/proto/`) |
| `:core:item` | Room database, login/item entities |
| `:core:ui` | Shared composables and UI utilities |
| `:core:sync` | OkHttp `HttpTransport` for the Rust `SyncClient` |
| `:core:util` | Shared utilities, `Result` type |
| `:feature:auth` | Auth/session flow (login gate, biometric prompt routing) |
| `:feature:autofill` | Android autofill service (framework + Chrome/inline datasets) |
Expand All @@ -65,10 +66,12 @@ Rust workspace (`rust/`, toolchain pinned in `rust-toolchain.toml`, edition 2024
| Crate | Purpose |
|-----------------|-------------------------------------------------------------------------------|
| `keygo-core` | Key hierarchy, ids, `Sealed<T>`, shared by client and server. Crypto sits behind the `crypto` feature; the server must leave it off, so it can store wrapped keys but never hold one |
| `keygo-api` | Sync API wire types (requests, responses, ids, tokens, `ErrorCode`) and the endpoint table, shared by server and client; no HTTP stack. JSON shapes are wire identity, pinned by `tests/wire.rs` |
| `keygo-client` | App-only: ARK session, passkeys, TOTP, backup format, card formatting. The server must not depend on it. `keygo_client::crypto` re-exports `keygo-core` |
| `keygo-uniffi` | UniFFI bindings exposing `keygo-client` to Kotlin (`libkeygo_bindings.so`) |
| `keygo-opaque` | OPAQUE (opaque-ke, ristretto255 + Argon2) client/server wrapper, `forbid(unsafe_code)` |
| `keygo-server` | Self-hostable sync server (axum + sqlx/Postgres + clap CLI), see Sync Server |
| `keygo-e2e` | Test-only: drives the real `SyncClient` against the real server router (in-process, real OPAQUE and DPoP) |
| `tools/uniffi-bindgen` | Bindgen runner used by `make bindgen` |

## Key Patterns
Expand Down Expand Up @@ -199,8 +202,9 @@ Caddy as TLS proxy; `.env.example` sets `DOMAIN` and signups).
multiple statements.
- **Trailing commas** on multi-line parameter lists and collection literals.
- **Rust constructors** — ids are made with `random()`, secret material (keys, tokens, codes) with
`generate()`. Ids the client and server share live in `keygo-core`; server-only ids come from the
`random_id!`/`uuid_id!` macros in `domain/ids.rs`.
`generate()`. Ids the client and server share live in `keygo-core`; the wire handles `LoginId`
and `RegistrationId` come from `random_id!` in `keygo-api`, and their `random()` needs its
`server` feature. Server-only ids stay in `keygo-server`.

## Testing

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package de.davis.keygo.rust

import de.davisalessandro.keygo.rust.Account
import de.davisalessandro.keygo.rust.ArkSession
import de.davisalessandro.keygo.rust.DeviceDetails
import de.davisalessandro.keygo.rust.DeviceId
import de.davisalessandro.keygo.rust.ServerInfo
import de.davisalessandro.keygo.rust.SyncClientInterface
import de.davisalessandro.keygo.rust.SyncDevice
import de.davisalessandro.keygo.rust.UserId

class FakeSyncClient : SyncClientInterface {

var deleteDeviceResult: Result<Unit> = Result.success(Unit)
var devicesResult: Result<List<SyncDevice>> = Result.success(emptyList())
var loginResult: Result<Account>? = null
var logoutResult: Result<Unit> = Result.success(Unit)
var metaResult: Result<ServerInfo>? = null
var registerResult: Result<Account>? = null
var stepUpResult: Result<Unit> = Result.success(Unit)

override suspend fun deleteDevice(id: DeviceId) = deleteDeviceResult.getOrThrow()

override suspend fun devices(): List<SyncDevice> = devicesResult.getOrThrow()

override suspend fun login(
arkSession: ArkSession,
username: String,
password: String,
device: DeviceDetails,
): Account = checkNotNull(loginResult) { "loginResult not set" }.getOrThrow()

override suspend fun logout() = logoutResult.getOrThrow()

override suspend fun meta(): ServerInfo =
checkNotNull(metaResult) { "metaResult not set" }.getOrThrow()

override suspend fun register(
arkSession: ArkSession,
userId: UserId,
username: String,
password: String,
invite: String?,
device: DeviceDetails,
): Account = checkNotNull(registerResult) { "registerResult not set" }.getOrThrow()

override suspend fun stepUp(password: String) = stepUpResult.getOrThrow()
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ internal class AccountRecordSealerImpl(
private fun SessionError.toAccountRecordError(): AccountRecordError = when (this) {
SessionError.Locked -> AccountRecordError.NoActiveSession
SessionError.DecryptionFailed -> AccountRecordError.Corrupted
SessionError.WrongPassword, is SessionError.Derivation, is SessionError.KeyWrap ->
SessionError.AccountMismatch,
SessionError.WrongPassword,
is SessionError.Derivation,
is SessionError.KeyWrap,
->
AccountRecordError.KeyUnwrapFailed
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ internal class CryptographicScopeProviderImpl(
private fun SessionError.toCryptoScopeError(): CryptoScopeError = when (this) {
SessionError.Locked -> CryptoScopeError.NoActiveSession
is SessionError.KeyWrap -> CryptoScopeError.KeyWrapError(cause)
SessionError.WrongPassword, is SessionError.Derivation, SessionError.DecryptionFailed ->
SessionError.AccountMismatch,
SessionError.WrongPassword,
is SessionError.Derivation,
SessionError.DecryptionFailed,
->
CryptoScopeError.KeyWrapError(KeyWrapException.UnwrapFailed())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ inline fun <T> Session.useArk(block: (ByteArray) -> T): Result<T, SessionError>
@PublishedApi
internal fun ArkSessionException.toSessionError(): SessionError = when (this) {
is ArkSessionException.Locked -> SessionError.Locked
is ArkSessionException.AccountMismatch -> SessionError.AccountMismatch
is ArkSessionException.WrongPassword -> SessionError.WrongPassword
is ArkSessionException.Derivation -> SessionError.Derivation(v1)
is ArkSessionException.DecryptionFailed -> SessionError.DecryptionFailed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import de.davisalessandro.keygo.rust.KeyWrapException
sealed interface SessionError {

data object Locked : SessionError
data object AccountMismatch : SessionError
data object WrongPassword : SessionError
data class Derivation(val message: String) : SessionError
data object DecryptionFailed : SessionError
Expand Down
18 changes: 18 additions & 0 deletions core/sync/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
plugins {
alias(libs.plugins.keygo.android.library)
}

android {
namespace = "de.davis.keygo.core.sync"
}

dependencies {
api(projects.core.rust)

implementation(libs.okhttp)
implementation(libs.kotlinx.coroutines.core)

testImplementation(libs.okhttp.jvm)
testImplementation(libs.okhttp.mockwebserver)
testImplementation(testFixtures(projects.core.rust))
}
Empty file added core/sync/consumer-rules.pro
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package de.davis.keygo.core.sync.data

import de.davisalessandro.keygo.rust.Header
import de.davisalessandro.keygo.rust.HttpRequest
import de.davisalessandro.keygo.rust.HttpResponse
import de.davisalessandro.keygo.rust.HttpTransport
import de.davisalessandro.keygo.rust.TransportException
import kotlinx.coroutines.suspendCancellableCoroutine
import okhttp3.Call
import okhttp3.Callback
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody.Companion.toRequestBody
import okhttp3.Response
import java.io.IOException
import java.util.concurrent.TimeUnit
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException

/** Never log [HttpRequest] or [HttpResponse]: their `toString()` prints tokens. */
class OkHttpTransport(client: OkHttpClient) : HttpTransport {

// No redirects: a DPoP proof is bound to one URL.
private val client = client.newBuilder()
.retryOnConnectionFailure(false)
.followRedirects(false)
.followSslRedirects(false)
.callTimeout(CALL_TIMEOUT_SECONDS, TimeUnit.SECONDS)
.build()

override suspend fun send(request: HttpRequest): HttpResponse {
val okRequest = try {
request.toOkHttp()
} catch (e: IllegalArgumentException) {
throw e.toTransportException()
}

return suspendCancellableCoroutine { continuation ->
val call = client.newCall(okRequest)
continuation.invokeOnCancellation { call.cancel() }
call.enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
continuation.resumeWithException(e.toTransportException())
}

override fun onResponse(call: Call, response: Response) {
try {
continuation.resume(response.use { it.toRust() })
} catch (e: IOException) {
continuation.resumeWithException(e.toTransportException())
}
}
})
}
}

private fun HttpRequest.toOkHttp(): Request {
val requestBody =
if (body.isEmpty() && method != "POST") null
else body.toRequestBody(null)

return Request.Builder()
.url(url)
.apply { headers.forEach { addHeader(it.name, it.value) } }
.method(method, requestBody)
.build()
}

private fun Response.toRust() = HttpResponse(
status = code.toUShort(),
headers = headers.map { (name, value) -> Header(name = name, value = value) },
body = body.bytes(),
)

private fun Exception.toTransportException() =
TransportException.Failed(reason = message ?: this::class.java.simpleName)

private companion object {
const val CALL_TIMEOUT_SECONDS = 30L
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package de.davis.keygo.core.sync.di

import de.davis.keygo.core.sync.data.OkHttpTransport
import de.davisalessandro.keygo.rust.HttpTransport
import okhttp3.OkHttpClient
import org.koin.core.annotation.ComponentScan
import org.koin.core.annotation.Configuration
import org.koin.core.annotation.Module
import org.koin.core.annotation.Single

@Module
@Configuration
@ComponentScan("de.davis.keygo.core.sync")
object CoreSyncModule {

@Single
internal fun provideHttpTransport(): HttpTransport = OkHttpTransport(OkHttpClient())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package de.davis.keygo.core.sync.data

import de.davisalessandro.keygo.rust.Header
import de.davisalessandro.keygo.rust.HttpRequest
import de.davisalessandro.keygo.rust.TransportException
import kotlinx.coroutines.test.runTest
import mockwebserver3.MockResponse
import mockwebserver3.MockWebServer
import mockwebserver3.SocketEffect
import okhttp3.OkHttpClient
import kotlin.test.AfterTest
import kotlin.test.BeforeTest
import kotlin.test.Test
import kotlin.test.assertContentEquals
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith

class OkHttpTransportTest {

private val server = MockWebServer()
private val transport = OkHttpTransport(OkHttpClient())

@BeforeTest
fun setUp() = server.start()

@AfterTest
fun tearDown() = server.close()

private fun request(
method: String,
body: ByteArray = byteArrayOf(),
headers: List<Header> = emptyList(),
) = HttpRequest(
method = method,
url = server.url("/api").toString(),
headers = headers,
body = body,
)

@Test
fun round_trips_method_headers_and_body_bytes() = runTest {
val payload = byteArrayOf(0, 1, 2, -1, -128, 127)
server.enqueue(
MockResponse.Builder()
.code(201)
.addHeader("x-reply", "yes")
.body(okio.Buffer().write(payload))
.build(),
)

val response = transport.send(
request("POST", payload, listOf(Header(name = "dpop", value = "proof"))),
)

val recorded = server.takeRequest()
assertEquals("POST", recorded.method)
assertEquals("proof", recorded.headers["dpop"])
assertContentEquals(payload, recorded.body!!.toByteArray())
assertEquals(201.toUShort(), response.status)
assertEquals("yes", response.headers.first { it.name.equals("x-reply", true) }.value)
assertContentEquals(payload, response.body)
}

@Test
fun post_with_empty_body_is_sent() = runTest {
server.enqueue(MockResponse.Builder().build())

transport.send(request("POST"))

val recorded = server.takeRequest()
assertEquals("POST", recorded.method)
assertEquals(0, recorded.bodySize)
}

@Test
fun get_sends_no_body() = runTest {
server.enqueue(MockResponse.Builder().build())

transport.send(request("GET"))

val recorded = server.takeRequest()
assertEquals("GET", recorded.method)
assertEquals(0, recorded.bodySize)
}

@Test
fun does_not_retry_after_a_connection_failure() = runTest {
server.enqueue(
MockResponse.Builder()
.onResponseStart(SocketEffect.CloseSocket())
.build(),
)

assertFailsWith<TransportException.Failed> { transport.send(request("GET")) }
assertEquals(1, server.requestCount)
}

@Test
fun does_not_follow_redirects() = runTest {
server.enqueue(
MockResponse.Builder()
.code(302)
.addHeader("Location", server.url("/elsewhere").toString())
.build(),
)

val response = transport.send(request("GET"))

assertEquals(302.toUShort(), response.status)
assertEquals(1, server.requestCount)
}

@Test
fun io_failure_throws_transport_exception() = runTest {
val unreachable = request("GET")
server.close()

assertFailsWith<TransportException.Failed> { transport.send(unreachable) }
}
}
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ squareup-kotlinpoet = { group = "com.squareup", name = "kotlinpoet-ksp", version

okhttp = { group = "com.squareup.okhttp3", name = "okhttp", version.ref = "okhttp" }
okhttp-jvm = { group = "com.squareup.okhttp3", name = "okhttp-jvm", version.ref = "okhttp" }
okhttp-mockwebserver = { group = "com.squareup.okhttp3", name = "mockwebserver3", version.ref = "okhttp" }

gosimple-nbvcxz = { group = "me.gosimple", name = "nbvcxz", version.ref = "nbvcxz" }

Expand Down
Loading
Loading