mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-01-20 19:19:52 +00:00
Merge branch 'feature/secureid' of https://github.com/peter-iakovlev/TelegramCoreDev into feature/secureid
* 'feature/secureid' of https://github.com/peter-iakovlev/TelegramCoreDev: no message
This commit is contained in:
@@ -99,7 +99,7 @@ func decryptedSecureSecret(encryptedSecretData: Data, password: String, salt: Da
|
||||
let secretHashData = sha256Digest(decryptedSecret)
|
||||
var secretId: Int64 = 0
|
||||
secretHashData.withUnsafeBytes { (bytes: UnsafePointer<Int8>) -> Void in
|
||||
memcpy(&secretId, bytes.advanced(by: secretHashData.count - 8), 8)
|
||||
memcpy(&secretId, bytes, 8)
|
||||
}
|
||||
|
||||
if secretId != id {
|
||||
@@ -113,7 +113,7 @@ func encryptedSecureSecret(secretData: Data, password: String, inputSalt: Data)
|
||||
let secretHashData = sha256Digest(secretData)
|
||||
var secretId: Int64 = 0
|
||||
secretHashData.withUnsafeBytes { (bytes: UnsafePointer<Int8>) -> Void in
|
||||
memcpy(&secretId, bytes.advanced(by: secretHashData.count - 8), 8)
|
||||
memcpy(&secretId, bytes, 8)
|
||||
}
|
||||
|
||||
guard let passwordData = password.data(using: .utf8) else {
|
||||
@@ -247,7 +247,7 @@ public func accessSecureId(network: Network, password: String) -> Signal<SecureI
|
||||
let secretHashData = sha256Digest(decryptedSecret)
|
||||
var secretId: Int64 = 0
|
||||
secretHashData.withUnsafeBytes { (bytes: UnsafePointer<Int8>) -> Void in
|
||||
memcpy(&secretId, bytes.advanced(by: secretHashData.count - 8), 8)
|
||||
memcpy(&secretId, bytes, 8)
|
||||
}
|
||||
return SecureIdAccessContext(secret: decryptedSecret, id: secretId)
|
||||
}
|
||||
|
||||
@@ -53,15 +53,19 @@ public func updatePeerMuteSetting(account: Account, peerId: PeerId, muteInterval
|
||||
|
||||
let muteState: PeerMuteState
|
||||
if let muteInterval = muteInterval {
|
||||
let absoluteUntil: Int32
|
||||
if muteInterval == Int32.max {
|
||||
absoluteUntil = Int32.max
|
||||
if muteInterval == 0 {
|
||||
muteState = .unmuted
|
||||
} else {
|
||||
absoluteUntil = Int32(Date().timeIntervalSince1970) + muteInterval
|
||||
let absoluteUntil: Int32
|
||||
if muteInterval == Int32.max {
|
||||
absoluteUntil = Int32.max
|
||||
} else {
|
||||
absoluteUntil = Int32(Date().timeIntervalSince1970) + muteInterval
|
||||
}
|
||||
muteState = .muted(until: absoluteUntil)
|
||||
}
|
||||
muteState = .muted(until: absoluteUntil)
|
||||
} else {
|
||||
muteState = .unmuted
|
||||
muteState = .default
|
||||
}
|
||||
|
||||
let updatedSettings = previousSettings.withUpdatedMuteState(muteState)
|
||||
|
||||
@@ -91,30 +91,31 @@ private func credentialsValueTypeName(value: SecureIdValue) -> String {
|
||||
private func generateCredentials(values: [SecureIdValueWithContext], opaquePayload: Data) -> Data? {
|
||||
var secureData: [String: Any] = [:]
|
||||
for value in values {
|
||||
var valueDict: [String: Any] = [:]
|
||||
if let encryptedMetadata = value.encryptedMetadata {
|
||||
var valueDict: [String: Any] = [:]
|
||||
|
||||
valueDict["data"] = [
|
||||
"data_hash": encryptedMetadata.valueDataHash.base64EncodedString(),
|
||||
"secret": encryptedMetadata.decryptedSecret.base64EncodedString()
|
||||
] as [String: Any]
|
||||
}
|
||||
|
||||
if !encryptedMetadata.files.isEmpty {
|
||||
valueDict["files"] = encryptedMetadata.files.map { file -> [String: Any] in
|
||||
return [
|
||||
"file_hash": file.hash.base64EncodedString(),
|
||||
"secret": file.secret.base64EncodedString()
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
if let selfie = encryptedMetadata.selfie {
|
||||
valueDict["selfie"] = [
|
||||
"file_hash": selfie.hash.base64EncodedString(),
|
||||
"secret": selfie.secret.base64EncodedString()
|
||||
] as [String: Any]
|
||||
if !value.files.isEmpty {
|
||||
valueDict["files"] = value.files.map { file -> [String: Any] in
|
||||
return [
|
||||
"file_hash": file.hash.base64EncodedString(),
|
||||
"secret": file.secret.base64EncodedString()
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
if let selfie = value.selfie {
|
||||
valueDict["selfie"] = [
|
||||
"file_hash": selfie.hash.base64EncodedString(),
|
||||
"secret": selfie.secret.base64EncodedString()
|
||||
] as [String: Any]
|
||||
}
|
||||
|
||||
if !valueDict.isEmpty {
|
||||
secureData[credentialsValueTypeName(value: value.value)] = valueDict
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +58,8 @@ func parseSecureValue(context: SecureIdAccessContext, value: Api.SecureValue) ->
|
||||
|
||||
let decryptedData: Data?
|
||||
let encryptedMetadata: SecureIdEncryptedValueMetadata?
|
||||
var parsedFileMetadata: [SecureIdEncryptedValueFileMetadata] = []
|
||||
var parsedSelfieMetadata: SecureIdEncryptedValueFileMetadata?
|
||||
if let data = data {
|
||||
let (encryptedData, decryptedHash, encryptedSecret) = parseSecureData(data)
|
||||
guard let valueContext = decryptedSecureValueAccessContext(context: context, encryptedSecret: encryptedSecret, decryptedDataHash: decryptedHash) else {
|
||||
@@ -68,26 +70,24 @@ func parseSecureValue(context: SecureIdAccessContext, value: Api.SecureValue) ->
|
||||
if decryptedData == nil {
|
||||
return nil
|
||||
}
|
||||
var parsedFileMetadata: [SecureIdEncryptedValueFileMetadata] = []
|
||||
for file in parsedFileReferences {
|
||||
guard let fileSecret = decryptedSecureIdFileSecret(context: context, fileHash: file.fileHash, encryptedSecret: file.encryptedSecret) else {
|
||||
return nil
|
||||
}
|
||||
parsedFileMetadata.append(SecureIdEncryptedValueFileMetadata(hash: file.fileHash, secret: fileSecret))
|
||||
}
|
||||
var parsedSelfieMetadata: SecureIdEncryptedValueFileMetadata?
|
||||
if let parsedSelfie = selfie.flatMap(SecureIdFileReference.init) {
|
||||
guard let fileSecret = decryptedSecureIdFileSecret(context: context, fileHash: parsedSelfie.fileHash, encryptedSecret: parsedSelfie.encryptedSecret) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
parsedSelfieMetadata = SecureIdEncryptedValueFileMetadata(hash: parsedSelfie.fileHash, secret: fileSecret)
|
||||
}
|
||||
encryptedMetadata = SecureIdEncryptedValueMetadata(valueDataHash: decryptedHash, decryptedSecret: valueContext.secret, files: parsedFileMetadata, selfie: parsedSelfieMetadata)
|
||||
encryptedMetadata = SecureIdEncryptedValueMetadata(valueDataHash: decryptedHash, decryptedSecret: valueContext.secret)
|
||||
} else {
|
||||
decryptedData = nil
|
||||
encryptedMetadata = nil
|
||||
}
|
||||
for file in parsedFileReferences {
|
||||
guard let fileSecret = decryptedSecureIdFileSecret(context: context, fileHash: file.fileHash, encryptedSecret: file.encryptedSecret) else {
|
||||
return nil
|
||||
}
|
||||
parsedFileMetadata.append(SecureIdEncryptedValueFileMetadata(hash: file.fileHash, secret: fileSecret))
|
||||
}
|
||||
if let parsedSelfie = selfie.flatMap(SecureIdFileReference.init) {
|
||||
guard let fileSecret = decryptedSecureIdFileSecret(context: context, fileHash: parsedSelfie.fileHash, encryptedSecret: parsedSelfie.encryptedSecret) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
parsedSelfieMetadata = SecureIdEncryptedValueFileMetadata(hash: parsedSelfie.fileHash, secret: fileSecret)
|
||||
}
|
||||
|
||||
let value: SecureIdValue
|
||||
|
||||
@@ -169,7 +169,7 @@ func parseSecureValue(context: SecureIdAccessContext, value: Api.SecureValue) ->
|
||||
}
|
||||
}
|
||||
|
||||
return ParsedSecureValue(valueWithContext: SecureIdValueWithContext(value: value, encryptedMetadata: encryptedMetadata, opaqueHash: hash.makeData()))
|
||||
return ParsedSecureValue(valueWithContext: SecureIdValueWithContext(value: value, files: parsedFileMetadata, selfie: parsedSelfieMetadata, encryptedMetadata: encryptedMetadata, opaqueHash: hash.makeData()))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,15 +4,15 @@ public struct SecureIdAddressValue: Equatable {
|
||||
public var street1: String
|
||||
public var street2: String
|
||||
public var city: String
|
||||
public var region: String
|
||||
public var state: String
|
||||
public var countryCode: String
|
||||
public var postcode: String
|
||||
|
||||
public init(street1: String, street2: String, city: String, region: String, countryCode: String, postcode: String) {
|
||||
public init(street1: String, street2: String, city: String, state: String, countryCode: String, postcode: String) {
|
||||
self.street1 = street1
|
||||
self.street2 = street2
|
||||
self.city = city
|
||||
self.region = region
|
||||
self.state = state
|
||||
self.countryCode = countryCode
|
||||
self.postcode = postcode
|
||||
}
|
||||
@@ -27,7 +27,7 @@ public struct SecureIdAddressValue: Equatable {
|
||||
if lhs.city != rhs.city {
|
||||
return false
|
||||
}
|
||||
if lhs.region != rhs.region {
|
||||
if lhs.state != rhs.state {
|
||||
return false
|
||||
}
|
||||
if lhs.countryCode != rhs.countryCode {
|
||||
@@ -49,17 +49,17 @@ extension SecureIdAddressValue {
|
||||
guard let city = dict["city"] as? String else {
|
||||
return nil
|
||||
}
|
||||
guard let region = dict["region"] as? String else {
|
||||
guard let state = dict["state"] as? String else {
|
||||
return nil
|
||||
}
|
||||
guard let countryCode = dict["country_iso2"] as? String else {
|
||||
guard let countryCode = dict["country_code"] as? String else {
|
||||
return nil
|
||||
}
|
||||
guard let postcode = dict["post_code"] as? String else {
|
||||
return nil
|
||||
}
|
||||
|
||||
self.init(street1: street1, street2: street2, city: city, region: region, countryCode: countryCode, postcode: postcode)
|
||||
self.init(street1: street1, street2: street2, city: city, state: state, countryCode: countryCode, postcode: postcode)
|
||||
}
|
||||
|
||||
func serialize() -> ([String: Any], [SecureIdVerificationDocumentReference]) {
|
||||
@@ -69,8 +69,8 @@ extension SecureIdAddressValue {
|
||||
dict["street_line2"] = self.street2
|
||||
}
|
||||
dict["city"] = self.city
|
||||
dict["region"] = self.region
|
||||
dict["country_iso2"] = self.countryCode
|
||||
dict["state"] = self.state
|
||||
dict["country_code"] = self.countryCode
|
||||
dict["post_code"] = self.postcode
|
||||
|
||||
return (dict, [])
|
||||
|
||||
@@ -2,14 +2,12 @@ import Foundation
|
||||
|
||||
public struct SecureIdDriversLicenseValue: Equatable {
|
||||
public var identifier: String
|
||||
public var issueDate: SecureIdDate
|
||||
public var expiryDate: SecureIdDate?
|
||||
public var verificationDocuments: [SecureIdVerificationDocumentReference]
|
||||
public var selfieDocument: SecureIdVerificationDocumentReference?
|
||||
|
||||
public init(identifier: String, issueDate: SecureIdDate, expiryDate: SecureIdDate?, verificationDocuments: [SecureIdVerificationDocumentReference], selfieDocument: SecureIdVerificationDocumentReference?) {
|
||||
public init(identifier: String, expiryDate: SecureIdDate?, verificationDocuments: [SecureIdVerificationDocumentReference], selfieDocument: SecureIdVerificationDocumentReference?) {
|
||||
self.identifier = identifier
|
||||
self.issueDate = issueDate
|
||||
self.expiryDate = expiryDate
|
||||
self.verificationDocuments = verificationDocuments
|
||||
self.selfieDocument = selfieDocument
|
||||
@@ -19,9 +17,6 @@ public struct SecureIdDriversLicenseValue: Equatable {
|
||||
if lhs.identifier != rhs.identifier {
|
||||
return false
|
||||
}
|
||||
if lhs.issueDate != rhs.issueDate {
|
||||
return false
|
||||
}
|
||||
if lhs.expiryDate != rhs.expiryDate {
|
||||
return false
|
||||
}
|
||||
@@ -40,20 +35,16 @@ extension SecureIdDriversLicenseValue {
|
||||
guard let identifier = dict["document_no"] as? String else {
|
||||
return nil
|
||||
}
|
||||
guard let issueDate = (dict["issue_date"] as? String).flatMap(SecureIdDate.init) else {
|
||||
return nil
|
||||
}
|
||||
let expiryDate = (dict["expiry_date"] as? String).flatMap(SecureIdDate.init)
|
||||
|
||||
let verificationDocuments: [SecureIdVerificationDocumentReference] = fileReferences
|
||||
|
||||
self.init(identifier: identifier, issueDate: issueDate, expiryDate: expiryDate, verificationDocuments: verificationDocuments, selfieDocument: selfieDocument)
|
||||
self.init(identifier: identifier, expiryDate: expiryDate, verificationDocuments: verificationDocuments, selfieDocument: selfieDocument)
|
||||
}
|
||||
|
||||
func serialize() -> ([String: Any], [SecureIdVerificationDocumentReference], SecureIdVerificationDocumentReference?) {
|
||||
var dict: [String: Any] = [:]
|
||||
dict["document_no"] = self.identifier
|
||||
dict["issue_date"] = self.issueDate.serialize()
|
||||
if let expiryDate = self.expiryDate {
|
||||
dict["expiry_date"] = expiryDate.serialize()
|
||||
}
|
||||
|
||||
@@ -2,14 +2,12 @@ import Foundation
|
||||
|
||||
public struct SecureIdIDCardValue: Equatable {
|
||||
public var identifier: String
|
||||
public var issueDate: SecureIdDate
|
||||
public var expiryDate: SecureIdDate?
|
||||
public var verificationDocuments: [SecureIdVerificationDocumentReference]
|
||||
public var selfieDocument: SecureIdVerificationDocumentReference?
|
||||
|
||||
public init(identifier: String, issueDate: SecureIdDate, expiryDate: SecureIdDate?, verificationDocuments: [SecureIdVerificationDocumentReference], selfieDocument: SecureIdVerificationDocumentReference?) {
|
||||
public init(identifier: String, expiryDate: SecureIdDate?, verificationDocuments: [SecureIdVerificationDocumentReference], selfieDocument: SecureIdVerificationDocumentReference?) {
|
||||
self.identifier = identifier
|
||||
self.issueDate = issueDate
|
||||
self.expiryDate = expiryDate
|
||||
self.verificationDocuments = verificationDocuments
|
||||
self.selfieDocument = selfieDocument
|
||||
@@ -19,9 +17,6 @@ public struct SecureIdIDCardValue: Equatable {
|
||||
if lhs.identifier != rhs.identifier {
|
||||
return false
|
||||
}
|
||||
if lhs.issueDate != rhs.issueDate {
|
||||
return false
|
||||
}
|
||||
if lhs.expiryDate != rhs.expiryDate {
|
||||
return false
|
||||
}
|
||||
@@ -40,20 +35,16 @@ extension SecureIdIDCardValue {
|
||||
guard let identifier = dict["document_no"] as? String else {
|
||||
return nil
|
||||
}
|
||||
guard let issueDate = (dict["issue_date"] as? String).flatMap(SecureIdDate.init) else {
|
||||
return nil
|
||||
}
|
||||
let expiryDate = (dict["expiry_date"] as? String).flatMap(SecureIdDate.init)
|
||||
|
||||
let verificationDocuments: [SecureIdVerificationDocumentReference] = fileReferences
|
||||
|
||||
self.init(identifier: identifier, issueDate: issueDate, expiryDate: expiryDate, verificationDocuments: verificationDocuments, selfieDocument: selfieDocument)
|
||||
self.init(identifier: identifier, expiryDate: expiryDate, verificationDocuments: verificationDocuments, selfieDocument: selfieDocument)
|
||||
}
|
||||
|
||||
func serialize() -> ([String: Any], [SecureIdVerificationDocumentReference], SecureIdVerificationDocumentReference?) {
|
||||
var dict: [String: Any] = [:]
|
||||
dict["document_no"] = self.identifier
|
||||
dict["issue_date"] = self.issueDate.serialize()
|
||||
if let expiryDate = self.expiryDate {
|
||||
dict["expiry_date"] = expiryDate.serialize()
|
||||
}
|
||||
|
||||
@@ -2,14 +2,12 @@ import Foundation
|
||||
|
||||
public struct SecureIdPassportValue: Equatable {
|
||||
public var identifier: String
|
||||
public var issueDate: SecureIdDate
|
||||
public var expiryDate: SecureIdDate?
|
||||
public var verificationDocuments: [SecureIdVerificationDocumentReference]
|
||||
public var selfieDocument: SecureIdVerificationDocumentReference?
|
||||
|
||||
public init(identifier: String, issueDate: SecureIdDate, expiryDate: SecureIdDate?, verificationDocuments: [SecureIdVerificationDocumentReference], selfieDocument: SecureIdVerificationDocumentReference?) {
|
||||
public init(identifier: String, expiryDate: SecureIdDate?, verificationDocuments: [SecureIdVerificationDocumentReference], selfieDocument: SecureIdVerificationDocumentReference?) {
|
||||
self.identifier = identifier
|
||||
self.issueDate = issueDate
|
||||
self.expiryDate = expiryDate
|
||||
self.verificationDocuments = verificationDocuments
|
||||
self.selfieDocument = selfieDocument
|
||||
@@ -19,9 +17,6 @@ public struct SecureIdPassportValue: Equatable {
|
||||
if lhs.identifier != rhs.identifier {
|
||||
return false
|
||||
}
|
||||
if lhs.issueDate != rhs.issueDate {
|
||||
return false
|
||||
}
|
||||
if lhs.expiryDate != rhs.expiryDate {
|
||||
return false
|
||||
}
|
||||
@@ -40,20 +35,16 @@ extension SecureIdPassportValue {
|
||||
guard let identifier = dict["document_no"] as? String else {
|
||||
return nil
|
||||
}
|
||||
guard let issueDate = (dict["issue_date"] as? String).flatMap(SecureIdDate.init) else {
|
||||
return nil
|
||||
}
|
||||
let expiryDate = (dict["expiry_date"] as? String).flatMap(SecureIdDate.init)
|
||||
|
||||
let verificationDocuments: [SecureIdVerificationDocumentReference] = fileReferences
|
||||
|
||||
self.init(identifier: identifier, issueDate: issueDate, expiryDate: expiryDate, verificationDocuments: verificationDocuments, selfieDocument: selfieDocument)
|
||||
self.init(identifier: identifier, expiryDate: expiryDate, verificationDocuments: verificationDocuments, selfieDocument: selfieDocument)
|
||||
}
|
||||
|
||||
func serialize() -> ([String: Any], [SecureIdVerificationDocumentReference], SecureIdVerificationDocumentReference?) {
|
||||
var dict: [String: Any] = [:]
|
||||
dict["document_no"] = self.identifier
|
||||
dict["issue_date"] = self.issueDate.serialize()
|
||||
if let expiryDate = self.expiryDate {
|
||||
dict["expiry_date"] = expiryDate.serialize()
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ extension SecureIdPersonalDetailsValue {
|
||||
guard let gender = (dict["gender"] as? String).flatMap(SecureIdGender.init) else {
|
||||
return nil
|
||||
}
|
||||
guard let countryCode = dict["country_iso2"] as? String else {
|
||||
guard let countryCode = dict["country_code"] as? String else {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ extension SecureIdPersonalDetailsValue {
|
||||
dict["last_name"] = self.lastName
|
||||
dict["birth_date"] = self.birthdate.serialize()
|
||||
dict["gender"] = self.gender.serialize()
|
||||
dict["country_iso2"] = self.countryCode
|
||||
dict["country_code"] = self.countryCode
|
||||
|
||||
return (dict, [])
|
||||
}
|
||||
|
||||
@@ -120,17 +120,19 @@ struct SecureIdEncryptedValueFileMetadata: Equatable {
|
||||
struct SecureIdEncryptedValueMetadata: Equatable {
|
||||
let valueDataHash: Data
|
||||
let decryptedSecret: Data
|
||||
let files: [SecureIdEncryptedValueFileMetadata]
|
||||
let selfie: SecureIdEncryptedValueFileMetadata?
|
||||
}
|
||||
|
||||
public struct SecureIdValueWithContext: Equatable {
|
||||
public let value: SecureIdValue
|
||||
let files: [SecureIdEncryptedValueFileMetadata]
|
||||
let selfie: SecureIdEncryptedValueFileMetadata?
|
||||
let encryptedMetadata: SecureIdEncryptedValueMetadata?
|
||||
let opaqueHash: Data
|
||||
|
||||
init(value: SecureIdValue, encryptedMetadata: SecureIdEncryptedValueMetadata?, opaqueHash: Data) {
|
||||
init(value: SecureIdValue, files: [SecureIdEncryptedValueFileMetadata], selfie: SecureIdEncryptedValueFileMetadata?, encryptedMetadata: SecureIdEncryptedValueMetadata?, opaqueHash: Data) {
|
||||
self.value = value
|
||||
self.files = files
|
||||
self.selfie = selfie
|
||||
self.encryptedMetadata = encryptedMetadata
|
||||
self.opaqueHash = opaqueHash
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user