Skip to content

Commit

Permalink
Debug prints
Browse files Browse the repository at this point in the history
  • Loading branch information
consuelita committed Apr 19, 2022
1 parent 28ed0b3 commit aea7308
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Sources/ShadowSwift/DarkStarClientConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 14 additions & 3 deletions Sources/ShadowSwift/DarkStarServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}

Expand Down

0 comments on commit aea7308

Please sign in to comment.