mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-22 14:26:01 +00:00
More logging to fix protobuf wrong error
This commit is contained in:
1 parent
088a3b5389
commit
58e488c0ad
5 files changed
+93
-19
No files matched your search
@@ -113,6 +113,9 @@ struct LargeAppIconView<Content: View>: View {
|
|||||||
print("Clicked \(taps) times")
|
print("Clicked \(taps) times")
|
||||||
|
|
||||||
if taps == 5 {
|
if taps == 5 {
|
||||||
|
|
||||||
|
NearbyConnectionManager.shared.checkSignature = false
|
||||||
|
|
||||||
sendLoggingString()
|
sendLoggingString()
|
||||||
print("Copied log to clipboard")
|
print("Copied log to clipboard")
|
||||||
|
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ class InboundNearbyConnection: NearbyConnection{
|
|||||||
|
|
||||||
log("Received frame in state \(currentState)...")
|
log("Received frame in state \(currentState)...")
|
||||||
|
|
||||||
do{
|
do {
|
||||||
switch currentState {
|
switch currentState {
|
||||||
case .initial:
|
case .initial:
|
||||||
let frame=try Location_Nearby_Connections_OfflineFrame(serializedBytes: frameData)
|
let frame=try Location_Nearby_Connections_OfflineFrame(serializedBytes: frameData)
|
||||||
@@ -68,26 +68,47 @@ class InboundNearbyConnection: NearbyConnection{
|
|||||||
let frame=try Location_Nearby_Connections_OfflineFrame(serializedBytes: frameData)
|
let frame=try Location_Nearby_Connections_OfflineFrame(serializedBytes: frameData)
|
||||||
try processConnectionResponseFrame(frame)
|
try processConnectionResponseFrame(frame)
|
||||||
default:
|
default:
|
||||||
let smsg=try Securemessage_SecureMessage(serializedBytes: frameData)
|
|
||||||
|
var smsg: Securemessage_SecureMessage
|
||||||
|
|
||||||
|
do {
|
||||||
|
smsg = try Securemessage_SecureMessage(serializedBytes: frameData)
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
log("Error deserializing secure message. Trying again....")
|
||||||
|
|
||||||
|
// last 32 bytes = HMAC key
|
||||||
|
// change 2 bytes before to 0x12 0x20 for Protobuf to succeed
|
||||||
|
|
||||||
|
if frameData.count < 34 {
|
||||||
|
throw NearbyError.protocolError("Frame too short")
|
||||||
|
}
|
||||||
|
|
||||||
|
var newData = frameData
|
||||||
|
let count = newData.count
|
||||||
|
newData[count - 34] = 0x12
|
||||||
|
newData[count - 33] = 0x20
|
||||||
|
|
||||||
|
smsg = try Securemessage_SecureMessage(serializedBytes: newData)
|
||||||
|
|
||||||
|
log("Secure message deserialized successfully after fixing Protobuf message")
|
||||||
|
}
|
||||||
try decryptAndProcessReceivedSecureMessage(smsg)
|
try decryptAndProcessReceivedSecureMessage(smsg)
|
||||||
}
|
}
|
||||||
}catch{
|
} catch {
|
||||||
lastError = error
|
lastError = error
|
||||||
log("Deserialization error: \(error) in state \(currentState). Payload: \(frameData.hex)")
|
log("Deserialization error: \(error) in state \(currentState). Payload: \(frameData.hex)")
|
||||||
|
|
||||||
let lastState = currentState
|
//log("Public Key: \(publicKey?.pem ?? "nil")")
|
||||||
log("Waiting for 5 seconds to check if connection is still alive")
|
//log("Private Key: \(privateKey?.pem ?? "nil")")
|
||||||
|
//log("Ukey Client Init Msg: \(ukeyClientInitMsgData?.hex ?? "nil")")
|
||||||
|
//log("Ukey Server Init Msg: \(ukeyServerInitMsgData?.hex ?? "nil")")
|
||||||
|
log("S1: \(decryptKey?.map { String(format: "%02x", $0) }.joined() ?? "nil")")
|
||||||
|
//log("Encrypt Key: \(encryptKey?.map { String(format: "%02x", $0) }.joined() ?? "nil")")
|
||||||
|
log("Received HMAC/Signature Key: \(recvHmacKey?.withUnsafeBytes { Data(Array($0)) }.map { String(format: "%02x", $0) }.joined() ?? "nil")")
|
||||||
|
log("Sent HMAC/Signature Key: \(sendHmacKey?.withUnsafeBytes { Data(Array($0)) }.map { String(format: "%02x", $0) }.joined() ?? "nil")")
|
||||||
|
|
||||||
DispatchQueue.main.asyncAfter(deadline: .now() + 5) {
|
self.protocolError()
|
||||||
|
|
||||||
if self.currentState == lastState {
|
|
||||||
log("Still in state \(self.currentState), last state was \(lastState)")
|
|
||||||
self.protocolError()
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
log("State changed to \(self.currentState), not closing connection")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -575,3 +596,21 @@ extension Data {
|
|||||||
return map { String(format: "%02hhx", $0) }.joined()
|
return map { String(format: "%02hhx", $0) }.joined()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension String {
|
||||||
|
var dataFromHex: Data {
|
||||||
|
var data = Data(capacity: count / 2)
|
||||||
|
var index = startIndex
|
||||||
|
while index < endIndex {
|
||||||
|
let nextIndex = self.index(index, offsetBy: 2)
|
||||||
|
if nextIndex <= endIndex,
|
||||||
|
let byte = UInt8(self[index..<nextIndex], radix: 16) {
|
||||||
|
data.append(byte)
|
||||||
|
} else {
|
||||||
|
break // or handle invalid hex gracefully
|
||||||
|
}
|
||||||
|
index = nextIndex
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -233,8 +233,12 @@ class NearbyConnection{
|
|||||||
|
|
||||||
internal func decryptAndProcessReceivedSecureMessage(_ smsg:Securemessage_SecureMessage) throws{
|
internal func decryptAndProcessReceivedSecureMessage(_ smsg:Securemessage_SecureMessage) throws{
|
||||||
guard smsg.hasSignature, smsg.hasHeaderAndBody else { throw NearbyError.requiredFieldMissing("secureMessage.signature|headerAndBody") }
|
guard smsg.hasSignature, smsg.hasHeaderAndBody else { throw NearbyError.requiredFieldMissing("secureMessage.signature|headerAndBody") }
|
||||||
let hmac=Data(HMAC<SHA256>.authenticationCode(for: smsg.headerAndBody, using: recvHmacKey!))
|
|
||||||
guard hmac==smsg.signature else { throw NearbyError.protocolError("hmac!=signature") }
|
if NearbyConnectionManager.shared.checkSignature {
|
||||||
|
let hmac = Data(HMAC<SHA256>.authenticationCode(for: smsg.headerAndBody, using: recvHmacKey!))
|
||||||
|
guard hmac == smsg.signature else { throw NearbyError.protocolError("hmac!=signature: Expected \(hmac), got \(smsg.signature)") }
|
||||||
|
}
|
||||||
|
|
||||||
let headerAndBody=try Securemessage_HeaderAndBody(serializedBytes: smsg.headerAndBody)
|
let headerAndBody=try Securemessage_HeaderAndBody(serializedBytes: smsg.headerAndBody)
|
||||||
var decryptedData=Data(count: headerAndBody.body.count)
|
var decryptedData=Data(count: headerAndBody.body.count)
|
||||||
|
|
||||||
|
|||||||
@@ -150,6 +150,14 @@ public protocol ShareExtensionDelegate:AnyObject{
|
|||||||
|
|
||||||
public class NearbyConnectionManager : NSObject, NetServiceDelegate, InboundNearbyConnectionDelegate, OutboundNearbyConnectionDelegate{
|
public class NearbyConnectionManager : NSObject, NetServiceDelegate, InboundNearbyConnectionDelegate, OutboundNearbyConnectionDelegate{
|
||||||
|
|
||||||
|
public var checkSignature = true {
|
||||||
|
didSet {
|
||||||
|
if !checkSignature {
|
||||||
|
log("WARNING: Signature checking is disabled. Resume with caution.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private var tcpListener:NWListener;
|
private var tcpListener:NWListener;
|
||||||
public let endpointID:[UInt8]=generateEndpointID()
|
public let endpointID:[UInt8]=generateEndpointID()
|
||||||
private var mdnsService:NetService?
|
private var mdnsService:NetService?
|
||||||
|
|||||||
@@ -201,6 +201,12 @@
|
|||||||
EB2F9BFA2DA04B67004010A2 /* Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Helpers.swift; sourceTree = "<group>"; };
|
EB2F9BFA2DA04B67004010A2 /* Helpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Helpers.swift; sourceTree = "<group>"; };
|
||||||
EB36435F2D73A29F009CDFF8 /* AudioManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioManager.swift; sourceTree = "<group>"; };
|
EB36435F2D73A29F009CDFF8 /* AudioManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioManager.swift; sourceTree = "<group>"; };
|
||||||
EB3643612D73A2CA009CDFF8 /* timeIsNow.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = timeIsNow.mp3; sourceTree = "<group>"; };
|
EB3643612D73A2CA009CDFF8 /* timeIsNow.mp3 */ = {isa = PBXFileReference; lastKnownFileType = audio.mp3; path = timeIsNow.mp3; sourceTree = "<group>"; };
|
||||||
|
EB3B73F32DC8FF3A00369951 /* device_to_device_messages.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = device_to_device_messages.proto; sourceTree = "<group>"; };
|
||||||
|
EB3B73F42DC8FF3A00369951 /* offline_wire_formats.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = offline_wire_formats.proto; sourceTree = "<group>"; };
|
||||||
|
EB3B73F52DC8FF3A00369951 /* securegcm.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = securegcm.proto; sourceTree = "<group>"; };
|
||||||
|
EB3B73F62DC8FF3A00369951 /* securemessage.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = securemessage.proto; sourceTree = "<group>"; };
|
||||||
|
EB3B73F72DC8FF3A00369951 /* ukey.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = ukey.proto; sourceTree = "<group>"; };
|
||||||
|
EB3B73F82DC8FF3A00369951 /* wire_format.proto */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.protobuf; path = wire_format.proto; sourceTree = "<group>"; };
|
||||||
EB6F62D62D91F4AC00534EC2 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
|
EB6F62D62D91F4AC00534EC2 /* SettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsView.swift; sourceTree = "<group>"; };
|
||||||
EB7CD1442D6FB0C100CB0CB5 /* Logger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; };
|
EB7CD1442D6FB0C100CB0CB5 /* Logger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; };
|
||||||
EB7F540F2D78E6DD00989564 /* Sidebar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Sidebar.swift; sourceTree = "<group>"; };
|
EB7F540F2D78E6DD00989564 /* Sidebar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Sidebar.swift; sourceTree = "<group>"; };
|
||||||
@@ -341,6 +347,7 @@
|
|||||||
isa = PBXGroup;
|
isa = PBXGroup;
|
||||||
children = (
|
children = (
|
||||||
EB2B41E32DC63AC80070FC39 /* SleepManager.swift */,
|
EB2B41E32DC63AC80070FC39 /* SleepManager.swift */,
|
||||||
|
EB3B73F92DC8FF3A00369951 /* ProtobufSource */,
|
||||||
69DA9A2729E18CB500A442DA /* Protobuf */,
|
69DA9A2729E18CB500A442DA /* Protobuf */,
|
||||||
69DA9A1E29E0C0B300A442DA /* NearbyConnectionManager.swift */,
|
69DA9A1E29E0C0B300A442DA /* NearbyConnectionManager.swift */,
|
||||||
69DA9A2229E17F0400A442DA /* InboundNearbyConnection.swift */,
|
69DA9A2229E17F0400A442DA /* InboundNearbyConnection.swift */,
|
||||||
@@ -352,6 +359,19 @@
|
|||||||
path = NearbyShare;
|
path = NearbyShare;
|
||||||
sourceTree = "<group>";
|
sourceTree = "<group>";
|
||||||
};
|
};
|
||||||
|
EB3B73F92DC8FF3A00369951 /* ProtobufSource */ = {
|
||||||
|
isa = PBXGroup;
|
||||||
|
children = (
|
||||||
|
EB3B73F32DC8FF3A00369951 /* device_to_device_messages.proto */,
|
||||||
|
EB3B73F42DC8FF3A00369951 /* offline_wire_formats.proto */,
|
||||||
|
EB3B73F52DC8FF3A00369951 /* securegcm.proto */,
|
||||||
|
EB3B73F62DC8FF3A00369951 /* securemessage.proto */,
|
||||||
|
EB3B73F72DC8FF3A00369951 /* ukey.proto */,
|
||||||
|
EB3B73F82DC8FF3A00369951 /* wire_format.proto */,
|
||||||
|
);
|
||||||
|
path = ProtobufSource;
|
||||||
|
sourceTree = "<group>";
|
||||||
|
};
|
||||||
/* End PBXGroup section */
|
/* End PBXGroup section */
|
||||||
|
|
||||||
/* Begin PBXHeadersBuildPhase section */
|
/* Begin PBXHeadersBuildPhase section */
|
||||||
@@ -789,7 +809,7 @@
|
|||||||
MTL_FAST_MATH = YES;
|
MTL_FAST_MATH = YES;
|
||||||
ONLY_ACTIVE_ARCH = YES;
|
ONLY_ACTIVE_ARCH = YES;
|
||||||
SDKROOT = macosx;
|
SDKROOT = macosx;
|
||||||
SHARED_BUILD = 31;
|
SHARED_BUILD = 32;
|
||||||
SHARED_VERSION = 1.7.3;
|
SHARED_VERSION = 1.7.3;
|
||||||
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
|
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
|
||||||
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
|
||||||
@@ -848,7 +868,7 @@
|
|||||||
MTL_ENABLE_DEBUG_INFO = NO;
|
MTL_ENABLE_DEBUG_INFO = NO;
|
||||||
MTL_FAST_MATH = YES;
|
MTL_FAST_MATH = YES;
|
||||||
SDKROOT = macosx;
|
SDKROOT = macosx;
|
||||||
SHARED_BUILD = 31;
|
SHARED_BUILD = 32;
|
||||||
SHARED_VERSION = 1.7.3;
|
SHARED_VERSION = 1.7.3;
|
||||||
SWIFT_COMPILATION_MODE = wholemodule;
|
SWIFT_COMPILATION_MODE = wholemodule;
|
||||||
SWIFT_OPTIMIZATION_LEVEL = "-O";
|
SWIFT_OPTIMIZATION_LEVEL = "-O";
|
||||||
|
|||||||
Reference in new issue
Block a user