NCEndToEndMetadataV20.swift 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. //
  2. // NCEndToEndMetadataV20.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 09/08/23.
  6. // Copyright © 2023 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import Foundation
  24. import UIKit
  25. import NextcloudKit
  26. import Gzip
  27. extension NCEndToEndMetadata {
  28. struct E2eeV20: Codable {
  29. struct Metadata: Codable {
  30. let ciphertext: String
  31. let nonce: String
  32. let authenticationTag: String
  33. struct ciphertext: Codable {
  34. let counter: Int
  35. let deleted: Bool?
  36. let keyChecksums: [String]?
  37. let files: [String: Files]?
  38. let folders: [String: String]?
  39. struct Files: Codable {
  40. let authenticationTag: String
  41. let filename: String
  42. let key: String
  43. let mimetype: String
  44. let nonce: String
  45. }
  46. }
  47. }
  48. struct Users: Codable {
  49. let userId: String
  50. let certificate: String
  51. let encryptedMetadataKey: String?
  52. }
  53. struct Filedrop: Codable {
  54. let ciphertext: String
  55. let nonce: String
  56. let authenticationTag: String
  57. let users: [UsersFiledrop]
  58. struct UsersFiledrop: Codable {
  59. let userId: String
  60. let encryptedFiledropKey: String
  61. }
  62. }
  63. let metadata: Metadata
  64. let users: [Users]?
  65. let filedrop: [String: Filedrop]?
  66. let version: String
  67. }
  68. struct E2eeV20Signature: Codable {
  69. struct Metadata: Codable {
  70. let ciphertext: String
  71. let nonce: String
  72. let authenticationTag: String
  73. }
  74. struct Users: Codable {
  75. let userId: String
  76. let certificate: String
  77. let encryptedMetadataKey: String?
  78. }
  79. let metadata: Metadata
  80. let users: [Users]?
  81. let version: String
  82. }
  83. // --------------------------------------------------------------------------------------------
  84. // MARK: Ecode JSON Metadata V2.0
  85. // --------------------------------------------------------------------------------------------
  86. func encodeMetadataV20(serverUrl: String, ocIdServerUrl: String, addUserId: String?, addCertificate: String?, removeUserId: String?, session: NCSession.Session) -> (metadata: String?, signature: String?, counter: Int, error: NKError) {
  87. guard let directoryTop = utilityFileSystem.getDirectoryE2EETop(serverUrl: serverUrl, account: session.account), let certificate = NCKeychain().getEndToEndCertificate(account: session.account) else {
  88. return (nil, nil, 0, NKError(errorCode: NCGlobal.shared.errorUnexpectedResponseFromDB, errorDescription: "_e2e_error_"))
  89. }
  90. let isDirectoryTop = utilityFileSystem.isDirectoryE2EETop(account: session.account, serverUrl: serverUrl)
  91. var metadataKey: String?
  92. var keyChecksums: [String] = []
  93. var usersCodable: [E2eeV20.Users] = []
  94. var filesCodable: [String: E2eeV20.Metadata.ciphertext.Files] = [:]
  95. var folders: [String: String] = [:]
  96. var counter: Int = 1
  97. func addUser(userId: String?, certificate: String?, key: Data) {
  98. guard let userId, let certificate else { return }
  99. if let metadataKeyEncrypted = NCEndToEndEncryption.shared().encryptAsymmetricData(key, certificate: certificate) {
  100. let encryptedMetadataKey = metadataKeyEncrypted.base64EncodedString()
  101. self.database.addE2EUsers(account: session.account, serverUrl: serverUrl, ocIdServerUrl: ocIdServerUrl, userId: userId, certificate: certificate, encryptedMetadataKey: encryptedMetadataKey, metadataKey: key)
  102. }
  103. }
  104. if isDirectoryTop {
  105. guard var key = NCEndToEndEncryption.shared().generateKey() else {
  106. return (nil, nil, 0, NKError(errorCode: NCGlobal.shared.errorUnexpectedResponseFromDB, errorDescription: "_e2e_error_"))
  107. }
  108. if let tableUserId = self.database.getE2EUser(account: session.account, ocIdServerUrl: directoryTop.ocId, userId: session.userId),
  109. let metadataKey = tableUserId.metadataKey {
  110. key = metadataKey
  111. } else {
  112. addUser(userId: session.userId, certificate: certificate, key: key)
  113. }
  114. // ADDUSERID
  115. if let addUserId {
  116. addUser(userId: addUserId, certificate: addCertificate, key: key)
  117. }
  118. // REMOVEUSERID
  119. if let removeUserId {
  120. self.database.deleteE2EUsers(account: session.account, ocIdServerUrl: ocIdServerUrl, userId: removeUserId)
  121. }
  122. // FOR SECURITY recreate all users with key
  123. if let users = self.database.getE2EUsers(account: session.account, ocIdServerUrl: ocIdServerUrl) {
  124. for user in users {
  125. addUser(userId: user.userId, certificate: user.certificate, key: key)
  126. }
  127. }
  128. metadataKey = key.base64EncodedString()
  129. } else {
  130. guard let tableUserId = self.database.getE2EUser(account: session.account, ocIdServerUrl: directoryTop.ocId, userId: session.userId), let key = tableUserId.metadataKey else {
  131. return (nil, nil, 0, NKError(errorCode: NCGlobal.shared.errorUnexpectedResponseFromDB, errorDescription: "_e2e_error_"))
  132. }
  133. metadataKey = key.base64EncodedString()
  134. }
  135. // USERS
  136. // CHECKSUM
  137. //
  138. if let users = self.database.getE2EUsers(account: session.account, ocIdServerUrl: directoryTop.ocId) {
  139. for user in users {
  140. if isDirectoryTop {
  141. usersCodable.append(E2eeV20.Users(userId: user.userId, certificate: user.certificate, encryptedMetadataKey: user.encryptedMetadataKey))
  142. }
  143. if let hash = NCEndToEndEncryption.shared().createSHA256(user.metadataKey) {
  144. keyChecksums.append(hash)
  145. }
  146. }
  147. }
  148. // COUNTER + 1
  149. //
  150. if let resultCounter = self.database.getCounterE2eMetadata(account: session.account, ocIdServerUrl: ocIdServerUrl) {
  151. counter = resultCounter + 1
  152. }
  153. // CIPERTEXT
  154. //
  155. let e2eEncryptions = self.database.getE2eEncryptions(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", session.account, serverUrl))
  156. for e2eEncryption in e2eEncryptions {
  157. if e2eEncryption.mimeType == "httpd/unix-directory" {
  158. folders[e2eEncryption.fileNameIdentifier] = e2eEncryption.fileName
  159. } else {
  160. let file = E2eeV20.Metadata.ciphertext.Files(authenticationTag: e2eEncryption.authenticationTag, filename: e2eEncryption.fileName, key: e2eEncryption.key, mimetype: e2eEncryption.mimeType, nonce: e2eEncryption.initializationVector)
  161. filesCodable.updateValue(file, forKey: e2eEncryption.fileNameIdentifier)
  162. }
  163. }
  164. do {
  165. var authenticationTag: NSString?
  166. var initializationVector: NSString?
  167. let json = try JSONEncoder().encode(E2eeV20.Metadata.ciphertext(counter: counter, deleted: false, keyChecksums: keyChecksums, files: filesCodable, folders: folders))
  168. let jsonZip = try json.gzipped()
  169. let ciphertextMetadata = NCEndToEndEncryption.shared().encryptPayloadFile(jsonZip, key: metadataKey, initializationVector: &initializationVector, authenticationTag: &authenticationTag)
  170. guard var ciphertextMetadata, let initializationVector = initializationVector as? String, let authenticationTag = authenticationTag as? String else {
  171. return (nil, nil, counter, NKError(errorCode: NCGlobal.shared.errorE2EEEncryptPayloadFile, errorDescription: "_e2e_error_"))
  172. }
  173. // Add initializationVector [ANDROID]
  174. ciphertextMetadata = ciphertextMetadata + "|" + initializationVector
  175. let metadataCodable = E2eeV20.Metadata(ciphertext: ciphertextMetadata, nonce: initializationVector, authenticationTag: authenticationTag)
  176. let e2eeCodable = E2eeV20(metadata: metadataCodable, users: usersCodable, filedrop: nil, version: NCGlobal.shared.e2eeVersionV20)
  177. let e2eeData = try JSONEncoder().encode(e2eeCodable)
  178. e2eeData.printJson()
  179. let e2eeJson = String(data: e2eeData, encoding: .utf8)
  180. let signature = createSignature(metadata: metadataCodable, users: usersCodable, version: NCGlobal.shared.e2eeVersionV20, certificate: certificate, session: session)
  181. return (e2eeJson, signature, counter, NKError())
  182. } catch let error {
  183. return (nil, nil, counter, NKError(errorCode: NCGlobal.shared.errorE2EEJSon, errorDescription: error.localizedDescription))
  184. }
  185. }
  186. // --------------------------------------------------------------------------------------------
  187. // MARK: Decode JSON Metadata V2.0
  188. // --------------------------------------------------------------------------------------------
  189. func decodeMetadataV20(_ json: String, signature: String?, serverUrl: String, ocIdServerUrl: String, session: NCSession.Session) -> NKError {
  190. guard let data = json.data(using: .utf8),
  191. let directoryTop = utilityFileSystem.getDirectoryE2EETop(serverUrl: serverUrl, account: session.account) else {
  192. return NKError(errorCode: NCGlobal.shared.errorE2EEKeyDecodeMetadata, errorDescription: "_e2e_error_")
  193. }
  194. let isDirectoryTop = utilityFileSystem.isDirectoryE2EETop(account: session.account, serverUrl: serverUrl)
  195. func addE2eEncryption(fileNameIdentifier: String, filename: String, authenticationTag: String, key: String, initializationVector: String, metadataKey: String, mimetype: String) {
  196. if let metadata = self.database.getMetadata(predicate: NSPredicate(format: "account == %@ AND fileName == %@", session.account, fileNameIdentifier)) {
  197. let object = tableE2eEncryption.init(account: session.account, ocIdServerUrl: ocIdServerUrl, fileNameIdentifier: fileNameIdentifier)
  198. object.authenticationTag = authenticationTag
  199. object.fileName = filename
  200. object.key = key
  201. object.initializationVector = initializationVector
  202. object.metadataKey = metadataKey
  203. object.mimeType = mimetype
  204. object.serverUrl = serverUrl
  205. object.version = NCGlobal.shared.e2eeVersionV20
  206. // Write file parameter for decrypted on DB
  207. self.database.addE2eEncryption(object)
  208. // Update metadata on tableMetadata
  209. metadata.fileNameView = filename
  210. let results = NextcloudKit.shared.nkCommonInstance.getInternalType(fileName: filename, mimeType: metadata.contentType, directory: metadata.directory, account: session.account)
  211. metadata.contentType = results.mimeType
  212. metadata.iconName = results.iconName
  213. metadata.classFile = results.classFile
  214. self.database.addMetadata(metadata)
  215. }
  216. }
  217. do {
  218. let json = try JSONDecoder().decode(E2eeV20.self, from: data)
  219. let metadata = json.metadata
  220. let users = json.users
  221. let filesdrop = json.filedrop
  222. let version = json.version as String? ?? NCGlobal.shared.e2eeVersionV20
  223. if isDirectoryTop {
  224. // SAVE IN DB ALL USER
  225. //
  226. if let users {
  227. for user in users {
  228. var metadataKey: Data?
  229. if let encryptedMetadataKey = user.encryptedMetadataKey {
  230. let data = Data(base64Encoded: encryptedMetadataKey)
  231. if let decrypted = NCEndToEndEncryption.shared().decryptAsymmetricData(data, privateKey: NCKeychain().getEndToEndPrivateKey(account: session.account)) {
  232. metadataKey = decrypted
  233. }
  234. }
  235. self.database.addE2EUsers(account: session.account, serverUrl: serverUrl, ocIdServerUrl: ocIdServerUrl, userId: user.userId, certificate: user.certificate, encryptedMetadataKey: user.encryptedMetadataKey, metadataKey: metadataKey)
  236. }
  237. }
  238. }
  239. // GET metadataKey, decryptedMetadataKey
  240. //
  241. guard let tableUser = self.database.getE2EUser(account: session.account, ocIdServerUrl: directoryTop.ocId, userId: session.userId),
  242. let metadataKey = tableUser.metadataKey?.base64EncodedString(),
  243. let decryptedMetadataKey = tableUser.metadataKey else {
  244. return NKError(errorCode: NCGlobal.shared.errorE2EENoUserFound, errorDescription: "_e2e_error_")
  245. }
  246. // SIGNATURE CHECK
  247. //
  248. if let signature {
  249. if !verifySignature(account: session.account, signature: signature, userId: tableUser.userId, metadata: metadata, users: users, version: version, certificate: tableUser.certificate) {
  250. return NKError(errorCode: NCGlobal.shared.errorE2EEKeyVerifySignature, errorDescription: "_e2e_error_")
  251. }
  252. }
  253. /*
  254. if let signature, !signature.isEmpty {
  255. if !verifySignature(account: session.account, signature: signature, userId: tableUser.userId, metadata: metadata, users: users, version: version, certificate: tableUser.certificate) {
  256. return NKError(errorCode: NCGlobal.shared.errorE2EEKeyVerifySignature, errorDescription: "_e2e_error_")
  257. }
  258. } else {
  259. return NKError(errorCode: NCGlobal.shared.errorE2EEKeyVerifySignature, errorDescription: "_e2e_error_")
  260. }
  261. */
  262. // FILEDROP
  263. //
  264. if let filesdrop {
  265. for filedop in filesdrop {
  266. let fileNameIdentifier = filedop.key
  267. let ciphertext = filedop.value.ciphertext
  268. let nonce = filedop.value.nonce
  269. let authenticationTag = filedop.value.authenticationTag
  270. for user in filedop.value.users where user.userId == session.userId {
  271. let data = Data(base64Encoded: user.encryptedFiledropKey)
  272. if let decryptedFiledropKey = NCEndToEndEncryption.shared().decryptAsymmetricData(data, privateKey: NCKeychain().getEndToEndPrivateKey(account: session.account)) {
  273. let filedropKey = decryptedFiledropKey.base64EncodedString()
  274. guard let decryptedFiledrop = NCEndToEndEncryption.shared().decryptPayloadFile(ciphertext, key: filedropKey, initializationVector: nonce, authenticationTag: authenticationTag),
  275. decryptedFiledrop.isGzipped else {
  276. return NKError(errorCode: NCGlobal.shared.errorE2EEKeyFiledropCiphertext, errorDescription: "_e2e_error_")
  277. }
  278. let data = try decryptedFiledrop.gunzipped()
  279. if let jsonText = String(data: data, encoding: .utf8) { print(jsonText) }
  280. let file = try JSONDecoder().decode(E2eeV20.Metadata.ciphertext.Files.self, from: data)
  281. print(file)
  282. addE2eEncryption(fileNameIdentifier: fileNameIdentifier, filename: file.filename, authenticationTag: file.authenticationTag, key: file.key, initializationVector: file.nonce, metadataKey: filedropKey, mimetype: file.mimetype)
  283. }
  284. }
  285. }
  286. }
  287. // CIPHERTEXT METADATA
  288. //
  289. guard let decryptedMetadata = NCEndToEndEncryption.shared().decryptPayloadFile(metadata.ciphertext, key: metadataKey, initializationVector: metadata.nonce, authenticationTag: metadata.authenticationTag),
  290. decryptedMetadata.isGzipped else {
  291. return NKError(errorCode: NCGlobal.shared.errorE2EEKeyCiphertext, errorDescription: "_e2e_error_")
  292. }
  293. let data = try decryptedMetadata.gunzipped()
  294. if let jsonText = String(data: data, encoding: .utf8) { print(jsonText) }
  295. let jsonCiphertextMetadata = try JSONDecoder().decode(E2eeV20.Metadata.ciphertext.self, from: data)
  296. // CHECKSUM CHECK
  297. //
  298. if let keyChecksums = jsonCiphertextMetadata.keyChecksums {
  299. guard let hash = NCEndToEndEncryption.shared().createSHA256(decryptedMetadataKey),
  300. keyChecksums.contains(hash) else {
  301. return NKError(errorCode: NCGlobal.shared.errorE2EEKeyChecksums, errorDescription: NSLocalizedString("_e2e_error_", comment: ""))
  302. }
  303. }
  304. print("\n\nCOUNTER -------------------------------")
  305. print("Counter: \(jsonCiphertextMetadata.counter)")
  306. // COUNTER CHECK
  307. //
  308. if let resultCounter = self.database.getCounterE2eMetadata(account: session.account, ocIdServerUrl: ocIdServerUrl) {
  309. print("Counter saved: \(resultCounter)")
  310. if jsonCiphertextMetadata.counter < resultCounter {
  311. // TODO: whats happen with < ?
  312. NCContentPresenter().showError(error: NKError(errorCode: NCGlobal.shared.errorE2EECounter, errorDescription: NSLocalizedString("_e2e_error_", comment: "")))
  313. } else if jsonCiphertextMetadata.counter > resultCounter {
  314. print("Counter UPDATED: \(jsonCiphertextMetadata.counter)")
  315. self.database.updateCounterE2eMetadata(account: session.account, ocIdServerUrl: ocIdServerUrl, counter: jsonCiphertextMetadata.counter)
  316. }
  317. } else {
  318. print("Counter RESET: \(jsonCiphertextMetadata.counter)")
  319. self.database.updateCounterE2eMetadata(account: session.account, ocIdServerUrl: ocIdServerUrl, counter: jsonCiphertextMetadata.counter)
  320. }
  321. // DELETE CHECK
  322. //
  323. if let deleted = jsonCiphertextMetadata.deleted, deleted {
  324. // TODO: We need to check deleted, id yes ???
  325. }
  326. self.database.addE2eMetadata(account: session.account,
  327. serverUrl: serverUrl,
  328. ocIdServerUrl: ocIdServerUrl,
  329. keyChecksums: jsonCiphertextMetadata.keyChecksums,
  330. deleted: jsonCiphertextMetadata.deleted ?? false,
  331. folders: jsonCiphertextMetadata.folders,
  332. version: version)
  333. if let files = jsonCiphertextMetadata.files {
  334. print("\nFILES ---------------------------------\n")
  335. for file in files {
  336. addE2eEncryption(fileNameIdentifier: file.key, filename: file.value.filename, authenticationTag: file.value.authenticationTag, key: file.value.key, initializationVector: file.value.nonce, metadataKey: metadataKey, mimetype: file.value.mimetype)
  337. print("filename: \(file.value.filename)")
  338. print("fileNameIdentifier: \(file.key)")
  339. print("mimetype: \(file.value.mimetype)")
  340. print("\n")
  341. }
  342. }
  343. if let folders = jsonCiphertextMetadata.folders {
  344. print("FOLDERS--------------------------------\n")
  345. for folder in folders {
  346. addE2eEncryption(fileNameIdentifier: folder.key, filename: folder.value, authenticationTag: metadata.authenticationTag, key: metadataKey, initializationVector: metadata.nonce, metadataKey: metadataKey, mimetype: "httpd/unix-directory")
  347. print("filename: \(folder.value)")
  348. print("fileNameIdentifier: \(folder.key)")
  349. print("\n")
  350. }
  351. }
  352. print("---------------------------------------\n\n")
  353. } catch let error {
  354. return NKError(errorCode: NCGlobal.shared.errorE2EEJSon, errorDescription: error.localizedDescription)
  355. }
  356. return NKError()
  357. }
  358. // MARK: -
  359. func createSignature(metadata: E2eeV20.Metadata, users: [E2eeV20.Users]?, version: String, certificate: String, session: NCSession.Session) -> String? {
  360. guard let users else { return nil }
  361. var usersSignatureCodable: [E2eeV20Signature.Users] = []
  362. for user in users {
  363. usersSignatureCodable.append(E2eeV20Signature.Users(userId: user.userId, certificate: user.certificate, encryptedMetadataKey: user.encryptedMetadataKey))
  364. }
  365. let signatureCodable = E2eeV20Signature(metadata: E2eeV20Signature.Metadata(ciphertext: metadata.ciphertext, nonce: metadata.nonce, authenticationTag: metadata.authenticationTag), users: usersSignatureCodable, version: version)
  366. do {
  367. let jsonEncoder = JSONEncoder()
  368. let json = try jsonEncoder.encode(signatureCodable)
  369. let dataSerialization = try JSONSerialization.jsonObject(with: json, options: [])
  370. let decoded = try? JSONSerialization.data(withJSONObject: dataSerialization, options: [.sortedKeys, .withoutEscapingSlashes])
  371. let base64 = decoded!.base64EncodedString()
  372. if let base64Data = base64.data(using: .utf8),
  373. let signatureData = NCEndToEndEncryption.shared().generateSignatureCMS(base64Data, certificate: certificate, privateKey: NCKeychain().getEndToEndPrivateKey(account: session.account), userId: session.userId) {
  374. return signatureData.base64EncodedString()
  375. }
  376. } catch {
  377. print("Error: \(error.localizedDescription)")
  378. }
  379. return nil
  380. }
  381. func verifySignature(account: String, signature: String, userId: String, metadata: E2eeV20.Metadata, users: [E2eeV20.Users]?, version: String, certificate: String) -> Bool {
  382. var signatureCodable: E2eeV20Signature?
  383. var certificates: [String] = []
  384. if let users {
  385. var usersSignatureCodable: [E2eeV20Signature.Users] = []
  386. for user in users {
  387. usersSignatureCodable.append(E2eeV20Signature.Users(userId: user.userId, certificate: user.certificate, encryptedMetadataKey: user.encryptedMetadataKey))
  388. }
  389. signatureCodable = E2eeV20Signature(metadata: E2eeV20Signature.Metadata(ciphertext: metadata.ciphertext, nonce: metadata.nonce, authenticationTag: metadata.authenticationTag), users: usersSignatureCodable, version: version)
  390. certificates = users.map { $0.certificate }
  391. } else {
  392. signatureCodable = E2eeV20Signature(metadata: E2eeV20Signature.Metadata(ciphertext: metadata.ciphertext, nonce: metadata.nonce, authenticationTag: metadata.authenticationTag), users: nil, version: version)
  393. certificates = [certificate]
  394. }
  395. do {
  396. let jsonEncoder = JSONEncoder()
  397. let json = try jsonEncoder.encode(signatureCodable)
  398. let dataSerialization = try JSONSerialization.jsonObject(with: json, options: [])
  399. if var dataSerialization = dataSerialization as? [String: Any?] {
  400. dataSerialization = dataSerialization.compactMapValues { $0 }
  401. let decodedSignatureCodable = try JSONSerialization.data(withJSONObject: dataSerialization, options: [.sortedKeys, .withoutEscapingSlashes])
  402. let base64 = decodedSignatureCodable.base64EncodedString()
  403. if let data = base64.data(using: .utf8), let signatureData = Data(base64Encoded: signature) {
  404. return NCEndToEndEncryption.shared().verifySignatureCMS(signatureData, data: data, certificates: certificates)
  405. }
  406. }
  407. } catch {
  408. print("Error: \(error.localizedDescription)")
  409. }
  410. return false
  411. }
  412. }