mirror of
https://github.com/leonboe1/QuickDrop.git
synced 2026-11-20 21:36:00 +00:00
Add auth for incoming transfers
This commit is contained in:
1 parent
216e2cf851
commit
2ef3bc3b44
1 file changed
+24
-4
@@ -12,6 +12,7 @@ import Network
|
|||||||
import System
|
import System
|
||||||
import BigInt
|
import BigInt
|
||||||
import SwiftECC
|
import SwiftECC
|
||||||
|
import ASN1
|
||||||
import LUI
|
import LUI
|
||||||
|
|
||||||
#if os(macOS)
|
#if os(macOS)
|
||||||
@@ -438,10 +439,29 @@ class InboundNearbyConnection: NearbyConnection {
|
|||||||
pairedEncryption.v1 = Sharing_Nearby_V1Frame()
|
pairedEncryption.v1 = Sharing_Nearby_V1Frame()
|
||||||
pairedEncryption.v1.type = .pairedKeyEncryption
|
pairedEncryption.v1.type = .pairedKeyEncryption
|
||||||
pairedEncryption.v1.pairedKeyEncryption = Sharing_Nearby_PairedKeyEncryptionFrame()
|
pairedEncryption.v1.pairedKeyEncryption = Sharing_Nearby_PairedKeyEncryptionFrame()
|
||||||
|
|
||||||
// For inbound connections, we do not use provide secretIDHash and signedData
|
if let signingPrivateKey = IdentityManager.shared.getPrivateKey(),
|
||||||
pairedEncryption.v1.pairedKeyEncryption.secretIDHash = Data.randomData(length: 6)
|
let publicKey = IdentityManager.shared.getPublicKey()?.toGenericPublicKey(),
|
||||||
pairedEncryption.v1.pairedKeyEncryption.signedData = Data.randomData(length: 72)
|
let publicKeyData = IdentityManager.shared.getPublicKey()?.toGenericPublicKeyData(),
|
||||||
|
let publicKeyID = publicKey.id(),
|
||||||
|
let authKeyData = self.authKey?.data() {
|
||||||
|
|
||||||
|
var cert = Sharing_Nearby_PublicCertificate()
|
||||||
|
cert.secretID = publicKeyID
|
||||||
|
cert.publicKey = publicKeyData
|
||||||
|
|
||||||
|
let signatureTuple = signingPrivateKey.sign(msg: authKeyData)
|
||||||
|
|
||||||
|
pairedEncryption.v1.certificateInfo.publicCertificate.append(cert)
|
||||||
|
pairedEncryption.v1.pairedKeyEncryption.secretIDHash = cert.secretID
|
||||||
|
pairedEncryption.v1.pairedKeyEncryption.signedData = Data(signatureTuple.asn1.encode())
|
||||||
|
|
||||||
|
pairedEncryption.v1.pairedKeyResult.status = .success
|
||||||
|
} else {
|
||||||
|
log("[InboundNearbyConnection \(self.id)] No private key available for receiver authentication.")
|
||||||
|
pairedEncryption.v1.pairedKeyEncryption.secretIDHash = Data.randomData(length: 6)
|
||||||
|
pairedEncryption.v1.pairedKeyEncryption.signedData = Data.randomData(length: 72)
|
||||||
|
}
|
||||||
|
|
||||||
try sendTransferSetupFrame(pairedEncryption)
|
try sendTransferSetupFrame(pairedEncryption)
|
||||||
currentState = .sentConnectionResponse
|
currentState = .sentConnectionResponse
|
||||||
|
|||||||
Reference in new issue
Block a user