xtool.git
Publicgit clone https://git.maproj.org/xtool.gitxtool.git / Sources / XKit / GrandSlam / Crypto / AppTokens.swift
AppTokens.swift42 lines · 1.1 KiBRaw
| 1 | // |
| 2 | // AppTokens.swift |
| 3 | // XKit |
| 4 | // |
| 5 | // Created by Kabir Oberai on 11/04/20. |
| 6 | // Copyright © 2020 Kabir Oberai. All rights reserved. |
| 7 | // |
| 8 | |
| 9 | import Foundation |
| 10 | import Crypto |
| 11 | |
| 12 | enum AppTokens { |
| 13 | |
| 14 | static func checksum(withSK sk: Data, adsid: String, apps: [String]) -> Data { |
| 15 | var hmac = HMAC<SHA256>(key: SymmetricKey(data: sk)) |
| 16 | hmac.update(data: Data("apptokens".utf8)) |
| 17 | hmac.update(data: Data(adsid.utf8)) |
| 18 | for app in apps { |
| 19 | hmac.update(data: Data(app.utf8)) |
| 20 | } |
| 21 | return Data(hmac.finalize()) |
| 22 | } |
| 23 | |
| 24 | // AppleIDAuthSupport`_AppleIDAuthSupportCreateDecryptedData |
| 25 | static func decrypt(gcm: Data, withSK sk: Data) throws -> Data { |
| 26 | let aad = gcm[..<3] // should be "XYZ" |
| 27 | let iv = gcm[3..<19] |
| 28 | let payload = gcm[19..<(gcm.count - 16)] |
| 29 | let tag = gcm[(gcm.count - 16)...] |
| 30 | |
| 31 | return try AES.GCM.open( |
| 32 | AES.GCM.SealedBox( |
| 33 | nonce: AES.GCM.Nonce(data: iv), |
| 34 | ciphertext: payload, |
| 35 | tag: tag |
| 36 | ), |
| 37 | using: SymmetricKey(data: sk), |
| 38 | authenticating: aad |
| 39 | ) |
| 40 | } |
| 41 | |
| 42 | } |