Post

Replies

Boosts

Views

Activity

Application code signing fails when using keychain-access-groups
I'm trying to add keychain-access-groups capability to my app for MacOs devices and I'm getting an error while signing the code. If I add this capability to an app for iOS devices, this does not happen and it works correctly. Are there any limitations to using this capability on MacOS devices? My entitlement file is the following: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>com.apple.security.app-sandbox</key> <true/> <key>com.apple.security.application-groups</key> <array> <string>group.com.cqesolutions</string> </array> <key>com.apple.security.files.user-selected.read-only</key> <true/> <key>com.apple.security.smartcard</key> <true/> <key>keychain-access-groups</key> <array> <string>$(AppIdentifierPrefix)com.cqesolutions.desktopDNIe</string> <!--<string>$(AppIdentifierPrefix)com.apple.token</string>--> <string>com.apple.token</string> </array> </dict> </plist>
0
0
561
Jan ’25
In somecases it´s not possible to use generated CriptoTokenKit
I am using the CryptoTokenKit functionality to be able to perform validations on web pages that use digital certificates to ensure the user's identity, using the digital certificates included in the Spanish national electronic identity document. I manage to use it correctly in most cases, but sometimes I get an error when trying to retrieve the previously created token. This error is fixed by restarting the phone. I had create the Feedback Assistant with number FB14095789.
1
0
952
Jul ’24
URLSession.dataTask not working on testflight
I have created an app that allows access to a url using URLSession and it is working correctly when I launch the app using XCode, but it does not work when I submit the app for testing in testfligh. It seems that something is blocking requests made from URLSession. Is it possible that there is some configuration that you are not taking into account for publishing to testflight
2
0
662
Jun ’24
How to validate in a webview using the certificate of a cryptographic card
I am working on a project that allows access to certificates from a cryptographic card that supports communication via NFC with the mobile device. At this point, I am able to read the data from the card (public certificate and root certificate) and am able to send data (a hash) to the card and have it sign it with the private certificate. On the other hand, with the following code I can validate a user while browsing using a webview when the server needs authentication with a digital certificate. func sendClientCertificate(for challenge: URLAuthenticationChallenge, via completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {     guard let data = try? Data(contentsOf: URL(fileURLWithPath: certificado!)),     let credential = credential(from: data, withPassword: password ?? "") else {      challenge.sender?.cancel(challenge)      return completionHandler(.rejectProtectionSpace, .none)    }    return completionHandler(.useCredential, credential);   }       func credential(from data: Data, withPassword password: String) -> URLCredential? {     guard let security = security(from: data, withPassword: password) else {      return .none     }     return URLCredential(      identity: security.identity,      certificates: security.certificates,      persistence: .permanent     )    }    func security(from data: Data, withPassword password: String) -> (identity: SecIdentity, trust: SecTrust, certificates: [SecCertificate])? {     var _items: CFArray?     let securityError = SecPKCS12Import(data as NSData,                       [ kSecImportExportPassphrase as String : password ] as CFDictionary,                       &_items);     guard let items = _items as? [Any],      let dict = items.first as? [String:Any],      securityError == errSecSuccess else {       return .none     }     let identity = dict["identity"] as! SecIdentity     let trust = dict["trust"] as! SecTrust;     // Certificate chain     var certificate: SecCertificate!     SecIdentityCopyCertificate(identity, &certificate);     return (identity, trust, [certificate]);    } What classes should I delegate to be able to control the communication at a low level and be able to send the data that the server needs to sign to the card?
1
0
988
Mar ’23
How to create Private SecKey from modulus and private exponent
I am working on an application on IOS and I need to be able to decrypt an element that has been encrypted with a public key, but I only know the modulus and the private exponent of the private key. How can I obtain the private key from these elements in IOS? In java, with the following code I can get the private key from these elements and I can decrypt the element. final RSAPrivateKeySpec privateSpec = new RSAPrivateKeySpec(MODULUS, PRIVATE_EXPONENT); final KeyFactory factory = KeyFactory.getInstance("RSA"); final PrivateKey priv = factory.generatePrivate(privateSpec); On ios, I got the following code, but it doesn't return the private key:      let smodulus = "00c35d6ac32d287dab681c78272931b60ca442bd4505e1b306432af92ef6e07bc3e4e24c2bc2dac69c94753390c3793b80734ef906520a96cafb146ce587ab383e78efc58c5ccf56b5084f3f9bc719e646a0361155ab56b7d71b49f1f90673383ea0fdb4a67900c0973930aa3bc7071c479b4a5d229fcab7ce22b84c1637d7e70b"     let sPrivateExponent = "1f2535700832fc55e73322b49b8ca14942a6a125efda1b805414f5c4d6f6d2c45828fb9bbe64c2651405db42a8e71ae54f7cb7969a5db5cc865aab41ac6f4f77deccb51496fe588f9dcd724a1d49cab96712621afc9c656c56dea011f8ab8e12a321fd62430902b15586a36093a6679e31b67017397da83b0992f5f816017701"     let sPublicExponent = "010001"    public static func getPrivateKey(smodulus: String, sPrivateExponent: String) -> SecKey? {              let pubExponent: [UInt8] = [1, 0, 1]     let exponent: [UInt8] = sPrivateExponent.hexaBytes     var modulus: [UInt8] = smodulus.hexaBytes           //modulus.insert(0x00, at: 0)           var modulusEncoded: [UInt8] = []     modulusEncoded.append(0x02)     modulusEncoded.append(contentsOf: lengthField(of: modulus))     modulusEncoded.append(contentsOf: modulus)     var exponentEncoded: [UInt8] = []     exponentEncoded.append(0x02)     exponentEncoded.append(contentsOf: lengthField(of: exponent))     exponentEncoded.append(contentsOf: exponent)           var sequenceEncoded: [UInt8] = []     sequenceEncoded.append(0x30)     sequenceEncoded.append(contentsOf: lengthField(of: (modulusEncoded + exponentEncoded)))     sequenceEncoded.append(contentsOf: (modulusEncoded + exponentEncoded))           let keyData = Data(bytes: sequenceEncoded)           // RSA key size is the number of bits of the modulus.     let keySize = (modulus.count * 8)     let attributes: [String: Any] = [       kSecAttrKeyType as String: kSecAttrKeyTypeRSA,       kSecAttrKeyClass as String: kSecAttrKeyClassPrivate,       kSecAttrKeySizeInBits as String: keySize     ]                 let privateKey = SecKeyCreateWithData(keyData as CFData, attributes as CFDictionary, nil)                       return privateKey   }  private static func lengthField(of valueField: [UInt8]) -> [UInt8] {     var count = valueField.count     if count < 128 {       return [ UInt8(count) ]     }     // The number of bytes needed to encode count.     let lengthBytesCount = Int((log2(Double(count)) / 8) + 1)     // The first byte in the length field encoding the number of remaining bytes.     let firstLengthFieldByte = UInt8(128 + lengthBytesCount)     var lengthField: [UInt8] = []     for _ in 0..<lengthBytesCount {       // Take the last 8 bits of count.       let lengthByte = UInt8(count & 0xff)       // Add them to the length field.       lengthField.insert(lengthByte, at: 0)       // Delete the last 8 bits of count.       count = count >> 8     }     // Include the first byte.     lengthField.insert(firstLengthFieldByte, at: 0)     return lengthField   } extension StringProtocol {   var hexaData: Data { .init(hexa) }   var hexaBytes: [UInt8] { .init(hexa) }   private var hexa: UnfoldSequence<UInt8, Index> {     sequence(state: startIndex) { startIndex in       guard startIndex < self.endIndex else { return nil }       let endIndex = self.index(startIndex, offsetBy: 2, limitedBy: self.endIndex) ?? self.endIndex       defer { startIndex = endIndex }       return UInt8(self[startIndex..<endIndex], radix: 16)     }   } }
3
0
1.8k
Feb ’23
Best practices in the initialization of a database in app ios
I have an app that uses an SQLite database to store some information. In the first installation of the app I create the database and pass a script to include the necessary data in it. Among these data I have a master of administrative regions of Spain, which implies a slow initialization process. What are the best practices to carry out this initial load? I've tried throwing it in a background thread, but if I do, I get an EXC_BAD_ACCESS error.
4
0
926
Apr ’22
Application code signing fails when using keychain-access-groups
I'm trying to add keychain-access-groups capability to my app for MacOs devices and I'm getting an error while signing the code. If I add this capability to an app for iOS devices, this does not happen and it works correctly. Are there any limitations to using this capability on MacOS devices? My entitlement file is the following: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>com.apple.security.app-sandbox</key> <true/> <key>com.apple.security.application-groups</key> <array> <string>group.com.cqesolutions</string> </array> <key>com.apple.security.files.user-selected.read-only</key> <true/> <key>com.apple.security.smartcard</key> <true/> <key>keychain-access-groups</key> <array> <string>$(AppIdentifierPrefix)com.cqesolutions.desktopDNIe</string> <!--<string>$(AppIdentifierPrefix)com.apple.token</string>--> <string>com.apple.token</string> </array> </dict> </plist>
Replies
0
Boosts
0
Views
561
Activity
Jan ’25
In somecases it´s not possible to use generated CriptoTokenKit
I am using the CryptoTokenKit functionality to be able to perform validations on web pages that use digital certificates to ensure the user's identity, using the digital certificates included in the Spanish national electronic identity document. I manage to use it correctly in most cases, but sometimes I get an error when trying to retrieve the previously created token. This error is fixed by restarting the phone. I had create the Feedback Assistant with number FB14095789.
Replies
1
Boosts
0
Views
952
Activity
Jul ’24
URLSession.dataTask not working on testflight
I have created an app that allows access to a url using URLSession and it is working correctly when I launch the app using XCode, but it does not work when I submit the app for testing in testfligh. It seems that something is blocking requests made from URLSession. Is it possible that there is some configuration that you are not taking into account for publishing to testflight
Replies
2
Boosts
0
Views
662
Activity
Jun ’24
How to validate in a webview using the certificate of a cryptographic card
I am working on a project that allows access to certificates from a cryptographic card that supports communication via NFC with the mobile device. At this point, I am able to read the data from the card (public certificate and root certificate) and am able to send data (a hash) to the card and have it sign it with the private certificate. On the other hand, with the following code I can validate a user while browsing using a webview when the server needs authentication with a digital certificate. func sendClientCertificate(for challenge: URLAuthenticationChallenge, via completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {     guard let data = try? Data(contentsOf: URL(fileURLWithPath: certificado!)),     let credential = credential(from: data, withPassword: password ?? "") else {      challenge.sender?.cancel(challenge)      return completionHandler(.rejectProtectionSpace, .none)    }    return completionHandler(.useCredential, credential);   }       func credential(from data: Data, withPassword password: String) -> URLCredential? {     guard let security = security(from: data, withPassword: password) else {      return .none     }     return URLCredential(      identity: security.identity,      certificates: security.certificates,      persistence: .permanent     )    }    func security(from data: Data, withPassword password: String) -> (identity: SecIdentity, trust: SecTrust, certificates: [SecCertificate])? {     var _items: CFArray?     let securityError = SecPKCS12Import(data as NSData,                       [ kSecImportExportPassphrase as String : password ] as CFDictionary,                       &_items);     guard let items = _items as? [Any],      let dict = items.first as? [String:Any],      securityError == errSecSuccess else {       return .none     }     let identity = dict["identity"] as! SecIdentity     let trust = dict["trust"] as! SecTrust;     // Certificate chain     var certificate: SecCertificate!     SecIdentityCopyCertificate(identity, &certificate);     return (identity, trust, [certificate]);    } What classes should I delegate to be able to control the communication at a low level and be able to send the data that the server needs to sign to the card?
Replies
1
Boosts
0
Views
988
Activity
Mar ’23
How to create Private SecKey from modulus and private exponent
I am working on an application on IOS and I need to be able to decrypt an element that has been encrypted with a public key, but I only know the modulus and the private exponent of the private key. How can I obtain the private key from these elements in IOS? In java, with the following code I can get the private key from these elements and I can decrypt the element. final RSAPrivateKeySpec privateSpec = new RSAPrivateKeySpec(MODULUS, PRIVATE_EXPONENT); final KeyFactory factory = KeyFactory.getInstance("RSA"); final PrivateKey priv = factory.generatePrivate(privateSpec); On ios, I got the following code, but it doesn't return the private key:      let smodulus = "00c35d6ac32d287dab681c78272931b60ca442bd4505e1b306432af92ef6e07bc3e4e24c2bc2dac69c94753390c3793b80734ef906520a96cafb146ce587ab383e78efc58c5ccf56b5084f3f9bc719e646a0361155ab56b7d71b49f1f90673383ea0fdb4a67900c0973930aa3bc7071c479b4a5d229fcab7ce22b84c1637d7e70b"     let sPrivateExponent = "1f2535700832fc55e73322b49b8ca14942a6a125efda1b805414f5c4d6f6d2c45828fb9bbe64c2651405db42a8e71ae54f7cb7969a5db5cc865aab41ac6f4f77deccb51496fe588f9dcd724a1d49cab96712621afc9c656c56dea011f8ab8e12a321fd62430902b15586a36093a6679e31b67017397da83b0992f5f816017701"     let sPublicExponent = "010001"    public static func getPrivateKey(smodulus: String, sPrivateExponent: String) -> SecKey? {              let pubExponent: [UInt8] = [1, 0, 1]     let exponent: [UInt8] = sPrivateExponent.hexaBytes     var modulus: [UInt8] = smodulus.hexaBytes           //modulus.insert(0x00, at: 0)           var modulusEncoded: [UInt8] = []     modulusEncoded.append(0x02)     modulusEncoded.append(contentsOf: lengthField(of: modulus))     modulusEncoded.append(contentsOf: modulus)     var exponentEncoded: [UInt8] = []     exponentEncoded.append(0x02)     exponentEncoded.append(contentsOf: lengthField(of: exponent))     exponentEncoded.append(contentsOf: exponent)           var sequenceEncoded: [UInt8] = []     sequenceEncoded.append(0x30)     sequenceEncoded.append(contentsOf: lengthField(of: (modulusEncoded + exponentEncoded)))     sequenceEncoded.append(contentsOf: (modulusEncoded + exponentEncoded))           let keyData = Data(bytes: sequenceEncoded)           // RSA key size is the number of bits of the modulus.     let keySize = (modulus.count * 8)     let attributes: [String: Any] = [       kSecAttrKeyType as String: kSecAttrKeyTypeRSA,       kSecAttrKeyClass as String: kSecAttrKeyClassPrivate,       kSecAttrKeySizeInBits as String: keySize     ]                 let privateKey = SecKeyCreateWithData(keyData as CFData, attributes as CFDictionary, nil)                       return privateKey   }  private static func lengthField(of valueField: [UInt8]) -> [UInt8] {     var count = valueField.count     if count < 128 {       return [ UInt8(count) ]     }     // The number of bytes needed to encode count.     let lengthBytesCount = Int((log2(Double(count)) / 8) + 1)     // The first byte in the length field encoding the number of remaining bytes.     let firstLengthFieldByte = UInt8(128 + lengthBytesCount)     var lengthField: [UInt8] = []     for _ in 0..<lengthBytesCount {       // Take the last 8 bits of count.       let lengthByte = UInt8(count & 0xff)       // Add them to the length field.       lengthField.insert(lengthByte, at: 0)       // Delete the last 8 bits of count.       count = count >> 8     }     // Include the first byte.     lengthField.insert(firstLengthFieldByte, at: 0)     return lengthField   } extension StringProtocol {   var hexaData: Data { .init(hexa) }   var hexaBytes: [UInt8] { .init(hexa) }   private var hexa: UnfoldSequence<UInt8, Index> {     sequence(state: startIndex) { startIndex in       guard startIndex < self.endIndex else { return nil }       let endIndex = self.index(startIndex, offsetBy: 2, limitedBy: self.endIndex) ?? self.endIndex       defer { startIndex = endIndex }       return UInt8(self[startIndex..<endIndex], radix: 16)     }   } }
Replies
3
Boosts
0
Views
1.8k
Activity
Feb ’23
Best practices in the initialization of a database in app ios
I have an app that uses an SQLite database to store some information. In the first installation of the app I create the database and pass a script to include the necessary data in it. Among these data I have a master of administrative regions of Spain, which implies a slow initialization process. What are the best practices to carry out this initial load? I've tried throwing it in a background thread, but if I do, I get an EXC_BAD_ACCESS error.
Replies
4
Boosts
0
Views
926
Activity
Apr ’22