Move PRNG initialization to namespace level

This commit is contained in:
Davide De Rosa 2019-05-19 15:52:55 +02:00
parent 821cf66d79
commit 8be0f14aa9
3 changed files with 20 additions and 19 deletions

View File

@ -205,7 +205,7 @@ open class TunnelKitProvider: NEPacketTunnelProvider {
log.info("Starting tunnel...")
cfg.clearLastError(in: appGroup)
guard OpenVPN.EncryptionBridge.prepareRandomNumberGenerator(seedLength: prngSeedLength) else {
guard OpenVPN.prepareRandomNumberGenerator(seedLength: prngSeedLength) else {
completionHandler(ProviderConfigurationError.prngInitialization)
return
}

View File

@ -39,28 +39,11 @@ import __TunnelKitCore
import __TunnelKitOpenVPN
extension OpenVPN {
/// Bridges native encryption for high-level operations.
public class EncryptionBridge {
class EncryptionBridge {
private static let maxHmacLength = 100
private let box: CryptoBox
/**
Initializes the PRNG. Must be issued before using `OpenVPNSession`.
- Parameter seedLength: The length in bytes of the pseudorandom seed that will feed the PRNG.
*/
public static func prepareRandomNumberGenerator(seedLength: Int) -> Bool {
let seed: ZeroingData
do {
seed = try SecureRandom.safeData(length: seedLength)
} catch {
return false
}
return CryptoBox.preparePRNG(withSeed: seed.bytes, length: seed.count)
}
// Ruby: keys_prf
private static func keysPRF(
_ label: String,

View File

@ -24,7 +24,25 @@
//
import Foundation
import __TunnelKitCore
import __TunnelKitOpenVPN
/// Container for OpenVPN classes.
public class OpenVPN {
/**
Initializes the PRNG. Must be issued before using `OpenVPNSession`.
- Parameter seedLength: The length in bytes of the pseudorandom seed that will feed the PRNG.
*/
public static func prepareRandomNumberGenerator(seedLength: Int) -> Bool {
let seed: ZeroingData
do {
seed = try SecureRandom.safeData(length: seedLength)
} catch {
return false
}
return CryptoBox.preparePRNG(withSeed: seed.bytes, length: seed.count)
}
}