Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xCode 11.4 / Swift 5.2 crashes on parsing PublicKey in simulators and <= iOS 12 #23

Open
habibrehmansg opened this issue Mar 27, 2020 · 3 comments

Comments

@habibrehmansg
Copy link

The following code crashes on Simulators and my iOS12.4 iPhone 6when built with xCode 11.4, but works ok on xCode 11.3.

Does not seem to crash on iOS 13.4.

let p256PrivateKey = try! ECPrivateKey.make(for: .prime256v1) print(p256PrivateKey.pemString) publicKey = try! p256PrivateKey.extractPublicKey() print(publicKey.pemString)

Error is happening at this line:
guard let secKey = SecKeyCreateWithData(keyData as CFData, [kSecAttrKeyType: kSecAttrKeyTypeECSECPrimeRandom, kSecAttrKeyClass: kSecAttrKeyClassPublic] as CFDictionary, &error)

Error:
objc[1049]: Class _TtGCs18_DictionaryStorageaSo11CFStringRefS0__$ is implemented in both /usr/lib/swift/libswiftCore.dylib (0x1c1d492d8) and /usr/lib/swift/libswiftCore.dylib (0x1c1d495e8). One of the two will be used. Which one is undefined. Fatal error: invalid unsafeDowncast

@JSteegmueller
Copy link

Exactly same issue here.

@habibrehmansg
Copy link
Author

I've imported the project manually (without pods), and it works at the moment.

fmcruz pushed a commit to stayawayinesctec/stayaway-app that referenced this issue Aug 6, 2020
…ency. As one of DP3T dependencies has a known issue when using Pod dependency manger (Kitura/BlueECC#23).
@dceddia
Copy link

dceddia commented Feb 6, 2021

I saw a similar problem with Xcode 12.2 compiling for macOS. Strange thing was, it worked fine in Debug builds, but it crashed with builds for Profiling or Release. Mine is crashing when parsing the PublicKey, but otherwise looks to be the same core problem:

guard let secKey = SecKeyCreateWithData(keyData as CFData,
                                        [kSecAttrKeyType: kSecAttrKeyTypeECSECPrimeRandom,
                                         kSecAttrKeyClass: kSecAttrKeyClassPublic] as CFDictionary,
                                         &error)

This looks like the relevant part of the stack trace:

Application Specific Information:
Fatal error: invalid unsafeDowncast: file /AppleInternal/BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-1103.8.25.8/swift/stdlib/public/core/Builtin.swift, line 235
 

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libswiftCore.dylib            	0x00007fff6bfe21e1 closure #1 in closure #1 in closure #1 in _assertionFailure(_:_:file:line:flags:) + 529
1   libswiftCore.dylib            	0x00007fff6bfe1cf7 closure #1 in closure #1 in _assertionFailure(_:_:file:line:flags:) + 87
2   libswiftCore.dylib            	0x00007fff6bfe19c3 closure #1 in _assertionFailure(_:_:file:line:flags:) + 99
3   libswiftCore.dylib            	0x00007fff6bfe15d5 _assertionFailure(_:_:file:line:flags:) + 533
4   libswiftCore.dylib            	0x00007fff6bfe18b0 _fatalErrorMessage(_:_:file:line:flags:) + 32
5   libswiftCore.dylib            	0x00007fff6c24d4a3 specialized _NativeDictionary.bridged() + 355
6   libswiftCore.dylib            	0x00007fff6c02a06f _NativeDictionary.bridged() + 15
7   co.tinywins.Recut             	0x0000000109087a73 specialized ECPublicKey.init(der:) + 1059 (ECPublicKey.swift:144)
8   co.tinywins.Recut             	0x0000000109087224 ECPublicKey.__allocating_init(key:) + 836 (ECPublicKey.swift:93)
9   co.tinywins.Recut             	0x00000001090d54c2 BlueECVerifier.verify(signature:for:) + 530 (BlueECDSA.swift:99)
10  co.tinywins.Recut             	0x00000001090d5281 BlueECVerifier.verify(jwt:) + 577 (BlueECDSA.swift:84)
11  co.tinywins.Recut             	0x00000001090d56e0 protocol witness for VerifierAlgorithm.verify(jwt:) in conformance BlueECVerifier + 16
12  co.tinywins.Recut             	0x00000001090e5e3b static JWT.verify(_:using:) + 59 (JWT.swift:108)

I don't see the same "One of the two will be used" warning like the OP, but that definitely feels like a build issue. The comment about switching away from pods made me curious, so I switched from installing from a Podfile to using Package.swift, and that fixed the problem!

Maybe it was some kind of library mismatch or something. Hope this helps if anyone else stumbles across the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants