From aea73089195fb12cf423f7bed8a5678be25a0917 Mon Sep 17 00:00:00 2001 From: consuelita Date: Tue, 19 Apr 2022 14:04:31 -0500 Subject: [PATCH] Debug prints --- .../ShadowSwift/DarkStarClientConnection.swift | 2 +- Sources/ShadowSwift/DarkStarServer.swift | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Sources/ShadowSwift/DarkStarClientConnection.swift b/Sources/ShadowSwift/DarkStarClientConnection.swift index c82dfcf..b9eed10 100644 --- a/Sources/ShadowSwift/DarkStarClientConnection.swift +++ b/Sources/ShadowSwift/DarkStarClientConnection.swift @@ -256,7 +256,7 @@ open class DarkStarClientConnection: Transport.Connection guard let lengthData = self.decryptingCipher.unpack(encrypted: someData, expectedCiphertextLength: Cipher.lengthSize) else { - // TODO: use decryptingCipher counter to see if this is the first time we have received something from the server + // use decryptingCipher counter to see if this is the first time we have received something from the server if decryptingCipher.decryptCounter == 1 { // TODO: if it is the first time and decryption fails, hang up and try again diff --git a/Sources/ShadowSwift/DarkStarServer.swift b/Sources/ShadowSwift/DarkStarServer.swift index fcc1dfc..0812b2d 100644 --- a/Sources/ShadowSwift/DarkStarServer.swift +++ b/Sources/ShadowSwift/DarkStarServer.swift @@ -118,16 +118,19 @@ public class DarkStarServer static public func createServerToClientSharedKey(serverPersistentPrivateKey: P256.KeyAgreement.PrivateKey, serverEphemeralPrivateKey: P256.KeyAgreement.PrivateKey, clientEphemeralPublicKey: P256.KeyAgreement.PublicKey, serverEndpoint: NWEndpoint) -> SymmetricKey? { - createServerSharedKey(serverPersistentPrivateKey: serverPersistentPrivateKey, serverEphemeralPrivateKey: serverEphemeralPrivateKey, clientEphemeralPublicKey: clientEphemeralPublicKey, serverEndpoint: serverEndpoint, personalizationString: ClientString) + print("**createServerToClientSharedKey**") + return createServerSharedKey(serverPersistentPrivateKey: serverPersistentPrivateKey, serverEphemeralPrivateKey: serverEphemeralPrivateKey, clientEphemeralPublicKey: clientEphemeralPublicKey, serverEndpoint: serverEndpoint, personalizationString: ClientString) } static public func createClientToServerSharedKey(serverPersistentPrivateKey: P256.KeyAgreement.PrivateKey, serverEphemeralPrivateKey: P256.KeyAgreement.PrivateKey, clientEphemeralPublicKey: P256.KeyAgreement.PublicKey, serverEndpoint: NWEndpoint) -> SymmetricKey? { - createServerSharedKey(serverPersistentPrivateKey: serverPersistentPrivateKey, serverEphemeralPrivateKey: serverEphemeralPrivateKey, clientEphemeralPublicKey: clientEphemeralPublicKey, serverEndpoint: serverEndpoint, personalizationString: ServerString) + print("**createClientToServerSharedKey**") + return createServerSharedKey(serverPersistentPrivateKey: serverPersistentPrivateKey, serverEphemeralPrivateKey: serverEphemeralPrivateKey, clientEphemeralPublicKey: clientEphemeralPublicKey, serverEndpoint: serverEndpoint, personalizationString: ServerString) } static func createServerSharedKey(serverPersistentPrivateKey: P256.KeyAgreement.PrivateKey, serverEphemeralPrivateKey: P256.KeyAgreement.PrivateKey, clientEphemeralPublicKey: P256.KeyAgreement.PublicKey, serverEndpoint: NWEndpoint, personalizationString: String) -> SymmetricKey? { + print("Generating a key:") guard let ephemeralECDH = try? serverEphemeralPrivateKey.sharedSecretFromKeyAgreement(with: clientEphemeralPublicKey) else { return nil @@ -153,16 +156,24 @@ public class DarkStarServer } var hash = SHA256() + + print("ephemeralECDHData: \(ephemeralECDHData.hex)") hash.update(data: ephemeralECDHData) + print("persistentECDHData: \(persistentECDHData.hex)") hash.update(data: persistentECDHData) + print("serverIdentifier: \(serverIdentifier.hex)") hash.update(data: serverIdentifier) + print("clientEphemeralPublicKeyData: \(clientEphemeralPublicKeyData)") hash.update(data: clientEphemeralPublicKeyData) + print("serverEphemeralPublicKeyData: \(serverEphemeralPublicKeyData)") hash.update(data: serverEphemeralPublicKeyData) + print("DarkStarString: \(DarkStarString.data.hex)") hash.update(data: DarkStarString.data) + print("personalizationString.data: \(personalizationString.data.hex)") hash.update(data: personalizationString.data) // Destination let hashed = hash.finalize() let hashedData = Data(hashed) - + print("hashedData: \(hashedData.hex)") return SymmetricKey(data: hashedData) }