안녕하세요.
오늘은 iOS 탈옥 체크 로직을 구성하여 혹시나 앱내부 해킹등에 방어 할수 있도록 탈옥을 체크 할수 있는 로직을 알려드리겠다.
하지만 주의 할점은 아래에 ->
iOS에서 탈옥 여부를 감지하는 것은 안정성 및 보안 문제로 인해 애플의 정책에 따라 권장되지 않는다, 탈옥 여부를 확인하는 것은 사용자의 개인 정보를 침해하거나 사용자의 동의 없이 기기를 변경할 수 있는 행위에 해당할 수 있다. 따라서 앱의 탈옥 여부를 확인하는 로직은 App Store에 제출되는 앱에 포함되어서는 안 된다.
앱의 탈옥 여부를 확인하는 것은 사용자의 프라이버시를 침해하고 앱의 보안을 약화시킬 수 있다. 따라서 iOS 앱 개발에서는 탈옥 여부를 확인하는 것을 지양하고, 대신 앱의 보안을 강화하고 사용자의 개인 정보를 보호하는 데 집중해야 한다.
앱이 탈옥된 기기에서 실행되는 것을 방지하기 위해, 애플은 iOS 디바이스의 보안을 강화하고 앱이 실행되는 환경을 보호하기 위한 다양한 보안 메커니즘을 제공하고 있다. 이러한 메커니즘을 활용하여 앱의 보안을 강화하고 탈옥된 기기에서 실행되는 것을 방지할 수 있다.
앱이 탈옥된 기기에서 실행되는 것을 방지하는 방법 중 하나는 앱이 실행되는 환경을 검사하여 탈옥 여부를 확인하는 것이다. 그러나 이러한 접근 방식은 사용자의 개인 정보를 침해할 수 있고, 사용자의 동의 없이 기기를 변경할 수 있는 위험이 있으므로 권장되지 않는다. 따라서 iOS 앱 개발에서는 이러한 접근 방식을 사용하지 않는 것이 좋다.
# 일단 앱 진입시 해당 부분을 호출하여 탈옥했는지 확인 한다.
func hasJailbreak() -> Bool {
guard let cydiaUrlScheme = NSURL(string: "cydia://package/com.example.package") else { return false }
if UIApplication.shared.canOpenURL(cydiaUrlScheme as URL) {
return true
}
#if arch(i386) || arch(x86_64)
return false
#endif
let fileManager = FileManager.default
if fileManager.fileExists(atPath: "/Applications/Cydia.app") ||
fileManager.fileExists(atPath: "/Library/MobileSubstrate/MobileSubstrate.dylib") ||
fileManager.fileExists(atPath: "/bin/bash") ||
fileManager.fileExists(atPath: "/usr/sbin/sshd") ||
fileManager.fileExists(atPath: "/etc/apt") ||
fileManager.fileExists(atPath: "/usr/bin/ssh") ||
fileManager.fileExists(atPath: "/private/var/lib/apt") {
return true
}
if canOpen(path: "/Applications/Cydia.app") ||
canOpen(path: "/Library/MobileSubstrate/MobileSubstrate.dylib") ||
canOpen(path: "/bin/bash") ||
canOpen(path: "/usr/sbin/sshd") ||
canOpen(path: "/etc/apt") ||
canOpen(path: "/usr/bin/ssh") {
return true
}
let path = "/private/" + NSUUID().uuidString
do {
try "anyString".write(toFile: path, atomically: true, encoding: String.Encoding.utf8)
try fileManager.removeItem(atPath: path)
return true
} catch {
return false
}
}
#오픈 가능 한지 확인
func canOpen(path: String) -> Bool {
let file = fopen(path, "r")
guard file != nil else { return false }
fclose(file)
return true
}
돌아오는 return 값이 Bool 형식으로 전달되는데 true 이면 탈옥, false 면 정상이라고 알수 있다.
그리하여 진행 해야하는 부분은
static let jail_break = "변경된 OS(탈옥 등)의 스마트폰은 서비스를 이용할 수 없습니다."
if(hasJailbreak()){
DispatchQueue.main.async {
let dialogAlertController = UIAlertController.init(title: "안내", message: ToastMessage.jail_break, preferredStyle: .alert)
dialogAlertController.addAction(UIAlertAction(title: "확인", style: .default, handler: { (action) in
exit(0)
}))
self.present(dialogAlertController, animated: true, completion: nil)
}}else{
completion()
}
DispatchQueue를 이용하여 탈옥이 확인 되면 "변경된 OS(탈옥 등)의 스마트폰은 서비스를 이용할 수 없습니다."문구와 함께 UIAlertController을 노출 하여 정상적으로 진입할수 없게 구성한다.
탈옥이 아니라면 DispatchQueue 부분에서 completion() 호출하여 다음 로직으로 이동 한다.
이렇게 하면 탈옥의 여부를 판단하여 그 판단에 따른 작업을 수행 할수 있다. 다만 위에서 언급했듯이
애플의 정책에 따라 권장되지 않는다 그리하여 해당 로직을 구현하는것을 지양해야한다.
판단은 본인의 몫.
'iOS, Swift 개발' 카테고리의 다른 글
iOS 탈옥 체크 로직 구성(Object-C) (0) | 2024.07.25 |
---|---|
iOS Appstoreconnect 심사 거부에 대한 고찰 (0) | 2024.07.23 |
iOS 웹뷰 with 스토리보드, WkWebview (0) | 2024.04.25 |
Swift Model Codable (0) | 2024.04.16 |
Swift UITableView의 리스트 Value 변경 방법 (0) | 2024.04.16 |