|
79 | 79 | : nullptr;
|
80 | 80 |
|
81 | 81 | dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
|
82 |
| - [FlipperKitQRReader read:^( |
83 |
| - NSString* key, |
84 |
| - NSError* error, |
85 |
| - BOOL cancelled, |
86 |
| - FBFlipperKitQRResultAck readResultAck) { |
87 |
| - if (error || cancelled) { |
88 |
| - // If the QR code was cancelled, we should not proceed on further |
89 |
| - // requests. |
90 |
| - cancelled_ = cancelled; |
91 |
| - certError = |
92 |
| - [NSError errorWithDomain:FBFlipperKitQRCertificateProviderErrorDomain |
93 |
| - code:-1 |
94 |
| - userInfo:@{ |
95 |
| - NSLocalizedDescriptionKey : NSLocalizedString( |
96 |
| - @"Unable to read key from QR code", nil), |
97 |
| - }]; |
| 82 | + if (@available(macCatalyst 14.0, *)) { |
| 83 | + [FlipperKitQRReader read:^( |
| 84 | + NSString* key, |
| 85 | + NSError* error, |
| 86 | + BOOL cancelled, |
| 87 | + FBFlipperKitQRResultAck readResultAck) { |
| 88 | + if (error || cancelled) { |
| 89 | + // If the QR code was cancelled, we should not proceed on further |
| 90 | + // requests. |
| 91 | + cancelled_ = cancelled; |
| 92 | + certError = [NSError |
| 93 | + errorWithDomain:FBFlipperKitQRCertificateProviderErrorDomain |
| 94 | + code:-1 |
| 95 | + userInfo:@{ |
| 96 | + NSLocalizedDescriptionKey : NSLocalizedString( |
| 97 | + @"Unable to read key from QR code", nil), |
| 98 | + }]; |
| 99 | + dispatch_semaphore_signal(semaphore); |
| 100 | + return; |
| 101 | + } |
| 102 | + |
| 103 | + // Get the data from the base64-encoded key. |
| 104 | + NSData* keyData = [[NSData alloc] initWithBase64EncodedString:key |
| 105 | + options:0]; |
| 106 | + // QR codes may be corrupt, invalid, or just contain a different |
| 107 | + // content to the one that is expected i.e. base-64 encoded key. |
| 108 | + // If that is the case, then just return with an error. |
| 109 | + if (!keyData) { |
| 110 | + readResultAck(QRReaderResultError); |
| 111 | + return; |
| 112 | + } |
| 113 | + |
| 114 | + auto success = AESDecrypt( |
| 115 | + [encryptedCertificatesPath UTF8String], |
| 116 | + [certificatesPath UTF8String], |
| 117 | + (const unsigned char*)[keyData bytes]); |
| 118 | + |
| 119 | + // If the decryption failed, must likely, the key is invalid which may be |
| 120 | + // caused by an erroneous QR read. |
| 121 | + if (!success) { |
| 122 | + readResultAck(QRReaderResultError); |
| 123 | + return; |
| 124 | + } |
| 125 | + |
| 126 | + // If the decryption was successful, we can now read the certificates. |
| 127 | + // The certificates are stored in a zip file. Unzip to destination. |
| 128 | + |
| 129 | + [SSZipArchive unzipFileAtPath:certificatesPath toDestination:destination]; |
| 130 | + |
| 131 | + // Remove the certificate zip file. |
| 132 | + [fileManager removeItemAtPath:certificatesPath error:nil]; |
| 133 | + |
| 134 | + // At this stage, dismiss the QR code reader. |
| 135 | + readResultAck(QRReaderResultAccepted); |
| 136 | + |
| 137 | + if (QRReadStep) { |
| 138 | + QRReadStep->complete(); |
| 139 | + } |
| 140 | + |
| 141 | + // Signal the semaphore as to unblock the connection thread. |
98 | 142 | dispatch_semaphore_signal(semaphore);
|
99 | 143 | return;
|
100 |
| - } |
101 |
| - |
102 |
| - // Get the data from the base64-encoded key. |
103 |
| - NSData* keyData = [[NSData alloc] initWithBase64EncodedString:key |
104 |
| - options:0]; |
105 |
| - // QR codes may be corrupt, invalid, or just contain a different |
106 |
| - // content to the one that is expected i.e. base-64 encoded key. |
107 |
| - // If that is the case, then just return with an error. |
108 |
| - if (!keyData) { |
109 |
| - readResultAck(QRReaderResultError); |
110 |
| - return; |
111 |
| - } |
112 |
| - |
113 |
| - auto success = AESDecrypt( |
114 |
| - [encryptedCertificatesPath UTF8String], |
115 |
| - [certificatesPath UTF8String], |
116 |
| - (const unsigned char*)[keyData bytes]); |
117 |
| - |
118 |
| - // If the decryption failed, must likely, the key is invalid which may be |
119 |
| - // caused by an erroneous QR read. |
120 |
| - if (!success) { |
121 |
| - readResultAck(QRReaderResultError); |
122 |
| - return; |
123 |
| - } |
124 |
| - |
125 |
| - // If the decryption was successful, we can now read the certificates. |
126 |
| - // The certificates are stored in a zip file. Unzip to destination. |
127 |
| - |
128 |
| - [SSZipArchive unzipFileAtPath:certificatesPath toDestination:destination]; |
129 |
| - |
130 |
| - // Remove the certificate zip file. |
131 |
| - [fileManager removeItemAtPath:certificatesPath error:nil]; |
132 |
| - |
133 |
| - // At this stage, dismiss the QR code reader. |
134 |
| - readResultAck(QRReaderResultAccepted); |
135 |
| - |
136 |
| - if (QRReadStep) { |
137 |
| - QRReadStep->complete(); |
138 |
| - } |
139 |
| - |
140 |
| - // Signal the semaphore as to unblock the connection thread. |
141 |
| - dispatch_semaphore_signal(semaphore); |
142 |
| - return; |
143 |
| - }]; |
144 |
| - |
145 |
| - // Wait for the semaphore to be signalled. This will block the connection |
146 |
| - // thread until the QR code is read or an error takes place. |
147 |
| - dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); |
| 144 | + }]; |
| 145 | + // Wait for the semaphore to be signalled. This will block the connection |
| 146 | + // thread until the QR code is read or an error takes place. |
| 147 | + dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER); |
| 148 | + } else { |
| 149 | + certError = [NSError |
| 150 | + errorWithDomain:FBFlipperKitQRCertificateProviderErrorDomain |
| 151 | + code:-1 |
| 152 | + userInfo:@{ |
| 153 | + NSLocalizedDescriptionKey : NSLocalizedString( |
| 154 | + @"Unsupported platform for QR Certificate Provider", nil), |
| 155 | + }]; |
| 156 | + } |
148 | 157 |
|
149 | 158 | // Remove the encrypted certificates.
|
150 | 159 | [fileManager removeItemAtPath:encryptedCertificatesPath error:nil];
|
|
0 commit comments