Archived
The wire layer, recovery codes, share links, and a command-line client
Everything between the engine and an app: server discovery, the account service, the file API, and a session that ties them together. Recovery codes and share links move into the engine, and both agree with the browser character for character — the vectors file now carries codes generated by the JavaScript implementation, including one containing a Q, because folding Q is the mistake that once corrupted a third of all codes. BigInteger drops leading zero bytes, so decoding left-pads rather than trusting the length; there is a test for exactly that. `X25519.publicFromPrivate` recovers the public half by agreeing with the basepoint. JCA hands back a public key only from a freshly generated pair, and a session that unlocked a stored record has just the scalar — storing a second copy would only create something that could disagree with itself. `filesctl` exists so the cryptography can be exercised without an app, an emulator, or a person tapping. Verified against the iOS engine as well: one uploads, the other downloads, and the digests match. MIT, matching the server. CI runs the suite on a plain JDK image, which is the point of keeping this out of an Android module.
This commit is contained in:
+4
-2
@@ -1,5 +1,7 @@
|
||||
.gradle/
|
||||
build/
|
||||
*/build/
|
||||
.gradle/
|
||||
.kotlin/
|
||||
local.properties
|
||||
*.iml
|
||||
.idea/
|
||||
.DS_Store
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
# The engine and client are plain JVM libraries precisely so this needs no
|
||||
# Android SDK and no emulator. A suite that needs a device is a suite that
|
||||
# runs rarely.
|
||||
default:
|
||||
tags: [vps]
|
||||
|
||||
test:
|
||||
image: gradle:8.10-jdk21
|
||||
script:
|
||||
- gradle :engine:test :client:build --no-daemon
|
||||
@@ -1,41 +0,0 @@
|
||||
kotlin version: 2.1.0
|
||||
error message: java.lang.IllegalArgumentException: 26.0.2.1
|
||||
at org.jetbrains.kotlin.com.intellij.util.lang.JavaVersion.parse(JavaVersion.java:307)
|
||||
at org.jetbrains.kotlin.com.intellij.util.lang.JavaVersion.current(JavaVersion.java:176)
|
||||
at org.jetbrains.kotlin.cli.jvm.modules.JavaVersionUtilsKt.isAtLeastJava9(javaVersionUtils.kt:11)
|
||||
at org.jetbrains.kotlin.cli.jvm.modules.CoreJrtFileSystem.globalJrtFsCache$lambda$2(CoreJrtFileSystem.kt:83)
|
||||
at org.jetbrains.kotlin.cli.jvm.modules.CoreJrtFileSystem.globalJrtFsCache$lambda$3(CoreJrtFileSystem.kt:74)
|
||||
at org.jetbrains.kotlin.com.intellij.util.containers.ConcurrentFactoryMap$2.create(ConcurrentFactoryMap.java:174)
|
||||
at org.jetbrains.kotlin.com.intellij.util.containers.ConcurrentFactoryMap.get(ConcurrentFactoryMap.java:40)
|
||||
at org.jetbrains.kotlin.cli.jvm.modules.CoreJrtFileSystem.roots$lambda$0(CoreJrtFileSystem.kt:34)
|
||||
at org.jetbrains.kotlin.cli.jvm.modules.CoreJrtFileSystem.roots$lambda$1(CoreJrtFileSystem.kt:33)
|
||||
at org.jetbrains.kotlin.com.intellij.util.containers.ConcurrentFactoryMap$2.create(ConcurrentFactoryMap.java:174)
|
||||
at org.jetbrains.kotlin.com.intellij.util.containers.ConcurrentFactoryMap.get(ConcurrentFactoryMap.java:40)
|
||||
at org.jetbrains.kotlin.cli.jvm.modules.CoreJrtFileSystem.findFileByPath(CoreJrtFileSystem.kt:42)
|
||||
at org.jetbrains.kotlin.cli.jvm.modules.CliJavaModuleFinder.<init>(CliJavaModuleFinder.kt:45)
|
||||
at org.jetbrains.kotlin.cli.jvm.compiler.pipeline.JvmCompilerPipelineKt.createProjectEnvironment(jvmCompilerPipeline.kt:297)
|
||||
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:139)
|
||||
at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:43)
|
||||
at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:102)
|
||||
at org.jetbrains.kotlin.cli.common.CLICompiler.exec(CLICompiler.kt:316)
|
||||
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:464)
|
||||
at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:73)
|
||||
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.doCompile(IncrementalCompilerRunner.kt:506)
|
||||
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileImpl(IncrementalCompilerRunner.kt:423)
|
||||
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileNonIncrementally(IncrementalCompilerRunner.kt:301)
|
||||
at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:129)
|
||||
at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execIncrementalCompiler(CompileServiceImpl.kt:674)
|
||||
at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execIncrementalCompiler(CompileServiceImpl.kt:91)
|
||||
at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1659)
|
||||
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:104)
|
||||
at java.base/java.lang.reflect.Method.invoke(Method.java:565)
|
||||
at java.rmi/sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:351)
|
||||
at java.rmi/sun.rmi.transport.Transport.serviceCall(Transport.java:166)
|
||||
at java.rmi/sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:543)
|
||||
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:744)
|
||||
at java.rmi/sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:623)
|
||||
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1090)
|
||||
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:614)
|
||||
at java.base/java.lang.Thread.run(Thread.java:1516)
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2026 Extant 2000 LLC
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -1,55 +1,72 @@
|
||||
# flamenet-files-android
|
||||
|
||||
The Android client for [Flamenet Files](https://flamenetfiles.com).
|
||||
The Android client for [Flamenet Files](https://flamenetfiles.com) — private,
|
||||
labelled file storage, encrypted on your device before it is uploaded.
|
||||
|
||||
**Private, deliberately.** The engine and its wire format are public at
|
||||
[gitlab.com/paulhitt/flamenet-files](https://gitlab.com/paulhitt/flamenet-files);
|
||||
the application is not. That split is only honest because the public half is a
|
||||
full specification — anyone can verify this client speaks the same protocol
|
||||
without reading its source.
|
||||
MIT licensed, like [the server and web
|
||||
client](https://gitlab.com/paulhitt/flamenet-files).
|
||||
|
||||
## What exists
|
||||
## What is here
|
||||
|
||||
`engine/` — the cryptographic engine in Kotlin, implementing
|
||||
[docs/SPEC.md](https://gitlab.com/paulhitt/flamenet-files/-/blob/main/docs/SPEC.md):
|
||||
the lattice, key derivation, the key hierarchy, filename digests and chunked
|
||||
content encryption.
|
||||
| | |
|
||||
|---|---|
|
||||
| `engine/` | The cryptography, in plain Kotlin over JCA. Implements [docs/SPEC.md](https://gitlab.com/paulhitt/flamenet-files/-/blob/main/docs/SPEC.md) — the lattice, key derivation, the key hierarchy, recovery codes, filename digests, chunked content, share links. |
|
||||
| `client/` | The wire layer: server discovery, the account service, the file API, a session that ties them together, and `filesctl`, a command-line client. |
|
||||
|
||||
It is a **plain JVM library, not an Android module**, so `gradle test` runs it
|
||||
without an emulator or the Android SDK. Crypto that can only be tested on a
|
||||
device is crypto that gets tested rarely.
|
||||
Both are plain JVM libraries, not Android modules, so `gradle test` runs them
|
||||
without an emulator or the Android SDK. Cryptography that can only be tested on
|
||||
a device is cryptography that gets tested rarely.
|
||||
|
||||
## Interop is the test suite
|
||||
|
||||
`engine/src/test` runs against vectors produced by the JavaScript reference
|
||||
implementation — the same vectors the iOS engine uses. They do not check that
|
||||
this code is self-consistent; they check that it agrees with the implementation
|
||||
people actually use. Ten tests currently pass.
|
||||
The tests do not check that this code is self-consistent — they check that it
|
||||
agrees with the implementation people actually use.
|
||||
|
||||
```bash
|
||||
gradle :engine:test
|
||||
```
|
||||
|
||||
The vectors are generated by the JavaScript engine in the public repository and
|
||||
copied here verbatim. A file written in the browser must open on a phone, a code
|
||||
printed on one device must work on another, and a divergence should fail here
|
||||
rather than in somebody's hands.
|
||||
|
||||
## Trying it against a real server
|
||||
|
||||
```bash
|
||||
gradle :client:run --args="https://files.flamenet.io probe"
|
||||
```
|
||||
|
||||
One address is enough. The server names its own account service —
|
||||
`files.flamenet.io` points at `accounts.flamenet.io`, a self-hosted box points at
|
||||
the service bundled alongside it — so there are no build flags and no baked-in
|
||||
list of which hostnames are "ours".
|
||||
|
||||
```bash
|
||||
gradle :client:run --args="http://127.0.0.1:8081 smoke myhandle 'a good passphrase'"
|
||||
```
|
||||
|
||||
`smoke` registers an account, signs in fresh, creates a folder, uploads 200 KB
|
||||
across four chunks, decrypts the name back, downloads and compares byte for
|
||||
byte, makes a password-protected share link, opens it, and checks that the same
|
||||
link is refused without the password.
|
||||
|
||||
## Three things worth knowing
|
||||
|
||||
- **X25519 raw format.** The wire format is the RFC 7748 32-byte little-endian
|
||||
u-coordinate; JCA models a public key as a `BigInteger`. Byte order and the
|
||||
ignored high bit are both easy to get wrong in a way that produces keys which
|
||||
look plausible and agree with nothing. `X25519.kt` handles both directions and
|
||||
the vectors cover it.
|
||||
- **HKDF is hand-written.** Neither the JDK nor Android exposes it through JCA.
|
||||
It is RFC 5869 extract-then-expand over HMAC, about thirty lines, and covered
|
||||
by the vectors rather than trusted.
|
||||
- **PKCS#8 versus raw.** WebCrypto exports an X25519 private key as PKCS#8;
|
||||
JCA here wants the raw scalar. Without the conversion in `Identity.kt` a
|
||||
browser-written record cannot be opened at all.
|
||||
- **HKDF is written out here.** Neither the JDK nor Android exposes it through
|
||||
JCA. It is extract-then-expand over HMAC and nothing more; thirty lines beats
|
||||
a dependency, and it is covered by the interop vectors rather than trusted.
|
||||
- **X25519 keys need endian care.** JCA's `XECPublicKey` carries a
|
||||
`BigInteger` in big-endian order while the wire format is little-endian, so
|
||||
`X25519` converts in both directions rather than assuming.
|
||||
- **Kotlin 2.4, JVM 17 bytecode.** No `jvmToolchain`, deliberately: pinning one
|
||||
demands a JDK that may not be installed, which is a poor trade for a library
|
||||
this size. Earlier Kotlin releases hit an internal compiler error on recent
|
||||
JDKs.
|
||||
|
||||
⚠️ **`XDH` requires Android API 33.** Below that, register a provider such as
|
||||
BouncyCastle at startup — the engine is provider-agnostic and needs no change.
|
||||
Decide the minimum API level before writing app code against it.
|
||||
## Status
|
||||
|
||||
## Not built yet
|
||||
The engine and the wire layer are complete and verified, including against the
|
||||
iOS engine: one uploads, the other downloads, and the bytes match.
|
||||
|
||||
The app itself: sign-in against `accounts.flamenet.io`, the file browser, upload
|
||||
and download, the label picker. The engine is the foundation, and it is done and
|
||||
verified.
|
||||
The Jetpack Compose app is in progress.
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
// The wire layer, like the engine, is a plain JVM library rather than an
|
||||
// Android module. That keeps it runnable from the command line — `gradle
|
||||
// :client:run` exercises registration, the key hierarchy and the chunked
|
||||
// content format against a real server in seconds, which is the only way these
|
||||
// paths get tested often enough to matter.
|
||||
plugins {
|
||||
kotlin("jvm") version "2.4.10"
|
||||
kotlin("plugin.serialization") version "2.4.10"
|
||||
application
|
||||
}
|
||||
|
||||
repositories { mavenCentral() }
|
||||
|
||||
dependencies {
|
||||
implementation(project(":engine"))
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3")
|
||||
testImplementation(kotlin("test"))
|
||||
}
|
||||
|
||||
kotlin {
|
||||
compilerOptions {
|
||||
jvmTarget.set(org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17)
|
||||
}
|
||||
}
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_17
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
application { mainClass.set("io.flamenet.files.client.FilesCtlKt") }
|
||||
|
||||
tasks.test { useJUnitPlatform() }
|
||||
@@ -0,0 +1,139 @@
|
||||
package io.flamenet.files.client
|
||||
|
||||
import io.flamenet.files.engine.Kdf
|
||||
import java.security.SecureRandom
|
||||
|
||||
/**
|
||||
* The shared FlameNet account service.
|
||||
*
|
||||
* One credential across products, with no shared key material. What this sends
|
||||
* is derived under an authentication context; the key that opens files comes
|
||||
* from an encryption context over the same passphrase. A fully compromised
|
||||
* account service can impersonate you to itself and decrypt nothing.
|
||||
*
|
||||
* The passphrase never leaves the device.
|
||||
*/
|
||||
class AccountsClient(val baseURL: String) {
|
||||
private val http = Http()
|
||||
private val random = SecureRandom()
|
||||
|
||||
private fun salt() = ByteArray(16).also(random::nextBytes)
|
||||
private fun auth(token: String?) =
|
||||
token?.let { mapOf("Authorization" to "Bearer $it") } ?: emptyMap()
|
||||
|
||||
/**
|
||||
* Stretch parameters for a handle.
|
||||
*
|
||||
* An unknown handle gets a deterministic fake, so this cannot be used to
|
||||
* discover who has an account — and this client cannot tell the difference,
|
||||
* which is the point. Do not build a "handle available?" check on it.
|
||||
*/
|
||||
fun params(handle: String): Wire.KdfParams {
|
||||
val escaped = java.net.URLEncoder.encode(handle.lowercase(), "UTF-8")
|
||||
val response = http.request("GET", Http.endpoint(baseURL, "/accounts/$escaped/params"))
|
||||
return http.decode(response.body)
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an account and its first identity in one call.
|
||||
*
|
||||
* The identity travels with the registration rather than after it, so both
|
||||
* land in a single transaction. Registering first and enrolling afterwards
|
||||
* left a window where an interrupted client stranded a handle that was
|
||||
* taken, unusable, and impossible to enrol into.
|
||||
*/
|
||||
fun register(
|
||||
handle: String,
|
||||
passphrase: String,
|
||||
recoveryEntropy: ByteArray?,
|
||||
identity: Wire.NewIdentity?,
|
||||
) {
|
||||
val kdfSalt = salt()
|
||||
val body = Wire.RegisterBody(
|
||||
handle = handle.lowercase(),
|
||||
authSecret = Http.b64(Kdf.authSecret(passphrase, kdfSalt)),
|
||||
kdfSalt = Http.b64(kdfSalt),
|
||||
kdfIterations = Kdf.Parameters.V1.iterations,
|
||||
recoveryAuthSecret = recoveryEntropy?.let { Http.b64(Kdf.recoveryAuthSecret(it)) },
|
||||
identity = identity,
|
||||
)
|
||||
http.request(
|
||||
"POST", Http.endpoint(baseURL, "/accounts"),
|
||||
jsonBody = Http.json.encodeToString(Wire.RegisterBody.serializer(), body),
|
||||
)
|
||||
}
|
||||
|
||||
/** Sign in. Returns the clearance token the file server verifies. */
|
||||
fun signIn(handle: String, passphrase: String, product: String = "files"): Wire.Session {
|
||||
val params = params(handle)
|
||||
val authSecret = Kdf.authSecret(
|
||||
passphrase, Http.unb64(params.kdfSalt),
|
||||
Kdf.Parameters(params.kdfID.toInt(), params.kdfIterations),
|
||||
)
|
||||
val body = Wire.SessionBody(handle.lowercase(), Http.b64(authSecret), product)
|
||||
try {
|
||||
val response = http.request(
|
||||
"POST", Http.endpoint(baseURL, "/sessions"),
|
||||
jsonBody = Http.json.encodeToString(Wire.SessionBody.serializer(), body),
|
||||
)
|
||||
return http.decode(response.body)
|
||||
} catch (error: ClientException.Http) {
|
||||
if (error.status == 401) throw ClientException.WrongPassphrase()
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prove a recovery code and set a new passphrase.
|
||||
*
|
||||
* The old code is retired and a fresh one issued: leaving a code in play
|
||||
* that somebody has already had cause to use is the wrong default.
|
||||
*/
|
||||
fun rotate(handle: String, entropy: ByteArray, newPassphrase: String, nextEntropy: ByteArray) {
|
||||
val kdfSalt = salt()
|
||||
val body = Wire.RotateBody(
|
||||
handle = handle.lowercase(),
|
||||
recoveryAuthSecret = Http.b64(Kdf.recoveryAuthSecret(entropy)),
|
||||
newAuthSecret = Http.b64(Kdf.authSecret(newPassphrase, kdfSalt)),
|
||||
newKdfSalt = Http.b64(kdfSalt),
|
||||
newKdfIterations = Kdf.Parameters.V1.iterations,
|
||||
newRecoveryAuthSecret = Http.b64(Kdf.recoveryAuthSecret(nextEntropy)),
|
||||
)
|
||||
http.request(
|
||||
"POST", Http.endpoint(baseURL, "/accounts/rotate"),
|
||||
jsonBody = Http.json.encodeToString(Wire.RotateBody.serializer(), body),
|
||||
)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------- identities
|
||||
//
|
||||
// These live here rather than on the file server. An identity belongs to
|
||||
// the account, not to one product's file tree — and holding them together
|
||||
// is what lets registration be atomic.
|
||||
|
||||
/** The caller's own identity, or null when they have not enrolled. */
|
||||
fun identity(token: String): Wire.Identity? {
|
||||
val response = http.request(
|
||||
"GET", Http.endpoint(baseURL, "/identity"), headers = auth(token))
|
||||
// 204: the account exists but has no identity for this product yet,
|
||||
// which is how the app decides between "unlock" and "create".
|
||||
if (response.status == 204 || response.body.isEmpty()) return null
|
||||
return http.decode(response.body)
|
||||
}
|
||||
|
||||
fun enroll(token: String, publicKey: ByteArray, protectedRecord: String, recoveryRecord: String?) {
|
||||
val body = Wire.EnrollBody(Http.b64(publicKey), protectedRecord, recoveryRecord)
|
||||
http.request(
|
||||
"POST", Http.endpoint(baseURL, "/identity"), headers = auth(token),
|
||||
jsonBody = Http.json.encodeToString(Wire.EnrollBody.serializer(), body),
|
||||
)
|
||||
}
|
||||
|
||||
fun rekey(token: String, protectedRecord: String, recoveryRecord: String?) {
|
||||
val body = Wire.RekeyBody(protectedRecord, recoveryRecord)
|
||||
http.request(
|
||||
"POST", Http.endpoint(baseURL, "/identity/rekey"), headers = auth(token),
|
||||
jsonBody = Http.json.encodeToString(Wire.RekeyBody.serializer(), body),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
package io.flamenet.files.client
|
||||
|
||||
import io.flamenet.files.engine.Label
|
||||
|
||||
/**
|
||||
* The file server.
|
||||
*
|
||||
* Two headers carry the session label on every request. Omitting them makes the
|
||||
* server fall back to the clearance *minimum*, never the maximum, so a bug here
|
||||
* under-privileges rather than over-privileges.
|
||||
*/
|
||||
class FilesApi(val baseURL: String, val token: String) {
|
||||
private val http = Http()
|
||||
var label: Label? = null
|
||||
|
||||
companion object {
|
||||
/** What a server says about itself. Unauthenticated, so it can be asked
|
||||
* before there is any credential to ask with. */
|
||||
fun config(baseURL: String): Wire.ServerConfig {
|
||||
val http = Http()
|
||||
return http.decode(http.request("GET", Http.endpoint(baseURL, "/api/config")).body)
|
||||
}
|
||||
}
|
||||
|
||||
private val headers: Map<String, String>
|
||||
get() = buildMap {
|
||||
put("Authorization", "Bearer $token")
|
||||
label?.let {
|
||||
put("X-Enclave-Classification", it.classification.toString())
|
||||
put("X-Enclave-Compartments", it.compartments.sorted().joinToString(","))
|
||||
}
|
||||
}
|
||||
|
||||
internal inline fun <reified T> get(path: String): T? {
|
||||
val response = http.request("GET", Http.endpoint(baseURL, path), headers = headers)
|
||||
if (response.status == 204 || response.body.isEmpty()) return null
|
||||
return http.decode(response.body)
|
||||
}
|
||||
|
||||
internal inline fun <reified T> post(path: String, body: String): T? {
|
||||
val response = http.request(
|
||||
"POST", Http.endpoint(baseURL, path), headers = headers, jsonBody = body)
|
||||
if (response.status == 204 || response.body.isEmpty()) return null
|
||||
return try { http.decode<T>(response.body) } catch (error: Exception) { null }
|
||||
}
|
||||
|
||||
fun delete(path: String) {
|
||||
http.request("DELETE", Http.endpoint(baseURL, path), headers = headers)
|
||||
}
|
||||
|
||||
// nodes
|
||||
|
||||
fun roots(): List<Wire.Node> = get<List<Wire.Node>>("/api/nodes/roots") ?: emptyList()
|
||||
|
||||
fun children(folderID: String): List<Wire.Node> =
|
||||
get<List<Wire.Node>>("/api/nodes/$folderID/children") ?: emptyList()
|
||||
|
||||
fun create(body: Wire.CreateNodeBody): Wire.Node? =
|
||||
post("/api/nodes", Http.json.encodeToString(Wire.CreateNodeBody.serializer(), body))
|
||||
|
||||
// keys
|
||||
|
||||
fun labelGrants(): List<Wire.LabelGrant> =
|
||||
get<List<Wire.LabelGrant>>("/api/keys/labels") ?: emptyList()
|
||||
|
||||
fun storeGrant(label: Label, wrappedKey: ByteArray) {
|
||||
val body = Wire.GrantBody(
|
||||
label.classification, label.compartments.sorted(), Http.b64(wrappedKey))
|
||||
post<Wire.LabelGrant>(
|
||||
"/api/keys/labels", Http.json.encodeToString(Wire.GrantBody.serializer(), body))
|
||||
}
|
||||
|
||||
fun nodeKey(nodeID: String): Wire.NodeKey =
|
||||
get<Wire.NodeKey>("/api/keys/nodes/$nodeID") ?: throw ClientException.Http(404, "")
|
||||
|
||||
// blobs
|
||||
|
||||
fun putBlob(ciphertext: ByteArray): String {
|
||||
val response = http.request(
|
||||
"POST", Http.endpoint(baseURL, "/api/blobs"), headers = headers, rawBody = ciphertext)
|
||||
return http.decode<Wire.BlobCreated>(response.body).id
|
||||
}
|
||||
|
||||
fun getBlob(blobID: String): ByteArray =
|
||||
http.request("GET", Http.endpoint(baseURL, "/api/blobs/$blobID"), headers = headers).body
|
||||
|
||||
// vocabulary
|
||||
|
||||
fun vocabulary(): Wire.Vocabulary = get<Wire.Vocabulary>("/api/vocabulary") ?: Wire.Vocabulary()
|
||||
|
||||
// shares
|
||||
|
||||
fun createShare(body: Wire.CreateShareBody): Wire.Share? =
|
||||
post("/api/shares", Http.json.encodeToString(Wire.CreateShareBody.serializer(), body))
|
||||
|
||||
fun share(shareID: String): Wire.Share? = get<Wire.Share>("/api/shares/$shareID")
|
||||
|
||||
fun shares(nodeID: String): List<Wire.Share> =
|
||||
get<List<Wire.Share>>("/api/shares/for/$nodeID") ?: emptyList()
|
||||
|
||||
fun revokeShare(shareID: String) = delete("/api/shares/$shareID")
|
||||
}
|
||||
@@ -0,0 +1,259 @@
|
||||
package io.flamenet.files.client
|
||||
|
||||
import io.flamenet.files.engine.Identity
|
||||
import io.flamenet.files.engine.Label
|
||||
import io.flamenet.files.engine.Recovery
|
||||
import java.util.Base64
|
||||
import kotlin.system.exitProcess
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.JsonObject
|
||||
import kotlinx.serialization.json.JsonPrimitive
|
||||
import kotlinx.serialization.json.int
|
||||
import kotlinx.serialization.json.jsonObject
|
||||
import kotlinx.serialization.json.jsonPrimitive
|
||||
import kotlinx.serialization.json.long
|
||||
|
||||
/**
|
||||
* A command-line exercise of the same engine and wire layer the app uses.
|
||||
*
|
||||
* The point is that this is not a mock: `smoke` runs the real registration, the
|
||||
* real key hierarchy and the real chunked content format against a real server,
|
||||
* from the command line, in seconds. Reaching the same confidence through an
|
||||
* emulator means a build, an install, and a person tapping — which in practice
|
||||
* means it gets done once and then not again.
|
||||
*
|
||||
* It also answers the question the app has to answer on first launch: point it
|
||||
* at any server and it will tell you which account service that server trusts.
|
||||
*/
|
||||
|
||||
private fun sha256(bytes: ByteArray): String =
|
||||
java.security.MessageDigest.getInstance("SHA-256").digest(bytes)
|
||||
.joinToString("") { "%02x".format(it) }
|
||||
|
||||
private fun fail(message: String): Nothing {
|
||||
System.err.println("error: $message")
|
||||
exitProcess(1)
|
||||
}
|
||||
|
||||
/**
|
||||
* The clearance claims, read out of the token the account service minted.
|
||||
*
|
||||
* Deliberately *not* verified here. A client verifying its own token proves
|
||||
* nothing: it would be checking a signature against a key handed to it by the
|
||||
* same party. The file server verifies, and that is the only verification that
|
||||
* matters. This decode exists so an interface can grey out a level the server
|
||||
* would refuse anyway — a courtesy, never a control.
|
||||
*/
|
||||
fun clearanceFrom(token: String): Clearance {
|
||||
val parts = token.split(".")
|
||||
if (parts.size != 3) throw ClientException.BadServer("The server issued an unreadable token.")
|
||||
val payload = String(Base64.getUrlDecoder().decode(parts[1]), Charsets.UTF_8)
|
||||
val claims = Json.parseToJsonElement(payload).jsonObject
|
||||
|
||||
fun short(key: String): Short =
|
||||
(claims[key] as? JsonPrimitive)?.int?.toShort() ?: 0
|
||||
|
||||
// Postgres has no unsigned 64-bit integer, so the compartment mask travels
|
||||
// as a signed one and bit 63 arrives negative. Reinterpreting the pattern
|
||||
// rather than converting the value is what keeps the top compartment usable.
|
||||
fun bits(key: String): Set<Int> {
|
||||
val mask = (claims[key] as? JsonPrimitive)?.long ?: 0L
|
||||
return (0..63).filter { (mask shr it) and 1L == 1L }.toSet()
|
||||
}
|
||||
|
||||
return Clearance(
|
||||
maximum = Label(short("mxc"), bits("mxk")),
|
||||
minimum = Label(short("mnc"), bits("mnk")),
|
||||
)
|
||||
}
|
||||
|
||||
fun main(argv: Array<String>) {
|
||||
if (argv.size < 2) {
|
||||
println(
|
||||
"""
|
||||
usage: filesctl <server-url> <command> [arguments]
|
||||
|
||||
commands:
|
||||
probe what this server says about itself
|
||||
register <handle> <passphrase> create an account and its identity
|
||||
signin <handle> <passphrase> sign in and list the root
|
||||
smoke <handle> <passphrase> full round trip against a fresh account
|
||||
put <handle> <passphrase> <file> upload, and print its sha256
|
||||
get <handle> <passphrase> <name> download by name, and print its sha256
|
||||
|
||||
The server names its own account service, so one address is enough:
|
||||
a self-hosted box points at its bundled service, files.flamenet.io
|
||||
points at accounts.flamenet.io.
|
||||
""".trimIndent(),
|
||||
)
|
||||
exitProcess(2)
|
||||
}
|
||||
|
||||
val server = argv[0]
|
||||
val command = argv[1]
|
||||
|
||||
fun openSession(handle: String, passphrase: String): FilesSession {
|
||||
val config = FilesApi.config(server)
|
||||
val accounts = AccountsClient(config.accountsURL)
|
||||
val session = accounts.signIn(handle, passphrase)
|
||||
val api = FilesApi(server, session.token)
|
||||
val files = FilesSession.open(
|
||||
api, accounts, session.token, passphrase, clearanceFrom(session.token))
|
||||
files.loadLabelKeys()
|
||||
return files
|
||||
}
|
||||
|
||||
try {
|
||||
when (command) {
|
||||
"probe" -> {
|
||||
val config = FilesApi.config(server)
|
||||
println("server: $server")
|
||||
println("accounts: ${config.accountsURL}")
|
||||
println("tenant: ${config.tenant}")
|
||||
println("site: ${config.siteURL}")
|
||||
println("source: ${config.sourceURL}")
|
||||
println("protocol: v${config.protocolVersion}")
|
||||
}
|
||||
|
||||
"register" -> {
|
||||
if (argv.size < 4) fail("register needs a handle and a passphrase")
|
||||
val config = FilesApi.config(server)
|
||||
val accounts = AccountsClient(config.accountsURL)
|
||||
val handle = argv[2]
|
||||
val passphrase = argv[3]
|
||||
|
||||
// Built before the account exists, so both land in one
|
||||
// transaction.
|
||||
val generated = Recovery.generate()
|
||||
val pair = Identity.generate()
|
||||
accounts.register(
|
||||
handle, passphrase, generated.entropy,
|
||||
Wire.NewIdentity(
|
||||
publicKey = Http.b64(Identity.exportPublicKey(pair.public)),
|
||||
protectedRecord = FilesSession.encodeRecord(
|
||||
Identity.protect(pair.private, passphrase)),
|
||||
recoveryRecord = FilesSession.encodeRecord(
|
||||
Identity.protectWithRecovery(pair.private, generated.entropy)),
|
||||
),
|
||||
)
|
||||
println("registered $handle on ${config.accountsURL}")
|
||||
println("recovery code: ${generated.code}")
|
||||
println(" This is shown once. Without it a lost passphrase loses the data.")
|
||||
}
|
||||
|
||||
"signin" -> {
|
||||
if (argv.size < 4) fail("signin needs a handle and a passphrase")
|
||||
val files = openSession(argv[2], argv[3])
|
||||
val clearance = files.clearance
|
||||
println(
|
||||
"signed in. clearance: classification " +
|
||||
"${clearance.maximum.classification}" +
|
||||
if (clearance.maximum.compartments.isEmpty()) ""
|
||||
else ", compartments ${clearance.maximum.compartments.sorted()}",
|
||||
)
|
||||
val entries = files.list(null)
|
||||
if (entries.isEmpty()) println("(the root is empty)")
|
||||
for (entry in entries) {
|
||||
val name = entry.name ?: "(no key for this area)"
|
||||
val kind = if (entry.isFolder) "dir " else "file"
|
||||
println(" $kind $name [c${entry.label.classification}]")
|
||||
}
|
||||
}
|
||||
|
||||
// Cross-engine interop: one engine writes, the other reads. Neither
|
||||
// the vectors file nor a self round-trip can catch a divergence
|
||||
// that only shows up once two implementations share an account.
|
||||
"put" -> {
|
||||
if (argv.size < 5) fail("put needs a handle, a passphrase and a file")
|
||||
val files = openSession(argv[2], argv[3])
|
||||
val file = java.io.File(argv[4])
|
||||
val bytes = file.readBytes()
|
||||
files.use(files.clearance.minimum)
|
||||
files.upload(bytes, file.name)
|
||||
println("uploaded ${file.name}, ${bytes.size} bytes")
|
||||
println("sha256: ${sha256(bytes)}")
|
||||
}
|
||||
|
||||
"get" -> {
|
||||
if (argv.size < 5) fail("get needs a handle, a passphrase and a name")
|
||||
val files = openSession(argv[2], argv[3])
|
||||
files.use(files.clearance.minimum)
|
||||
val entry = files.list(null).firstOrNull { it.name == argv[4] }
|
||||
?: fail("no file named '${argv[4]}' that this session can read")
|
||||
val bytes = files.download(entry.node)
|
||||
println("downloaded ${argv[4]}, ${bytes.size} bytes")
|
||||
println("sha256: ${sha256(bytes)}")
|
||||
}
|
||||
|
||||
"smoke" -> {
|
||||
if (argv.size < 4) fail("smoke needs a handle and a passphrase")
|
||||
val handle = argv[2]
|
||||
val passphrase = argv[3]
|
||||
val config = FilesApi.config(server)
|
||||
val accounts = AccountsClient(config.accountsURL)
|
||||
println("· server $server → accounts ${config.accountsURL}")
|
||||
|
||||
val generated = Recovery.generate()
|
||||
val pair = Identity.generate()
|
||||
accounts.register(
|
||||
handle, passphrase, generated.entropy,
|
||||
Wire.NewIdentity(
|
||||
publicKey = Http.b64(Identity.exportPublicKey(pair.public)),
|
||||
protectedRecord = FilesSession.encodeRecord(
|
||||
Identity.protect(pair.private, passphrase)),
|
||||
recoveryRecord = FilesSession.encodeRecord(
|
||||
Identity.protectWithRecovery(pair.private, generated.entropy)),
|
||||
),
|
||||
)
|
||||
println("· registered $handle")
|
||||
|
||||
// Signing in fresh, rather than reusing the keypair in memory,
|
||||
// is the point: it proves the record the server stored opens.
|
||||
val files = openSession(handle, passphrase)
|
||||
println("· signed in, clearance c${files.clearance.maximum.classification}")
|
||||
|
||||
files.use(files.clearance.minimum)
|
||||
val folder = files.createFolder("smoke") ?: fail("no folder returned")
|
||||
println("· created a folder")
|
||||
|
||||
val payload = ByteArray(200_000) { (it % 251).toByte() }
|
||||
val uploaded = files.upload(payload, "sample.bin", folder.id)
|
||||
?: fail("no file returned")
|
||||
println("· uploaded ${payload.size} bytes across ${payload.size / 65536 + 1} chunks")
|
||||
|
||||
val listed = files.list(folder.id)
|
||||
val entry = listed.firstOrNull { it.name == "sample.bin" }
|
||||
?: fail("the uploaded file did not come back with a readable name")
|
||||
println("· listed it and decrypted its name")
|
||||
|
||||
if (!files.download(uploaded).contentEquals(payload)) {
|
||||
fail("the downloaded bytes do not match")
|
||||
}
|
||||
println("· downloaded and the bytes match exactly")
|
||||
|
||||
val share = files.createShare(entry, password = "hunter2")
|
||||
println("· made a password-protected link")
|
||||
|
||||
val opened = files.openShare(share.id, share.secret, "hunter2")
|
||||
if (!opened.bytes.contentEquals(payload) || opened.name != "sample.bin") {
|
||||
fail("the share did not open to the original file")
|
||||
}
|
||||
println("· opened it with the password")
|
||||
|
||||
try {
|
||||
files.openShare(share.id, share.secret)
|
||||
fail("the link opened WITHOUT its password — the third factor is not enforced")
|
||||
} catch (error: Exception) {
|
||||
println("· refused it without the password")
|
||||
}
|
||||
|
||||
println()
|
||||
println("all good. recovery code for $handle: ${generated.code}")
|
||||
}
|
||||
|
||||
else -> fail("unknown command '$command'")
|
||||
}
|
||||
} catch (error: ClientException) {
|
||||
fail(error.message ?: error.toString())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,436 @@
|
||||
package io.flamenet.files.client
|
||||
|
||||
import io.flamenet.files.engine.Content
|
||||
import io.flamenet.files.engine.Identity
|
||||
import io.flamenet.files.engine.Keys
|
||||
import io.flamenet.files.engine.Label
|
||||
import io.flamenet.files.engine.Names
|
||||
import io.flamenet.files.engine.Recovery
|
||||
import io.flamenet.files.engine.Shares
|
||||
import io.flamenet.files.engine.X25519
|
||||
import java.security.PrivateKey
|
||||
import java.security.PublicKey
|
||||
import java.security.SecureRandom
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
/** A clearance range. Mirrors the token's four claims. */
|
||||
data class Clearance(val maximum: Label, val minimum: Label) {
|
||||
/** Both bounds, always: a label must sit inside the range, not merely below
|
||||
* the top of it. */
|
||||
fun permits(label: Label): Boolean =
|
||||
maximum.dominates(label) && label.dominates(minimum)
|
||||
}
|
||||
|
||||
/**
|
||||
* An unlocked working session.
|
||||
*
|
||||
* Holds the identity private key and any unwrapped label keys in memory only.
|
||||
* Nothing is written to disk — not the passphrase, not the keys, not a cached
|
||||
* file listing. Closing the app forgets everything, which is the intended
|
||||
* behaviour and not an omission.
|
||||
*/
|
||||
class FilesSession internal constructor(
|
||||
val api: FilesApi,
|
||||
val accounts: AccountsClient,
|
||||
val token: String,
|
||||
val clearance: Clearance,
|
||||
private val privateKey: PrivateKey,
|
||||
var recoveryCode: String? = null,
|
||||
) {
|
||||
// Derived rather than carried: the server's copy is authoritative for other
|
||||
// people, but for ourselves the private key is the source of truth and
|
||||
// cannot disagree with itself.
|
||||
private val publicKey: PublicKey = X25519.publicFromPrivate(privateKey)
|
||||
private val labelKeys = mutableMapOf<Label, ByteArray>()
|
||||
private val random = SecureRandom()
|
||||
|
||||
var label: Label = clearance.minimum
|
||||
private set
|
||||
|
||||
class Entry(
|
||||
val node: Wire.Node,
|
||||
/** Null when this session holds no key for the row's label: visible to
|
||||
* the database, unreadable here. Showing it as an unnamed row is more
|
||||
* honest than hiding it. */
|
||||
val name: String?,
|
||||
) {
|
||||
val id get() = node.id
|
||||
val label get() = node.label
|
||||
val isFolder get() = node.isFolder
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val json = Json { ignoreUnknownKeys = true; encodeDefaults = true }
|
||||
|
||||
fun encodeRecord(record: Identity.Record): String =
|
||||
json.encodeToString(RecordSurrogate.serializer(), RecordSurrogate.of(record))
|
||||
|
||||
fun decodeRecord(text: String): Identity.Record =
|
||||
json.decodeFromString(RecordSurrogate.serializer(), text).toRecord()
|
||||
|
||||
/**
|
||||
* Unlock an existing identity, enrolling one if the account has none.
|
||||
*
|
||||
* Identity records live on the account service, so this asks there
|
||||
* rather than the file server — the file server no longer holds
|
||||
* anything about who you are.
|
||||
*
|
||||
* No identity is an ordinary state, not an error: an account created
|
||||
* before Files existed has none. Enrolling is safe because the server
|
||||
* allows it exactly once, so a second keypair can never orphan the
|
||||
* label keys wrapped to a first.
|
||||
*/
|
||||
fun open(
|
||||
api: FilesApi,
|
||||
accounts: AccountsClient,
|
||||
token: String,
|
||||
passphrase: String,
|
||||
clearance: Clearance,
|
||||
recoveryEntropy: ByteArray? = null,
|
||||
): FilesSession {
|
||||
api.label = clearance.minimum
|
||||
val record = accounts.identity(token)
|
||||
val protectedRecord = record?.protectedRecord
|
||||
?: return enrol(api, accounts, token, passphrase, clearance, recoveryEntropy)
|
||||
|
||||
val privateKey = try {
|
||||
Identity.unlock(decodeRecord(protectedRecord), passphrase)
|
||||
} catch (error: Exception) {
|
||||
// The only realistic cause is a wrong passphrase: the record is
|
||||
// authenticated, so tampering and a bad key look identical.
|
||||
throw ClientException.WrongPassphrase()
|
||||
}
|
||||
return FilesSession(api, accounts, token, clearance, privateKey)
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and enrol a keypair for an account that has none.
|
||||
*
|
||||
* Returns a session carrying the recovery code, which is the only
|
||||
* moment it exists anywhere: it is not stored, not derivable from the
|
||||
* passphrase, and cannot be reissued.
|
||||
*/
|
||||
fun enrol(
|
||||
api: FilesApi,
|
||||
accounts: AccountsClient,
|
||||
token: String,
|
||||
passphrase: String,
|
||||
clearance: Clearance,
|
||||
recoveryEntropy: ByteArray?,
|
||||
): FilesSession {
|
||||
val entropy = recoveryEntropy ?: Recovery.generate().entropy
|
||||
val pair = Identity.generate()
|
||||
accounts.enroll(
|
||||
token,
|
||||
Identity.exportPublicKey(pair.public),
|
||||
encodeRecord(Identity.protect(pair.private, passphrase)),
|
||||
encodeRecord(Identity.protectWithRecovery(pair.private, entropy)),
|
||||
)
|
||||
return FilesSession(
|
||||
api, accounts, token, clearance, pair.private, Recovery.encode(entropy))
|
||||
}
|
||||
|
||||
/**
|
||||
* Adopt a keypair this device just created during registration.
|
||||
*
|
||||
* Registration writes the identity in the same transaction as the
|
||||
* account, so by the time there is a token the record already exists.
|
||||
* Fetching and unwrapping it again would be 650,000 wasted iterations.
|
||||
*/
|
||||
fun enrolled(
|
||||
api: FilesApi,
|
||||
accounts: AccountsClient,
|
||||
token: String,
|
||||
privateKey: PrivateKey,
|
||||
clearance: Clearance,
|
||||
recoveryCode: String?,
|
||||
): FilesSession {
|
||||
api.label = clearance.minimum
|
||||
return FilesSession(api, accounts, token, clearance, privateKey, recoveryCode)
|
||||
}
|
||||
|
||||
/**
|
||||
* Unlock with a recovery code and set a new passphrase.
|
||||
*
|
||||
* The keypair is unchanged, so every label key already wrapped to it
|
||||
* stays valid and nothing needs re-encrypting. A fresh code is issued
|
||||
* and the old one stops working.
|
||||
*/
|
||||
fun recover(
|
||||
api: FilesApi,
|
||||
accounts: AccountsClient,
|
||||
token: String,
|
||||
code: String,
|
||||
newPassphrase: String,
|
||||
clearance: Clearance,
|
||||
nextEntropy: ByteArray,
|
||||
): FilesSession {
|
||||
api.label = clearance.minimum
|
||||
val recoveryRecord = accounts.identity(token)?.recoveryRecord
|
||||
?: throw ClientException.BadServer("This account has no recovery code on file.")
|
||||
|
||||
val entropy = Recovery.decode(code)
|
||||
val privateKey = Identity.unlockWithRecovery(decodeRecord(recoveryRecord), entropy)
|
||||
|
||||
accounts.rekey(
|
||||
token,
|
||||
encodeRecord(Identity.protect(privateKey, newPassphrase)),
|
||||
encodeRecord(Identity.protectWithRecovery(privateKey, nextEntropy)),
|
||||
)
|
||||
return FilesSession(
|
||||
api, accounts, token, clearance, privateKey, Recovery.encode(nextEntropy))
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: label keys
|
||||
|
||||
/** Load and unwrap every label key granted to this principal. */
|
||||
fun loadLabelKeys(): List<Label> {
|
||||
for (grant in api.labelGrants()) {
|
||||
try {
|
||||
labelKeys[grant.label] = Keys.acceptLabelKey(
|
||||
Http.unb64(grant.wrappedKey), grant.label, privateKey, publicKey)
|
||||
} catch (error: Exception) {
|
||||
// A grant that will not unwrap is not fatal: it may have been
|
||||
// wrapped to a superseded identity key. Skip it rather than
|
||||
// failing the whole session.
|
||||
continue
|
||||
}
|
||||
}
|
||||
return labelKeys.keys.toList()
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure a label key exists for [wanted], creating and self-granting one if
|
||||
* not.
|
||||
*
|
||||
* The server's insert policy allows a self-grant at exactly the session
|
||||
* label and nothing else, so this cannot widen anyone's clearance — it only
|
||||
* materialises a key for a label the caller could already assert.
|
||||
*/
|
||||
private fun ensureLabelKey(wanted: Label): ByteArray {
|
||||
if (!clearance.permits(wanted)) throw ClientException.NotCleared()
|
||||
labelKeys[wanted]?.let { return it }
|
||||
|
||||
val key = ByteArray(32).also(random::nextBytes)
|
||||
val previous = api.label
|
||||
api.label = wanted
|
||||
try {
|
||||
api.storeGrant(wanted, Keys.grantLabelKey(key, wanted, publicKey))
|
||||
} finally {
|
||||
api.label = previous
|
||||
}
|
||||
labelKeys[wanted] = key
|
||||
return key
|
||||
}
|
||||
|
||||
fun use(wanted: Label) {
|
||||
if (!clearance.permits(wanted)) throw ClientException.NotCleared()
|
||||
ensureLabelKey(wanted)
|
||||
label = wanted
|
||||
api.label = wanted
|
||||
}
|
||||
|
||||
private val currentLabelKey: ByteArray
|
||||
get() = labelKeys[label] ?: throw ClientException.NotCleared()
|
||||
|
||||
/** The key that names a folder's children. Root entries use the label key. */
|
||||
private fun folderKey(folderID: String?): ByteArray {
|
||||
if (folderID == null) return currentLabelKey
|
||||
return Keys.unwrapNodeKey(
|
||||
Http.unb64(api.nodeKey(folderID).wrappedKey), currentLabelKey, label)
|
||||
}
|
||||
|
||||
// MARK: browsing
|
||||
|
||||
/** List a folder, decrypting each visible child's name locally. */
|
||||
fun list(folderID: String?): List<Entry> {
|
||||
val nodes = if (folderID == null) api.roots() else api.children(folderID)
|
||||
|
||||
// Inside a folder every child is named under that folder's node key,
|
||||
// which the caller necessarily holds to have got here at all.
|
||||
//
|
||||
// A root listing is different: it spans labels, and each entry was named
|
||||
// under the key of its *own* label. Using the session's label key for
|
||||
// all of them leaves a cleared user staring at rows they can see but
|
||||
// cannot read, which is worse than not showing them at all.
|
||||
val folderNodeKey = if (folderID == null) null else folderKey(folderID)
|
||||
|
||||
return nodes.map { node ->
|
||||
val key = folderNodeKey ?: labelKeys[node.label]
|
||||
val name = key?.let {
|
||||
try {
|
||||
Names.decrypt(
|
||||
it, Http.unb64(node.nameCiphertext),
|
||||
Http.unb64(node.nameDigest), node.label)
|
||||
} catch (error: Exception) {
|
||||
null
|
||||
}
|
||||
}
|
||||
Entry(node, name)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: writing
|
||||
|
||||
fun createFolder(name: String, parentID: String? = null): Wire.Node? {
|
||||
val folderKey = folderKey(parentID)
|
||||
val nodeKey = ByteArray(32).also(random::nextBytes)
|
||||
val named = Names.encrypt(folderKey, name, label)
|
||||
return api.create(
|
||||
Wire.CreateNodeBody(
|
||||
parentID = parentID,
|
||||
nameDigest = Http.b64(named.first),
|
||||
nameCiphertext = Http.b64(named.second),
|
||||
isFolder = true,
|
||||
wrappedKey = Http.b64(Keys.wrapNodeKey(nodeKey, currentLabelKey, label)),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Encrypt then upload.
|
||||
*
|
||||
* The content key is wrapped to the *node* key, which is itself wrapped to
|
||||
* the label key — never to the parent folder's key. That is what keeps the
|
||||
* key hierarchy aligned with the lattice rather than with the tree.
|
||||
*/
|
||||
fun upload(bytes: ByteArray, name: String, parentID: String? = null): Wire.Node? {
|
||||
val folderKey = folderKey(parentID)
|
||||
val nodeKey = ByteArray(32).also(random::nextBytes)
|
||||
val contentKey = ByteArray(32).also(random::nextBytes)
|
||||
|
||||
val blobID = api.putBlob(Content.encrypt(bytes, contentKey, label))
|
||||
val named = Names.encrypt(folderKey, name, label)
|
||||
|
||||
return api.create(
|
||||
Wire.CreateNodeBody(
|
||||
parentID = parentID,
|
||||
nameDigest = Http.b64(named.first),
|
||||
nameCiphertext = Http.b64(named.second),
|
||||
isFolder = false,
|
||||
wrappedKey = Http.b64(Keys.wrapNodeKey(nodeKey, currentLabelKey, label)),
|
||||
contentKey = Http.b64(Keys.wrapContentKey(contentKey, nodeKey, label)),
|
||||
blobID = blobID,
|
||||
sizeBytes = bytes.size.toLong(),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
fun download(node: Wire.Node): ByteArray {
|
||||
val blobID = node.blobID
|
||||
val wrappedContentKey = node.contentKey
|
||||
if (blobID == null || wrappedContentKey == null) {
|
||||
throw ClientException.BadServer("That entry has no contents.")
|
||||
}
|
||||
val nodeKey = Keys.unwrapNodeKey(
|
||||
Http.unb64(api.nodeKey(node.id).wrappedKey), currentLabelKey, node.label)
|
||||
val contentKey = Keys.unwrapContentKey(
|
||||
Http.unb64(wrappedContentKey), nodeKey, node.label)
|
||||
return Content.decrypt(api.getBlob(blobID), contentKey, node.label)
|
||||
}
|
||||
|
||||
// MARK: shares
|
||||
|
||||
class CreatedShare(val id: String, val secret: String, val expiresAt: String?) {
|
||||
/** The link. The secret goes in the fragment, which browsers never
|
||||
* transmit — so the server storing this share cannot open it. */
|
||||
fun url(site: String) = "$site/s/$id#$secret"
|
||||
}
|
||||
|
||||
fun createShare(
|
||||
entry: Entry,
|
||||
expiresInHours: Int = 168,
|
||||
password: String? = null,
|
||||
): CreatedShare {
|
||||
val wrappedContentKey = entry.node.contentKey
|
||||
val name = entry.name
|
||||
if (wrappedContentKey == null || name == null) {
|
||||
throw ClientException.BadServer("Only files you can read can be shared.")
|
||||
}
|
||||
val nodeKey = Keys.unwrapNodeKey(
|
||||
Http.unb64(api.nodeKey(entry.node.id).wrappedKey), currentLabelKey, entry.label)
|
||||
val contentKey = Keys.unwrapContentKey(
|
||||
Http.unb64(wrappedContentKey), nodeKey, entry.label)
|
||||
|
||||
val secret = Shares.createSecret()
|
||||
val sealed = Shares.seal(
|
||||
currentLabelKey, entry.label, secret, contentKey, name, password)
|
||||
|
||||
val created = api.createShare(
|
||||
Wire.CreateShareBody(
|
||||
nodeID = entry.node.id,
|
||||
wrappedContentKey = Http.b64(sealed.wrappedContentKey),
|
||||
wrappedName = Http.b64(sealed.wrappedName),
|
||||
passwordSalt = sealed.passwordSalt?.let(Http::b64),
|
||||
passwordIterations = sealed.passwordIterations,
|
||||
expiresInHours = expiresInHours,
|
||||
),
|
||||
) ?: throw ClientException.BadServer("The server did not return the new link.")
|
||||
|
||||
return CreatedShare(created.id, Shares.encodeSecret(secret), created.expiresAt)
|
||||
}
|
||||
|
||||
class OpenedShare(val name: String, val label: Label, val bytes: ByteArray)
|
||||
|
||||
/**
|
||||
* Open a shared file.
|
||||
*
|
||||
* Fails for anyone not cleared for its label, twice over: the server will
|
||||
* not serve the wrapped material to an undominated session, and without the
|
||||
* label key the share key cannot be derived even if it did.
|
||||
*/
|
||||
fun openShare(shareID: String, secret: String, password: String? = null): OpenedShare {
|
||||
val row = api.share(shareID) ?: throw ClientException.Http(404, "")
|
||||
val classification = row.classification
|
||||
val wrappedContentKey = row.wrappedContentKey
|
||||
val wrappedName = row.wrappedName
|
||||
val blobID = row.blobID
|
||||
if (classification == null || wrappedContentKey == null ||
|
||||
wrappedName == null || blobID == null
|
||||
) {
|
||||
throw ClientException.Http(404, "")
|
||||
}
|
||||
|
||||
val shareLabel = Label(classification, (row.compartments ?: emptyList()).toSet())
|
||||
val labelKey = labelKeys[shareLabel] ?: throw ClientException.NotCleared()
|
||||
|
||||
val opened = Shares.open(
|
||||
labelKey, shareLabel, Shares.decodeSecret(secret),
|
||||
Http.unb64(wrappedContentKey), Http.unb64(wrappedName),
|
||||
password, row.passwordSalt?.let(Http::unb64),
|
||||
row.passwordIterations ?: Shares.PASSWORD_ITERATIONS,
|
||||
)
|
||||
return OpenedShare(
|
||||
opened.name, shareLabel,
|
||||
Content.decrypt(api.getBlob(blobID), opened.contentKey, shareLabel),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The identity record's JSON shape.
|
||||
*
|
||||
* A surrogate rather than annotating the engine's own type: the engine is
|
||||
* deliberately free of serialization dependencies, so that it can be dropped
|
||||
* into an Android app without dragging a JSON library into the crypto path.
|
||||
*/
|
||||
@kotlinx.serialization.Serializable
|
||||
internal data class RecordSurrogate(
|
||||
val v: Int,
|
||||
val kdf: Int,
|
||||
val iterations: Int,
|
||||
val context: String,
|
||||
val salt: String,
|
||||
val nonce: String,
|
||||
val privateKey: String,
|
||||
) {
|
||||
fun toRecord() = Identity.Record(v, kdf, iterations, context, salt, nonce, privateKey)
|
||||
|
||||
companion object {
|
||||
fun of(record: Identity.Record) = RecordSurrogate(
|
||||
record.v, record.kdf, record.iterations,
|
||||
record.context, record.salt, record.nonce, record.privateKey,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
package io.flamenet.files.client
|
||||
|
||||
import java.io.IOException
|
||||
import java.net.HttpURLConnection
|
||||
import java.net.URI
|
||||
import java.net.URL
|
||||
import java.util.Base64
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
/**
|
||||
* A very small HTTP layer.
|
||||
*
|
||||
* No third-party networking. This app moves ciphertext and bearer tokens, and
|
||||
* every dependency in that path is one more place a supply-chain compromise
|
||||
* reads plaintext — the browser client made the same call for the same reason.
|
||||
*/
|
||||
internal class Http {
|
||||
companion object {
|
||||
val json = Json {
|
||||
ignoreUnknownKeys = true
|
||||
encodeDefaults = true
|
||||
explicitNulls = false
|
||||
}
|
||||
|
||||
fun b64(bytes: ByteArray): String = Base64.getEncoder().encodeToString(bytes)
|
||||
fun unb64(text: String): ByteArray = Base64.getDecoder().decode(text)
|
||||
|
||||
/**
|
||||
* Joins a path onto a base that may or may not have a trailing slash,
|
||||
* and refuses anything that is not http(s) — a `file:` base would
|
||||
* otherwise silently "work" and read the device's own storage.
|
||||
*/
|
||||
fun endpoint(base: String, path: String): URL {
|
||||
var trimmed = base.trim()
|
||||
if (trimmed.isEmpty()) throw ClientException.BadServer("Enter a server address.")
|
||||
if (!trimmed.contains("://")) trimmed = "https://$trimmed"
|
||||
trimmed = trimmed.trimEnd('/')
|
||||
val uri = try {
|
||||
URI(trimmed + path)
|
||||
} catch (error: Exception) {
|
||||
throw ClientException.BadServer("That doesn't look like a server address.")
|
||||
}
|
||||
if (uri.scheme?.lowercase() !in setOf("http", "https")) {
|
||||
throw ClientException.BadServer("That doesn't look like a server address.")
|
||||
}
|
||||
return uri.toURL()
|
||||
}
|
||||
}
|
||||
|
||||
class Response(val body: ByteArray, val status: Int)
|
||||
|
||||
fun request(
|
||||
method: String,
|
||||
url: URL,
|
||||
headers: Map<String, String> = emptyMap(),
|
||||
jsonBody: String? = null,
|
||||
rawBody: ByteArray? = null,
|
||||
): Response {
|
||||
val connection = url.openConnection() as HttpURLConnection
|
||||
connection.requestMethod = method
|
||||
connection.connectTimeout = 15_000
|
||||
connection.readTimeout = 60_000
|
||||
// Nothing here should be cached: responses carry wrapped keys and, for
|
||||
// the identity endpoint, the protected private key record.
|
||||
connection.useCaches = false
|
||||
connection.setRequestProperty("Cache-Control", "no-store")
|
||||
headers.forEach(connection::setRequestProperty)
|
||||
|
||||
when {
|
||||
jsonBody != null -> {
|
||||
connection.setRequestProperty("Content-Type", "application/json")
|
||||
connection.doOutput = true
|
||||
connection.outputStream.use { it.write(jsonBody.toByteArray(Charsets.UTF_8)) }
|
||||
}
|
||||
rawBody != null -> {
|
||||
connection.setRequestProperty("Content-Type", "application/octet-stream")
|
||||
connection.doOutput = true
|
||||
connection.outputStream.use { it.write(rawBody) }
|
||||
}
|
||||
}
|
||||
|
||||
val status = try {
|
||||
connection.responseCode
|
||||
} catch (error: IOException) {
|
||||
throw ClientException.BadServer("Could not reach that server.")
|
||||
}
|
||||
val body = (if (status in 200..299) connection.inputStream else connection.errorStream)
|
||||
?.use { it.readBytes() } ?: ByteArray(0)
|
||||
connection.disconnect()
|
||||
|
||||
if (status !in 200..299) throw ClientException.Http(status, reason(body))
|
||||
return Response(body, status)
|
||||
}
|
||||
|
||||
/**
|
||||
* Vapor puts a human-readable message in `reason`. Fall back to the raw
|
||||
* body only if it is short — a stack trace in a toast helps nobody.
|
||||
*/
|
||||
private fun reason(body: ByteArray): String {
|
||||
val text = String(body, Charsets.UTF_8)
|
||||
return try {
|
||||
json.parseToJsonElement(text).let { element ->
|
||||
(element as? kotlinx.serialization.json.JsonObject)
|
||||
?.get("reason")
|
||||
?.let { (it as? kotlinx.serialization.json.JsonPrimitive)?.content }
|
||||
?: if (text.length <= 200) text else ""
|
||||
}
|
||||
} catch (error: Exception) {
|
||||
if (text.length <= 200) text else ""
|
||||
}
|
||||
}
|
||||
|
||||
inline fun <reified T> decode(body: ByteArray): T =
|
||||
try {
|
||||
json.decodeFromString<T>(String(body, Charsets.UTF_8))
|
||||
} catch (error: Exception) {
|
||||
throw ClientException.BadServer(
|
||||
"The server sent something this version cannot read. It may be newer than the app.")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
package io.flamenet.files.client
|
||||
|
||||
import io.flamenet.files.engine.Label
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
|
||||
/**
|
||||
* The wire types, spelled out rather than parsed loosely.
|
||||
*
|
||||
* Every field here crosses a trust boundary, so each one is named and typed: a
|
||||
* silently-missing key that becomes null and then becomes a default is how a
|
||||
* client ends up encrypting under the wrong label.
|
||||
*
|
||||
* Byte fields travel as base64 strings, which is what Vapor encodes `Data` as.
|
||||
* They are kept as `String` at this layer and decoded explicitly, so a
|
||||
* malformed one fails where it is read rather than somewhere downstream.
|
||||
*/
|
||||
object Wire {
|
||||
/**
|
||||
* What a server says about itself, before anyone has signed in.
|
||||
*
|
||||
* This is how the app learns which account service to authenticate against.
|
||||
* Point it at files.flamenet.io and it is told accounts.flamenet.io; point
|
||||
* it at a self-hosted box and it is told that box's own bundled service. No
|
||||
* build flags, and no hardcoded list of which hostnames are "ours" — which
|
||||
* would be wrong the moment somebody forks this.
|
||||
*/
|
||||
@Serializable
|
||||
data class ServerConfig(
|
||||
val accountsURL: String,
|
||||
val tenant: String,
|
||||
val siteURL: String,
|
||||
val sourceURL: String,
|
||||
val protocolVersion: Int,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class KdfParams(val kdfSalt: String, val kdfID: Short, val kdfIterations: Int)
|
||||
|
||||
@Serializable
|
||||
data class Session(val token: String, val pseudonym: String, val expiresAt: String)
|
||||
|
||||
@Serializable
|
||||
data class Identity(
|
||||
val principalID: String,
|
||||
val publicKey: String,
|
||||
val protectedRecord: String? = null,
|
||||
val recoveryRecord: String? = null,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class NewIdentity(
|
||||
val product: String = "files",
|
||||
val publicKey: String,
|
||||
val protectedRecord: String,
|
||||
val recoveryRecord: String? = null,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class RegisterBody(
|
||||
val handle: String,
|
||||
val authSecret: String,
|
||||
val kdfSalt: String,
|
||||
val kdfIterations: Int,
|
||||
val recoveryAuthSecret: String? = null,
|
||||
val identity: NewIdentity? = null,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class SessionBody(val handle: String, val authSecret: String, val product: String)
|
||||
|
||||
@Serializable
|
||||
data class RotateBody(
|
||||
val handle: String,
|
||||
val recoveryAuthSecret: String,
|
||||
val newAuthSecret: String,
|
||||
val newKdfSalt: String,
|
||||
val newKdfIterations: Int,
|
||||
val newRecoveryAuthSecret: String,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class EnrollBody(
|
||||
val publicKey: String,
|
||||
val protectedRecord: String,
|
||||
val recoveryRecord: String? = null,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class RekeyBody(val protectedRecord: String, val recoveryRecord: String? = null)
|
||||
|
||||
/** A node as the server sees it: a label, two opaque name blobs, and
|
||||
* nothing it can read. */
|
||||
@Serializable
|
||||
data class Node(
|
||||
val id: String,
|
||||
val parentID: String? = null,
|
||||
val classification: Short,
|
||||
val compartments: List<Int> = emptyList(),
|
||||
val nameDigest: String,
|
||||
val nameCiphertext: String,
|
||||
val isFolder: Boolean,
|
||||
val blobID: String? = null,
|
||||
val contentKey: String? = null,
|
||||
val sizeBytes: Long? = null,
|
||||
) {
|
||||
val label: Label get() = Label(classification, compartments.toSet())
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class CreateNodeBody(
|
||||
val parentID: String? = null,
|
||||
val nameDigest: String,
|
||||
val nameCiphertext: String,
|
||||
val isFolder: Boolean,
|
||||
val wrappedKey: String,
|
||||
val contentKey: String? = null,
|
||||
val blobID: String? = null,
|
||||
val sizeBytes: Long = 0,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class LabelGrant(
|
||||
val classification: Short,
|
||||
val compartments: List<Int> = emptyList(),
|
||||
val wrappedKey: String,
|
||||
) {
|
||||
val label: Label get() = Label(classification, compartments.toSet())
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class GrantBody(
|
||||
val classification: Short,
|
||||
val compartments: List<Int>,
|
||||
val wrappedKey: String,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class NodeKey(val wrappedKey: String)
|
||||
|
||||
@Serializable
|
||||
data class BlobCreated(val id: String)
|
||||
|
||||
/** What this deployment calls its levels and areas. Purely presentational:
|
||||
* nothing in the lattice depends on the words. */
|
||||
@Serializable
|
||||
data class Vocabulary(
|
||||
val levels: List<Level> = emptyList(),
|
||||
val compartments: List<Compartment> = emptyList(),
|
||||
val canEdit: Boolean? = null,
|
||||
) {
|
||||
@Serializable data class Level(val ordinal: Short, val name: String)
|
||||
@Serializable data class Compartment(val bit: Int, val name: String)
|
||||
|
||||
fun name(label: Label): String {
|
||||
val level = levels.firstOrNull { it.ordinal == label.classification }?.name
|
||||
?: "Level ${label.classification}"
|
||||
val areas = label.compartments.sorted().map { bit ->
|
||||
compartments.firstOrNull { it.bit == bit }?.name ?: "Area $bit"
|
||||
}
|
||||
return if (areas.isEmpty()) level else "$level // ${areas.joinToString(", ")}"
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
data class CreateShareBody(
|
||||
val nodeID: String,
|
||||
val wrappedContentKey: String,
|
||||
val wrappedName: String,
|
||||
val passwordSalt: String? = null,
|
||||
val passwordIterations: Int? = null,
|
||||
val expiresInHours: Int,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
data class Share(
|
||||
val id: String,
|
||||
val expiresAt: String? = null,
|
||||
val classification: Short? = null,
|
||||
val compartments: List<Int>? = null,
|
||||
val wrappedContentKey: String? = null,
|
||||
val wrappedName: String? = null,
|
||||
val passwordSalt: String? = null,
|
||||
val passwordIterations: Int? = null,
|
||||
val needsPassword: Boolean? = null,
|
||||
val blobID: String? = null,
|
||||
)
|
||||
}
|
||||
|
||||
/** What went wrong, in terms the interface can actually say out loud. */
|
||||
sealed class ClientException(message: String) : Exception(message) {
|
||||
class Http(val status: Int, val detail: String) : ClientException(
|
||||
when {
|
||||
// 404 is deliberate on this server: a row you are not cleared to see
|
||||
// is missing, not forbidden. Saying "forbidden" would leak that it
|
||||
// exists, so the app does not say it either.
|
||||
status == 404 -> "Not found."
|
||||
status == 401 -> "Your session has expired. Sign in again."
|
||||
status == 403 -> "That's outside your clearance."
|
||||
detail.isNotEmpty() -> detail
|
||||
else -> "The server returned $status."
|
||||
}
|
||||
)
|
||||
|
||||
class NotCleared : ClientException("You aren't cleared for this.")
|
||||
class WrongPassphrase : ClientException("That handle and passphrase don't match.")
|
||||
class BadServer(why: String) : ClientException(why)
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
package io.flamenet.files.engine
|
||||
|
||||
import java.security.KeyPair
|
||||
import java.security.PrivateKey
|
||||
import java.security.PublicKey
|
||||
import java.security.SecureRandom
|
||||
import java.util.Base64
|
||||
|
||||
/**
|
||||
@@ -41,6 +44,64 @@ object Identity {
|
||||
val privateKey: String,
|
||||
)
|
||||
|
||||
fun generate(): KeyPair = X25519.generate()
|
||||
|
||||
/** Raw 32 bytes: what every FlameNet server stores. */
|
||||
fun exportPublicKey(key: PublicKey): ByteArray = X25519.rawFromPublic(key)
|
||||
|
||||
/**
|
||||
* Encrypt a private key for storage.
|
||||
*
|
||||
* The context string is the authenticated data as well as the KDF domain
|
||||
* separator, so a record produced for one product cannot be unlocked as
|
||||
* another's even with the right passphrase.
|
||||
*
|
||||
* The iteration count is written into the record rather than looked up from
|
||||
* a registry. Raising the default must not strand accounts whose records
|
||||
* were made under the old one, so the record has to say what actually
|
||||
* produced its key.
|
||||
*/
|
||||
fun protect(
|
||||
privateKey: PrivateKey,
|
||||
passphrase: String,
|
||||
parameters: Kdf.Parameters = Kdf.Parameters.V1,
|
||||
context: String = Kdf.Context.FILES_IDENTITY,
|
||||
): Record {
|
||||
val encode = Base64.getEncoder()
|
||||
val salt = ByteArray(16).also(SecureRandom()::nextBytes)
|
||||
val nonce = ByteArray(12).also(SecureRandom()::nextBytes)
|
||||
val kek = Kdf.derive(passphrase, salt, context, parameters)
|
||||
// PKCS#8, not raw: the browser writes this format and the two have to
|
||||
// read each other's records.
|
||||
val sealed = Wrap.seal(
|
||||
kek, pkcs8FromRaw(X25519.rawFromPrivate(privateKey)),
|
||||
context.toByteArray(Charsets.UTF_8), nonce,
|
||||
)
|
||||
return Record(
|
||||
v = 1, kdf = parameters.id, iterations = parameters.iterations, context = context,
|
||||
salt = encode.encodeToString(salt),
|
||||
nonce = encode.encodeToString(nonce),
|
||||
privateKey = encode.encodeToString(sealed),
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap the same private key under a recovery code.
|
||||
*
|
||||
* A different context, so neither secret reveals the other and changing the
|
||||
* passphrase does not invalidate the code. Rotating an identity fully means
|
||||
* replacing both records.
|
||||
*/
|
||||
fun protectWithRecovery(
|
||||
privateKey: PrivateKey,
|
||||
entropy: ByteArray,
|
||||
parameters: Kdf.Parameters = Kdf.Parameters.V1,
|
||||
): Record = protect(
|
||||
privateKey, Recovery.kdfSecret(entropy), parameters, Kdf.Context.FILES_RECOVERY)
|
||||
|
||||
fun unlockWithRecovery(record: Record, entropy: ByteArray): PrivateKey =
|
||||
unlock(record, Recovery.kdfSecret(entropy))
|
||||
|
||||
fun unlock(record: Record, passphrase: String): PrivateKey {
|
||||
if (record.v != 1) throw EngineException("unsupported identity record version ${record.v}")
|
||||
val decode = Base64.getDecoder()
|
||||
|
||||
@@ -19,6 +19,13 @@ object Kdf {
|
||||
const val FILES_IDENTITY = "flamenet/files/identity/v1"
|
||||
const val FILES_AUTH = "flamenet/files/auth/v1"
|
||||
const val MESSENGER_IDENTITY = "flamenet/messenger/identity/v1"
|
||||
const val FILES_RECOVERY = "flamenet/files/recovery/v1"
|
||||
|
||||
/**
|
||||
* The account-side half of a recovery code. HKDF only: the code already
|
||||
* carries 128 bits of its own entropy, so there is nothing to stretch.
|
||||
*/
|
||||
const val FILES_AUTH_RECOVERY = "flamenet/files/auth-recovery/v1"
|
||||
}
|
||||
|
||||
/** Stage one. Shared across products, never used directly. */
|
||||
@@ -43,4 +50,18 @@ object Kdf {
|
||||
*/
|
||||
fun authSecret(passphrase: String, salt: ByteArray, parameters: Parameters = Parameters.V1): ByteArray =
|
||||
derive(passphrase, salt, Context.FILES_AUTH, parameters)
|
||||
|
||||
/**
|
||||
* The account-side proof of a recovery code.
|
||||
*
|
||||
* No PBKDF2, and that is not an oversight: the code is 128 random bits, so
|
||||
* there is nothing to stretch. HKDF over it is enough, and the server keeps
|
||||
* only a salted hash of the result.
|
||||
*/
|
||||
fun recoveryAuthSecret(entropy: ByteArray): ByteArray = Hkdf.derive(
|
||||
ikm = Recovery.kdfSecret(entropy).toByteArray(Charsets.UTF_8),
|
||||
salt = ByteArray(0),
|
||||
info = Context.FILES_AUTH_RECOVERY.toByteArray(Charsets.UTF_8),
|
||||
length = 32,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
package io.flamenet.files.engine
|
||||
|
||||
import java.math.BigInteger
|
||||
import java.security.MessageDigest
|
||||
import java.security.SecureRandom
|
||||
|
||||
/**
|
||||
* Recovery codes. Specification §7.
|
||||
*
|
||||
* Losing a passphrase otherwise loses the data outright: the server holds no
|
||||
* key that opens anything. A recovery code is a second, high-entropy secret
|
||||
* that wraps the *same* identity private key under a different context, so
|
||||
* either secret unlocks the account and neither reveals the other.
|
||||
*
|
||||
* Crockford base32 rather than a word list. A twelve-word phrase transcribes
|
||||
* more kindly, but vendoring BIP-39 means carrying 2,048 words that have to be
|
||||
* byte-exact — one wrong entry silently produces codes that cannot be decoded.
|
||||
* Crockford needs no vendored data and is unambiguous by construction: `I`,
|
||||
* `L`, `O` and `U` are absent from the alphabet, and the glyphs people actually
|
||||
* confuse are folded on input.
|
||||
*
|
||||
* 128 bits entropy || 12 bits checksum = 140 bits = 28 characters
|
||||
* grouped as XXXX-XXXX-XXXX-XXXX-XXXX-XXXX-XXXX
|
||||
*
|
||||
* The checksum catches a typo in microseconds, before the deliberately slow key
|
||||
* derivation runs.
|
||||
*/
|
||||
object Recovery {
|
||||
private const val ALPHABET = "0123456789ABCDEFGHJKMNPQRSTVWXYZ"
|
||||
const val ENTROPY_BYTES = 16
|
||||
private const val CHECKSUM_BITS = 12
|
||||
private const val CODE_LENGTH = 28
|
||||
|
||||
private val random = SecureRandom()
|
||||
|
||||
private fun checksum(entropy: ByteArray): Int {
|
||||
val digest = MessageDigest.getInstance("SHA-256").digest(entropy)
|
||||
// Top 12 bits.
|
||||
return ((digest[0].toInt() and 0xFF) shl 4) or ((digest[1].toInt() and 0xFF) ushr 4)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fold the ambiguous glyphs and drop formatting, so a code read off paper
|
||||
* as "O" for zero or "l" for one still decodes.
|
||||
*
|
||||
* ⚠️ Only `O` and `I`/`L` fold. `Q` is a *valid* Crockford character —
|
||||
* folding it corrupts every code containing one, which is a mistake this
|
||||
* codebase has made once already.
|
||||
*/
|
||||
fun normalize(text: String): String = buildString {
|
||||
for (character in text.uppercase()) {
|
||||
when {
|
||||
character == 'O' -> append('0')
|
||||
character == 'I' || character == 'L' -> append('1')
|
||||
character in '0'..'9' || character in 'A'..'Z' -> append(character)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class Generated(val entropy: ByteArray, val code: String) {
|
||||
override fun equals(other: Any?) =
|
||||
other is Generated && entropy.contentEquals(other.entropy) && code == other.code
|
||||
override fun hashCode() = 31 * entropy.contentHashCode() + code.hashCode()
|
||||
}
|
||||
|
||||
fun generate(): Generated {
|
||||
val entropy = ByteArray(ENTROPY_BYTES).also(random::nextBytes)
|
||||
return Generated(entropy, encode(entropy))
|
||||
}
|
||||
|
||||
fun encode(entropy: ByteArray): String {
|
||||
if (entropy.size != ENTROPY_BYTES) {
|
||||
throw EngineException("entropy must be $ENTROPY_BYTES bytes")
|
||||
}
|
||||
// 140 bits does not fit any fixed-width integer. BigInteger with a
|
||||
// leading zero byte keeps it unsigned; without it a high bit makes the
|
||||
// value negative and every shift goes wrong.
|
||||
var value = BigInteger(1, entropy)
|
||||
value = value.shiftLeft(CHECKSUM_BITS).or(BigInteger.valueOf(checksum(entropy).toLong()))
|
||||
|
||||
val out = CharArray(CODE_LENGTH)
|
||||
val thirtyOne = BigInteger.valueOf(31)
|
||||
for (index in CODE_LENGTH - 1 downTo 0) {
|
||||
out[index] = ALPHABET[value.and(thirtyOne).toInt()]
|
||||
value = value.shiftRight(5)
|
||||
}
|
||||
return String(out).chunked(4).joinToString("-")
|
||||
}
|
||||
|
||||
fun decode(text: String): ByteArray {
|
||||
val normalized = normalize(text)
|
||||
if (normalized.length != CODE_LENGTH) {
|
||||
throw EngineException(
|
||||
"recovery code must be $CODE_LENGTH characters, got ${normalized.length}")
|
||||
}
|
||||
|
||||
var value = BigInteger.ZERO
|
||||
for (character in normalized) {
|
||||
val index = ALPHABET.indexOf(character)
|
||||
if (index < 0) throw EngineException("invalid character '$character' in recovery code")
|
||||
value = value.shiftLeft(5).or(BigInteger.valueOf(index.toLong()))
|
||||
}
|
||||
|
||||
val mask = BigInteger.ONE.shiftLeft(CHECKSUM_BITS).subtract(BigInteger.ONE)
|
||||
val provided = value.and(mask).toInt()
|
||||
value = value.shiftRight(CHECKSUM_BITS)
|
||||
|
||||
// Left-pad: BigInteger drops leading zero bytes, and a code whose
|
||||
// entropy begins with one would otherwise decode short.
|
||||
val raw = value.toByteArray()
|
||||
val entropy = ByteArray(ENTROPY_BYTES)
|
||||
val take = minOf(raw.size, ENTROPY_BYTES)
|
||||
raw.copyInto(entropy, ENTROPY_BYTES - take, raw.size - take, raw.size)
|
||||
|
||||
if (checksum(entropy) != provided) {
|
||||
throw EngineException("recovery code checksum does not match — check for a typo")
|
||||
}
|
||||
return entropy
|
||||
}
|
||||
|
||||
/**
|
||||
* The string fed to the KDF.
|
||||
*
|
||||
* Derived from the entropy rather than from the typed code, so formatting
|
||||
* differences — grouping, case, folded glyphs — cannot produce two
|
||||
* different keys from what is really one code.
|
||||
*/
|
||||
fun kdfSecret(entropy: ByteArray): String =
|
||||
entropy.joinToString("") { "%02x".format(it) }
|
||||
}
|
||||
@@ -0,0 +1,116 @@
|
||||
package io.flamenet.files.engine
|
||||
|
||||
import java.security.SecureRandom
|
||||
import java.util.Base64
|
||||
import javax.crypto.SecretKeyFactory
|
||||
import javax.crypto.spec.PBEKeySpec
|
||||
|
||||
/**
|
||||
* Share links that still respect the lattice. Specification §8.
|
||||
*
|
||||
* An ordinary "anyone with the link" share is incompatible with labels. A label
|
||||
* makes access depend on who you are; a bearer link makes it depend on what you
|
||||
* hold, and forwarding defeats it. So a share here needs *two* things:
|
||||
*
|
||||
* - the link, whose fragment carries a secret the server never receives
|
||||
* - the label key, which only a cleared principal holds
|
||||
*
|
||||
* shareKey = HKDF-SHA256(labelKey ‖ secret, info = "enclave/share/v1")
|
||||
*
|
||||
* Forward the link to someone who is not cleared and they get nothing. The
|
||||
* server cannot read it either: the secret lives only in the URL fragment, and
|
||||
* fragments are never transmitted.
|
||||
*
|
||||
* An optional password is a third factor, as DoD SAFE does it. It is stretched
|
||||
* hard, because a share password is chosen under time pressure and will be
|
||||
* short — and it is never sent anywhere, so no server can test a guess against
|
||||
* it. A wrong password simply produces a key that does not decrypt.
|
||||
*/
|
||||
object Shares {
|
||||
private const val INFO = "enclave/share/v1"
|
||||
private const val INFO_PASSWORD = "enclave/share/v2"
|
||||
const val PASSWORD_ITERATIONS = 250_000
|
||||
|
||||
private val random = SecureRandom()
|
||||
|
||||
class Sealed(
|
||||
val wrappedContentKey: ByteArray,
|
||||
val wrappedName: ByteArray,
|
||||
/** Public. A salt is not a secret and the recipient needs it. */
|
||||
val passwordSalt: ByteArray?,
|
||||
val passwordIterations: Int?,
|
||||
)
|
||||
|
||||
fun createSecret(): ByteArray = ByteArray(32).also(random::nextBytes)
|
||||
|
||||
private fun passwordKey(password: String, salt: ByteArray, iterations: Int): ByteArray =
|
||||
SecretKeyFactory.getInstance("PBKDF2WithHmacSHA256")
|
||||
.generateSecret(PBEKeySpec(password.toCharArray(), salt, iterations, 256))
|
||||
.encoded
|
||||
|
||||
/**
|
||||
* Two factors always; three when a password is set.
|
||||
*
|
||||
* The info string differs between the two constructions, so a
|
||||
* password-protected share cannot be opened as though it had none.
|
||||
*/
|
||||
private fun shareKey(labelKey: ByteArray, secret: ByteArray, passwordKey: ByteArray?): ByteArray =
|
||||
Hkdf.derive(
|
||||
ikm = if (passwordKey == null) labelKey + secret else labelKey + secret + passwordKey,
|
||||
salt = ByteArray(0),
|
||||
info = (if (passwordKey == null) INFO else INFO_PASSWORD).toByteArray(Charsets.UTF_8),
|
||||
length = 32,
|
||||
)
|
||||
|
||||
/**
|
||||
* Both the key and the name carry the label as authenticated data, exactly
|
||||
* as everything else does, so a share cannot be replayed against a row the
|
||||
* server has since relabelled.
|
||||
*/
|
||||
fun seal(
|
||||
labelKey: ByteArray, label: Label, secret: ByteArray,
|
||||
contentKey: ByteArray, name: String, password: String? = null,
|
||||
): Sealed {
|
||||
val salt = if (password == null) null else ByteArray(16).also(random::nextBytes)
|
||||
val pwKey = password?.let { passwordKey(it, salt!!, PASSWORD_ITERATIONS) }
|
||||
val key = shareKey(labelKey, secret, pwKey)
|
||||
val aad = label.bytes
|
||||
return Sealed(
|
||||
wrappedContentKey = Wrap.withKey(key, contentKey, aad),
|
||||
wrappedName = Wrap.withKey(key, name.toByteArray(Charsets.UTF_8), aad),
|
||||
passwordSalt = salt,
|
||||
passwordIterations = if (password == null) null else PASSWORD_ITERATIONS,
|
||||
)
|
||||
}
|
||||
|
||||
class Opened(val contentKey: ByteArray, val name: String)
|
||||
|
||||
fun open(
|
||||
labelKey: ByteArray, label: Label, secret: ByteArray,
|
||||
wrappedContentKey: ByteArray, wrappedName: ByteArray,
|
||||
password: String? = null, passwordSalt: ByteArray? = null,
|
||||
passwordIterations: Int = PASSWORD_ITERATIONS,
|
||||
): Opened {
|
||||
if (passwordSalt != null && password == null) {
|
||||
throw EngineException("This link needs the password it was sent with.")
|
||||
}
|
||||
val pwKey = passwordSalt?.let { passwordKey(password!!, it, passwordIterations) }
|
||||
val key = shareKey(labelKey, secret, pwKey)
|
||||
val aad = label.bytes
|
||||
return Opened(
|
||||
contentKey = Wrap.openWithKey(key, wrappedContentKey, aad),
|
||||
name = String(Wrap.openWithKey(key, wrappedName, aad), Charsets.UTF_8),
|
||||
)
|
||||
}
|
||||
|
||||
/** The fragment form. Base64url, so it survives a URL untouched. */
|
||||
fun encodeSecret(secret: ByteArray): String =
|
||||
Base64.getUrlEncoder().withoutPadding().encodeToString(secret)
|
||||
|
||||
fun decodeSecret(text: String): ByteArray =
|
||||
try {
|
||||
Base64.getUrlDecoder().decode(text)
|
||||
} catch (error: IllegalArgumentException) {
|
||||
throw EngineException("share secret is not valid base64url")
|
||||
}
|
||||
}
|
||||
@@ -56,6 +56,20 @@ object X25519 {
|
||||
fun rawFromPrivate(key: PrivateKey): ByteArray =
|
||||
(key as XECPrivateKey).scalar.orElseThrow { EngineException("private key is not extractable") }
|
||||
|
||||
/**
|
||||
* Derive the public half from a private key.
|
||||
*
|
||||
* JCA hands back a public key only from a freshly generated KeyPair, and a
|
||||
* session that unlocked a stored record has just the scalar. Scalar
|
||||
* multiplication against the generator is exactly what agreement does, so
|
||||
* agreeing with the basepoint recovers it — no second stored copy, and no
|
||||
* chance of the two disagreeing.
|
||||
*/
|
||||
fun publicFromPrivate(privateKey: PrivateKey): PublicKey {
|
||||
val basepoint = ByteArray(32).also { it[0] = 9 }
|
||||
return publicFromRaw(agree(privateKey, publicFromRaw(basepoint)))
|
||||
}
|
||||
|
||||
fun agree(privateKey: PrivateKey, publicKey: PublicKey): ByteArray =
|
||||
KeyAgreement.getInstance("XDH").run {
|
||||
init(privateKey)
|
||||
|
||||
@@ -0,0 +1,166 @@
|
||||
package io.flamenet.files.engine
|
||||
|
||||
import kotlinx.serialization.json.*
|
||||
import java.util.Base64
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertContentEquals
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertFailsWith
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
/**
|
||||
* Recovery codes and identity protection.
|
||||
*
|
||||
* The interop cases are the ones that matter: a code printed on one device has
|
||||
* to work on another, so this engine must agree with the browser character for
|
||||
* character. The self round-trips catch the other failure mode — a code that
|
||||
* encodes and does not decode is worthless, and it fails silently at exactly
|
||||
* the moment somebody needs it.
|
||||
*/
|
||||
class RecoveryTest {
|
||||
private val vectors: JsonObject = javaClass.getResourceAsStream("/vectors/v1.json")!!
|
||||
.bufferedReader().use { Json.parseToJsonElement(it.readText()).jsonObject }
|
||||
|
||||
private fun b64(s: String): ByteArray = Base64.getDecoder().decode(s)
|
||||
|
||||
private val browserCases: List<JsonObject>
|
||||
get() = vectors["recovery"]!!.jsonArray.map { it.jsonObject } +
|
||||
listOf(vectors["recoveryWithQ"]!!.jsonObject)
|
||||
|
||||
@Test
|
||||
fun `agrees with the browser`() {
|
||||
for (expected in browserCases) {
|
||||
val entropy = b64(expected["entropy"]!!.jsonPrimitive.content)
|
||||
val code = expected["code"]!!.jsonPrimitive.content
|
||||
assertEquals(code, Recovery.encode(entropy))
|
||||
assertContentEquals(entropy, Recovery.decode(code))
|
||||
assertEquals(expected["kdfSecret"]!!.jsonPrimitive.content, Recovery.kdfSecret(entropy))
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A code containing Q, decoded as if read off paper: lower-cased, spaces
|
||||
* instead of dashes. Folding Q here is the bug that once corrupted roughly
|
||||
* a third of all codes.
|
||||
*/
|
||||
@Test
|
||||
fun `the Q case survives transcription`() {
|
||||
val expected = vectors["recoveryWithQ"]!!.jsonObject
|
||||
val code = expected["code"]!!.jsonPrimitive.content
|
||||
assertTrue(code.contains("Q"), "vector should contain a Q")
|
||||
assertContentEquals(
|
||||
b64(expected["entropy"]!!.jsonPrimitive.content),
|
||||
Recovery.decode(code.lowercase().replace("-", " ")),
|
||||
)
|
||||
assertEquals("Q", Recovery.normalize("Q"))
|
||||
assertEquals("0", Recovery.normalize("O"))
|
||||
assertEquals("1", Recovery.normalize("I"))
|
||||
assertEquals("1", Recovery.normalize("L"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `codes round trip`() {
|
||||
repeat(200) {
|
||||
val generated = Recovery.generate()
|
||||
assertEquals(28, generated.code.replace("-", "").length)
|
||||
assertContentEquals(generated.entropy, Recovery.decode(generated.code))
|
||||
}
|
||||
}
|
||||
|
||||
/** BigInteger drops leading zero bytes; entropy that starts with one must
|
||||
* still decode to sixteen bytes rather than fifteen. */
|
||||
@Test
|
||||
fun `leading zero entropy survives`() {
|
||||
val entropy = ByteArray(16).also { it[15] = 1 }
|
||||
assertContentEquals(entropy, Recovery.decode(Recovery.encode(entropy)))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the checksum catches a typo`() {
|
||||
val generated = Recovery.generate()
|
||||
val characters = Recovery.normalize(generated.code).toCharArray()
|
||||
characters[3] = if (characters[3] == '7') '8' else '7'
|
||||
assertFailsWith<EngineException> { Recovery.decode(String(characters)) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `identity records round trip`() {
|
||||
// A low iteration count: this asserts the format, not the work factor.
|
||||
val fast = Kdf.Parameters(1, 1_000)
|
||||
val pair = Identity.generate()
|
||||
val record = Identity.protect(pair.private, "correct horse", fast)
|
||||
assertContentEquals(
|
||||
X25519.rawFromPrivate(pair.private),
|
||||
X25519.rawFromPrivate(Identity.unlock(record, "correct horse")),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the wrong passphrase does not open it`() {
|
||||
val fast = Kdf.Parameters(1, 1_000)
|
||||
val record = Identity.protect(Identity.generate().private, "one", fast)
|
||||
assertFailsWith<Exception> { Identity.unlock(record, "two") }
|
||||
}
|
||||
|
||||
/** The passphrase and the code wrap the same key independently, so changing
|
||||
* one must not disturb the other. */
|
||||
@Test
|
||||
fun `recovery opens the same key`() {
|
||||
val fast = Kdf.Parameters(1, 1_000)
|
||||
val pair = Identity.generate()
|
||||
val entropy = Recovery.generate().entropy
|
||||
val record = Identity.protectWithRecovery(pair.private, entropy, fast)
|
||||
assertEquals(Kdf.Context.FILES_RECOVERY, record.context)
|
||||
assertContentEquals(
|
||||
X25519.rawFromPrivate(pair.private),
|
||||
X25519.rawFromPrivate(Identity.unlockWithRecovery(record, entropy)),
|
||||
)
|
||||
}
|
||||
|
||||
/** Different contexts, so a record made for one secret cannot be opened as
|
||||
* the other's even when the derived material would otherwise line up. */
|
||||
@Test
|
||||
fun `a recovery record is not a passphrase record`() {
|
||||
val fast = Kdf.Parameters(1, 1_000)
|
||||
val entropy = Recovery.generate().entropy
|
||||
val record = Identity.protectWithRecovery(Identity.generate().private, entropy, fast)
|
||||
assertFailsWith<Exception> {
|
||||
Identity.unlock(
|
||||
record.copy(context = Kdf.Context.FILES_IDENTITY),
|
||||
Recovery.kdfSecret(entropy),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deriving the public half from a stored private key.
|
||||
*
|
||||
* A session that unlocked a record has only the scalar, and every label key it
|
||||
* ever accepts is wrapped to the matching public key. If this derivation were
|
||||
* wrong, nothing would fail loudly — grants would simply stop unwrapping.
|
||||
*/
|
||||
class PublicKeyDerivationTest {
|
||||
@Test
|
||||
fun `matches the generated pair`() {
|
||||
repeat(20) {
|
||||
val pair = X25519.generate()
|
||||
assertContentEquals(
|
||||
X25519.rawFromPublic(pair.public),
|
||||
X25519.rawFromPublic(X25519.publicFromPrivate(pair.private)),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/** And it survives the PKCS#8 round trip a stored record goes through. */
|
||||
@Test
|
||||
fun `survives a record round trip`() {
|
||||
val pair = X25519.generate()
|
||||
val record = Identity.protect(pair.private, "pass", Kdf.Parameters(1, 1_000))
|
||||
val reopened = Identity.unlock(record, "pass")
|
||||
assertContentEquals(
|
||||
X25519.rawFromPublic(pair.public),
|
||||
X25519.rawFromPublic(X25519.publicFromPrivate(reopened)),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -95,5 +95,42 @@
|
||||
"code": "BKKR-SJXB-E8M8-1A6B-CN47-WNM7-6RQN",
|
||||
"entropy": "XOeMy6tyKICoy2VIflaHNg=="
|
||||
}
|
||||
},
|
||||
"recovery": [
|
||||
{
|
||||
"entropy": "AEeO1RxjqvE4f8YNVJviKQ==",
|
||||
"code": "013R-XN8W-CENF-2E3Z-RR6N-96Z2-57K9",
|
||||
"kdfSecret": "00478ed51c63aaf1387fc60d549be229"
|
||||
},
|
||||
{
|
||||
"entropy": "JWyz+kGIzxZdpOsyecAHTg==",
|
||||
"code": "4NPB-7YJ1-H37H-CQD4-XCS7-KG07-9RBA",
|
||||
"kdfSecret": "256cb3fa4188cf165da4eb3279c0074e"
|
||||
},
|
||||
{
|
||||
"entropy": "SpHYH2at9DuCyRBXnuUscw==",
|
||||
"code": "9A8X-G7V6-NQT3-Q0P9-21BS-XS9C-EE7C",
|
||||
"kdfSecret": "4a91d81f66adf43b82c910579ee52c73"
|
||||
},
|
||||
{
|
||||
"entropy": "b7b9RIvSGWCn7jV8wwpRmA==",
|
||||
"code": "DYVF-TH4B-T8CP-19ZE-6NYC-62JH-K3JD",
|
||||
"kdfSecret": "6fb6fd448bd21960a7ee357cc30a5198"
|
||||
},
|
||||
{
|
||||
"entropy": "lNsiabD3PoXME1qh6C92vQ==",
|
||||
"code": "JKDJ-4TDG-YWZ8-BK0K-BAGY-GBVP-QN2Y",
|
||||
"kdfSecret": "94db2269b0f73e85cc135aa1e82f76bd"
|
||||
},
|
||||
{
|
||||
"entropy": "uQBHjtUcY6rxOH/GDVSb4g==",
|
||||
"code": "Q404-F3PN-3HHT-NW9R-FZ30-TN4V-W87R",
|
||||
"kdfSecret": "b900478ed51c63aaf1387fc60d549be2"
|
||||
}
|
||||
],
|
||||
"recoveryWithQ": {
|
||||
"entropy": "AB06V3SRrsvoBSI/XHmWsw==",
|
||||
"code": "00EK-MNVM-J6QC-QT05-48ZN-RYCP-PDSA",
|
||||
"kdfSecret": "001d3a577491aecbe805223f5c7996b3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
rootProject.name = "flamenet-files-android"
|
||||
include(":engine")
|
||||
include(":client")
|
||||
|
||||
Reference in New Issue
Block a user