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

Handling Non Standard Keys Test Failed #185

Open
joey-gm opened this issue Jun 27, 2023 · 3 comments
Open

Handling Non Standard Keys Test Failed #185

joey-gm opened this issue Jun 27, 2023 · 3 comments

Comments

@joey-gm
Copy link
Contributor

joey-gm commented Jun 27, 2023

The following 6 "awkward RSA Keys" tests failed (XCTAssertEqual failed: threw error "incorrectParameterSize") when built with Swift 5.9 - Apple Swift version 5.9 (swiftlang-5.9.0.114.10 clang-1500.0.29.1)

XCTAssertEqual(try _RSA.Signing.PrivateKey(pemRepresentation: awkwardRSAPrivateKeyPEM).keySizeInBits, 2056)
XCTAssertEqual(try _RSA.Signing.PrivateKey(pemRepresentation: awkwardRSAPrivateKeyPKCS8PEM).keySizeInBits, 2056)
XCTAssertEqual(try _RSA.Signing.PrivateKey(derRepresentation: awkwardRSAPrivateKeyDER).keySizeInBits, 2056)
XCTAssertEqual(try _RSA.Signing.PrivateKey(derRepresentation: awkwardRSAPrivateKeyPKCS8DER).keySizeInBits, 2056)
XCTAssertEqual(try _RSA.Signing.PublicKey(pemRepresentation: awkwardRSAPublicKeyPEM).keySizeInBits, 2056)
XCTAssertEqual(try _RSA.Signing.PublicKey(derRepresentation: awkwardRSAPublicKeyDER).keySizeInBits, 2056)

@Lukasa
Copy link
Contributor

Lukasa commented Jun 27, 2023

Can you copy-paste the test output please?

@joey-gm
Copy link
Contributor Author

joey-gm commented Jun 27, 2023

Can you copy-paste the test output please?

swift-crypto % swift test
Building for debugging...
swift-crypto/Tests/CryptoExtrasTests/Utils/BytesUtil.swift:74:20: warning: 'init(bytesNoCopy:length:encoding:freeWhenDone:)' was deprecated in macOS 13: String does not support no-copy initialization
return String(bytesNoCopy: ptr, length: hexLen, encoding: .utf8, freeWhenDone: true)!
^
swift-crypto/Tests/CryptoTests/Utils/XCTestUtils.swift:20:18: warning: generic parameter 'T' shadows generic parameter from outer scope with the same name; this is an error in Swift 6
func wrapper(
closure: () throws -> T, file: StaticString, line: UInt) throws -> T {
^
swift-crypto/Tests/CryptoTests/Utils/XCTestUtils.swift:19:13: note: 'T' previously declared here
func orFail(file: StaticString = #file, line: UInt = #line, _ closure: () throws -> T) throws -> T {
^
swift-crypto/Tests/CryptoTests/Utils/XCTestUtils.swift:20:18: warning: generic parameter 'T' shadows generic parameter from outer scope with the same name; this is an error in Swift 6
func wrapper(_ closure: () throws -> T, file: StaticString, line: UInt) throws -> T {
^
swift-crypto/Tests/CryptoTests/Utils/XCTestUtils.swift:19:13: note: 'T' previously declared here
func orFail(file: StaticString = #file, line: UInt = #line, _ closure: () throws -> T) throws -> T {
^
swift-crypto/Tests/CryptoTests/Utils/XCTestUtils.swift:20:18: warning: generic parameter 'T' shadows generic parameter from outer scope with the same name; this is an error in Swift 6
func wrapper(_ closure: () throws -> T, file: StaticString, line: UInt) throws -> T {
^
swift-crypto/Tests/CryptoTests/Utils/XCTestUtils.swift:19:13: note: 'T' previously declared here
func orFail(file: StaticString = #file, line: UInt = #line, _ closure: () throws -> T) throws -> T {
^
[42/42] Linking swift-cryptoPackageTests
Build complete! (11.62s)
Test Suite 'All tests' started at 2023-06-27 18:28:30.977.
Test Suite 'swift-cryptoPackageTests.xctest' started at 2023-06-27 18:28:30.978.
Test Suite 'AESBlockFunctionTests' started at 2023-06-27 18:28:30.978.
Test Case '-[_CryptoExtrasTests.AESBlockFunctionTests test128BitDecrypt]' started.
Test Case '-[_CryptoExtrasTests.AESBlockFunctionTests test128BitDecrypt]' passed (0.001 seconds).
Test Case '-[_CryptoExtrasTests.AESBlockFunctionTests test128BitEncrypt]' started.
Test Case '-[_CryptoExtrasTests.AESBlockFunctionTests test128BitEncrypt]' passed (0.000 seconds).
Test Case '-[_CryptoExtrasTests.AESBlockFunctionTests test192BitDecrypt]' started.
Test Case '-[_CryptoExtrasTests.AESBlockFunctionTests test192BitDecrypt]' passed (0.000 seconds).
Test Case '-[_CryptoExtrasTests.AESBlockFunctionTests test192BitEncrypt]' started.
Test Case '-[_CryptoExtrasTests.AESBlockFunctionTests test192BitEncrypt]' passed (0.000 seconds).
Test Case '-[_CryptoExtrasTests.AESBlockFunctionTests test256BitDecrypt]' started.
Test Case '-[_CryptoExtrasTests.AESBlockFunctionTests test256BitDecrypt]' passed (0.000 seconds).
Test Case '-[_CryptoExtrasTests.AESBlockFunctionTests test256BitEncrypt]' started.
Test Case '-[_CryptoExtrasTests.AESBlockFunctionTests test256BitEncrypt]' passed (0.000 seconds).
Test Case '-[_CryptoExtrasTests.AESBlockFunctionTests testRejectInvalidBlockSizes]' started.
Test Case '-[_CryptoExtrasTests.AESBlockFunctionTests testRejectInvalidBlockSizes]' passed (0.001 seconds).
Test Case '-[_CryptoExtrasTests.AESBlockFunctionTests testRejectsInvalidKeySizes]' started.
Test Case '-[_CryptoExtrasTests.AESBlockFunctionTests testRejectsInvalidKeySizes]' passed (0.000 seconds).
Test Suite 'AESBlockFunctionTests' passed at 2023-06-27 18:28:30.982.
Executed 8 tests, with 0 failures (0 unexpected) in 0.004 (0.004) seconds
Test Suite 'AESGCMSIVTests' started at 2023-06-27 18:28:30.982.
Test Case '-[_CryptoExtrasTests.AESGCMSIVTests testBadKeySize]' started.
Test Case '-[_CryptoExtrasTests.AESGCMSIVTests testBadKeySize]' passed (0.000 seconds).
Test Case '-[_CryptoExtrasTests.AESGCMSIVTests testEncryptDecrypt]' started.
Test Case '-[_CryptoExtrasTests.AESGCMSIVTests testEncryptDecrypt]' passed (0.000 seconds).
Test Case '-[_CryptoExtrasTests.AESGCMSIVTests testExtractingBytesFromNonce]' started.
Test Case '-[_CryptoExtrasTests.AESGCMSIVTests testExtractingBytesFromNonce]' passed (0.000 seconds).
Test Case '-[_CryptoExtrasTests.AESGCMSIVTests testPropertiesStayTheSameAfterFailedOpening]' started.
Test Case '-[_CryptoExtrasTests.AESGCMSIVTests testPropertiesStayTheSameAfterFailedOpening]' passed (0.000 seconds).
Test Case '-[_CryptoExtrasTests.AESGCMSIVTests testRoundTripDataProtocols]' started.
Test Case '-[_CryptoExtrasTests.AESGCMSIVTests testRoundTripDataProtocols]' passed (0.000 seconds).
Test Case '-[_CryptoExtrasTests.AESGCMSIVTests testUserConstructedSealedBoxesCombined]' started.
Test Case '-[_CryptoExtrasTests.AESGCMSIVTests testUserConstructedSealedBoxesCombined]' passed (0.000 seconds).
Test Case '-[_CryptoExtrasTests.AESGCMSIVTests testUserConstructedSealedBoxesSplit]' started.
Test Case '-[_CryptoExtrasTests.AESGCMSIVTests testUserConstructedSealedBoxesSplit]' passed (0.000 seconds).
Test Case '-[_CryptoExtrasTests.AESGCMSIVTests testWycheproof]' started.
Test Case '-[_CryptoExtrasTests.AESGCMSIVTests testWycheproof]' passed (0.023 seconds).
Test Suite 'AESGCMSIVTests' passed at 2023-06-27 18:28:31.008.
Executed 8 tests, with 0 failures (0 unexpected) in 0.025 (0.026) seconds
Test Suite 'AESGCMTests' started at 2023-06-27 18:28:31.008.
Test Case '-[CryptoTests.AESGCMTests testBadKeySize]' started.
Test Case '-[CryptoTests.AESGCMTests testBadKeySize]' passed (0.000 seconds).
Test Case '-[CryptoTests.AESGCMTests testEncryptDecrypt]' started.
Test Case '-[CryptoTests.AESGCMTests testEncryptDecrypt]' passed (0.000 seconds).
Test Case '-[CryptoTests.AESGCMTests testExtractingBytesFromNonce]' started.
Test Case '-[CryptoTests.AESGCMTests testExtractingBytesFromNonce]' passed (0.000 seconds).
Test Case '-[CryptoTests.AESGCMTests testNonStandardNonceSizeCombinedRepresentation]' started.
Test Case '-[CryptoTests.AESGCMTests testNonStandardNonceSizeCombinedRepresentation]' passed (0.000 seconds).
Test Case '-[CryptoTests.AESGCMTests testPropertiesStayTheSameAfterFailedOpening]' started.
Test Case '-[CryptoTests.AESGCMTests testPropertiesStayTheSameAfterFailedOpening]' passed (0.000 seconds).
Test Case '-[CryptoTests.AESGCMTests testRoundTripDataProtocols]' started.
Test Case '-[CryptoTests.AESGCMTests testRoundTripDataProtocols]' passed (0.000 seconds).
Test Case '-[CryptoTests.AESGCMTests testUserConstructedSealedBoxesCombined]' started.
Test Case '-[CryptoTests.AESGCMTests testUserConstructedSealedBoxesCombined]' passed (0.000 seconds).
Test Case '-[CryptoTests.AESGCMTests testUserConstructedSealedBoxesSplit]' started.
Test Case '-[CryptoTests.AESGCMTests testUserConstructedSealedBoxesSplit]' passed (0.000 seconds).
Test Case '-[CryptoTests.AESGCMTests testWycheproof]' started.
Test Case '-[CryptoTests.AESGCMTests testWycheproof]' passed (0.050 seconds).
Test Suite 'AESGCMTests' passed at 2023-06-27 18:28:31.060.
Executed 9 tests, with 0 failures (0 unexpected) in 0.052 (0.052) seconds
Test Suite 'ChaCha20CTRTests' started at 2023-06-27 18:28:31.060.
Test Case '-[_CryptoExtrasTests.ChaCha20CTRTests testChaCha20CTR_InvalidParameters]' started.
Test Case '-[_CryptoExtrasTests.ChaCha20CTRTests testChaCha20CTR_InvalidParameters]' passed (0.000 seconds).
Test Case '-[_CryptoExtrasTests.ChaCha20CTRTests testChaCha20CTR_v1]' started.
Test Case '-[_CryptoExtrasTests.ChaCha20CTRTests testChaCha20CTR_v1]' passed (0.000 seconds).
Test Case '-[_CryptoExtrasTests.ChaCha20CTRTests testChaCha20CTR_v2]' started.
Test Case '-[_CryptoExtrasTests.ChaCha20CTRTests testChaCha20CTR_v2]' passed (0.000 seconds).
Test Suite 'ChaCha20CTRTests' passed at 2023-06-27 18:28:31.061.
Executed 3 tests, with 0 failures (0 unexpected) in 0.001 (0.001) seconds
Test Suite 'ChaChaPolyTests' started at 2023-06-27 18:28:31.061.
Test Case '-[CryptoTests.ChaChaPolyTests testEncryptDecrypt]' started.
Test Case '-[CryptoTests.ChaChaPolyTests testEncryptDecrypt]' passed (0.000 seconds).
Test Case '-[CryptoTests.ChaChaPolyTests testExtractingBytesFromNonce]' started.
Test Case '-[CryptoTests.ChaChaPolyTests testExtractingBytesFromNonce]' passed (0.000 seconds).
Test Case '-[CryptoTests.ChaChaPolyTests testIncorrectKeySize]' started.
Test Case '-[CryptoTests.ChaChaPolyTests testIncorrectKeySize]' passed (0.000 seconds).
Test Case '-[CryptoTests.ChaChaPolyTests testRoundTripDataProtocols]' started.
Test Case '-[CryptoTests.ChaChaPolyTests testRoundTripDataProtocols]' passed (0.000 seconds).
Test Case '-[CryptoTests.ChaChaPolyTests testUserConstructedSealedBoxesCombined]' started.
Test Case '-[CryptoTests.ChaChaPolyTests testUserConstructedSealedBoxesCombined]' passed (0.000 seconds).
Test Case '-[CryptoTests.ChaChaPolyTests testUserConstructedSealedBoxesSplit]' started.
Test Case '-[CryptoTests.ChaChaPolyTests testUserConstructedSealedBoxesSplit]' passed (0.000 seconds).
Test Case '-[CryptoTests.ChaChaPolyTests testWycheproof]' started.
Test Case '-[CryptoTests.ChaChaPolyTests testWycheproof]' passed (0.059 seconds).
Test Suite 'ChaChaPolyTests' passed at 2023-06-27 18:28:31.121.
Executed 7 tests, with 0 failures (0 unexpected) in 0.060 (0.060) seconds
Test Suite 'DigestsTests' started at 2023-06-27 18:28:31.121.
Test Case '-[CryptoTests.DigestsTests testBlockSizes]' started.
Test Case '-[CryptoTests.DigestsTests testBlockSizes]' passed (0.000 seconds).
Test Case '-[CryptoTests.DigestsTests testHashFunctions]' started.
Test Case '-[CryptoTests.DigestsTests testHashFunctions]' passed (0.001 seconds).
Test Case '-[CryptoTests.DigestsTests testHashFunctionsImplementCow]' started.
Test Case '-[CryptoTests.DigestsTests testHashFunctionsImplementCow]' passed (0.000 seconds).
Test Case '-[CryptoTests.DigestsTests testMD5]' started.
Test Case '-[CryptoTests.DigestsTests testMD5]' passed (0.000 seconds).
Test Suite 'DigestsTests' passed at 2023-06-27 18:28:31.122.
Executed 4 tests, with 0 failures (0 unexpected) in 0.001 (0.001) seconds
Test Suite 'Ed25519Tests' started at 2023-06-27 18:28:31.122.
Test Case '-[CryptoTests.Ed25519Tests testExample]' started.
Test Case '-[CryptoTests.Ed25519Tests testExample]' passed (0.001 seconds).
Test Case '-[CryptoTests.Ed25519Tests testRejectingInvalidSignaturesOnDiscontiguousData]' started.
Test Case '-[CryptoTests.Ed25519Tests testRejectingInvalidSignaturesOnDiscontiguousData]' passed (0.001 seconds).
Test Case '-[CryptoTests.Ed25519Tests testSigningDiscontiguousData]' started.
Test Case '-[CryptoTests.Ed25519Tests testSigningDiscontiguousData]' passed (0.001 seconds).
Test Case '-[CryptoTests.Ed25519Tests testSigningZeroRegionDataProtocol]' started.
Test Case '-[CryptoTests.Ed25519Tests testSigningZeroRegionDataProtocol]' passed (0.001 seconds).
Test Case '-[CryptoTests.Ed25519Tests testWycheProof]' started.
Test Case '-[CryptoTests.Ed25519Tests testWycheProof]' passed (0.032 seconds).
Test Suite 'Ed25519Tests' passed at 2023-06-27 18:28:31.158.
Executed 5 tests, with 0 failures (0 unexpected) in 0.036 (0.036) seconds
Test Suite 'TestRSASigning' started at 2023-06-27 18:28:31.158.
Test Case '-[_CryptoExtrasTests.TestRSASigning test_wycheproofPKCS1Vectors]' started.
Test Case '-[_CryptoExtrasTests.TestRSASigning test_wycheproofPKCS1Vectors]' passed (0.667 seconds).
Test Case '-[_CryptoExtrasTests.TestRSASigning test_wycheproofPSSVectors]' started.
Test Case '-[_CryptoExtrasTests.TestRSASigning test_wycheproofPSSVectors]' passed (0.358 seconds).
Test Case '-[_CryptoExtrasTests.TestRSASigning testHandlingNonStandardKeys]' started.
swift-crypto/Tests/_CryptoExtrasTests/TestRSASigning.swift:512: error: -[_CryptoExtrasTests.TestRSASigning testHandlingNonStandardKeys] : XCTAssertEqual failed: threw error "incorrectParameterSize"
swift-crypto/Tests/_CryptoExtrasTests/TestRSASigning.swift:513: error: -[_CryptoExtrasTests.TestRSASigning testHandlingNonStandardKeys] : XCTAssertEqual failed: threw error "incorrectParameterSize"
swift-crypto/Tests/_CryptoExtrasTests/TestRSASigning.swift:514: error: -[_CryptoExtrasTests.TestRSASigning testHandlingNonStandardKeys] : XCTAssertEqual failed: threw error "incorrectParameterSize"
swift-crypto/Tests/_CryptoExtrasTests/TestRSASigning.swift:515: error: -[_CryptoExtrasTests.TestRSASigning testHandlingNonStandardKeys] : XCTAssertEqual failed: threw error "incorrectParameterSize"
swift-crypto/Tests/_CryptoExtrasTests/TestRSASigning.swift:516: error: -[_CryptoExtrasTests.TestRSASigning testHandlingNonStandardKeys] : XCTAssertEqual failed: threw error "incorrectParameterSize"
swift-crypto/Tests/_CryptoExtrasTests/TestRSASigning.swift:517: error: -[_CryptoExtrasTests.TestRSASigning testHandlingNonStandardKeys] : XCTAssertEqual failed: threw error "incorrectParameterSize"
Test Case '-[_CryptoExtrasTests.TestRSASigning testHandlingNonStandardKeys]' failed (0.142 seconds).
Test Case '-[_CryptoExtrasTests.TestRSASigning testKeySizes]' started.
Test Case '-[_CryptoExtrasTests.TestRSASigning testKeySizes]' passed (8.627 seconds).
Test Case '-[_CryptoExtrasTests.TestRSASigning testMangledPKCS8DERKey]' started.
Test Case '-[_CryptoExtrasTests.TestRSASigning testMangledPKCS8DERKey]' passed (0.097 seconds).
Test Case '-[_CryptoExtrasTests.TestRSASigning testParsingPKCS1PublicKeyDER]' started.
Test Case '-[_CryptoExtrasTests.TestRSASigning testParsingPKCS1PublicKeyDER]' passed (0.000 seconds).
Test Case '-[_CryptoExtrasTests.TestRSASigning testParsingPKCS1PublicKeyPEM]' started.
Test Case '-[_CryptoExtrasTests.TestRSASigning testParsingPKCS1PublicKeyPEM]' passed (0.001 seconds).
Test Case '-[_CryptoExtrasTests.TestRSASigning testParsingSPKIPublicKeyDER]' started.
Test Case '-[_CryptoExtrasTests.TestRSASigning testParsingSPKIPublicKeyDER]' passed (0.000 seconds).
Test Case '-[_CryptoExtrasTests.TestRSASigning testParsingSPKIPublicKeyPEM]' started.
Test Case '-[_CryptoExtrasTests.TestRSASigning testParsingSPKIPublicKeyPEM]' passed (0.001 seconds).
Test Case '-[_CryptoExtrasTests.TestRSASigning testPKCS1Signing]' started.
Test Case '-[_CryptoExtrasTests.TestRSASigning testPKCS1Signing]' passed (7.371 seconds).
Test Case '-[_CryptoExtrasTests.TestRSASigning testPSSSigning]' started.
Test Case '-[_CryptoExtrasTests.TestRSASigning testPSSSigning]' passed (7.074 seconds).
Test Case '-[_CryptoExtrasTests.TestRSASigning testRefuseToConstructSmallKeys]' started.
Test Case '-[_CryptoExtrasTests.TestRSASigning testRefuseToConstructSmallKeys]' passed (0.000 seconds).
Test Case '-[_CryptoExtrasTests.TestRSASigning testRejectSmallKeys]' started.
Test Case '-[_CryptoExtrasTests.TestRSASigning testRejectSmallKeys]' passed (0.000 seconds).
Test Case '-[_CryptoExtrasTests.TestRSASigning testSignatureSerialization]' started.
Test Case '-[_CryptoExtrasTests.TestRSASigning testSignatureSerialization]' passed (0.468 seconds).
Test Suite 'TestRSASigning' failed at 2023-06-27 18:28:55.967.
Executed 14 tests, with 6 failures (6 unexpected) in 24.808 (24.809) seconds
Test Suite 'swift-cryptoPackageTests.xctest' failed at 2023-06-27 18:28:55.967.
Executed 58 tests, with 6 failures (6 unexpected) in 24.986 (24.989) seconds
Test Suite 'All tests' failed at 2023-06-27 18:28:55.967.
Executed 58 tests, with 6 failures (6 unexpected) in 24.986 (24.990) seconds

swift-crypto % swift -v
Apple Swift version 5.9 (swiftlang-5.9.0.114.10 clang-1500.0.29.1)
Target: arm64-apple-macosx13.0
/Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-help intro

@Lukasa
Copy link
Contributor

Lukasa commented Jun 27, 2023

This is a change in the beta SDKs. Applying an appropriate fix will want to return something byte-aligned from keySizeInBits, which can be done using SecKeyGetBlockSize instead of the current use of SecKeyCopyAttributes and kSecAttrKeySizeInBits. Would you be interested in fixing that up?

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

2 participants