Skip to content

Replace Hardcoded Authentication in TwoFactorAuthService #95

@DrunkOnJava

Description

@DrunkOnJava

📋 Sub-task of #94

Critical Security Issue

TwoFactorAuthService.swift:252 contains hardcoded verification code '123456' which is a severe security vulnerability.

Current Implementation

// Line 252: FIXME - Mock verification (hardcoded)
private func verifyCode(_ code: String) -> Bool {
    return code == "123456"
}

Required Changes

  • Remove hardcoded PIN from TwoFactorAuthService
  • Implement secure code generation using CryptoKit
  • Add time-based one-time password (TOTP) support
  • Store secrets securely in Keychain
  • Add code expiration (30 seconds)
  • Implement retry limits and lockout

Implementation Details

  1. Generate cryptographically secure codes
  2. Store shared secret in Keychain
  3. Implement TOTP algorithm (RFC 6238)
  4. Add rate limiting for verification attempts
  5. Log security events for audit trail

Security Requirements

  • Codes must be 6-8 digits
  • Expire after 30 seconds
  • Maximum 3 retry attempts
  • 5-minute lockout after failures
  • Secure random number generation

Testing Requirements

  • Test code generation randomness
  • Test expiration timing
  • Test retry limit enforcement
  • Test keychain storage/retrieval
  • Security penetration testing

Files to Update

  • Modules/Core/Sources/Services/TwoFactorAuthService.swift
  • Create: Modules/Core/Sources/Services/TOTPGenerator.swift

Estimated Effort: 2 days

Priority: P0 - Critical Security Fix

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0Production blocker - must fix immediatelybugSomething isn't workingsecuritySecurity related changes

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions