Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Como deixar os meus apps mais seguros

Sponsored · SiteGround - Reliable hosting with speed, security, and support you can count on. →
Salmo Junior
February 27, 2018

Como deixar os meus apps mais seguros

Salmo Junior

February 27, 2018

Transcript

23 slides
  1. Salmo Junior » Dev iOS desde 2011 » Chapter Leader

    do CocoaHeadsBH » Viciado em queijo » Aspirante a corredor [email protected] @salmojr
  2. Três perspectivas para se preocupar em seu aplicativo » Dados

    dos usuários » Conexão segura com API » Seu código
  3. Deixe os dados ainda mais seguros no Keychain » Configure

    o Accessibility » Crie Keys dinâmicas por usuários » Use Keys com hash e Values quando possível
  4. Keychain com accessibility configurado Exemplo usando o wrapper KeychainAccess let

    keychain = Keychain(service: "com.example.github-token") .accessibility(.whenUnlockedThisDeviceOnly) keychain["kishikawakatsumi"] = "01234567-89ab-cdef-0123-456789abcdef"
  5. Keychain com Common Crypto func sha256(string: String) -> String? {

    guard let messageData = string.data(using:String.Encoding.utf8) else { return nil } var digestData = Data(count: Int(CC_SHA256_DIGEST_LENGTH)) _ = digestData.withUnsafeMutableBytes {digestBytes in messageData.withUnsafeBytes {messageBytes in CC_SHA256(messageBytes, CC_LONG(messageData.count), digestBytes) } } return digestData.map { String(format: "%02hhx", $0) }.joined() } "hello world" = b94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9
  6. Verificação de Jailbreak // Verify Jailbreak static func isJailBroken() ->

    Bool { guard TARGET_OS_SIMULATOR != 1 else { return false } // Check 1: existence of files that are common for jailbroken devices guard let cydiaURL = URL(string: "cydia://") else { return false } if FileManager.default.fileExists(atPath: "/Applications/Cydia.app") || FileManager.default.fileExists(atPath: "/Library/MobileSubstrate/MobileSubstrate.dylib") || FileManager.default.fileExists(atPath: "/bin/bash") || FileManager.default.fileExists(atPath: "/usr/sbin/sshd") || FileManager.default.fileExists(atPath: "/etc/apt") || FileManager.default.fileExists(atPath: "/private/var/lib/apt/") || UIApplication.shared.canOpenURL(cydiaURL) { // Device is jailbroken return true }
  7. Verificação de Jailbreak . . . // Check 2: Reading

    and writing in system directories (sandbox violation) do { let stringToWrite = "Jailbreak Test" try stringToWrite.write(toFile: "/private/JailbreakTest.txt", atomically: true, encoding: String.Encoding.utf8) // Device is jailbroken return true } catch { return false } }
  8. App Transport Security » TLS/SSL » Exceções como na imagem

    abaixo, somente em alguns casos (ex: ambiente de mock)
  9. Certificate Pinning Com o acesso a redes wifi inseguras em

    todo lugar, é necessário uma camada extra de segurança na comunicação com o backend, evitando assim ataque como o MITM.
  10. Cache Policy public enum CachePolicy : UInt { case useProtocolCachePolicy

    case reloadIgnoringLocalCacheData case reloadIgnoringLocalAndRemoteCacheData case returnCacheDataElseLoad case returnCacheDataDontLoad case reloadRevalidatingCacheData public static var reloadIgnoringCacheData: NSURLRequest.CachePolicy { get } } let request = NSMutableURLRequest() ... request.cachePolicy = .reloadIgnoringCacheData
  11. Código seguro » Evite Secret Keys fixas no código »

    Cuidado com o nível de acesso de Classes/Métodos » Crie chaves de criptografia de forma aleatória » Ofusque Strings sensíveis
  12. Ofuscação de Strings sensíveis A biblioteca Obfuscator.swift transforma strings em

    array de bytes import Obfuscator let o = Obfuscator(withSalt: [AppDelegate.self, NSObject.self, NSString.self]) let bytes = o.bytesByObfuscatingString(string: “555555556ABC”) print(bytes) /*[110, 97, 80, 70, 65, 122, 87, 83, 67, 50, 33, 34]*
  13. Ofuscação de Strings sensíveis Código sem strings, evitando a fácil

    identicação ao fazer uma varredura do código struct Constants { static let GOOGLE_API_KEY: [UInt8] = [106, 102, 86, 66, 69, 123, 87, 80, 52, 49, 32] static let FACEBOOK_API_KEY: [UInt8] = [110, 97, 80, 70, 65, 122, 87, 83, 67, 50, 33, 34] } let value = o.reveal(key: Constants.FACEBOOK_API_KEY) print(value) /*555555556ABC*/

More Decks by Salmo Junior

Other Decks in Technology