Skip to content

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
buggmagnet committed Aug 27, 2024
1 parent 62b3c6d commit 63e78ad
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
14 changes: 7 additions & 7 deletions ios/MullvadRustRuntime/PacketTunnelProvider+TCPConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,32 +87,32 @@ func tcpConnectionReceive(
/// If `rawEphemeralKey` is nil, the negotiation is considered failed.
///
/// - Parameters:
/// - rawPacketTunnel: A raw pointer to the running instance of `NEPacketTunnelProvider`
/// - rawEphemeralPeerReceiver: A raw pointer to the running instance of `NEPacketTunnelProvider`
/// - rawPresharedKey: A raw pointer to the quantum-secure pre shared key
/// - rawEphemeralKey: A raw pointer to the ephemeral private key of the device
@_cdecl("swift_ephemeral_peer_ready")
func receivePostQuantumKey(
rawPostQuantumKeyReceiver: UnsafeMutableRawPointer?,
rawEphemeralPeerReceiver: UnsafeMutableRawPointer?,
rawPresharedKey: UnsafeMutableRawPointer?,
rawEphemeralKey: UnsafeMutableRawPointer?
) {
guard let rawPostQuantumKeyReceiver else { return }
let postQuantumKeyReceiver = Unmanaged<EphemeralPeerReceiver>.fromOpaque(rawPostQuantumKeyReceiver)
guard let rawEphemeralPeerReceiver else { return }
let ephemeralPeerReceiver = Unmanaged<EphemeralPeerReceiver>.fromOpaque(rawEphemeralPeerReceiver)
.takeUnretainedValue()

// If there are no private keys for the ephemeral peer, then the negotiation either failed, or timed out.
guard let rawEphemeralKey,
let ephemeralKey = PrivateKey(rawValue: Data(bytes: rawEphemeralKey, count: 32)) else {
postQuantumKeyReceiver.ephemeralPeerExchangeFailed()
ephemeralPeerReceiver.ephemeralPeerExchangeFailed()
return
}

// If there is a pre-shared key, an ephemeral peer was negotiated with Post Quantum options
// Otherwise, a Daita enabled ephemeral peer was requested
if let rawPresharedKey, let key = PreSharedKey(rawValue: Data(bytes: rawPresharedKey, count: 32)) {
postQuantumKeyReceiver.receivePostQuantumKey(key, ephemeralKey: ephemeralKey)
ephemeralPeerReceiver.receivePostQuantumKey(key, ephemeralKey: ephemeralKey)
} else {
postQuantumKeyReceiver.receiveEphemeralPeerPrivateKey(ephemeralKey)
ephemeralPeerReceiver.receiveEphemeralPeerPrivateKey(ephemeralKey)
}
return
}
2 changes: 1 addition & 1 deletion ios/MullvadTypes/Protocols/EphemeralPeerReceiving.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// PostQuantumKeyReceiving.swift
// EphemeralPeerReceiving.swift
// MullvadTypes
//
// Created by Andrew Bulhak on 2024-03-05.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ extension PacketTunnelActor {
preSharedKey: firstHop.configuration.preSharedKey
).makeConfiguration()

// wireguard-go will only turn on daita for the entry peer,
// so pass the daita configuration to the exit peer for consistency
let exitConfiguration = try ConfigurationBuilder(
privateKey: secondHop.configuration.privateKey,
interfaceAddresses: settings.interfaceAddresses,
Expand Down

0 comments on commit 63e78ad

Please sign in to comment.