Skip to content

Commit

Permalink
✨ Impl secret key storage capability (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
guiyanakuang authored Dec 3, 2023
1 parent dea8f17 commit 8e0b527
Show file tree
Hide file tree
Showing 27 changed files with 338 additions and 357 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package com.clipevery.model

import kotlinx.serialization.Serializable
import java.util.Locale
import java.util.UUID

@Serializable
data class AppConfig(
val appInstanceId: String = UUID.randomUUID().toString(),
val bindingState: Boolean = false,
val language: String = Locale.getDefault().language,
val isFollowSystem: Boolean = true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.clipevery.model

const val AppName: String = "Clipevery"

data class AppInfo(
val appName: String = "Clipevery",
val appInstanceId: String,
val appVersion: String,
val userName: String
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.clipevery.model

import org.signal.libsignal.protocol.SignalProtocolAddress

data class SyncInfo(
val appInfo: AppInfo,
val endpointInfo: EndpointInfo,
val state: SyncState)
val state: SyncState
): SignalProtocolAddress(appInfo.appInstanceId, 1)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.clipevery.data
package com.clipevery.presist.data

import app.cash.sqldelight.db.SqlDriver
import com.clipevery.Database
Expand All @@ -9,8 +9,7 @@ expect class DriverFactory {

fun createDatabase(driverFactory: DriverFactory): Database {
val driver = driverFactory.createDriver()
val database = Database(driver)

// Do more work with the database (see below).
return database;
return Database(driver);
}
7 changes: 5 additions & 2 deletions composeApp/src/commonMain/kotlin/com/clipevery/ui/SyncUI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ import com.clipevery.platform.Platform
import com.clipevery.platform.currentPlatform

@Composable
fun Devices() {
fun Syncs() {
val current = LocalKoinApplication.current
val deviceFactory = current.koin.get<DeviceInfoFactory>()
val deviceInfo = deviceFactory.createDeviceInfo()
SyncItem(SyncInfo(
appInfo = AppInfo(
appInstanceId = "1234567890",
appVersion = "1.0.0",
userName = "John Doe"
),
Expand All @@ -39,6 +40,7 @@ fun Devices() {
Divider(modifier = Modifier.fillMaxWidth())
SyncItem(SyncInfo(
appInfo = AppInfo(
appInstanceId = "1234567890",
appVersion = "1.0.0",
userName = "John Doe"
),
Expand All @@ -63,6 +65,7 @@ fun Devices() {
Divider(modifier = Modifier.fillMaxWidth())
SyncItem(SyncInfo(
appInfo = AppInfo(
appInstanceId = "1234567890",
appVersion = "1.0.0",
userName = "John Doe"
),
Expand All @@ -89,7 +92,7 @@ fun Devices() {
@Composable
fun test() {
Column(modifier = Modifier.fillMaxSize()) {
Devices()
Syncs()
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fun TabsUI() {
Column(modifier = Modifier.fillMaxSize()) {
when (selectedTabIndex) {
0 -> ClipPreview()
1 -> Devices()
1 -> Syncs()
2 -> {
if (!config.value.bindingState) {
bindingQRCode()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CREATE TABLE identityKey (
app_instance_id TEXT NOT NULL PRIMARY KEY,
registrationId INTEGER NOT NULL,
serialized BLOB NOT NULL
);

select:
SELECT * FROM identityKey WHERE app_instance_id = ?;

tryInit:
INSERT OR FAIL INTO identityKey (app_instance_id, registrationId, serialized) VALUES (?, ?, ?);

update:
UPDATE identityKey SET serialized = ? WHERE app_instance_id = ? AND registrationId = ?;

16 changes: 16 additions & 0 deletions composeApp/src/commonMain/sqldelight/com/clipevery/data/PreKey.sq
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
CREATE TABLE preKey (
id INTEGER PRIMARY KEY,
serialized BLOB NOT NULL
);

selectById:
SELECT * FROM preKey WHERE id = ?;

insert:
INSERT OR REPLACE INTO preKey (id, serialized) VALUES (?, ?);

count:
SELECT count(1) FROM preKey WHERE id = ?;

delete:
DELETE FROM preKey WHERE id = ?;
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
CREATE TABLE signedPreKey (
id INTEGER PRIMARY KEY,
serialized BLOB NOT NULL
);

selectById:
SELECT * FROM signedPreKey WHERE id = ?;

selectAll:
SELECT * FROM signedPreKey;

insert:
INSERT OR REPLACE INTO signedPreKey (id, serialized) VALUES (?, ?);

count:
SELECT COUNT(*) FROM signedPreKey WHERE id = ?;

delete:
DELETE FROM signedPreKey WHERE id = ?;
36 changes: 32 additions & 4 deletions composeApp/src/commonMain/sqldelight/com/clipevery/data/Sync.sq
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CREATE TABLE syncInfo (
app_instance_name TEXT NOT NULL PRIMARY KEY,
app_instance_id TEXT NOT NULL PRIMARY KEY,
app_version TEXT NOT NULL,
app_user_name TEXT NOT NULL,
device_id TEXT NOT NULL,
Expand All @@ -10,7 +10,9 @@ CREATE TABLE syncInfo (
platform_name TEXT NOT NULL,
platform_arch TEXT NOT NULL,
platform_bit_mode INTEGER NOT NULL,
platform_version TEXT NOT NULL
platform_version TEXT NOT NULL,
public_key BLOB,
sessionRecord BLOB
);


Expand All @@ -20,6 +22,32 @@ selectAll:
SELECT *
FROM syncInfo;

selectSessionRecord:
SELECT sessionRecord FROM syncInfo WHERE app_instance_id = ?;

selectSessionRecords:
SELECT sessionRecord FROM syncInfo WHERE app_instance_id IN ?;

selectPublicKey:
SELECT public_key FROM syncInfo WHERE app_instance_id = ?;

selectSubDevice:
SELECT app_instance_id FROM syncInfo WHERE app_instance_id = ?;

insert:
INSERT INTO syncInfo(app_instance_name, app_version, app_user_name, device_id, device_name, device_state, host_address, port, platform_name, platform_arch, platform_bit_mode, platform_version)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
INSERT INTO syncInfo(app_instance_id, app_version, app_user_name,
device_id, device_name, device_state, host_address, port, platform_name,
platform_arch, platform_bit_mode, platform_version)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);

updatePublicKey:
UPDATE syncInfo SET public_key = ? WHERE app_instance_id = ?;

updateSessionRecord:
UPDATE syncInfo SET sessionRecord = ? WHERE app_instance_id = ?;

count:
SELECT COUNT(1) FROM syncInfo WHERE app_instance_id = ?;

delete:
DELETE FROM syncInfo WHERE app_instance_id = ?;

This file was deleted.

Loading

0 comments on commit 8e0b527

Please sign in to comment.