App crashes when trying to get signature using private key

Hi, for some of our users the app crashes when we try to get the EdDSA signature using the private key.

We use the following method from CryptoKit in the Curve25519.Signing.PrivateKey extension:

public func signature<D>(for data: D) throws -> Data where D : DataProtocol

The data that we want to sign is a string that is converted using the algorithm SHA256

Our implementation looks something like this:

func foo(text: String) throws -> String {

    var algorithm = SHA256()
    algorithm.update(data: text.data(using: .utf8)!)

    guard self.hasPrivateKey else {
        // Error handling
    }

    do {
        let signature = try self.privateKey.signature(for: algorithm.finalize()) // App crashes here if not using do-catch statement
        // signature will be used and transformed to return String...
    } catch {
        // Error handling
    }

}

I would appreciate any hints on how to solve or inspect this.

Many thanks.

for some of our users the app crashes when we try to get the EdDSA signature using the private key.

Do you have an Apple crash report for this? If so, please post it here. Use the text attachment feature (click the paperclip icon and then choose Add File) to avoid clogging up the timeline.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Hi eskimo, thanks for the quick reply. Attached you find the report.

Attached you find the report.

Thanks.

Exception Type:  EXC_BREAKPOINT (SIGTRAP)

This exception type usually means that the process hit a trap, that is, some code within the process detected a problem and deliberately crashed. The most common cause of this is a Swift trap, for example, force unwrapping an optional that’s nil or accessing an array out of bounds.

Thread 0 name:
Thread 0 Crashed:
0   libswiftCore.dylib … _assertionFailure(_:_:file:line:flags:) + 1532 (AssertCommon.swift:132)
1   libswiftCore.dylib … swift_unexpectedError + 788 (ErrorType.swift:188)
2   MySpenditCard      … CryptoManager.signAndHexEncode(text:) + 748 (CryptoManager.swift:93)

This crashing thread backtrace indicates shows that it’s your code that’s trapped (specifically line 93 of CryptoManager.swift).

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

App crashes when trying to get signature using private key
 
 
Q