mirror of
https://github.com/grishka/NearDrop.git
synced 2026-04-03 01:36:15 +02:00
Add descriptions to requiredFieldMissing and be more lenient
fixes #156, fixes #159
This commit is contained in:
@@ -823,7 +823,7 @@
|
|||||||
CODE_SIGN_ENTITLEMENTS = NearDrop/NearDrop.entitlements;
|
CODE_SIGN_ENTITLEMENTS = NearDrop/NearDrop.entitlements;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
COMBINE_HIDPI_IMAGES = YES;
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
CURRENT_PROJECT_VERSION = 6;
|
CURRENT_PROJECT_VERSION = 7;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
|
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
|
||||||
INFOPLIST_KEY_LSUIElement = YES;
|
INFOPLIST_KEY_LSUIElement = YES;
|
||||||
@@ -835,7 +835,7 @@
|
|||||||
"@executable_path/../Frameworks",
|
"@executable_path/../Frameworks",
|
||||||
);
|
);
|
||||||
MACOSX_DEPLOYMENT_TARGET = 11.0;
|
MACOSX_DEPLOYMENT_TARGET = 11.0;
|
||||||
MARKETING_VERSION = 2.0.2;
|
MARKETING_VERSION = 2.0.3;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = me.grishka.NearDrop;
|
PRODUCT_BUNDLE_IDENTIFIER = me.grishka.NearDrop;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||||
@@ -855,7 +855,7 @@
|
|||||||
CODE_SIGN_ENTITLEMENTS = NearDrop/NearDrop.entitlements;
|
CODE_SIGN_ENTITLEMENTS = NearDrop/NearDrop.entitlements;
|
||||||
CODE_SIGN_STYLE = Automatic;
|
CODE_SIGN_STYLE = Automatic;
|
||||||
COMBINE_HIDPI_IMAGES = YES;
|
COMBINE_HIDPI_IMAGES = YES;
|
||||||
CURRENT_PROJECT_VERSION = 6;
|
CURRENT_PROJECT_VERSION = 7;
|
||||||
GENERATE_INFOPLIST_FILE = YES;
|
GENERATE_INFOPLIST_FILE = YES;
|
||||||
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
|
INFOPLIST_KEY_LSApplicationCategoryType = "public.app-category.utilities";
|
||||||
INFOPLIST_KEY_LSUIElement = YES;
|
INFOPLIST_KEY_LSUIElement = YES;
|
||||||
@@ -867,7 +867,7 @@
|
|||||||
"@executable_path/../Frameworks",
|
"@executable_path/../Frameworks",
|
||||||
);
|
);
|
||||||
MACOSX_DEPLOYMENT_TARGET = 11.0;
|
MACOSX_DEPLOYMENT_TARGET = 11.0;
|
||||||
MARKETING_VERSION = 2.0.2;
|
MARKETING_VERSION = 2.0.3;
|
||||||
PRODUCT_BUNDLE_IDENTIFIER = me.grishka.NearDrop;
|
PRODUCT_BUNDLE_IDENTIFIER = me.grishka.NearDrop;
|
||||||
PRODUCT_NAME = "$(TARGET_NAME)";
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
||||||
SWIFT_EMIT_LOC_STRINGS = YES;
|
SWIFT_EMIT_LOC_STRINGS = YES;
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
{
|
{
|
||||||
"originHash" : "5bbb4a57a61db67d6ce8adc203fbc456a84ce246fff6c01807617c5de6a47adc",
|
|
||||||
"pins" : [
|
"pins" : [
|
||||||
{
|
{
|
||||||
"identity" : "asn1",
|
"identity" : "asn1",
|
||||||
@@ -38,5 +37,5 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"version" : 3
|
"version" : 2
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ class InboundNearbyConnection: NearbyConnection{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func processConnectionRequestFrame(_ frame:Location_Nearby_Connections_OfflineFrame) throws{
|
private func processConnectionRequestFrame(_ frame:Location_Nearby_Connections_OfflineFrame) throws{
|
||||||
guard frame.hasV1 && frame.v1.hasConnectionRequest && frame.v1.connectionRequest.hasEndpointInfo else { throw NearbyError.requiredFieldMissing }
|
guard frame.hasV1 && frame.v1.hasConnectionRequest && frame.v1.connectionRequest.hasEndpointInfo else { throw NearbyError.requiredFieldMissing("connectionRequest.endpointInfo") }
|
||||||
guard case .connectionRequest = frame.v1.type else { throw NearbyError.protocolError("Unexpected frame type \(frame.v1.type)") }
|
guard case .connectionRequest = frame.v1.type else { throw NearbyError.protocolError("Unexpected frame type \(frame.v1.type)") }
|
||||||
let endpointInfo=frame.v1.connectionRequest.endpointInfo
|
let endpointInfo=frame.v1.connectionRequest.endpointInfo
|
||||||
guard endpointInfo.count>17 else { throw NearbyError.protocolError("Endpoint info too short") }
|
guard endpointInfo.count>17 else { throw NearbyError.protocolError("Endpoint info too short") }
|
||||||
@@ -142,7 +142,7 @@ class InboundNearbyConnection: NearbyConnection{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func processUkey2ClientInit(_ msg:Securegcm_Ukey2Message) throws{
|
private func processUkey2ClientInit(_ msg:Securegcm_Ukey2Message) throws{
|
||||||
guard msg.hasMessageType, msg.hasMessageData else { throw NearbyError.requiredFieldMissing }
|
guard msg.hasMessageType, msg.hasMessageData else { throw NearbyError.requiredFieldMissing("clientInit ukey2message.type|data") }
|
||||||
guard case .clientInit = msg.messageType else{
|
guard case .clientInit = msg.messageType else{
|
||||||
sendUkey2Alert(type: .badMessageType)
|
sendUkey2Alert(type: .badMessageType)
|
||||||
throw NearbyError.ukey2
|
throw NearbyError.ukey2
|
||||||
@@ -206,7 +206,7 @@ class InboundNearbyConnection: NearbyConnection{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func processUkey2ClientFinish(_ msg:Securegcm_Ukey2Message, raw:Data) throws{
|
private func processUkey2ClientFinish(_ msg:Securegcm_Ukey2Message, raw:Data) throws{
|
||||||
guard msg.hasMessageType, msg.hasMessageData else { throw NearbyError.requiredFieldMissing }
|
guard msg.hasMessageType, msg.hasMessageData else { throw NearbyError.requiredFieldMissing("clientFinish ukey2message.type|data") }
|
||||||
guard case .clientFinish = msg.messageType else { throw NearbyError.ukey2 }
|
guard case .clientFinish = msg.messageType else { throw NearbyError.ukey2 }
|
||||||
|
|
||||||
var sha=SHA512()
|
var sha=SHA512()
|
||||||
@@ -214,7 +214,7 @@ class InboundNearbyConnection: NearbyConnection{
|
|||||||
guard cipherCommitment==Data(sha.finalize()) else { throw NearbyError.ukey2 }
|
guard cipherCommitment==Data(sha.finalize()) else { throw NearbyError.ukey2 }
|
||||||
|
|
||||||
let clientFinish=try Securegcm_Ukey2ClientFinished(serializedData: msg.messageData)
|
let clientFinish=try Securegcm_Ukey2ClientFinished(serializedData: msg.messageData)
|
||||||
guard clientFinish.hasPublicKey else {throw NearbyError.requiredFieldMissing }
|
guard clientFinish.hasPublicKey else {throw NearbyError.requiredFieldMissing("ukey2clientFinish.publicKey") }
|
||||||
let clientKey=try Securemessage_GenericPublicKey(serializedData: clientFinish.publicKey)
|
let clientKey=try Securemessage_GenericPublicKey(serializedData: clientFinish.publicKey)
|
||||||
|
|
||||||
try finalizeKeyExchange(peerKey: clientKey)
|
try finalizeKeyExchange(peerKey: clientKey)
|
||||||
@@ -223,7 +223,7 @@ class InboundNearbyConnection: NearbyConnection{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func processConnectionResponseFrame(_ frame:Location_Nearby_Connections_OfflineFrame) throws{
|
private func processConnectionResponseFrame(_ frame:Location_Nearby_Connections_OfflineFrame) throws{
|
||||||
guard frame.hasV1, frame.v1.hasType else { throw NearbyError.requiredFieldMissing }
|
guard frame.hasV1, frame.v1.hasType else { throw NearbyError.requiredFieldMissing("offlineFrame.v1.type") }
|
||||||
if case .connectionResponse = frame.v1.type {
|
if case .connectionResponse = frame.v1.type {
|
||||||
var resp=Location_Nearby_Connections_OfflineFrame()
|
var resp=Location_Nearby_Connections_OfflineFrame()
|
||||||
resp.version = .v1
|
resp.version = .v1
|
||||||
@@ -254,7 +254,7 @@ class InboundNearbyConnection: NearbyConnection{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func processPairedKeyEncryptionFrame(_ frame:Sharing_Nearby_Frame) throws{
|
private func processPairedKeyEncryptionFrame(_ frame:Sharing_Nearby_Frame) throws{
|
||||||
guard frame.hasV1, frame.v1.hasPairedKeyEncryption else { throw NearbyError.requiredFieldMissing }
|
guard frame.hasV1, frame.v1.hasPairedKeyEncryption else { throw NearbyError.requiredFieldMissing("shareNearbyFrame.v1.pairedKeyEncryption") }
|
||||||
var pairedResult=Sharing_Nearby_Frame()
|
var pairedResult=Sharing_Nearby_Frame()
|
||||||
pairedResult.version = .v1
|
pairedResult.version = .v1
|
||||||
pairedResult.v1=Sharing_Nearby_V1Frame()
|
pairedResult.v1=Sharing_Nearby_V1Frame()
|
||||||
@@ -266,12 +266,12 @@ class InboundNearbyConnection: NearbyConnection{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func processPairedKeyResultFrame(_ frame:Sharing_Nearby_Frame) throws{
|
private func processPairedKeyResultFrame(_ frame:Sharing_Nearby_Frame) throws{
|
||||||
guard frame.hasV1, frame.v1.hasPairedKeyResult else { throw NearbyError.requiredFieldMissing }
|
guard frame.hasV1, frame.v1.hasPairedKeyResult else { throw NearbyError.requiredFieldMissing("shareNearbyFrame.v1.pairedKeyResult") }
|
||||||
currentState = .receivedPairedKeyResult
|
currentState = .receivedPairedKeyResult
|
||||||
}
|
}
|
||||||
|
|
||||||
private func processIntroductionFrame(_ frame:Sharing_Nearby_Frame) throws{
|
private func processIntroductionFrame(_ frame:Sharing_Nearby_Frame) throws{
|
||||||
guard frame.hasV1, frame.v1.hasIntroduction else { throw NearbyError.requiredFieldMissing }
|
guard frame.hasV1, frame.v1.hasIntroduction else { throw NearbyError.requiredFieldMissing("shareNearbyFrame.v1.introduction") }
|
||||||
currentState = .waitingForUserConsent
|
currentState = .waitingForUserConsent
|
||||||
if frame.v1.introduction.fileMetadata.count>0 && frame.v1.introduction.textMetadata.isEmpty{
|
if frame.v1.introduction.fileMetadata.count>0 && frame.v1.introduction.textMetadata.isEmpty{
|
||||||
let downloadsDirectory=(try FileManager.default.url(for: .downloadsDirectory, in: .userDomainMask, appropriateFor: nil, create: true)).resolvingSymlinksInPath()
|
let downloadsDirectory=(try FileManager.default.url(for: .downloadsDirectory, in: .userDomainMask, appropriateFor: nil, create: true)).resolvingSymlinksInPath()
|
||||||
|
|||||||
@@ -232,7 +232,7 @@ 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 }
|
guard smsg.hasSignature, smsg.hasHeaderAndBody else { throw NearbyError.requiredFieldMissing("secureMessage.signature|headerAndBody") }
|
||||||
let hmac=Data(HMAC<SHA256>.authenticationCode(for: smsg.headerAndBody, using: recvHmacKey!))
|
let hmac=Data(HMAC<SHA256>.authenticationCode(for: smsg.headerAndBody, using: recvHmacKey!))
|
||||||
guard hmac==smsg.signature else { throw NearbyError.protocolError("hmac!=signature") }
|
guard hmac==smsg.signature else { throw NearbyError.protocolError("hmac!=signature") }
|
||||||
let headerAndBody=try Securemessage_HeaderAndBody(serializedData: smsg.headerAndBody)
|
let headerAndBody=try Securemessage_HeaderAndBody(serializedData: smsg.headerAndBody)
|
||||||
@@ -254,19 +254,18 @@ class NearbyConnection{
|
|||||||
})
|
})
|
||||||
decryptedData=decryptedData.prefix(decryptedLength)
|
decryptedData=decryptedData.prefix(decryptedLength)
|
||||||
let d2dMsg=try Securegcm_DeviceToDeviceMessage(serializedData: decryptedData)
|
let d2dMsg=try Securegcm_DeviceToDeviceMessage(serializedData: decryptedData)
|
||||||
guard d2dMsg.hasMessage, d2dMsg.hasSequenceNumber else { throw NearbyError.requiredFieldMissing }
|
guard d2dMsg.hasMessage, d2dMsg.hasSequenceNumber else { throw NearbyError.requiredFieldMissing("d2dMessage.message|sequenceNumber") }
|
||||||
clientSeq+=1
|
clientSeq+=1
|
||||||
guard d2dMsg.sequenceNumber==clientSeq else { throw NearbyError.protocolError("Wrong sequence number. Expected \(clientSeq), got \(d2dMsg.sequenceNumber)") }
|
guard d2dMsg.sequenceNumber==clientSeq else { throw NearbyError.protocolError("Wrong sequence number. Expected \(clientSeq), got \(d2dMsg.sequenceNumber)") }
|
||||||
let offlineFrame=try Location_Nearby_Connections_OfflineFrame(serializedData: d2dMsg.message)
|
let offlineFrame=try Location_Nearby_Connections_OfflineFrame(serializedData: d2dMsg.message)
|
||||||
guard offlineFrame.hasV1, offlineFrame.v1.hasType else { throw NearbyError.requiredFieldMissing }
|
|
||||||
|
|
||||||
if case .payloadTransfer = offlineFrame.v1.type {
|
if offlineFrame.hasV1 && offlineFrame.v1.hasType, case .payloadTransfer = offlineFrame.v1.type {
|
||||||
guard offlineFrame.v1.hasPayloadTransfer else { throw NearbyError.requiredFieldMissing }
|
guard offlineFrame.v1.hasPayloadTransfer else { throw NearbyError.requiredFieldMissing("offlineFrame.v1.payloadTransfer") }
|
||||||
let payloadTransfer=offlineFrame.v1.payloadTransfer
|
let payloadTransfer=offlineFrame.v1.payloadTransfer
|
||||||
let header=payloadTransfer.payloadHeader;
|
let header=payloadTransfer.payloadHeader;
|
||||||
let chunk=payloadTransfer.payloadChunk;
|
let chunk=payloadTransfer.payloadChunk;
|
||||||
guard header.hasType, header.hasID else { throw NearbyError.requiredFieldMissing }
|
guard header.hasType, header.hasID else { throw NearbyError.requiredFieldMissing("payloadHeader.type|id") }
|
||||||
guard payloadTransfer.hasPayloadChunk, chunk.hasOffset, chunk.hasFlags else { throw NearbyError.requiredFieldMissing }
|
guard payloadTransfer.hasPayloadChunk, chunk.hasOffset, chunk.hasFlags else { throw NearbyError.requiredFieldMissing("payloadTransfer.payloadChunk|offset|flags") }
|
||||||
if case .bytes = header.type{
|
if case .bytes = header.type{
|
||||||
let payloadID=header.id
|
let payloadID=header.id
|
||||||
if header.totalSize>InboundNearbyConnection.SANE_FRAME_LENGTH{
|
if header.totalSize>InboundNearbyConnection.SANE_FRAME_LENGTH{
|
||||||
@@ -294,7 +293,7 @@ class NearbyConnection{
|
|||||||
}else if case .file = header.type{
|
}else if case .file = header.type{
|
||||||
try processFileChunk(frame: payloadTransfer)
|
try processFileChunk(frame: payloadTransfer)
|
||||||
}
|
}
|
||||||
}else if case .keepAlive = offlineFrame.v1.type{
|
}else if offlineFrame.hasV1 && offlineFrame.v1.hasType, case .keepAlive = offlineFrame.v1.type{
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
print("Sent keep-alive")
|
print("Sent keep-alive")
|
||||||
#endif
|
#endif
|
||||||
@@ -321,7 +320,7 @@ class NearbyConnection{
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal func finalizeKeyExchange(peerKey:Securemessage_GenericPublicKey) throws{
|
internal func finalizeKeyExchange(peerKey:Securemessage_GenericPublicKey) throws{
|
||||||
guard peerKey.hasEcP256PublicKey else { throw NearbyError.requiredFieldMissing }
|
guard peerKey.hasEcP256PublicKey else { throw NearbyError.requiredFieldMissing("peerKey.ecP256PublicKey") }
|
||||||
|
|
||||||
let domain=Domain.instance(curve: .EC256r1)
|
let domain=Domain.instance(curve: .EC256r1)
|
||||||
var clientX=peerKey.ecP256PublicKey.x
|
var clientX=peerKey.ecP256PublicKey.x
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public struct RemoteDeviceInfo{
|
|||||||
|
|
||||||
public enum NearbyError:Error{
|
public enum NearbyError:Error{
|
||||||
case protocolError(_ message:String)
|
case protocolError(_ message:String)
|
||||||
case requiredFieldMissing
|
case requiredFieldMissing(_ message:String)
|
||||||
case ukey2
|
case ukey2
|
||||||
case inputOutput(cause:Errno)
|
case inputOutput(cause:Errno)
|
||||||
case canceled(reason:CancellationReason)
|
case canceled(reason:CancellationReason)
|
||||||
|
|||||||
@@ -243,7 +243,7 @@ class OutboundNearbyConnection:NearbyConnection{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func processPairedKeyEncryption(frame:Sharing_Nearby_Frame) throws{
|
private func processPairedKeyEncryption(frame:Sharing_Nearby_Frame) throws{
|
||||||
guard frame.hasV1, frame.v1.hasPairedKeyEncryption else { throw NearbyError.requiredFieldMissing }
|
guard frame.hasV1, frame.v1.hasPairedKeyEncryption else { throw NearbyError.requiredFieldMissing("sharingNearbyFrame.v1.pairedKeyEncryption") }
|
||||||
var pairedResult=Sharing_Nearby_Frame()
|
var pairedResult=Sharing_Nearby_Frame()
|
||||||
pairedResult.version = .v1
|
pairedResult.version = .v1
|
||||||
pairedResult.v1=Sharing_Nearby_V1Frame()
|
pairedResult.v1=Sharing_Nearby_V1Frame()
|
||||||
@@ -255,7 +255,7 @@ class OutboundNearbyConnection:NearbyConnection{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func processPairedKeyResult(frame:Sharing_Nearby_Frame) throws{
|
private func processPairedKeyResult(frame:Sharing_Nearby_Frame) throws{
|
||||||
guard frame.hasV1, frame.v1.hasPairedKeyResult else { throw NearbyError.requiredFieldMissing }
|
guard frame.hasV1, frame.v1.hasPairedKeyResult else { throw NearbyError.requiredFieldMissing("sharingNearbyFrame.v1.pairedKeyResult") }
|
||||||
|
|
||||||
var introduction=Sharing_Nearby_Frame()
|
var introduction=Sharing_Nearby_Frame()
|
||||||
introduction.version = .v1
|
introduction.version = .v1
|
||||||
@@ -308,7 +308,7 @@ class OutboundNearbyConnection:NearbyConnection{
|
|||||||
}
|
}
|
||||||
|
|
||||||
private func processConsent(frame:Sharing_Nearby_Frame) throws{
|
private func processConsent(frame:Sharing_Nearby_Frame) throws{
|
||||||
guard frame.version == .v1, frame.v1.type == .response else {throw NearbyError.requiredFieldMissing}
|
guard frame.version == .v1, frame.v1.type == .response else {throw NearbyError.requiredFieldMissing("sharingNearbyFrame.v1.type==response")}
|
||||||
switch frame.v1.connectionResponse.status{
|
switch frame.v1.connectionResponse.status{
|
||||||
case .accept:
|
case .accept:
|
||||||
currentState = .sendingFiles
|
currentState = .sendingFiles
|
||||||
|
|||||||
Reference in New Issue
Block a user