mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-22 22:36:01 +00:00
Better error message for failed signature check, throw error on canceled file transfer
This commit is contained in:
1 parent
f18649b959
commit
ddd9a32023
4 files changed
+227
-7
No files matched your search
@@ -26,6 +26,7 @@ class NearbyConnection {
|
||||
var encryptionDone: Bool = false
|
||||
var lastError: Error?
|
||||
var bytesTransferred: Int64 = 0
|
||||
var cancelled: Bool = false
|
||||
|
||||
private var payloadBuffers: [Int64: NSMutableData] = [:]
|
||||
private var connectionClosed: Bool = false
|
||||
@@ -299,7 +300,7 @@ class NearbyConnection {
|
||||
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: Expected \(hmac), got \(smsg.signature)") }
|
||||
guard hmac == smsg.signature else { throw NearbyError.protocolError("Error.Signature".localized()) }
|
||||
|
||||
let headerAndBody = try Securemessage_HeaderAndBody(serializedBytes: smsg.headerAndBody)
|
||||
var decryptedData = Data(count: headerAndBody.body.count)
|
||||
@@ -338,8 +339,14 @@ class NearbyConnection {
|
||||
|
||||
guard header.hasType, header.hasID else { throw NearbyError.requiredFieldMissing("payloadHeader.type|id") }
|
||||
guard payloadTransfer.hasPayloadChunk, chunk.hasOffset, chunk.hasFlags else {
|
||||
log("[NearbyConnection] Payload transfer chunk is missing offset or flags, likely canceled.")
|
||||
throw NearbyError.canceled(reason: .userCanceled)
|
||||
|
||||
if payloadTransfer.controlMessage.event == .payloadCanceled {
|
||||
log("[NearbyConnection] Cancel control frame received.")
|
||||
throw NearbyError.canceled(reason: .userCanceled)
|
||||
}
|
||||
|
||||
log("[NearbyConnection] Payload transfer chunk is missing offset or flags. Frame is \(payloadTransfer.debugDescription)")
|
||||
throw NearbyError.requiredFieldMissing("payloadChunk.offset|flags")
|
||||
}
|
||||
|
||||
if case .bytes = header.type {
|
||||
|
||||
Reference in new issue
Block a user