mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-11-22 08:17:28 +00:00
expose the signing keys a board confirmation can come from
Verified peers, plus peers vouched for by someone we verified, mapped through the Noise-authenticated signing-key bindings only. An announce that merely claims a trusted peer's key does not qualify. Same validity rules as the vouch trust level: unverifying the voucher or letting the vouch expire removes the vouchee's key.
This commit is contained in:
parent
d3305b9c56
commit
de15e90645
@ -140,6 +140,7 @@ protocol SecureIdentityStateManagerProtocol {
|
||||
func markVouchBatchSent(to fingerprint: String, at date: Date)
|
||||
func signingPublicKey(forFingerprint fingerprint: String) -> Data?
|
||||
func mostRecentlyVerifiedFingerprints(limit: Int, excluding fingerprint: String) -> [String]
|
||||
func trustedSigningKeys() -> Set<Data>
|
||||
|
||||
// MARK: Noise-authenticated announcement identity
|
||||
func bindAuthenticatedSigningPublicKey(_ signingPublicKey: Data, fingerprint: String)
|
||||
@ -843,6 +844,27 @@ final class SecureIdentityStateManager: SecureIdentityStateManagerProtocol {
|
||||
queue.sync { cache.cryptographicIdentities[fingerprint]?.signingPublicKey }
|
||||
}
|
||||
|
||||
/// Ed25519 keys of peers whose word counts for board confirmations: ones
|
||||
/// I verified, plus ones vouched for by someone I verified. Only
|
||||
/// Noise-authenticated bindings qualify, so an announce that merely
|
||||
/// claims a trusted peer's key cannot borrow its standing.
|
||||
func trustedSigningKeys() -> Set<Data> {
|
||||
trustedSigningKeys(now: Date())
|
||||
}
|
||||
|
||||
func trustedSigningKeys(now: Date) -> Set<Data> {
|
||||
queue.sync {
|
||||
let bindings = cache.authenticatedSigningKeysByFingerprint ?? [:]
|
||||
var keys = Set<Data>()
|
||||
for (fingerprint, key) in bindings
|
||||
where cache.verifiedFingerprints.contains(fingerprint)
|
||||
|| !validVouchersLocked(for: fingerprint, now: now).isEmpty {
|
||||
keys.insert(key)
|
||||
}
|
||||
return keys
|
||||
}
|
||||
}
|
||||
|
||||
/// Verified fingerprints ordered most recently verified first (entries
|
||||
/// without a recorded verification time sort last), excluding the given
|
||||
/// fingerprint. Feeds the outgoing vouch batch.
|
||||
|
||||
@ -160,4 +160,8 @@ final class MockIdentityManager: SecureIdentityStateManagerProtocol {
|
||||
func mostRecentlyVerifiedFingerprints(limit: Int, excluding fingerprint: String) -> [String] {
|
||||
[]
|
||||
}
|
||||
|
||||
func trustedSigningKeys() -> Set<Data> {
|
||||
[]
|
||||
}
|
||||
}
|
||||
|
||||
@ -317,6 +317,59 @@ struct SecureIdentityStateManagerVouchTests {
|
||||
#expect(reloaded.validVouchers(for: vouchee).count == 1)
|
||||
}
|
||||
|
||||
// MARK: - Trusted signing keys (board confirmations)
|
||||
|
||||
@Test
|
||||
func trustedSigningKeys_includesVerifiedAndVouchedAuthenticatedKeys() {
|
||||
let manager = makeManager()
|
||||
let stranger = String(repeating: "0c", count: 32)
|
||||
let voucherKey = Data(repeating: 0xA1, count: 32)
|
||||
let voucheeKey = Data(repeating: 0xB1, count: 32)
|
||||
let strangerKey = Data(repeating: 0xC1, count: 32)
|
||||
manager.bindAuthenticatedSigningPublicKey(voucherKey, fingerprint: voucher)
|
||||
manager.bindAuthenticatedSigningPublicKey(voucheeKey, fingerprint: vouchee)
|
||||
manager.bindAuthenticatedSigningPublicKey(strangerKey, fingerprint: stranger)
|
||||
#expect(manager.trustedSigningKeys().isEmpty)
|
||||
|
||||
manager.setVerified(fingerprint: voucher, verified: true)
|
||||
#expect(manager.trustedSigningKeys() == [voucherKey])
|
||||
|
||||
manager.recordVouch(voucheeFingerprint: vouchee, voucherFingerprint: voucher, timestamp: Date())
|
||||
#expect(manager.trustedSigningKeys() == [voucherKey, voucheeKey])
|
||||
}
|
||||
|
||||
@Test
|
||||
func trustedSigningKeys_ignoresVerifiedPeerWithoutAuthenticatedBinding() {
|
||||
let manager = makeManager()
|
||||
manager.setVerified(fingerprint: voucher, verified: true)
|
||||
#expect(manager.trustedSigningKeys().isEmpty)
|
||||
}
|
||||
|
||||
@Test
|
||||
func trustedSigningKeys_dropsVoucheeWhenVoucherIsUnverified() {
|
||||
let manager = makeManager()
|
||||
let voucheeKey = Data(repeating: 0xB2, count: 32)
|
||||
manager.bindAuthenticatedSigningPublicKey(voucheeKey, fingerprint: vouchee)
|
||||
manager.setVerified(fingerprint: voucher, verified: true)
|
||||
manager.recordVouch(voucheeFingerprint: vouchee, voucherFingerprint: voucher, timestamp: Date())
|
||||
#expect(manager.trustedSigningKeys().contains(voucheeKey))
|
||||
|
||||
manager.setVerified(fingerprint: voucher, verified: false)
|
||||
#expect(!manager.trustedSigningKeys().contains(voucheeKey))
|
||||
}
|
||||
|
||||
@Test
|
||||
func trustedSigningKeys_dropsExpiredVouch() {
|
||||
let manager = makeManager()
|
||||
let voucheeKey = Data(repeating: 0xB3, count: 32)
|
||||
manager.bindAuthenticatedSigningPublicKey(voucheeKey, fingerprint: vouchee)
|
||||
manager.setVerified(fingerprint: voucher, verified: true)
|
||||
manager.recordVouch(voucheeFingerprint: vouchee, voucherFingerprint: voucher, timestamp: Date())
|
||||
|
||||
let later = Date().addingTimeInterval(VouchAttestation.maxAge + 60)
|
||||
#expect(!manager.trustedSigningKeys(now: later).contains(voucheeKey))
|
||||
}
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
private func waitUntil(
|
||||
|
||||
@ -346,6 +346,10 @@ private final class TestIdentityManager: SecureIdentityStateManagerProtocol {
|
||||
nil
|
||||
}
|
||||
|
||||
func trustedSigningKeys() -> Set<Data> {
|
||||
[]
|
||||
}
|
||||
|
||||
func mostRecentlyVerifiedFingerprints(limit: Int, excluding fingerprint: String) -> [String] {
|
||||
[]
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user