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

Unit Test Failure - CryptorRSATests#testSpecificPEM #85

Open
LowAmmo opened this issue Feb 5, 2025 · 1 comment
Open

Unit Test Failure - CryptorRSATests#testSpecificPEM #85

LowAmmo opened this issue Feb 5, 2025 · 1 comment

Comments

@LowAmmo
Copy link
Contributor

LowAmmo commented Feb 5, 2025

Getting a Unit Test Failure when running on Xcode 15 and Xcode 16, targeting the iPhone Simulator or the Mac.

func testSpecificPEM() {

The specific error that is thrown from the CryptorRSA.createPublicKey() method is:

 Error code: -9999(0x-270F), Couldn't create key reference from key data

The actual failing API is the call to SecKeyCreateWithData

guard let key = SecKeyCreateWithData(keyData as CFData, keyDict as CFDictionary, nil) else {

The key line seems to be where we are stripping the first 27 bytes due to the 26th byte being 0x30 -

if keyData[26] == 0x30 {

(not advancing 26 bytes there allows the test to pass, however then a different test fails - test_private_initWithPKCS8

func test_private_initWithPKCS8() throws {

(because it fails to create the privateKey - returns nil)

Proposed Solution

It appears the issue (based on code comments) is that it is stripping the first 26 bytes on any key type (public or private), but should ONLY strip the bytes for a private key.

So, making a change to only strip if the type is private.

Will get a PR out - assuming that is the correct fix.

LowAmmo added a commit to LowAmmo/BlueRSA that referenced this issue Feb 5, 2025
* Also address build warning about an unused variable
@LowAmmo
Copy link
Contributor Author

LowAmmo commented Feb 5, 2025

Pull Request to fix: #86

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

1 participant