Compare commits

...

3 Commits

Author SHA1 Message Date
Christoph Hagen
9beb2e423e Improve key screen layout 2022-05-02 23:25:11 +02:00
Christoph Hagen
efc68ad803 Allow compensation of DST 2022-05-02 23:25:11 +02:00
Christoph Hagen
9444917186 Add banner resources
Update screenshot
2022-05-02 23:25:11 +02:00
5 changed files with 37 additions and 17 deletions

BIN
Banner.key Executable file

Binary file not shown.

View File

@ -8,6 +8,9 @@ struct ContentView: View {
@AppStorage("counter") @AppStorage("counter")
var nextMessageCounter: Int = 0 var nextMessageCounter: Int = 0
@AppStorage("compensate")
var isCompensatingDaylightTime: Bool = false
@State @State
var keyManager = KeyManagement() var keyManager = KeyManagement()
@ -31,6 +34,10 @@ struct ContentView: View {
@State @State
private var showHistorySheet = false private var showHistorySheet = false
var compensationTime: UInt32 {
isCompensatingDaylightTime ? 3600 : 0
}
var isPerformingRequests: Bool { var isPerformingRequests: Bool {
hasActiveRequest || hasActiveRequest ||
state == .waitingForResponse state == .waitingForResponse
@ -109,7 +116,7 @@ struct ContentView: View {
.frame(width: geo.size.width, height: geo.size.height) .frame(width: geo.size.width, height: geo.size.height)
.animation(.easeInOut, value: state.color) .animation(.easeInOut, value: state.color)
.sheet(isPresented: $showKeySheet) { .sheet(isPresented: $showKeySheet) {
KeyView(keyManager: $keyManager) KeyView(keyManager: $keyManager, isCompensatingDaylightTime: $isCompensatingDaylightTime)
} }
.sheet(isPresented: $showHistorySheet) { .sheet(isPresented: $showHistorySheet) {
HistoryView(manager: history) HistoryView(manager: history)
@ -126,8 +133,9 @@ struct ContentView: View {
let count = UInt32(nextMessageCounter) let count = UInt32(nextMessageCounter)
let sentTime = Date() let sentTime = Date()
// Add time to compensate that the device is using daylight savings time
let content = Message.Content( let content = Message.Content(
time: sentTime.timestamp, time: sentTime.timestamp + compensationTime,
id: count) id: count)
let message = content.authenticate(using: key) let message = content.authenticate(using: key)
let historyItem = HistoryItem(sent: message, date: sentTime) let historyItem = HistoryItem(sent: message, date: sentTime)
@ -139,7 +147,6 @@ struct ContentView: View {
responseTime = receivedTime responseTime = receivedTime
state = newState state = newState
let finishedItem = historyItem.didReceive(response: newState, date: receivedTime, message: message) let finishedItem = historyItem.didReceive(response: newState, date: receivedTime, message: message)
print("Interval: \(receivedTime.timeIntervalSince(sentTime))", "\(finishedItem.roundTripTime ?? -1)")
process(item: finishedItem) process(item: finishedItem)
} }
} }

View File

@ -29,10 +29,10 @@ struct HistoryListItem: View {
return startText return startText
} }
let diff = Int(rCounter) - Int(sentCounter) let diff = Int(rCounter) - Int(sentCounter)
guard diff != 1 else { guard diff != 1 && diff != 0 else {
return startText return startText
} }
return startText + "\(rCounter)" return startText + " (\(diff))"
} }
var timeOffsetText: String { var timeOffsetText: String {

View File

@ -5,14 +5,23 @@ struct KeyView: View {
@Binding @Binding
var keyManager: KeyManagement var keyManager: KeyManagement
@Binding
var isCompensatingDaylightTime: Bool
var body: some View { var body: some View {
GeometryReader { geo in ScrollView {
VStack(alignment: .leading, spacing: 16) { VStack(alignment: .leading, spacing: 8) {
ForEach(KeyManagement.KeyType.allCases) { keyType in ForEach(KeyManagement.KeyType.allCases) { keyType in
SingleKeyView( SingleKeyView(
keyManager: $keyManager, keyManager: $keyManager,
type: keyType) 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() }.padding()
} }
} }
@ -20,6 +29,8 @@ struct KeyView: View {
struct KeyView_Previews: PreviewProvider { struct KeyView_Previews: PreviewProvider {
static var previews: some View { static var previews: some View {
KeyView(keyManager: .constant(KeyManagement())) KeyView(
keyManager: .constant(KeyManagement()),
isCompensatingDaylightTime: .constant(true))
} }
} }

View File

@ -45,13 +45,15 @@ struct SingleKeyView: View {
keyManager.generate(type) keyManager.generate(type)
needRefresh.toggle() needRefresh.toggle()
} }
.padding() .padding([.horizontal, .bottom])
.padding(.top, 4)
Button(type.usesHashing ? "Copy hash" : "Copy") { Button(type.usesHashing ? "Copy hash" : "Copy") {
UIPasteboard.general.string = copyText UIPasteboard.general.string = copyText
} }
.disabled(!hasKey) .disabled(!hasKey)
.padding() .padding([.horizontal, .bottom])
.padding(.top, 4)
Spacer() Spacer()
} }
} }