Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : QYVORA7// File : Sources/QyvoraUI/DeviceIntegrity.swift8// Module : Qyvora UI9// Repository : https://git.spboucher.ai/qyvora10// Project Website : Not specified11// Created : 2026-12-0412// Last Modified : 2026-12-0413//14// Author : Simon-Pierre Boucher15// Position : Professor of Finance16// Institution : Université du Québec en Outaouais (UQO)17// Organization : SP Boucher18// Website : https://spboucher.ai19// Git : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development : dev@spboucher.ai23// Support : support@spboucher.ai24// Security/Admin : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License : None specified (no license file in this repository)33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import Foundation42import SwiftUI4344/// Signs that the device is jailbroken or that the process is being debugged (QYV-APP-009, MASVS-RESILIENCE-1).45///46/// This is a warning for the user, not a defence: on a compromised device the Keychain and the memory of the47/// application can be read whatever the application does, and every check below can be hidden from it by the same48/// tools that it looks for. The wallet therefore does not refuse to run; it says what it sees before a recovery phrase49/// is shown or typed, so that the user can decide. Nothing is sent anywhere.50public enum DeviceIntegrity {51 /// Files and directories that exist on a jailbroken iOS and not on a stock one.52 public static let jailbreakPaths = [53 "/Applications/Cydia.app", "/Applications/Sileo.app", "/Applications/Zebra.app", "/Applications/Installer.app",54 "/Library/MobileSubstrate/MobileSubstrate.dylib", "/usr/lib/libsubstitute.dylib", "/usr/lib/libhooker.dylib",55 "/usr/lib/TweakInject", "/var/jb", "/private/var/lib/apt", "/private/var/lib/cydia", "/private/var/stash",56 "/etc/apt", "/usr/libexec/cydia", "/usr/sbin/sshd", "/usr/bin/sshd", "/bin/bash", "/usr/bin/cycript",57 "/.bootstrapped_electra", "/.cydia_no_stash", "/.installed_unc0ver", "/.installed_dopamine",58 ]5960 /// The paths of `jailbreakPaths` that exist, as seen through `fileExists`.61 public static func jailbreakIndicators(fileExists: (String) -> Bool) -> [String] {62 jailbreakPaths.filter(fileExists)63 }6465 /// The indicators found on this device. Always empty in the simulator and on macOS, where these paths are ordinary.66 public static func jailbreakIndicators() -> [String] {67 #if os(iOS) && !targetEnvironment(simulator)68 return jailbreakIndicators { FileManager.default.fileExists(atPath: $0) }69 #else70 return []71 #endif72 }7374 /// True when a debugger is attached to this process (`P_TRACED`).75 public static var isDebuggerAttached: Bool {76 var info = kinfo_proc()77 var size = MemoryLayout<kinfo_proc>.stride78 var name: [Int32] = [CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()]79 guard sysctl(&name, UInt32(name.count), &info, &size, nil, 0) == 0 else { return false }80 return info.kp_proc.p_flag & P_TRACED != 081 }8283 /// The sentence to show before a recovery phrase is displayed or typed, or nil when nothing was found.84 /// `debuggerMatters` is false in development builds, where a debugger is expected.85 public static func warning(indicators: [String], debuggerAttached: Bool, debuggerMatters: Bool) -> String? {86 var reasons = [String]()87 if !indicators.isEmpty { reasons.append("it shows signs of a jailbreak (\(indicators.count) found)") }88 if debuggerAttached, debuggerMatters { reasons.append("a debugger is attached to QYVORA") }89 guard !reasons.isEmpty else { return nil }90 return "This device may be compromised: " + reasons.joined(separator: " and ")91 + ". Other software on it could read a recovery phrase shown or typed here, and the keys of an unlocked vault. Prefer a device you trust."92 }9394 /// The warning for this device and this build.95 public static func currentWarning() -> String? {96 #if DEBUG97 let debuggerMatters = false98 #else99 let debuggerMatters = true100 #endif101 return warning(indicators: jailbreakIndicators(), debuggerAttached: isDebuggerAttached, debuggerMatters: debuggerMatters)102 }103}104105/// Critical banner shown on the screens that display or accept a recovery phrase when the device looks compromised.106/// Shows nothing on a device without indicator.107public struct CompromisedDeviceNotice: View {108 @State private var message: String?109110 public init() {}111112 public var body: some View {113 Group {114 if let message {115 WarningBanner(.critical, title: "This device may be compromised", message: message)116 }117 }118 .task { message = DeviceIntegrity.currentWarning() }119 }120}121