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

bioConversionFailure in ECDSAKey when using P384 #118

Closed
NeedleInAJayStack opened this issue Aug 28, 2023 · 10 comments · Fixed by #107
Closed

bioConversionFailure in ECDSAKey when using P384 #118

NeedleInAJayStack opened this issue Aug 28, 2023 · 10 comments · Fixed by #107
Assignees
Labels
bug Something isn't working

Comments

@NeedleInAJayStack
Copy link

NeedleInAJayStack commented Aug 28, 2023

Describe the bug

When a P384 private key from Crypto is used to create a ECDSAKey, I get the following error in release mode on MacOS:

JWTKit error: signing algorithm error: bioConversionFailure

However, when using a P256 private key, creating a ECDSAKey does not error.

To Reproduce

Build and run the following in release mode:

import JWT
import Crypto

let generatedPriv = P384.Signing.PrivateKey()
let priv = try ECDSAKey.private(pem: generatedPriv.pemRepresentation)
let pub = try ECDSAKey.public(pem: generatedPriv.publicKey.pemRepresentation)

Note that just switching P256 out for P384 is able to run without error.

Expected behavior

I would expect that a P384 curve would be able to be used without error.

Environment

  • Vapor Framework version: 4.78.0
  • Vapor Toolbox version: 18.7.1
  • OS version: MacOS 13.4.1
  • swift-crypto: 2.6.0
  • jwt: 4.2.2

Additional context

None

@NeedleInAJayStack NeedleInAJayStack added the bug Something isn't working label Aug 28, 2023
@NeedleInAJayStack NeedleInAJayStack changed the title P384 JWTKit error: signing algorithm error: bioConversionFailure bioConversionFailure in ECDSAKey when using P384 Aug 28, 2023
@vzsg
Copy link
Member

vzsg commented Sep 4, 2023

I ran the code out of curiousity inside Xcode and Linux, in both debug and release configurations, and I'm not experiencing any issues. Is it consistently happening for you?

@0xTim
Copy link
Member

0xTim commented Sep 5, 2023

Yeah I've just run this in a new project on macOS in release mode in VSCode and it worked fine for me too

@fibrechannelscsi
Copy link

This is occurring on the nightly toolchains. I've installed the latest 09-05 toolchain (in the default location for macOS) and attempted to run it as such:
/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2023-09-05-a.xctoolchain/usr/bin/swift run -c release
and I get the following:

[918/918] Linking bssl
Build complete! (156.02s)
Swift/ErrorType.swift:200: Fatal error: Error raised at top level: JWTKit error: signing algorithm error: bioConversionFailure
zsh: trace trap   run -c release

Toolchains 2023-08-27a and 2023-08-03a also exhibit this issue.

@0xTim
Copy link
Member

0xTim commented Sep 7, 2023

Have you tried the code without JWT and just using Swift Crypto?

import Crypto

let generatedPriv = P384.Signing.PrivateKey()
let priv = try ECDSAKey.private(pem: generatedPriv.pemRepresentation)
let pub = try ECDSAKey.public(pem: generatedPriv.publicKey.pemRepresentation)

None of that code is JWT stuff IIRC. If that also fails it's probably better to open an issue there

@GNMoseke
Copy link

GNMoseke commented Sep 7, 2023

ECDSAKey is a JWTKit Type.

The error itself is also in JWTKit here. My suspicion personally is that something in one of the new nightly toolchains is optimizing out something in boringSSL when compiling in release mode.

Potentially related is that JWTKit and Swift Crypto bundle 2 different versions of boringSSL on linux, but I don't know why that would cause this issue to crop up on macOS. I know there's already a PR in progress to remove the bundled boringSSL which may help.

@BradLarson
Copy link

I tested this against top-of-tree Swift as of the 2023-09-20 nightly trunk snapshot, and I still experience the bioConversionFailure described above with that toolchain. I do not see it with the 5.9 release branch toolchains, so this appears to be due to something in main since the 5.9 branch point. That means it won't be reproducible in Xcode 15's default Swift toolchain, but it is still an issue with Swift main after the 5.9 branch point.

@0xTim
Copy link
Member

0xTim commented Oct 20, 2023

We'll keep an eye on this - we're almost finished ripping out BoringSSL (#99) at which point this should no longer be an issue

@0xTim
Copy link
Member

0xTim commented Nov 6, 2023

Going to transfer this to JWTKit as that's where the code lives and we can just write a test to ensure it's no longer an issue

cc @ptoffy

@0xTim 0xTim transferred this issue from vapor/jwt Nov 6, 2023
@BradLarson
Copy link

BradLarson commented Nov 21, 2023

Just to confirm, the jwtkit-5 branch (and matching v5 branch of JWT) no longer experiences this issue in the above reproducer with nightly Swift toolchain snapshots, as anticipated after the move off of BoringSSL. Once that's in main, this should be fully resolved.

@0xTim
Copy link
Member

0xTim commented Nov 21, 2023

Oh that's great to hear!

@ptoffy ptoffy mentioned this issue Nov 23, 2023
Merged
16 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants