Compare commits
3 Commits
1.0.0
...
f599cb790b
Author | SHA1 | Date | |
---|---|---|---|
f599cb790b | |||
9b14f442b0 | |||
8a17eef19b |
@ -0,0 +1,11 @@
|
||||
{
|
||||
"colors" : [
|
||||
{
|
||||
"idiom" : "universal"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"platform" : "watchos",
|
||||
"size" : "1024x1024"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
6
Sesame-Watch Watch App/Assets.xcassets/Contents.json
Normal file
6
Sesame-Watch Watch App/Assets.xcassets/Contents.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
150
Sesame-Watch Watch App/ContentView.swift
Normal file
150
Sesame-Watch Watch App/ContentView.swift
Normal file
@ -0,0 +1,150 @@
|
||||
import SwiftUI
|
||||
import CryptoKit
|
||||
|
||||
struct ContentView: View {
|
||||
|
||||
@AppStorage("server")
|
||||
var serverPath: String = "https://christophhagen.de/sesame/"
|
||||
|
||||
@AppStorage("localIP")
|
||||
var localAddress: String = "192.168.178.104/"
|
||||
|
||||
@AppStorage("counter")
|
||||
var nextMessageCounter: Int = 0
|
||||
|
||||
@AppStorage("compensate")
|
||||
var isCompensatingDaylightTime: Bool = false
|
||||
|
||||
@AppStorage("local")
|
||||
private var useLocalConnection = false
|
||||
|
||||
@AppStorage("deviceId")
|
||||
private var deviceId: Int = 0
|
||||
|
||||
@EnvironmentObject
|
||||
var keyManager: KeyManagement
|
||||
|
||||
@State
|
||||
var state: ClientState = .noKeyAvailable
|
||||
|
||||
@State
|
||||
private var hasActiveRequest = false
|
||||
|
||||
let server = Client()
|
||||
|
||||
var buttonBackground: Color {
|
||||
state.allowsAction ?
|
||||
.white.opacity(0.2) :
|
||||
.black.opacity(0.2)
|
||||
}
|
||||
|
||||
let buttonBorderWidth: CGFloat = 3
|
||||
|
||||
var buttonColor: Color {
|
||||
state.allowsAction ? .white : .gray
|
||||
}
|
||||
|
||||
private let sidePaddingRatio: CGFloat = 0.05
|
||||
private let buttonSizeRatio: CGFloat = 0.9
|
||||
|
||||
private let smallButtonHeight: CGFloat = 50
|
||||
|
||||
private let smallButtonWidth: CGFloat = 120
|
||||
|
||||
private let smallButtonBorderWidth: CGFloat = 1
|
||||
|
||||
var compensationTime: UInt32 {
|
||||
isCompensatingDaylightTime ? 3600 : 0
|
||||
}
|
||||
|
||||
var isPerformingRequests: Bool {
|
||||
hasActiveRequest ||
|
||||
state == .waitingForResponse
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .center) {
|
||||
Spacer()
|
||||
GeometryReader { geo in
|
||||
HStack(alignment: .center) {
|
||||
Spacer()
|
||||
let buttonWidth = min(geo.size.width, geo.size.height)
|
||||
Text(state.actionText)
|
||||
.frame(width: buttonWidth, height: buttonWidth)
|
||||
.background(buttonBackground)
|
||||
.cornerRadius(buttonWidth / 2)
|
||||
.overlay(RoundedRectangle(cornerRadius: buttonWidth / 2)
|
||||
.stroke(lineWidth: buttonBorderWidth).foregroundColor(buttonColor))
|
||||
.foregroundColor(buttonColor)
|
||||
.font(.title)
|
||||
.disabled(!state.allowsAction)
|
||||
.onTapGesture(perform: mainButtonPressed)
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
.background(state.color)
|
||||
.animation(.easeInOut, value: state.color)
|
||||
}
|
||||
|
||||
func mainButtonPressed() {
|
||||
guard let key = keyManager.get(.remoteKey),
|
||||
let token = keyManager.get(.authToken)?.data,
|
||||
let deviceId = UInt8(exactly: deviceId) else {
|
||||
return
|
||||
}
|
||||
let count = UInt32(nextMessageCounter)
|
||||
let sentTime = Date()
|
||||
// Add time to compensate that the device is using daylight savings time
|
||||
let content = Message.Content(
|
||||
time: sentTime.timestamp + compensationTime,
|
||||
id: count,
|
||||
device: deviceId)
|
||||
let message = content.authenticate(using: key)
|
||||
let historyItem = HistoryItem(sent: message.content, date: sentTime, local: useLocalConnection)
|
||||
state = .waitingForResponse
|
||||
print("Sending message \(count)")
|
||||
Task {
|
||||
let (newState, responseMessage) = await send(message, authToken: token)
|
||||
let receivedTime = Date.now
|
||||
//responseTime = receivedTime
|
||||
state = newState
|
||||
let finishedItem = historyItem.didReceive(response: newState, date: receivedTime, message: responseMessage?.content)
|
||||
guard let key = keyManager.get(.deviceKey) else {
|
||||
save(historyItem: finishedItem.notAuthenticated())
|
||||
return
|
||||
}
|
||||
guard let responseMessage else {
|
||||
save(historyItem: finishedItem)
|
||||
return
|
||||
}
|
||||
guard responseMessage.isValid(using: key) else {
|
||||
save(historyItem: finishedItem.invalidated())
|
||||
return
|
||||
}
|
||||
|
||||
nextMessageCounter = Int(responseMessage.content.id)
|
||||
save(historyItem: finishedItem)
|
||||
}
|
||||
}
|
||||
|
||||
private func send(_ message: Message, authToken: Data) async -> (state: ClientState, response: Message?) {
|
||||
if useLocalConnection {
|
||||
return await server.sendMessageOverLocalNetwork(message, server: localAddress)
|
||||
} else {
|
||||
return await server.send(message, server: serverPath, authToken: authToken)
|
||||
}
|
||||
}
|
||||
|
||||
private func save(historyItem: HistoryItem) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
struct ContentView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ContentView()
|
||||
.environmentObject(KeyManagement())
|
||||
}
|
||||
}
|
12
Sesame-Watch Watch App/Date+Extensions.swift
Normal file
12
Sesame-Watch Watch App/Date+Extensions.swift
Normal file
@ -0,0 +1,12 @@
|
||||
import Foundation
|
||||
|
||||
extension Date {
|
||||
|
||||
var timestamp: UInt32 {
|
||||
UInt32(timeIntervalSince1970.rounded())
|
||||
}
|
||||
|
||||
init(timestamp: UInt32) {
|
||||
self.init(timeIntervalSince1970: TimeInterval(timestamp))
|
||||
}
|
||||
}
|
13
Sesame-Watch Watch App/HistoryView.swift
Normal file
13
Sesame-Watch Watch App/HistoryView.swift
Normal file
@ -0,0 +1,13 @@
|
||||
import SwiftUI
|
||||
|
||||
struct HistoryView: View {
|
||||
var body: some View {
|
||||
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
|
||||
}
|
||||
}
|
||||
|
||||
struct HistoryView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
HistoryView()
|
||||
}
|
||||
}
|
121
Sesame-Watch Watch App/KeyManagement.swift
Normal file
121
Sesame-Watch Watch App/KeyManagement.swift
Normal file
@ -0,0 +1,121 @@
|
||||
import Foundation
|
||||
import CryptoKit
|
||||
import SwiftUI
|
||||
|
||||
private let localKey: [UInt8] = [
|
||||
0x98, 0x36, 0x91, 0x09, 0x29, 0xa0, 0x54, 0x44,
|
||||
0x03, 0x0c, 0xa5, 0xb4, 0x20, 0x16, 0x10, 0x0d,
|
||||
0xaf, 0x41, 0x9b, 0x26, 0x4f, 0x75, 0xa4, 0x61,
|
||||
0xed, 0x15, 0x0c, 0xb3, 0x06, 0x39, 0x92, 0x59]
|
||||
|
||||
|
||||
private let remoteKey: [UInt8] = [
|
||||
0xfa, 0x23, 0xf6, 0x98, 0xea, 0x87, 0x23, 0xa0,
|
||||
0xa0, 0xbe, 0x9a, 0xdb, 0x31, 0x28, 0xcb, 0x7d,
|
||||
0xd3, 0xa5, 0x7b, 0xf0, 0xc0, 0xeb, 0x45, 0x65,
|
||||
0x4d, 0x94, 0x50, 0x1a, 0x2f, 0x6f, 0xeb, 0x70]
|
||||
|
||||
private let authToken: [UInt8] = {
|
||||
let s = "Y6QzDK5DaFK1w2oEX5OkzoC0nTqP8w5IxpvWAR1mpro="
|
||||
let t = Data(base64Encoded: s.data(using: .utf8)!)!
|
||||
return Array(t)
|
||||
}()
|
||||
|
||||
extension KeyManagement {
|
||||
|
||||
enum KeyType: String, Identifiable, CaseIterable {
|
||||
|
||||
case deviceKey = "sesame-device"
|
||||
case remoteKey = "sesame-remote"
|
||||
case authToken = "sesame-remote-auth"
|
||||
|
||||
var id: String {
|
||||
rawValue
|
||||
}
|
||||
|
||||
var displayName: String {
|
||||
switch self {
|
||||
case .deviceKey:
|
||||
return "Device Key"
|
||||
case .remoteKey:
|
||||
return "Remote Key"
|
||||
case .authToken:
|
||||
return "Authentication Token"
|
||||
}
|
||||
}
|
||||
|
||||
var keyLength: SymmetricKeySize {
|
||||
.bits256
|
||||
}
|
||||
|
||||
var usesHashing: Bool {
|
||||
switch self {
|
||||
case .authToken:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension KeyManagement.KeyType: CustomStringConvertible {
|
||||
|
||||
var description: String {
|
||||
displayName
|
||||
}
|
||||
}
|
||||
|
||||
final class KeyManagement: ObservableObject {
|
||||
|
||||
|
||||
@Published
|
||||
private(set) var hasRemoteKey = true
|
||||
|
||||
@Published
|
||||
private(set) var hasDeviceKey = true
|
||||
|
||||
@Published
|
||||
private(set) var hasAuthToken = true
|
||||
|
||||
var hasAllKeys: Bool {
|
||||
hasRemoteKey && hasDeviceKey && hasAuthToken
|
||||
}
|
||||
|
||||
init() {}
|
||||
|
||||
func has(_ type: KeyType) -> Bool {
|
||||
switch type {
|
||||
case .deviceKey:
|
||||
return hasDeviceKey
|
||||
case .remoteKey:
|
||||
return hasRemoteKey
|
||||
case .authToken:
|
||||
return hasAuthToken
|
||||
}
|
||||
}
|
||||
|
||||
func get(_ type: KeyType) -> SymmetricKey? {
|
||||
let bytes: [UInt8] = get(type)
|
||||
return SymmetricKey(data: bytes)
|
||||
}
|
||||
|
||||
private func get(_ type: KeyType) -> [UInt8] {
|
||||
switch type {
|
||||
case .deviceKey:
|
||||
return remoteKey
|
||||
case .remoteKey:
|
||||
return localKey
|
||||
case .authToken:
|
||||
return authToken
|
||||
}
|
||||
}
|
||||
|
||||
func delete(_ type: KeyType) {
|
||||
|
||||
}
|
||||
|
||||
func generate(_ type: KeyType) {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
{
|
||||
"info" : {
|
||||
"author" : "xcode",
|
||||
"version" : 1
|
||||
}
|
||||
}
|
19
Sesame-Watch Watch App/Sesame_WatchApp.swift
Normal file
19
Sesame-Watch Watch App/Sesame_WatchApp.swift
Normal file
@ -0,0 +1,19 @@
|
||||
import SwiftUI
|
||||
|
||||
@main
|
||||
struct Sesame_Watch_Watch_AppApp: App {
|
||||
|
||||
let keyManagement = KeyManagement()
|
||||
|
||||
var body: some Scene {
|
||||
WindowGroup {
|
||||
TabView {
|
||||
ContentView()
|
||||
.environmentObject(keyManagement)
|
||||
SettingsView()
|
||||
HistoryView()
|
||||
}
|
||||
.tabViewStyle(PageTabViewStyle())
|
||||
}
|
||||
}
|
||||
}
|
19
Sesame-Watch Watch App/SettingsView.swift
Normal file
19
Sesame-Watch Watch App/SettingsView.swift
Normal file
@ -0,0 +1,19 @@
|
||||
import SwiftUI
|
||||
|
||||
struct SettingsView: View {
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
VStack {
|
||||
Text(/*@START_MENU_TOKEN@*/"Hello, World!"/*@END_MENU_TOKEN@*/)
|
||||
}
|
||||
}
|
||||
.navigationTitle("Settings")
|
||||
}
|
||||
}
|
||||
|
||||
struct SettingsView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
SettingsView()
|
||||
.previewDevice("Apple Watch Series 7 - 41mm")
|
||||
}
|
||||
}
|
@ -14,13 +14,36 @@
|
||||
884A45C5279F4BBE00D6E650 /* KeyManagement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884A45C4279F4BBE00D6E650 /* KeyManagement.swift */; };
|
||||
884A45C927A43D7900D6E650 /* ClientState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884A45C827A43D7900D6E650 /* ClientState.swift */; };
|
||||
884A45CB27A464C000D6E650 /* SymmetricKey+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884A45CA27A464C000D6E650 /* SymmetricKey+Extensions.swift */; };
|
||||
884A45CD27A465F500D6E650 /* Client.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884A45CC27A465F500D6E650 /* Client.swift */; };
|
||||
884A45CF27A5402D00D6E650 /* MessageResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884A45CE27A5402D00D6E650 /* MessageResult.swift */; };
|
||||
8864664F29E5684C004FE2BE /* CBORCoding in Frameworks */ = {isa = PBXBuildFile; productRef = 8864664E29E5684C004FE2BE /* CBORCoding */; };
|
||||
8864665229E5939C004FE2BE /* SFSafeSymbols in Frameworks */ = {isa = PBXBuildFile; productRef = 8864665129E5939C004FE2BE /* SFSafeSymbols */; };
|
||||
888362342A80F3F90032BBB2 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 888362332A80F3F90032BBB2 /* SettingsView.swift */; };
|
||||
888362362A80F4420032BBB2 /* HistoryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 888362352A80F4420032BBB2 /* HistoryView.swift */; };
|
||||
88E197B229EDC9BC00BF1D19 /* Sesame_WatchApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88E197B129EDC9BC00BF1D19 /* Sesame_WatchApp.swift */; };
|
||||
88E197B429EDC9BC00BF1D19 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88E197B329EDC9BC00BF1D19 /* ContentView.swift */; };
|
||||
88E197B629EDC9BD00BF1D19 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 88E197B529EDC9BD00BF1D19 /* Assets.xcassets */; };
|
||||
88E197B929EDC9BD00BF1D19 /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 88E197B829EDC9BD00BF1D19 /* Preview Assets.xcassets */; };
|
||||
88E197C229EDCB0900BF1D19 /* KeyManagement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88E197C129EDCB0900BF1D19 /* KeyManagement.swift */; };
|
||||
88E197C429EDCC8900BF1D19 /* Client.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884A45CC27A465F500D6E650 /* Client.swift */; };
|
||||
88E197C729EDCCBD00BF1D19 /* Client.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884A45CC27A465F500D6E650 /* Client.swift */; };
|
||||
88E197C829EDCCCE00BF1D19 /* ClientState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884A45C827A43D7900D6E650 /* ClientState.swift */; };
|
||||
88E197C929EDCCE100BF1D19 /* Message.swift in Sources */ = {isa = PBXBuildFile; fileRef = E24EE77827FF95E00011CFD2 /* Message.swift */; };
|
||||
88E197CC29EDCD4900BF1D19 /* NIOCore in Frameworks */ = {isa = PBXBuildFile; productRef = 88E197CB29EDCD4900BF1D19 /* NIOCore */; };
|
||||
88E197CE29EDCD7500BF1D19 /* CBORCoding in Frameworks */ = {isa = PBXBuildFile; productRef = 88E197CD29EDCD7500BF1D19 /* CBORCoding */; };
|
||||
88E197D029EDCD7D00BF1D19 /* SFSafeSymbols in Frameworks */ = {isa = PBXBuildFile; productRef = 88E197CF29EDCD7D00BF1D19 /* SFSafeSymbols */; };
|
||||
88E197D129EDCE5F00BF1D19 /* Data+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E24EE77127FDCCC00011CFD2 /* Data+Extensions.swift */; };
|
||||
88E197D229EDCE6600BF1D19 /* RouteAPI.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2C5C1DA2806FE8900769EF6 /* RouteAPI.swift */; };
|
||||
88E197D329EDCE6E00BF1D19 /* MessageResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884A45CE27A5402D00D6E650 /* MessageResult.swift */; };
|
||||
88E197D429EDCE7600BF1D19 /* UInt32+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2C5C1DC281B3AC400769EF6 /* UInt32+Extensions.swift */; };
|
||||
88E197D529EDCE8800BF1D19 /* ServerMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2C5C1F7281E769F00769EF6 /* ServerMessage.swift */; };
|
||||
88E197D729EDCFE800BF1D19 /* Date+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 88E197D629EDCFE800BF1D19 /* Date+Extensions.swift */; };
|
||||
88E197D829EDD13B00BF1D19 /* SymmetricKey+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 884A45CA27A464C000D6E650 /* SymmetricKey+Extensions.swift */; };
|
||||
88E197D929EDD14D00BF1D19 /* HistoryItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = E28DED34281EB17600259690 /* HistoryItem.swift */; };
|
||||
E24EE77227FDCCC00011CFD2 /* Data+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E24EE77127FDCCC00011CFD2 /* Data+Extensions.swift */; };
|
||||
E24EE77427FF95920011CFD2 /* DeviceResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = E24EE77327FF95920011CFD2 /* DeviceResponse.swift */; };
|
||||
E24EE77727FF95C00011CFD2 /* NIOCore in Frameworks */ = {isa = PBXBuildFile; productRef = E24EE77627FF95C00011CFD2 /* NIOCore */; };
|
||||
E24EE77927FF95E00011CFD2 /* Message.swift in Sources */ = {isa = PBXBuildFile; fileRef = E24EE77827FF95E00011CFD2 /* Message.swift */; };
|
||||
E28DED2D281E840B00259690 /* KeyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E28DED2C281E840B00259690 /* KeyView.swift */; };
|
||||
E28DED2D281E840B00259690 /* SettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E28DED2C281E840B00259690 /* SettingsView.swift */; };
|
||||
E28DED2F281E8A0500259690 /* SingleKeyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E28DED2E281E8A0500259690 /* SingleKeyView.swift */; };
|
||||
E28DED31281EAE9100259690 /* HistoryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E28DED30281EAE9100259690 /* HistoryView.swift */; };
|
||||
E28DED33281EB15B00259690 /* HistoryListItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = E28DED32281EB15B00259690 /* HistoryListItem.swift */; };
|
||||
@ -42,10 +65,19 @@
|
||||
884A45CA27A464C000D6E650 /* SymmetricKey+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SymmetricKey+Extensions.swift"; sourceTree = "<group>"; };
|
||||
884A45CC27A465F500D6E650 /* Client.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Client.swift; sourceTree = "<group>"; };
|
||||
884A45CE27A5402D00D6E650 /* MessageResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageResult.swift; sourceTree = "<group>"; };
|
||||
888362332A80F3F90032BBB2 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
|
||||
888362352A80F4420032BBB2 /* HistoryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HistoryView.swift; sourceTree = "<group>"; };
|
||||
88E197AC29EDC9BC00BF1D19 /* Sesame-Watch Watch App.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Sesame-Watch Watch App.app"; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
88E197B129EDC9BC00BF1D19 /* Sesame_WatchApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Sesame_WatchApp.swift; sourceTree = "<group>"; };
|
||||
88E197B329EDC9BC00BF1D19 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
|
||||
88E197B529EDC9BD00BF1D19 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
88E197B829EDC9BD00BF1D19 /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
|
||||
88E197C129EDCB0900BF1D19 /* KeyManagement.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyManagement.swift; sourceTree = "<group>"; };
|
||||
88E197D629EDCFE800BF1D19 /* Date+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Date+Extensions.swift"; sourceTree = "<group>"; };
|
||||
E24EE77127FDCCC00011CFD2 /* Data+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+Extensions.swift"; sourceTree = "<group>"; };
|
||||
E24EE77327FF95920011CFD2 /* DeviceResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeviceResponse.swift; sourceTree = "<group>"; };
|
||||
E24EE77827FF95E00011CFD2 /* Message.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Message.swift; sourceTree = "<group>"; };
|
||||
E28DED2C281E840B00259690 /* KeyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyView.swift; sourceTree = "<group>"; };
|
||||
E28DED2C281E840B00259690 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
|
||||
E28DED2E281E8A0500259690 /* SingleKeyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SingleKeyView.swift; sourceTree = "<group>"; };
|
||||
E28DED30281EAE9100259690 /* HistoryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HistoryView.swift; sourceTree = "<group>"; };
|
||||
E28DED32281EB15B00259690 /* HistoryListItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HistoryListItem.swift; sourceTree = "<group>"; };
|
||||
@ -62,10 +94,22 @@
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
8864665229E5939C004FE2BE /* SFSafeSymbols in Frameworks */,
|
||||
8864664F29E5684C004FE2BE /* CBORCoding in Frameworks */,
|
||||
E24EE77727FF95C00011CFD2 /* NIOCore in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
88E197A929EDC9BC00BF1D19 /* Frameworks */ = {
|
||||
isa = PBXFrameworksBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
88E197D029EDCD7D00BF1D19 /* SFSafeSymbols in Frameworks */,
|
||||
88E197CE29EDCD7500BF1D19 /* CBORCoding in Frameworks */,
|
||||
88E197CC29EDCD4900BF1D19 /* NIOCore in Frameworks */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXFrameworksBuildPhase section */
|
||||
|
||||
/* Begin PBXGroup section */
|
||||
@ -73,7 +117,9 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
884A45B5279F48C100D6E650 /* Sesame */,
|
||||
88E197B029EDC9BC00BF1D19 /* Sesame-Watch Watch App */,
|
||||
884A45B4279F48C100D6E650 /* Products */,
|
||||
88E197CA29EDCD4900BF1D19 /* Frameworks */,
|
||||
);
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
@ -81,6 +127,7 @@
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
884A45B3279F48C100D6E650 /* Sesame.app */,
|
||||
88E197AC29EDC9BC00BF1D19 /* Sesame-Watch Watch App.app */,
|
||||
);
|
||||
name = Products;
|
||||
sourceTree = "<group>";
|
||||
@ -96,10 +143,10 @@
|
||||
E28DED32281EB15B00259690 /* HistoryListItem.swift */,
|
||||
E28DED34281EB17600259690 /* HistoryItem.swift */,
|
||||
E28DED36281EC7FB00259690 /* HistoryManager.swift */,
|
||||
E28DED2C281E840B00259690 /* KeyView.swift */,
|
||||
E28DED2C281E840B00259690 /* SettingsView.swift */,
|
||||
E28DED2E281E8A0500259690 /* SingleKeyView.swift */,
|
||||
884A45CC27A465F500D6E650 /* Client.swift */,
|
||||
884A45C827A43D7900D6E650 /* ClientState.swift */,
|
||||
884A45CC27A465F500D6E650 /* Client.swift */,
|
||||
884A45C4279F4BBE00D6E650 /* KeyManagement.swift */,
|
||||
884A45CA27A464C000D6E650 /* SymmetricKey+Extensions.swift */,
|
||||
884A45BA279F48C300D6E650 /* Assets.xcassets */,
|
||||
@ -116,6 +163,36 @@
|
||||
path = "Preview Content";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
88E197B029EDC9BC00BF1D19 /* Sesame-Watch Watch App */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
88E197B129EDC9BC00BF1D19 /* Sesame_WatchApp.swift */,
|
||||
88E197B329EDC9BC00BF1D19 /* ContentView.swift */,
|
||||
888362332A80F3F90032BBB2 /* SettingsView.swift */,
|
||||
888362352A80F4420032BBB2 /* HistoryView.swift */,
|
||||
88E197C129EDCB0900BF1D19 /* KeyManagement.swift */,
|
||||
88E197B529EDC9BD00BF1D19 /* Assets.xcassets */,
|
||||
88E197B729EDC9BD00BF1D19 /* Preview Content */,
|
||||
88E197D629EDCFE800BF1D19 /* Date+Extensions.swift */,
|
||||
);
|
||||
path = "Sesame-Watch Watch App";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
88E197B729EDC9BD00BF1D19 /* Preview Content */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
88E197B829EDC9BD00BF1D19 /* Preview Assets.xcassets */,
|
||||
);
|
||||
path = "Preview Content";
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
88E197CA29EDCD4900BF1D19 /* Frameworks */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
);
|
||||
name = Frameworks;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
E2C5C1D92806FE4A00769EF6 /* API */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@ -148,11 +225,35 @@
|
||||
name = Sesame;
|
||||
packageProductDependencies = (
|
||||
E24EE77627FF95C00011CFD2 /* NIOCore */,
|
||||
8864664E29E5684C004FE2BE /* CBORCoding */,
|
||||
8864665129E5939C004FE2BE /* SFSafeSymbols */,
|
||||
);
|
||||
productName = Sesame;
|
||||
productReference = 884A45B3279F48C100D6E650 /* Sesame.app */;
|
||||
productType = "com.apple.product-type.application";
|
||||
};
|
||||
88E197AB29EDC9BC00BF1D19 /* Sesame-Watch Watch App */ = {
|
||||
isa = PBXNativeTarget;
|
||||
buildConfigurationList = 88E197BF29EDC9BD00BF1D19 /* Build configuration list for PBXNativeTarget "Sesame-Watch Watch App" */;
|
||||
buildPhases = (
|
||||
88E197A829EDC9BC00BF1D19 /* Sources */,
|
||||
88E197A929EDC9BC00BF1D19 /* Frameworks */,
|
||||
88E197AA29EDC9BC00BF1D19 /* Resources */,
|
||||
);
|
||||
buildRules = (
|
||||
);
|
||||
dependencies = (
|
||||
);
|
||||
name = "Sesame-Watch Watch App";
|
||||
packageProductDependencies = (
|
||||
88E197CB29EDCD4900BF1D19 /* NIOCore */,
|
||||
88E197CD29EDCD7500BF1D19 /* CBORCoding */,
|
||||
88E197CF29EDCD7D00BF1D19 /* SFSafeSymbols */,
|
||||
);
|
||||
productName = "Sesame-Watch Watch App";
|
||||
productReference = 88E197AC29EDC9BC00BF1D19 /* Sesame-Watch Watch App.app */;
|
||||
productType = "com.apple.product-type.application";
|
||||
};
|
||||
/* End PBXNativeTarget section */
|
||||
|
||||
/* Begin PBXProject section */
|
||||
@ -160,11 +261,15 @@
|
||||
isa = PBXProject;
|
||||
attributes = {
|
||||
BuildIndependentTargetsInParallel = 1;
|
||||
LastSwiftUpdateCheck = 1320;
|
||||
LastSwiftUpdateCheck = 1430;
|
||||
LastUpgradeCheck = 1320;
|
||||
TargetAttributes = {
|
||||
884A45B2279F48C100D6E650 = {
|
||||
CreatedOnToolsVersion = 13.2.1;
|
||||
LastSwiftMigration = 1430;
|
||||
};
|
||||
88E197AB29EDC9BC00BF1D19 = {
|
||||
CreatedOnToolsVersion = 14.3;
|
||||
};
|
||||
};
|
||||
};
|
||||
@ -179,12 +284,15 @@
|
||||
mainGroup = 884A45AA279F48C100D6E650;
|
||||
packageReferences = (
|
||||
E24EE77527FF95C00011CFD2 /* XCRemoteSwiftPackageReference "swift-nio" */,
|
||||
8864664D29E5684C004FE2BE /* XCRemoteSwiftPackageReference "CBORCoding" */,
|
||||
8864665029E5939C004FE2BE /* XCRemoteSwiftPackageReference "SFSafeSymbols" */,
|
||||
);
|
||||
productRefGroup = 884A45B4279F48C100D6E650 /* Products */;
|
||||
projectDirPath = "";
|
||||
projectRoot = "";
|
||||
targets = (
|
||||
884A45B2279F48C100D6E650 /* Sesame */,
|
||||
88E197AB29EDC9BC00BF1D19 /* Sesame-Watch Watch App */,
|
||||
);
|
||||
};
|
||||
/* End PBXProject section */
|
||||
@ -199,6 +307,15 @@
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
88E197AA29EDC9BC00BF1D19 /* Resources */ = {
|
||||
isa = PBXResourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
88E197B929EDC9BD00BF1D19 /* Preview Assets.xcassets in Resources */,
|
||||
88E197B629EDC9BD00BF1D19 /* Assets.xcassets in Resources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXResourcesBuildPhase section */
|
||||
|
||||
/* Begin PBXSourcesBuildPhase section */
|
||||
@ -212,7 +329,6 @@
|
||||
E28DED37281EC7FB00259690 /* HistoryManager.swift in Sources */,
|
||||
E2C5C1DB2806FE8900769EF6 /* RouteAPI.swift in Sources */,
|
||||
E2C5C1DD281B3AC400769EF6 /* UInt32+Extensions.swift in Sources */,
|
||||
884A45CD27A465F500D6E650 /* Client.swift in Sources */,
|
||||
E24EE77227FDCCC00011CFD2 /* Data+Extensions.swift in Sources */,
|
||||
E24EE77427FF95920011CFD2 /* DeviceResponse.swift in Sources */,
|
||||
884A45CB27A464C000D6E650 /* SymmetricKey+Extensions.swift in Sources */,
|
||||
@ -221,13 +337,37 @@
|
||||
E28DED35281EB17600259690 /* HistoryItem.swift in Sources */,
|
||||
884A45C927A43D7900D6E650 /* ClientState.swift in Sources */,
|
||||
E28DED33281EB15B00259690 /* HistoryListItem.swift in Sources */,
|
||||
E28DED2D281E840B00259690 /* KeyView.swift in Sources */,
|
||||
E28DED2D281E840B00259690 /* SettingsView.swift in Sources */,
|
||||
884A45B7279F48C100D6E650 /* SesameApp.swift in Sources */,
|
||||
88E197C429EDCC8900BF1D19 /* Client.swift in Sources */,
|
||||
884A45C5279F4BBE00D6E650 /* KeyManagement.swift in Sources */,
|
||||
E2C5C1F8281E769F00769EF6 /* ServerMessage.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
88E197A829EDC9BC00BF1D19 /* Sources */ = {
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
888362342A80F3F90032BBB2 /* SettingsView.swift in Sources */,
|
||||
88E197B429EDC9BC00BF1D19 /* ContentView.swift in Sources */,
|
||||
888362362A80F4420032BBB2 /* HistoryView.swift in Sources */,
|
||||
88E197D329EDCE6E00BF1D19 /* MessageResult.swift in Sources */,
|
||||
88E197D529EDCE8800BF1D19 /* ServerMessage.swift in Sources */,
|
||||
88E197D129EDCE5F00BF1D19 /* Data+Extensions.swift in Sources */,
|
||||
88E197D229EDCE6600BF1D19 /* RouteAPI.swift in Sources */,
|
||||
88E197D729EDCFE800BF1D19 /* Date+Extensions.swift in Sources */,
|
||||
88E197C829EDCCCE00BF1D19 /* ClientState.swift in Sources */,
|
||||
88E197B229EDC9BC00BF1D19 /* Sesame_WatchApp.swift in Sources */,
|
||||
88E197C929EDCCE100BF1D19 /* Message.swift in Sources */,
|
||||
88E197D929EDD14D00BF1D19 /* HistoryItem.swift in Sources */,
|
||||
88E197C729EDCCBD00BF1D19 /* Client.swift in Sources */,
|
||||
88E197D429EDCE7600BF1D19 /* UInt32+Extensions.swift in Sources */,
|
||||
88E197D829EDD13B00BF1D19 /* SymmetricKey+Extensions.swift in Sources */,
|
||||
88E197C229EDCB0900BF1D19 /* KeyManagement.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
/* End PBXSourcesBuildPhase section */
|
||||
|
||||
/* Begin XCBuildConfiguration section */
|
||||
@ -352,6 +492,7 @@
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
DEVELOPMENT_ASSET_PATHS = "\"Sesame/Preview Content\"";
|
||||
@ -373,6 +514,8 @@
|
||||
PRODUCT_BUNDLE_IDENTIFIER = de.christophhagen.Sesame;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "";
|
||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||
SWIFT_VERSION = 5.0;
|
||||
TARGETED_DEVICE_FAMILY = 1;
|
||||
};
|
||||
@ -383,6 +526,7 @@
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||
CLANG_ENABLE_MODULES = YES;
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
DEVELOPMENT_ASSET_PATHS = "\"Sesame/Preview Content\"";
|
||||
@ -404,11 +548,74 @@
|
||||
PRODUCT_BUNDLE_IDENTIFIER = de.christophhagen.Sesame;
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
SWIFT_OBJC_BRIDGING_HEADER = "";
|
||||
SWIFT_VERSION = 5.0;
|
||||
TARGETED_DEVICE_FAMILY = 1;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
88E197BD29EDC9BD00BF1D19 /* Debug */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
DEVELOPMENT_ASSET_PATHS = "\"Sesame-Watch Watch App/Preview Content\"";
|
||||
DEVELOPMENT_TEAM = H8WR4M6QQ4;
|
||||
ENABLE_PREVIEWS = YES;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
INFOPLIST_KEY_CFBundleDisplayName = "Sesame-Watch";
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown";
|
||||
INFOPLIST_KEY_WKWatchOnly = YES;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 1.0;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "de.christophhagen.Sesame-Watch.watchkitapp";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SDKROOT = watchos;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
SWIFT_VERSION = 5.0;
|
||||
TARGETED_DEVICE_FAMILY = 4;
|
||||
WATCHOS_DEPLOYMENT_TARGET = 9.4;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
88E197BE29EDC9BD00BF1D19 /* Release */ = {
|
||||
isa = XCBuildConfiguration;
|
||||
buildSettings = {
|
||||
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
|
||||
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
|
||||
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
|
||||
CODE_SIGN_STYLE = Automatic;
|
||||
CURRENT_PROJECT_VERSION = 1;
|
||||
DEVELOPMENT_ASSET_PATHS = "\"Sesame-Watch Watch App/Preview Content\"";
|
||||
DEVELOPMENT_TEAM = H8WR4M6QQ4;
|
||||
ENABLE_PREVIEWS = YES;
|
||||
GENERATE_INFOPLIST_FILE = YES;
|
||||
INFOPLIST_KEY_CFBundleDisplayName = "Sesame-Watch";
|
||||
INFOPLIST_KEY_UISupportedInterfaceOrientations = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown";
|
||||
INFOPLIST_KEY_WKWatchOnly = YES;
|
||||
LD_RUNPATH_SEARCH_PATHS = (
|
||||
"$(inherited)",
|
||||
"@executable_path/Frameworks",
|
||||
);
|
||||
MARKETING_VERSION = 1.0;
|
||||
PRODUCT_BUNDLE_IDENTIFIER = "de.christophhagen.Sesame-Watch.watchkitapp";
|
||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||
SDKROOT = watchos;
|
||||
SKIP_INSTALL = YES;
|
||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||
SWIFT_VERSION = 5.0;
|
||||
TARGETED_DEVICE_FAMILY = 4;
|
||||
WATCHOS_DEPLOYMENT_TARGET = 9.4;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
/* End XCBuildConfiguration section */
|
||||
|
||||
/* Begin XCConfigurationList section */
|
||||
@ -430,9 +637,34 @@
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
88E197BF29EDC9BD00BF1D19 /* Build configuration list for PBXNativeTarget "Sesame-Watch Watch App" */ = {
|
||||
isa = XCConfigurationList;
|
||||
buildConfigurations = (
|
||||
88E197BD29EDC9BD00BF1D19 /* Debug */,
|
||||
88E197BE29EDC9BD00BF1D19 /* Release */,
|
||||
);
|
||||
defaultConfigurationIsVisible = 0;
|
||||
defaultConfigurationName = Release;
|
||||
};
|
||||
/* End XCConfigurationList section */
|
||||
|
||||
/* Begin XCRemoteSwiftPackageReference section */
|
||||
8864664D29E5684C004FE2BE /* XCRemoteSwiftPackageReference "CBORCoding" */ = {
|
||||
isa = XCRemoteSwiftPackageReference;
|
||||
repositoryURL = "https://github.com/christophhagen/CBORCoding";
|
||||
requirement = {
|
||||
kind = upToNextMajorVersion;
|
||||
minimumVersion = 1.0.0;
|
||||
};
|
||||
};
|
||||
8864665029E5939C004FE2BE /* XCRemoteSwiftPackageReference "SFSafeSymbols" */ = {
|
||||
isa = XCRemoteSwiftPackageReference;
|
||||
repositoryURL = "https://github.com/SFSafeSymbols/SFSafeSymbols";
|
||||
requirement = {
|
||||
kind = upToNextMajorVersion;
|
||||
minimumVersion = 4.0.0;
|
||||
};
|
||||
};
|
||||
E24EE77527FF95C00011CFD2 /* XCRemoteSwiftPackageReference "swift-nio" */ = {
|
||||
isa = XCRemoteSwiftPackageReference;
|
||||
repositoryURL = "https://github.com/apple/swift-nio.git";
|
||||
@ -444,6 +676,31 @@
|
||||
/* End XCRemoteSwiftPackageReference section */
|
||||
|
||||
/* Begin XCSwiftPackageProductDependency section */
|
||||
8864664E29E5684C004FE2BE /* CBORCoding */ = {
|
||||
isa = XCSwiftPackageProductDependency;
|
||||
package = 8864664D29E5684C004FE2BE /* XCRemoteSwiftPackageReference "CBORCoding" */;
|
||||
productName = CBORCoding;
|
||||
};
|
||||
8864665129E5939C004FE2BE /* SFSafeSymbols */ = {
|
||||
isa = XCSwiftPackageProductDependency;
|
||||
package = 8864665029E5939C004FE2BE /* XCRemoteSwiftPackageReference "SFSafeSymbols" */;
|
||||
productName = SFSafeSymbols;
|
||||
};
|
||||
88E197CB29EDCD4900BF1D19 /* NIOCore */ = {
|
||||
isa = XCSwiftPackageProductDependency;
|
||||
package = E24EE77527FF95C00011CFD2 /* XCRemoteSwiftPackageReference "swift-nio" */;
|
||||
productName = NIOCore;
|
||||
};
|
||||
88E197CD29EDCD7500BF1D19 /* CBORCoding */ = {
|
||||
isa = XCSwiftPackageProductDependency;
|
||||
package = 8864664D29E5684C004FE2BE /* XCRemoteSwiftPackageReference "CBORCoding" */;
|
||||
productName = CBORCoding;
|
||||
};
|
||||
88E197CF29EDCD7D00BF1D19 /* SFSafeSymbols */ = {
|
||||
isa = XCSwiftPackageProductDependency;
|
||||
package = 8864665029E5939C004FE2BE /* XCRemoteSwiftPackageReference "SFSafeSymbols" */;
|
||||
productName = SFSafeSymbols;
|
||||
};
|
||||
E24EE77627FF95C00011CFD2 /* NIOCore */ = {
|
||||
isa = XCSwiftPackageProductDependency;
|
||||
package = E24EE77527FF95C00011CFD2 /* XCRemoteSwiftPackageReference "swift-nio" */;
|
||||
|
@ -1,5 +1,23 @@
|
||||
{
|
||||
"pins" : [
|
||||
{
|
||||
"identity" : "cborcoding",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/christophhagen/CBORCoding",
|
||||
"state" : {
|
||||
"revision" : "1e52c77523fca12cc290b17eed12fadb50ad72af",
|
||||
"version" : "1.0.0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "sfsafesymbols",
|
||||
"kind" : "remoteSourceControl",
|
||||
"location" : "https://github.com/SFSafeSymbols/SFSafeSymbols",
|
||||
"state" : {
|
||||
"revision" : "7cca2d60925876b5953a2cf7341cd80fbeac983c",
|
||||
"version" : "4.1.1"
|
||||
}
|
||||
},
|
||||
{
|
||||
"identity" : "swift-nio",
|
||||
"kind" : "remoteSourceControl",
|
||||
|
Binary file not shown.
@ -4,11 +4,16 @@
|
||||
<dict>
|
||||
<key>SchemeUserState</key>
|
||||
<dict>
|
||||
<key>Sesame.xcscheme_^#shared#^_</key>
|
||||
<key>Sesame-Watch Watch App.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>0</integer>
|
||||
</dict>
|
||||
<key>Sesame.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>1</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
|
@ -29,6 +29,14 @@ struct Message: Equatable, Hashable {
|
||||
}
|
||||
}
|
||||
|
||||
extension Message: Codable {
|
||||
|
||||
enum CodingKeys: Int, CodingKey {
|
||||
case mac = 1
|
||||
case content = 2
|
||||
}
|
||||
}
|
||||
|
||||
extension Message {
|
||||
|
||||
/**
|
||||
@ -41,15 +49,18 @@ extension Message {
|
||||
|
||||
/// The counter of the message (for freshness)
|
||||
let id: UInt32
|
||||
|
||||
let deviceId: UInt8?
|
||||
|
||||
/**
|
||||
Create new message content.
|
||||
- Parameter time: The time of message creation,
|
||||
- Parameter id: The counter of the message
|
||||
*/
|
||||
init(time: UInt32, id: UInt32) {
|
||||
init(time: UInt32, id: UInt32, device: UInt8) {
|
||||
self.time = time
|
||||
self.id = id
|
||||
self.deviceId = device
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,20 +72,29 @@ extension Message {
|
||||
*/
|
||||
init<T: Sequence>(decodeFrom data: T) where T.Element == UInt8 {
|
||||
self.time = UInt32(data: Data(data.prefix(MemoryLayout<UInt32>.size)))
|
||||
self.id = UInt32(data: Data(data.dropFirst(MemoryLayout<UInt32>.size)))
|
||||
self.id = UInt32(data: Data(data.dropLast().suffix(MemoryLayout<UInt32>.size)))
|
||||
self.deviceId = data.suffix(1).last!
|
||||
}
|
||||
|
||||
/// The byte length of an encoded message content
|
||||
static var length: Int {
|
||||
MemoryLayout<UInt32>.size * 2
|
||||
MemoryLayout<UInt32>.size * 2 + 1
|
||||
}
|
||||
|
||||
/// The message content encoded to data
|
||||
var encoded: Data {
|
||||
time.encoded + id.encoded
|
||||
time.encoded + id.encoded + Data([deviceId ?? 0])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extension Message.Content: Codable {
|
||||
|
||||
enum CodingKeys: Int, CodingKey {
|
||||
case time = 1
|
||||
case id = 2
|
||||
case deviceId = 3
|
||||
}
|
||||
}
|
||||
|
||||
extension Message {
|
||||
|
@ -25,6 +25,9 @@ enum MessageResult: UInt8 {
|
||||
|
||||
/// The key was accepted by the device, and the door will be opened
|
||||
case messageAccepted = 7
|
||||
|
||||
/// The device id is invalid
|
||||
case messageDeviceInvalid = 8
|
||||
|
||||
|
||||
/// The request did not contain body data with the key
|
||||
@ -61,6 +64,8 @@ extension MessageResult: CustomStringConvertible {
|
||||
return "Message counter invalid"
|
||||
case .messageAccepted:
|
||||
return "Message accepted"
|
||||
case .messageDeviceInvalid:
|
||||
return "Invalid device ID"
|
||||
case .noBodyData:
|
||||
return "No body data included in the request"
|
||||
case .deviceNotConnected:
|
||||
|
@ -1,30 +1,49 @@
|
||||
import Foundation
|
||||
import CryptoKit
|
||||
|
||||
struct Client {
|
||||
|
||||
let server: URL
|
||||
final class Client {
|
||||
|
||||
// TODO: Use or delete
|
||||
private let delegate = NeverCacheDelegate()
|
||||
|
||||
init(server: URL) {
|
||||
self.server = server
|
||||
}
|
||||
init() {}
|
||||
|
||||
func deviceStatus(authToken: Data) async -> ClientState {
|
||||
await send(path: .getDeviceStatus, data: authToken).state
|
||||
func deviceStatus(authToken: Data, server: String) async -> ClientState {
|
||||
await send(path: .getDeviceStatus, server: server, data: authToken).state
|
||||
}
|
||||
|
||||
func send(_ message: Message, authToken: Data) async -> (state: ClientState, response: Message?) {
|
||||
func sendMessageOverLocalNetwork(_ message: Message, server: String) async -> (state: ClientState, response: Message?) {
|
||||
let data = message.encoded.hexEncoded
|
||||
guard let url = URL(string: server + "message?m=\(data)") else {
|
||||
return (.internalError("Invalid server url"), nil)
|
||||
}
|
||||
|
||||
var request = URLRequest(url: url)
|
||||
request.httpMethod = "POST"
|
||||
return await requestAndDecode(request)
|
||||
}
|
||||
|
||||
func send(_ message: Message, server: String, authToken: Data) async -> (state: ClientState, response: Message?) {
|
||||
let serverMessage = ServerMessage(authToken: authToken, message: message)
|
||||
return await send(path: .postMessage, data: serverMessage.encoded)
|
||||
return await send(path: .postMessage, server: server, data: serverMessage.encoded)
|
||||
}
|
||||
|
||||
private func send(path: RouteAPI, server: String, data: Data) async -> (state: ClientState, response: Message?) {
|
||||
guard let url = URL(string: server) else {
|
||||
return (.internalError("Invalid server url"), nil)
|
||||
}
|
||||
let fullUrl = url.appendingPathComponent(path.rawValue)
|
||||
return await send(to: fullUrl, data: data)
|
||||
}
|
||||
|
||||
private func send(path: RouteAPI, data: Data) async -> (state: ClientState, response: Message?) {
|
||||
let url = server.appendingPathComponent(path.rawValue)
|
||||
private func send(to url: URL, data: Data) async -> (state: ClientState, response: Message?) {
|
||||
var request = URLRequest(url: url)
|
||||
request.httpBody = data
|
||||
request.httpMethod = "POST"
|
||||
return await requestAndDecode(request)
|
||||
}
|
||||
|
||||
private func requestAndDecode(_ request: URLRequest) async -> (state: ClientState, response: Message?) {
|
||||
guard let data = await fulfill(request) else {
|
||||
return (.deviceNotAvailable(.serverNotReached), nil)
|
||||
}
|
||||
@ -36,6 +55,9 @@ struct Client {
|
||||
}
|
||||
let result = ClientState(keyResult: status)
|
||||
guard data.count == Message.length + 1 else {
|
||||
if data.count != 1 {
|
||||
print("Device response with only \(data.count) bytes")
|
||||
}
|
||||
return (result, nil)
|
||||
}
|
||||
let messageData = Array(data.advanced(by: 1))
|
||||
|
@ -19,6 +19,7 @@ extension ConnectionError: CustomStringConvertible {
|
||||
}
|
||||
|
||||
enum RejectionCause {
|
||||
case invalidDeviceId
|
||||
case invalidCounter
|
||||
case invalidTime
|
||||
case invalidAuthentication
|
||||
@ -30,6 +31,8 @@ extension RejectionCause: CustomStringConvertible {
|
||||
|
||||
var description: String {
|
||||
switch self {
|
||||
case .invalidDeviceId:
|
||||
return "Invalid device ID"
|
||||
case .invalidCounter:
|
||||
return "Invalid counter"
|
||||
case .invalidTime:
|
||||
@ -92,6 +95,8 @@ enum ClientState {
|
||||
self = .messageRejected(.timeout)
|
||||
case .messageAccepted:
|
||||
self = .openSesame
|
||||
case .messageDeviceInvalid:
|
||||
self = .messageRejected(.invalidDeviceId)
|
||||
case .noBodyData, .invalidMessageData, .textReceived, .unexpectedSocketEvent:
|
||||
self = .internalError(keyResult.description)
|
||||
case .deviceNotConnected:
|
||||
@ -137,7 +142,7 @@ enum ClientState {
|
||||
|
||||
var allowsAction: Bool {
|
||||
switch self {
|
||||
case .requestingStatus, .deviceNotAvailable, .waitingForResponse, .noKeyAvailable:
|
||||
case .noKeyAvailable:
|
||||
return false
|
||||
default:
|
||||
return true
|
||||
@ -188,7 +193,7 @@ extension ClientState {
|
||||
Data([code])
|
||||
}
|
||||
|
||||
private var code: UInt8 {
|
||||
var code: UInt8 {
|
||||
switch self {
|
||||
case .noKeyAvailable:
|
||||
return 1
|
||||
@ -207,6 +212,8 @@ extension ClientState {
|
||||
return 6
|
||||
case .messageRejected(let rejectionCause):
|
||||
switch rejectionCause {
|
||||
case .invalidDeviceId:
|
||||
return 19
|
||||
case .invalidCounter:
|
||||
return 7
|
||||
case .invalidTime:
|
||||
@ -230,6 +237,8 @@ extension ClientState {
|
||||
return 15
|
||||
case .missingKey:
|
||||
return 16
|
||||
case .invalidDeviceId:
|
||||
return 20
|
||||
}
|
||||
case .openSesame:
|
||||
return 17
|
||||
@ -276,6 +285,10 @@ extension ClientState {
|
||||
self = .openSesame
|
||||
case 18:
|
||||
self = .internalError("")
|
||||
case 19:
|
||||
self = .messageRejected(.invalidDeviceId)
|
||||
case 20:
|
||||
self = .responseRejected(.invalidDeviceId)
|
||||
default:
|
||||
self = .internalError("Unknown code \(code)")
|
||||
}
|
||||
|
@ -1,15 +1,25 @@
|
||||
import SwiftUI
|
||||
import CryptoKit
|
||||
|
||||
let server = Client(server: URL(string: "https://christophhagen.de/sesame/")!)
|
||||
|
||||
struct ContentView: View {
|
||||
|
||||
@AppStorage("server")
|
||||
var serverPath: String = "https://christophhagen.de/sesame/"
|
||||
|
||||
@AppStorage("localIP")
|
||||
var localAddress: String = "192.168.178.104/"
|
||||
|
||||
@AppStorage("counter")
|
||||
var nextMessageCounter: Int = 0
|
||||
|
||||
@AppStorage("compensate")
|
||||
var isCompensatingDaylightTime: Bool = false
|
||||
|
||||
@AppStorage("local")
|
||||
private var useLocalConnection = false
|
||||
|
||||
@AppStorage("deviceID")
|
||||
private var deviceID: Int = 0
|
||||
|
||||
@State
|
||||
var keyManager = KeyManagement()
|
||||
@ -29,10 +39,15 @@ struct ContentView: View {
|
||||
private var responseTime: Date? = nil
|
||||
|
||||
@State
|
||||
private var showKeySheet = false
|
||||
private var showSettingsSheet = false
|
||||
|
||||
@State
|
||||
private var showHistorySheet = false
|
||||
|
||||
@State
|
||||
private var didShowKeySheetOnce = false
|
||||
|
||||
let server = Client()
|
||||
|
||||
var compensationTime: UInt32 {
|
||||
isCompensatingDaylightTime ? 3600 : 0
|
||||
@ -77,7 +92,7 @@ struct ContentView: View {
|
||||
.font(.title2)
|
||||
.padding()
|
||||
Spacer()
|
||||
Button("Keys", action: { showKeySheet = true })
|
||||
Button("Settings", action: { showSettingsSheet = true })
|
||||
.frame(width: smallButtonWidth,
|
||||
height: smallButtonHeight)
|
||||
.background(.white.opacity(0.2))
|
||||
@ -97,7 +112,8 @@ struct ContentView: View {
|
||||
height: buttonWidth)
|
||||
.background(buttonBackground)
|
||||
.cornerRadius(buttonWidth / 2)
|
||||
.overlay(RoundedRectangle(cornerRadius: buttonWidth / 2).stroke(lineWidth: buttonBorderWidth).foregroundColor(buttonColor))
|
||||
.overlay(RoundedRectangle(cornerRadius: buttonWidth / 2)
|
||||
.stroke(lineWidth: buttonBorderWidth).foregroundColor(buttonColor))
|
||||
.foregroundColor(buttonColor)
|
||||
.font(.title)
|
||||
.disabled(!state.allowsAction)
|
||||
@ -115,8 +131,15 @@ struct ContentView: View {
|
||||
}
|
||||
.frame(width: geo.size.width, height: geo.size.height)
|
||||
.animation(.easeInOut, value: state.color)
|
||||
.sheet(isPresented: $showKeySheet) {
|
||||
KeyView(keyManager: $keyManager, isCompensatingDaylightTime: $isCompensatingDaylightTime)
|
||||
.sheet(isPresented: $showSettingsSheet) {
|
||||
SettingsView(
|
||||
keyManager: $keyManager,
|
||||
serverAddress: $serverPath,
|
||||
localAddress: $localAddress,
|
||||
deviceID: $deviceID,
|
||||
nextMessageCounter: $nextMessageCounter,
|
||||
isCompensatingDaylightTime: $isCompensatingDaylightTime,
|
||||
useLocalConnection: $useLocalConnection)
|
||||
}
|
||||
.sheet(isPresented: $showHistorySheet) {
|
||||
HistoryView(manager: history)
|
||||
@ -127,7 +150,8 @@ struct ContentView: View {
|
||||
|
||||
func mainButtonPressed() {
|
||||
guard let key = keyManager.get(.remoteKey),
|
||||
let token = keyManager.get(.authToken)?.data else {
|
||||
let token = keyManager.get(.authToken)?.data,
|
||||
let deviceId = UInt8(exactly: deviceID) else {
|
||||
return
|
||||
}
|
||||
|
||||
@ -136,37 +160,42 @@ struct ContentView: View {
|
||||
// Add time to compensate that the device is using daylight savings time
|
||||
let content = Message.Content(
|
||||
time: sentTime.timestamp + compensationTime,
|
||||
id: count)
|
||||
id: count,
|
||||
device: deviceId)
|
||||
let message = content.authenticate(using: key)
|
||||
let historyItem = HistoryItem(sent: message, date: sentTime)
|
||||
let historyItem = HistoryItem(sent: message.content, date: sentTime, local: useLocalConnection)
|
||||
state = .waitingForResponse
|
||||
print("Sending message \(count)")
|
||||
Task {
|
||||
let (newState, message) = await server.send(message, authToken: token)
|
||||
let (newState, responseMessage) = await send(message, authToken: token)
|
||||
let receivedTime = Date.now
|
||||
responseTime = receivedTime
|
||||
state = newState
|
||||
let finishedItem = historyItem.didReceive(response: newState, date: receivedTime, message: message)
|
||||
process(item: finishedItem)
|
||||
let finishedItem = historyItem.didReceive(response: newState, date: receivedTime, message: responseMessage?.content)
|
||||
guard let key = keyManager.get(.deviceKey) else {
|
||||
save(historyItem: finishedItem.notAuthenticated())
|
||||
return
|
||||
}
|
||||
guard let responseMessage else {
|
||||
save(historyItem: finishedItem)
|
||||
return
|
||||
}
|
||||
guard responseMessage.isValid(using: key) else {
|
||||
save(historyItem: finishedItem.invalidated())
|
||||
return
|
||||
}
|
||||
|
||||
nextMessageCounter = Int(responseMessage.content.id)
|
||||
save(historyItem: finishedItem)
|
||||
}
|
||||
}
|
||||
|
||||
private func process(item: HistoryItem) {
|
||||
guard let message = item.incomingMessage else {
|
||||
save(historyItem: item)
|
||||
return
|
||||
|
||||
private func send(_ message: Message, authToken: Data) async -> (state: ClientState, response: Message?) {
|
||||
if useLocalConnection {
|
||||
return await server.sendMessageOverLocalNetwork(message, server: localAddress)
|
||||
} else {
|
||||
return await server.send(message, server: serverPath, authToken: authToken)
|
||||
}
|
||||
|
||||
guard let key = keyManager.get(.deviceKey) else {
|
||||
save(historyItem: item.notAuthenticated())
|
||||
return
|
||||
}
|
||||
guard message.isValid(using: key) else {
|
||||
save(historyItem: item.invalidated())
|
||||
return
|
||||
}
|
||||
nextMessageCounter = Int(message.content.id)
|
||||
save(historyItem: item)
|
||||
}
|
||||
|
||||
private func save(historyItem: HistoryItem) {
|
||||
@ -194,7 +223,14 @@ struct ContentView: View {
|
||||
}
|
||||
|
||||
func checkDeviceStatus(_ timer: Timer) {
|
||||
guard !useLocalConnection else {
|
||||
return
|
||||
}
|
||||
guard let authToken = keyManager.get(.authToken) else {
|
||||
if !didShowKeySheetOnce {
|
||||
didShowKeySheetOnce = true
|
||||
//showSettingsSheet = true
|
||||
}
|
||||
return
|
||||
}
|
||||
guard !hasActiveRequest else {
|
||||
@ -202,7 +238,7 @@ struct ContentView: View {
|
||||
}
|
||||
hasActiveRequest = true
|
||||
Task {
|
||||
let newState = await server.deviceStatus(authToken: authToken.data)
|
||||
let newState = await server.deviceStatus(authToken: authToken.data, server: serverPath)
|
||||
hasActiveRequest = false
|
||||
switch state {
|
||||
case .noKeyAvailable:
|
||||
|
@ -1,168 +1,131 @@
|
||||
import Foundation
|
||||
|
||||
|
||||
struct HistoryItem {
|
||||
|
||||
|
||||
/// The sent/received date (local time, not including compensation offset)
|
||||
let requestDate: Date
|
||||
|
||||
let outgoingDate: Date
|
||||
|
||||
let outgoingMessage: Message
|
||||
|
||||
let incomingDate: Date?
|
||||
|
||||
let incomingMessage: Message?
|
||||
|
||||
let request: Message.Content
|
||||
|
||||
let usedLocalConnection: Bool
|
||||
|
||||
let response: ClientState?
|
||||
|
||||
let responseMessage: Message.Content?
|
||||
|
||||
let responseDate: Date?
|
||||
|
||||
init(sent message: Message, date: Date) {
|
||||
self.outgoingDate = date
|
||||
self.outgoingMessage = message
|
||||
self.incomingDate = nil
|
||||
self.incomingMessage = nil
|
||||
init(sent message: Message.Content, date: Date, local: Bool) {
|
||||
self.requestDate = date
|
||||
self.request = message
|
||||
self.responseMessage = nil
|
||||
self.response = nil
|
||||
self.responseDate = nil
|
||||
self.usedLocalConnection = local
|
||||
}
|
||||
|
||||
func didReceive(response: ClientState, date: Date?, message: Message?) -> HistoryItem {
|
||||
func didReceive(response: ClientState, date: Date?, message: Message.Content?) -> HistoryItem {
|
||||
.init(sent: self, response: response, date: date, message: message)
|
||||
}
|
||||
|
||||
func invalidated() -> HistoryItem {
|
||||
didReceive(response: .responseRejected(.invalidAuthentication), date: incomingDate, message: incomingMessage)
|
||||
didReceive(response: .responseRejected(.invalidAuthentication), date: responseDate, message: responseMessage)
|
||||
}
|
||||
|
||||
func notAuthenticated() -> HistoryItem {
|
||||
didReceive(response: .responseRejected(.missingKey), date: incomingDate, message: incomingMessage)
|
||||
didReceive(response: .responseRejected(.missingKey), date: responseDate, message: responseMessage)
|
||||
}
|
||||
|
||||
private init(sent: HistoryItem, response: ClientState, date: Date?, message: Message?) {
|
||||
self.outgoingDate = sent.outgoingDate
|
||||
self.outgoingMessage = sent.outgoingMessage
|
||||
self.incomingDate = date
|
||||
self.incomingMessage = message
|
||||
private init(sent: HistoryItem, response: ClientState, date: Date?, message: Message.Content?) {
|
||||
self.requestDate = sent.requestDate
|
||||
self.request = sent.request
|
||||
self.responseDate = date
|
||||
self.responseMessage = message
|
||||
self.response = response
|
||||
self.usedLocalConnection = sent.usedLocalConnection
|
||||
}
|
||||
|
||||
// MARK: Statistics
|
||||
|
||||
var roundTripTime: TimeInterval? {
|
||||
incomingDate?.timeIntervalSince(outgoingDate)
|
||||
responseDate?.timeIntervalSince(requestDate)
|
||||
}
|
||||
|
||||
var deviceTime: Date? {
|
||||
guard let timestamp = incomingMessage?.content.time else {
|
||||
guard let timestamp = responseMessage?.time else {
|
||||
return nil
|
||||
}
|
||||
return Date(timestamp: timestamp)
|
||||
}
|
||||
|
||||
var requestLatency: TimeInterval? {
|
||||
deviceTime?.timeIntervalSince(outgoingDate)
|
||||
deviceTime?.timeIntervalSince(requestDate)
|
||||
}
|
||||
|
||||
var responseLatency: TimeInterval? {
|
||||
guard let deviceTime = deviceTime else {
|
||||
return nil
|
||||
}
|
||||
return incomingDate?.timeIntervalSince(deviceTime)
|
||||
return responseDate?.timeIntervalSince(deviceTime)
|
||||
}
|
||||
|
||||
var clockOffset: Int? {
|
||||
guard let interval = roundTripTime, let deviceTime = deviceTime else {
|
||||
return nil
|
||||
}
|
||||
let estimatedArrival = outgoingDate.advanced(by: interval / 2)
|
||||
let estimatedArrival = requestDate.advanced(by: interval / 2)
|
||||
return Int(deviceTime.timeIntervalSince(estimatedArrival))
|
||||
}
|
||||
|
||||
// MARK: Coding
|
||||
}
|
||||
|
||||
static func testEncoding() {
|
||||
|
||||
}
|
||||
|
||||
var encoded: Data {
|
||||
var result = outgoingDate.encoded + outgoingMessage.encoded
|
||||
if let date = incomingDate {
|
||||
result += Data([1]) + date.encoded
|
||||
} else {
|
||||
result += Data([0])
|
||||
}
|
||||
if let message = incomingMessage {
|
||||
result += Data([1]) + message.encoded
|
||||
} else {
|
||||
result += Data([0])
|
||||
}
|
||||
result += response?.encoded ?? Data([0])
|
||||
return result
|
||||
}
|
||||
|
||||
init?(decodeFrom data: Data, index: inout Int) {
|
||||
guard let outgoingDate = Date(decodeFrom: data, index: &index) else {
|
||||
return nil
|
||||
}
|
||||
self.outgoingDate = outgoingDate
|
||||
|
||||
guard let outgoingMessage = Message(decodeFrom: data, index: &index) else {
|
||||
return nil
|
||||
}
|
||||
self.outgoingMessage = outgoingMessage
|
||||
|
||||
if data[index] > 0 {
|
||||
index += 1
|
||||
guard let incomingDate = Date(decodeFrom: data, index: &index) else {
|
||||
return nil
|
||||
}
|
||||
self.incomingDate = incomingDate
|
||||
} else {
|
||||
self.incomingDate = nil
|
||||
index += 1
|
||||
}
|
||||
|
||||
if data[index] > 0 {
|
||||
index += 1
|
||||
guard let incomingMessage = Message(decodeFrom: data, index: &index) else {
|
||||
return nil
|
||||
}
|
||||
self.incomingMessage = incomingMessage
|
||||
} else {
|
||||
self.incomingMessage = nil
|
||||
index += 1
|
||||
}
|
||||
guard index < data.count else {
|
||||
return nil
|
||||
}
|
||||
self.response = ClientState(code: data[index])
|
||||
index += 1
|
||||
extension HistoryItem: Codable {
|
||||
|
||||
enum CodingKeys: Int, CodingKey {
|
||||
case requestDate = 1
|
||||
case request = 2
|
||||
case usedLocalConnection = 3
|
||||
case response = 4
|
||||
case responseMessage = 5
|
||||
case responseDate = 6
|
||||
}
|
||||
}
|
||||
|
||||
private extension Date {
|
||||
|
||||
static var encodedSize: Int {
|
||||
MemoryLayout<Double>.size
|
||||
extension ClientState: Codable {
|
||||
|
||||
init(from decoder: Decoder) throws {
|
||||
let code = try decoder.singleValueContainer().decode(UInt8.self)
|
||||
self.init(code: code)
|
||||
}
|
||||
|
||||
var encoded: Data {
|
||||
.init(from: timeIntervalSince1970)
|
||||
}
|
||||
|
||||
init?(decodeFrom data: Data, index: inout Int) {
|
||||
guard index + Date.encodedSize <= data.count else {
|
||||
return nil
|
||||
}
|
||||
self.init(timeIntervalSince1970: data.advanced(by: index).convert(into: .zero))
|
||||
index += Date.encodedSize
|
||||
|
||||
func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.singleValueContainer()
|
||||
try container.encode(code)
|
||||
}
|
||||
}
|
||||
|
||||
extension HistoryItem: Identifiable {
|
||||
|
||||
var id: UInt32 {
|
||||
outgoingDate.timestamp
|
||||
requestDate.timestamp
|
||||
}
|
||||
}
|
||||
|
||||
extension HistoryItem: Comparable {
|
||||
|
||||
static func < (lhs: HistoryItem, rhs: HistoryItem) -> Bool {
|
||||
lhs.outgoingDate < rhs.outgoingDate
|
||||
lhs.requestDate < rhs.requestDate
|
||||
}
|
||||
}
|
||||
|
||||
extension HistoryItem {
|
||||
|
||||
static var mock: HistoryItem {
|
||||
let content = Message.Content(time: Date.now.timestamp, id: 123, device: 0)
|
||||
let content2 = Message.Content(time: (Date.now + 1).timestamp, id: 124, device: 0)
|
||||
return .init(sent: content, date: .now, local: false)
|
||||
.didReceive(response: .openSesame, date: .now + 2, message: content2)
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import SwiftUI
|
||||
import SFSafeSymbols
|
||||
|
||||
private let df: DateFormatter = {
|
||||
let df = DateFormatter()
|
||||
@ -12,20 +13,20 @@ struct HistoryListItem: View {
|
||||
let entry: HistoryItem
|
||||
|
||||
var entryTime: String {
|
||||
df.string(from: entry.outgoingDate)
|
||||
df.string(from: entry.requestDate)
|
||||
}
|
||||
|
||||
var roundTripText: String {
|
||||
var roundTripText: String? {
|
||||
guard let time = entry.roundTripTime else {
|
||||
return ""
|
||||
return nil
|
||||
}
|
||||
return "⇆ \(Int(time * 1000)) ms"
|
||||
return "\(Int(time * 1000)) ms"
|
||||
}
|
||||
|
||||
var counterText: String {
|
||||
let sentCounter = entry.outgoingMessage.content.id
|
||||
let startText = "🔗 \(sentCounter)"
|
||||
guard let rCounter = entry.incomingMessage?.content.id else {
|
||||
let sentCounter = entry.request.id
|
||||
let startText = "\(sentCounter)"
|
||||
guard let rCounter = entry.responseMessage?.id else {
|
||||
return startText
|
||||
}
|
||||
let diff = Int(rCounter) - Int(sentCounter)
|
||||
@ -35,15 +36,15 @@ struct HistoryListItem: View {
|
||||
return startText + " (\(diff))"
|
||||
}
|
||||
|
||||
var timeOffsetText: String {
|
||||
guard let offset = entry.clockOffset, offset != 0 else {
|
||||
return ""
|
||||
var timeOffsetText: String? {
|
||||
guard let offset = entry.clockOffset else {
|
||||
return nil
|
||||
}
|
||||
return "🕓 \(offset) s"
|
||||
return "\(offset) s"
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VStack {
|
||||
VStack(alignment: .leading) {
|
||||
HStack {
|
||||
Text(entry.response?.description ?? "")
|
||||
.font(.headline)
|
||||
@ -51,18 +52,25 @@ struct HistoryListItem: View {
|
||||
Text(entryTime)
|
||||
}.padding(.bottom, 1)
|
||||
HStack {
|
||||
Text(roundTripText)
|
||||
.font(.subheadline)
|
||||
.foregroundColor(.secondary)
|
||||
if let roundTripText {
|
||||
Image(systemSymbol: entry.usedLocalConnection ? .wifi : .network)
|
||||
//Image(systemSymbol: .arrowUpArrowDownCircle)
|
||||
Text(roundTripText)
|
||||
.font(.subheadline)
|
||||
}
|
||||
//Spacer()
|
||||
Image(systemSymbol: .personalhotspot)
|
||||
Text(counterText)
|
||||
.font(.subheadline)
|
||||
.foregroundColor(.secondary)
|
||||
Text(timeOffsetText)
|
||||
.font(.subheadline)
|
||||
.foregroundColor(.secondary)
|
||||
Spacer()
|
||||
}
|
||||
}.padding()
|
||||
if let timeOffsetText {
|
||||
//Spacer()
|
||||
Image(systemSymbol: .stopwatch)
|
||||
Text(timeOffsetText)
|
||||
.font(.subheadline)
|
||||
}
|
||||
}.foregroundColor(.secondary)
|
||||
}
|
||||
//.padding()
|
||||
}
|
||||
}
|
||||
|
||||
@ -71,19 +79,3 @@ struct HistoryListItem_Previews: PreviewProvider {
|
||||
HistoryListItem(entry: .mock)
|
||||
}
|
||||
}
|
||||
|
||||
private extension HistoryItem {
|
||||
|
||||
static var mock: HistoryItem {
|
||||
let mac = Data(repeating: 42, count: 32)
|
||||
let content = Message.Content(time: Date.now.timestamp, id: 123)
|
||||
let content2 = Message.Content(time: (Date.now + 1).timestamp, id: 124)
|
||||
return .init(
|
||||
sent: Message(mac: mac, content: content),
|
||||
date: .now)
|
||||
.didReceive(
|
||||
response: .openSesame,
|
||||
date: .now + 2,
|
||||
message: Message(mac: mac, content: content2))
|
||||
}
|
||||
}
|
||||
|
@ -1,59 +1,92 @@
|
||||
import Foundation
|
||||
import CBORCoding
|
||||
|
||||
final class HistoryManager {
|
||||
protocol HistoryManagerProtocol {
|
||||
|
||||
func loadEntries() -> [HistoryItem]
|
||||
|
||||
func save(item: HistoryItem) throws
|
||||
}
|
||||
|
||||
final class HistoryManager: HistoryManagerProtocol {
|
||||
|
||||
private let encoder = CBOREncoder(dateEncodingStrategy: .secondsSince1970)
|
||||
|
||||
private var fm: FileManager {
|
||||
.default
|
||||
}
|
||||
|
||||
var documentDirectory: URL {
|
||||
try! fm.url(
|
||||
static var documentDirectory: URL {
|
||||
try! FileManager.default.url(
|
||||
for: .documentDirectory,
|
||||
in: .userDomainMask,
|
||||
appropriateFor: nil, create: true)
|
||||
}
|
||||
|
||||
private var fileUrl: URL {
|
||||
documentDirectory.appendingPathComponent("history.bin")
|
||||
private let fileUrl: URL
|
||||
|
||||
init() {
|
||||
self.fileUrl = HistoryManager.documentDirectory.appendingPathComponent("history2.bin")
|
||||
}
|
||||
|
||||
|
||||
func loadEntries() -> [HistoryItem] {
|
||||
let url = fileUrl
|
||||
guard fm.fileExists(atPath: url.path) else {
|
||||
guard fm.fileExists(atPath: fileUrl.path) else {
|
||||
print("No history data found")
|
||||
return []
|
||||
}
|
||||
let content: Data
|
||||
do {
|
||||
content = try Data(contentsOf: url)
|
||||
content = try Data(contentsOf: fileUrl)
|
||||
} catch {
|
||||
print("Failed to read history data: \(error)")
|
||||
return []
|
||||
}
|
||||
let decoder = CBORDecoder()
|
||||
var index = 0
|
||||
var entries = [HistoryItem]()
|
||||
while index < content.count {
|
||||
guard let entry = HistoryItem(decodeFrom: content, index: &index) else {
|
||||
print("Failed to read entry at index \(index)")
|
||||
let length = Int(content[index])
|
||||
index += 1
|
||||
if index + length > content.count {
|
||||
print("Missing bytes in history file: needed \(length), has only \(content.count - index)")
|
||||
return entries
|
||||
}
|
||||
let entryData = content[index..<index+length]
|
||||
index += length
|
||||
do {
|
||||
let entry: HistoryItem = try decoder.decode(from: entryData)
|
||||
entries.append(entry)
|
||||
} catch {
|
||||
print("Failed to decode history (index: \(index), length \(length)): \(error)")
|
||||
return entries
|
||||
}
|
||||
entries.append(entry)
|
||||
}
|
||||
return entries.sorted().reversed()
|
||||
}
|
||||
|
||||
func save(item: HistoryItem) throws {
|
||||
let url = fileUrl
|
||||
let data = item.encoded
|
||||
guard fm.fileExists(atPath: url.path) else {
|
||||
try data.write(to: url)
|
||||
print("First history item written")
|
||||
let entryData = try encoder.encode(item)
|
||||
let data = Data([UInt8(entryData.count)]) + entryData
|
||||
guard fm.fileExists(atPath: fileUrl.path) else {
|
||||
try data.write(to: fileUrl)
|
||||
print("First history item written (\(data[0]))")
|
||||
return
|
||||
}
|
||||
let handle = try FileHandle(forWritingTo: url)
|
||||
let handle = try FileHandle(forWritingTo: fileUrl)
|
||||
try handle.seekToEnd()
|
||||
try handle.write(contentsOf: data)
|
||||
try handle.close()
|
||||
print("History item written")
|
||||
print("History item written (\(data[0]))")
|
||||
}
|
||||
}
|
||||
|
||||
final class HistoryManagerMock: HistoryManagerProtocol {
|
||||
|
||||
func loadEntries() -> [HistoryItem] {
|
||||
[.mock]
|
||||
}
|
||||
|
||||
func save(item: HistoryItem) throws {
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -2,17 +2,20 @@ import SwiftUI
|
||||
|
||||
struct HistoryView: View {
|
||||
|
||||
let manager: HistoryManager
|
||||
let manager: HistoryManagerProtocol
|
||||
|
||||
var body: some View {
|
||||
List(manager.loadEntries()) { entry in
|
||||
HistoryListItem(entry: entry)
|
||||
NavigationView {
|
||||
List(manager.loadEntries()) { entry in
|
||||
HistoryListItem(entry: entry)
|
||||
}
|
||||
.navigationTitle("History")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct HistoryView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
HistoryView(manager: .init())
|
||||
HistoryView(manager: HistoryManagerMock())
|
||||
}
|
||||
}
|
||||
|
@ -17,11 +17,11 @@ extension KeyManagement {
|
||||
var displayName: String {
|
||||
switch self {
|
||||
case .deviceKey:
|
||||
return "Device Key"
|
||||
return "Unlock Key"
|
||||
case .remoteKey:
|
||||
return "Remote Key"
|
||||
return "Response Key"
|
||||
case .authToken:
|
||||
return "Authentication Token"
|
||||
return "Server Token"
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,6 +148,15 @@ final class KeyManagement: ObservableObject {
|
||||
|
||||
func generate(_ type: KeyType) {
|
||||
let key = SymmetricKey(size: type.keyLength)
|
||||
save(type, key: key)
|
||||
}
|
||||
|
||||
func save(_ type: KeyType, data: Data) {
|
||||
let key = SymmetricKey(data: data)
|
||||
save(type, key: key)
|
||||
}
|
||||
|
||||
private func save(_ type: KeyType, key: SymmetricKey) {
|
||||
if keyChain.has(type) {
|
||||
keyChain.delete(type)
|
||||
}
|
||||
|
@ -1,36 +0,0 @@
|
||||
import SwiftUI
|
||||
|
||||
struct KeyView: View {
|
||||
|
||||
@Binding
|
||||
var keyManager: KeyManagement
|
||||
|
||||
@Binding
|
||||
var isCompensatingDaylightTime: Bool
|
||||
|
||||
var body: some View {
|
||||
ScrollView {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
ForEach(KeyManagement.KeyType.allCases) { keyType in
|
||||
SingleKeyView(
|
||||
keyManager: $keyManager,
|
||||
type: keyType)
|
||||
}
|
||||
Toggle(isOn: $isCompensatingDaylightTime) {
|
||||
Text("Compensate daylight savings time")
|
||||
}
|
||||
Text("If the remote has daylight savings time wrongly set, then the time validation will fail. Use this option to send messages with adjusted timestamps. Warning: Incorrect use of this option will allow replay attacks.")
|
||||
.font(.caption)
|
||||
.foregroundColor(.secondary)
|
||||
}.padding()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct KeyView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
KeyView(
|
||||
keyManager: .constant(KeyManagement()),
|
||||
isCompensatingDaylightTime: .constant(true))
|
||||
}
|
||||
}
|
168
Sesame/SettingsView.swift
Normal file
168
Sesame/SettingsView.swift
Normal file
@ -0,0 +1,168 @@
|
||||
import SwiftUI
|
||||
|
||||
struct SettingsView: View {
|
||||
|
||||
@Binding
|
||||
var keyManager: KeyManagement
|
||||
|
||||
@Binding
|
||||
var serverAddress: String
|
||||
|
||||
@Binding
|
||||
var localAddress: String
|
||||
|
||||
@Binding
|
||||
var deviceID: Int
|
||||
|
||||
@Binding
|
||||
var nextMessageCounter: Int
|
||||
|
||||
@Binding
|
||||
var isCompensatingDaylightTime: Bool
|
||||
|
||||
@Binding
|
||||
var useLocalConnection: Bool
|
||||
|
||||
@State
|
||||
private var showDeviceIdInput = false
|
||||
|
||||
@State
|
||||
private var deviceIdText = ""
|
||||
|
||||
@State
|
||||
private var showCounterInput = false
|
||||
|
||||
@State
|
||||
private var counterText = ""
|
||||
|
||||
|
||||
var body: some View {
|
||||
NavigationView {
|
||||
ScrollView {
|
||||
VStack(alignment: .leading, spacing: 8) {
|
||||
VStack(alignment: .leading) {
|
||||
Text("Server address")
|
||||
.bold()
|
||||
TextField("Server address", text: $serverAddress)
|
||||
.foregroundColor(.secondary)
|
||||
.padding(.leading, 8)
|
||||
}.padding(.vertical, 8)
|
||||
VStack(alignment: .leading) {
|
||||
Text("Local address")
|
||||
.bold()
|
||||
TextField("Local address", text: $localAddress)
|
||||
.foregroundColor(.secondary)
|
||||
.padding(.leading, 8)
|
||||
}.padding(.vertical, 8)
|
||||
Toggle(isOn: $useLocalConnection) {
|
||||
Text("Use direct connection to device")
|
||||
}
|
||||
Text("Attempt to communicate directly with the device. This is useful if the server is unavailable. Requires a WiFi connection on the same network as the device.")
|
||||
.font(.caption)
|
||||
.foregroundColor(.secondary)
|
||||
VStack(alignment: .leading) {
|
||||
Text("Device id")
|
||||
.bold()
|
||||
HStack(alignment: .bottom) {
|
||||
Text("\(deviceID)")
|
||||
.font(.system(.body, design: .monospaced))
|
||||
.foregroundColor(.secondary)
|
||||
.padding([.trailing, .bottom])
|
||||
Button("Edit", action: showAlertToChangeDeviceID)
|
||||
.padding([.horizontal, .bottom])
|
||||
.padding(.top, 4)
|
||||
}
|
||||
}.padding(.vertical, 8)
|
||||
VStack(alignment: .leading) {
|
||||
Text("Message counter")
|
||||
.bold()
|
||||
HStack(alignment: .bottom) {
|
||||
Text("\(nextMessageCounter)")
|
||||
.font(.system(.body, design: .monospaced))
|
||||
.foregroundColor(.secondary)
|
||||
.padding([.trailing, .bottom])
|
||||
Button("Edit", action: showAlertToChangeCounter)
|
||||
.padding([.horizontal, .bottom])
|
||||
.padding(.top, 4)
|
||||
}
|
||||
}.padding(.vertical, 8)
|
||||
ForEach(KeyManagement.KeyType.allCases) { keyType in
|
||||
SingleKeyView(
|
||||
keyManager: $keyManager,
|
||||
type: keyType)
|
||||
}
|
||||
Toggle(isOn: $isCompensatingDaylightTime) {
|
||||
Text("Compensate daylight savings time")
|
||||
}
|
||||
Text("If the remote has daylight savings time wrongly set, then the time validation will fail. Use this option to send messages with adjusted timestamps. Warning: Incorrect use of this option will allow replay attacks.")
|
||||
.font(.caption)
|
||||
.foregroundColor(.secondary)
|
||||
}.padding()
|
||||
}.onDisappear {
|
||||
if !localAddress.hasSuffix("/") {
|
||||
localAddress += "/"
|
||||
}
|
||||
}
|
||||
.navigationTitle("Settings")
|
||||
.alert("Update device ID", isPresented: $showDeviceIdInput, actions: {
|
||||
TextField("Device ID", text: $deviceIdText)
|
||||
.keyboardType(.decimalPad)
|
||||
.font(.system(.body, design: .monospaced))
|
||||
.foregroundColor(.black)
|
||||
Button("Save", action: saveDeviceID)
|
||||
Button("Cancel", role: .cancel, action: {})
|
||||
}, message: {
|
||||
Text("Enter the device ID")
|
||||
})
|
||||
.alert("Update message counter", isPresented: $showCounterInput, actions: {
|
||||
TextField("Message counter", text: $counterText)
|
||||
.keyboardType(.decimalPad)
|
||||
.font(.system(.body, design: .monospaced))
|
||||
.foregroundColor(.black)
|
||||
Button("Save", action: saveCounter)
|
||||
Button("Cancel", role: .cancel, action: {})
|
||||
}, message: {
|
||||
Text("Enter the message counter")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
private func showAlertToChangeDeviceID() {
|
||||
deviceIdText = "\(deviceID)"
|
||||
showDeviceIdInput = true
|
||||
}
|
||||
|
||||
private func saveDeviceID() {
|
||||
guard let id = UInt8(deviceIdText) else {
|
||||
print("Invalid device id '\(deviceIdText)'")
|
||||
return
|
||||
}
|
||||
self.deviceID = Int(id)
|
||||
}
|
||||
|
||||
private func showAlertToChangeCounter() {
|
||||
counterText = "\(nextMessageCounter)"
|
||||
showCounterInput = true
|
||||
}
|
||||
|
||||
private func saveCounter() {
|
||||
guard let id = UInt32(counterText) else {
|
||||
print("Invalid message counter '\(counterText)'")
|
||||
return
|
||||
}
|
||||
self.nextMessageCounter = Int(id)
|
||||
}
|
||||
}
|
||||
|
||||
struct SettingsView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
SettingsView(
|
||||
keyManager: .constant(KeyManagement()),
|
||||
serverAddress: .constant("https://example.com"),
|
||||
localAddress: .constant("192.168.178.42"),
|
||||
deviceID: .constant(0),
|
||||
nextMessageCounter: .constant(12345678),
|
||||
isCompensatingDaylightTime: .constant(true),
|
||||
useLocalConnection: .constant(false))
|
||||
}
|
||||
}
|
@ -8,6 +8,12 @@ struct SingleKeyView: View {
|
||||
|
||||
@Binding
|
||||
var keyManager: KeyManagement
|
||||
|
||||
@State
|
||||
private var showEditWindow = false
|
||||
|
||||
@State
|
||||
private var keyText = ""
|
||||
|
||||
let type: KeyManagement.KeyType
|
||||
|
||||
@ -54,9 +60,41 @@ struct SingleKeyView: View {
|
||||
.disabled(!hasKey)
|
||||
.padding([.horizontal, .bottom])
|
||||
.padding(.top, 4)
|
||||
Button("Edit") {
|
||||
keyText = keyManager.get(type)?.displayString ?? ""
|
||||
print("Set key text to '\(keyText)'")
|
||||
showEditWindow = true
|
||||
}
|
||||
.padding([.horizontal, .bottom])
|
||||
.padding(.top, 4)
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
.alert("Update key", isPresented: $showEditWindow, actions: {
|
||||
TextField("Key data", text: $keyText)
|
||||
.lineLimit(4)
|
||||
.font(.system(.body, design: .monospaced))
|
||||
.foregroundColor(.black)
|
||||
Button("Save", action: saveKey)
|
||||
Button("Cancel", role: .cancel, action: {})
|
||||
}, message: {
|
||||
Text("Enter the hex encoded key")
|
||||
})
|
||||
}
|
||||
|
||||
private func saveKey() {
|
||||
let cleanText = keyText.replacingOccurrences(of: " ", with: "")
|
||||
guard let keyData = Data(fromHexEncodedString: cleanText) else {
|
||||
print("Invalid key string")
|
||||
return
|
||||
}
|
||||
let keyLength = type.keyLength.bitCount
|
||||
guard keyData.count * 8 == keyLength else {
|
||||
print("Invalid key length \(keyData.count * 8) bits, expected \(keyLength)")
|
||||
return
|
||||
}
|
||||
keyManager.save(type, data: keyData)
|
||||
print("Key \(type) saved")
|
||||
}
|
||||
}
|
||||
|
||||
@ -65,5 +103,6 @@ struct SingleKeyView_Previews: PreviewProvider {
|
||||
SingleKeyView(
|
||||
keyManager: .constant(KeyManagement()),
|
||||
type: .deviceKey)
|
||||
.previewLayout(.fixed(width: 350, height: 100))
|
||||
}
|
||||
}
|
||||
|
@ -46,3 +46,26 @@ extension String {
|
||||
return results.map { String($0) }
|
||||
}
|
||||
}
|
||||
|
||||
let protocolSalt = "CryptoKit Playgrounds Putting It Together".data(using: .utf8)!
|
||||
|
||||
/// Generates an ephemeral key agreement key and performs key agreement to get the shared secret and derive the symmetric encryption key.
|
||||
func encrypt(_ data: Data, to theirEncryptionKey: Curve25519.KeyAgreement.PublicKey, signedBy ourSigningKey: Curve25519.Signing.PrivateKey) throws ->
|
||||
(ephemeralPublicKeyData: Data, ciphertext: Data, signature: Data) {
|
||||
let ephemeralKey = Curve25519.KeyAgreement.PrivateKey()
|
||||
let ephemeralPublicKey = ephemeralKey.publicKey.rawRepresentation
|
||||
|
||||
let sharedSecret = try ephemeralKey.sharedSecretFromKeyAgreement(with: theirEncryptionKey)
|
||||
|
||||
let symmetricKey = sharedSecret.hkdfDerivedSymmetricKey(using: SHA256.self,
|
||||
salt: protocolSalt,
|
||||
sharedInfo: ephemeralPublicKey +
|
||||
theirEncryptionKey.rawRepresentation +
|
||||
ourSigningKey.publicKey.rawRepresentation,
|
||||
outputByteCount: 32)
|
||||
|
||||
let ciphertext = try ChaChaPoly.seal(data, using: symmetricKey).combined
|
||||
let signature = try ourSigningKey.signature(for: ciphertext + ephemeralPublicKey + theirEncryptionKey.rawRepresentation)
|
||||
|
||||
return (ephemeralPublicKey, ciphertext, signature)
|
||||
}
|
||||
|
Reference in New Issue
Block a user