Skip to content

Commit

Permalink
Bloom Filter for Replay Attacks
Browse files Browse the repository at this point in the history
  • Loading branch information
consuelita committed Apr 6, 2022
1 parent 40274cf commit 68c21f3
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
17 changes: 12 additions & 5 deletions Sources/ShadowSwift/DarkStar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,18 +163,25 @@ public struct DarkStar



static public func handleTheirEphemeralPublicKey(connection: Connection, bloomFilter: BloomFilter<Data>) -> P256.KeyAgreement.PublicKey?
static public func handleTheirEphemeralPublicKey(connection: Connection, bloomFilter: BloomFilter<Data>?) -> P256.KeyAgreement.PublicKey?
{
// Receive their ephemeral key
guard let theirEphemeralPublicKeyData = connection.read(size: P256KeySize) else
{
return nil
}

// TODO: See if theirEphemeralPublicKeyData is in the BloomFilter, return nil if it is.

// TODO: If it's not in a BloomFilter, add it to the BloomFilter and Save the BloomFilter

if let serverBloomFilter = bloomFilter // Server
{
// TODO: See if theirEphemeralPublicKeyData is in the BloomFilter, return nil if it is.

// TODO: If it's not in a BloomFilter, add it to the BloomFilter and Save the BloomFilter
}
else // Client
{

}

guard let theirEphemeralPublicKey = try? P256.KeyAgreement.PublicKey(compactRepresentation: theirEphemeralPublicKeyData) else
{
return nil
Expand Down
3 changes: 2 additions & 1 deletion Sources/ShadowSwift/DarkStarClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,8 @@ public class DarkStarClient
guard DarkStarClient.handleClientConfirmationCode(connection: connection, theirPublicKey: serverPersistentPublicKey, myPrivateKey: clientEphemeralPrivateKey, endpoint: endpoint, serverPersistentPublicKey: serverPersistentPublicKey, clientEphemeralPublicKey: clientEphemeralPublicKey) else {return nil}

// Receive server ephemeral key
guard let serverEphemeralPublicKey = DarkStar.handleTheirEphemeralPublicKey(connection: connection) else {return nil}
guard let serverEphemeralPublicKey = DarkStar.handleTheirEphemeralPublicKey(connection: connection, bloomFilter: nil) else
{return nil}

// Create shared key
guard let clientToServerSharedKey = DarkStarClient.createClientToServerSharedKey(clientEphemeralPrivateKey: clientEphemeralPrivateKey, serverEphemeralPublicKey: serverEphemeralPublicKey, serverPersistentPublicKey: serverPersistentPublicKey, serverEndpoint: endpoint) else {return nil}
Expand Down
2 changes: 1 addition & 1 deletion Sources/ShadowSwift/DarkStarServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public class DarkStarServer
let serverPersistentPublicKey = serverPersistentPrivateKey.publicKey

// Receive client ephemeral key
guard let clientEphemeralPublicKey = DarkStar.handleTheirEphemeralPublicKey(connection: connection) else
guard let clientEphemeralPublicKey = DarkStar.handleTheirEphemeralPublicKey(connection: connection, bloomFilter: bloomFilter) else
{
let transport = TransmissionToTransportConnection({return connection})

Expand Down
2 changes: 1 addition & 1 deletion Sources/ShadowSwift/DarkStarServerConnection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ open class DarkStarServerConnection: Transport.Connection
return nil
}

guard let server = DarkStarServer(serverPersistentPrivateKey: serverPersistentPrivateKey, endpoint: endpoint, connection: connection) else
guard let server = DarkStarServer(serverPersistentPrivateKey: serverPersistentPrivateKey, endpoint: endpoint, connection: connection, bloomFilter: bloomFilter) else
{
logger.error("Failed to init DarkStarServer")
return nil
Expand Down

0 comments on commit 68c21f3

Please sign in to comment.