Skip to content

Remove openssl#1700

Closed
mamcx wants to merge 7 commits into
masterfrom
mamcx/openssl_no_more
Closed

Remove openssl#1700
mamcx wants to merge 7 commits into
masterfrom
mamcx/openssl_no_more

Conversation

@mamcx
Copy link
Copy Markdown
Contributor

@mamcx mamcx commented Sep 11, 2024

Description of Changes

Using the openssl crate significantly increases the build times on Windows. Switching to rustls improves it:

# Windows 11
# 1.79.0-x86_64-pc-windows-msvc 
# AMD Ryzen 9 7940HS w/ Radeon 780M Graphics        4.00 GHz
#  32.0 GB (25.8 GB usable)

   Compiling spacetimedb-core v0.12.0 (C:\Proyectos\space\SpacetimeDB\crates\core)
   Compiling spacetimedb-client-api v0.12.0 (C:\Proyectos\space\SpacetimeDB\crates\client-api)
   Compiling spacetimedb-standalone v0.12.0 (C:\Proyectos\space\SpacetimeDB\crates\standalone)   

OpenSSL:

    Finished `dev` profile [unoptimized + debuginfo] target(s) in 4m 01s
    Finished `release` profile [optimized] target(s) in 4m 39s    

RusTls:

    Finished `dev` profile [unoptimized + debuginfo] target(s) in 1m 21s
    Finished `release` profile [optimized] target(s) in 2m 02s    

Expected complexity level and risk

*How complicated do you think these changes are? Grade on a scale from 1 to 5,

3

It looks correct to me the generation and reading of keys. However, even if trivial, changing libraries that do crypto requires careful eyes.

Testing

  • * Check using https://8gwifi.org/PemParserFunctions.jsp that we use the same algorithms and settings as from openssl.*
  • Publish quickstart and re-read the keys
  • Manual inspection of the keys and config files

@mamcx mamcx added release-any To be landed in any release window no runtime change This change does not affect the final binaries labels Sep 11, 2024
@mamcx mamcx self-assigned this Sep 11, 2024
@gefjon
Copy link
Copy Markdown
Contributor

gefjon commented Sep 11, 2024

I strongly request that we not do potentially dangerous changes which are not intended to be API breaks within the 0.12 release window. This can, and therefore should, wait.

@mamcx mamcx marked this pull request as draft September 11, 2024 19:16
@mamcx
Copy link
Copy Markdown
Contributor Author

mamcx commented Sep 11, 2024

Changed to draft so we don't merge yet

@mamcx mamcx force-pushed the mamcx/openssl_no_more branch from 40c7d9d to 1f9c3d8 Compare September 11, 2024 19:25
@mamcx
Copy link
Copy Markdown
Contributor Author

mamcx commented Sep 12, 2024

Btw, this adds cmake as a requirement on Windows.

@RReverser
Copy link
Copy Markdown
Contributor

RReverser commented Sep 12, 2024

Btw, this adds [cmake](https://aws.github.io/aws-lc-rs/requirements/windows0 as a requirement on Windows.

Sigh. It's somewhat unfortunate to replace one external dependency for Windows devs (Perl or prebuilt OpenSSL) with another (CMake).

@mamcx
Copy link
Copy Markdown
Contributor Author

mamcx commented Nov 14, 2024

Is now good time to change this from Draft?

@mamcx mamcx requested a review from gefjon November 20, 2024 15:55
@mamcx mamcx marked this pull request as ready for review December 12, 2024 17:33
@mamcx mamcx force-pushed the mamcx/openssl_no_more branch 2 times, most recently from f48a869 to 97a1c00 Compare December 13, 2024 18:30
@dare3path
Copy link
Copy Markdown

closes #1504

@bfops bfops linked an issue Apr 14, 2025 that may be closed by this pull request
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 3, 2025

CLA assistant check
All committers have signed the CLA.

@mamcx mamcx mentioned this pull request May 5, 2025
3 tasks
@bfops bfops linked an issue Jun 22, 2025 that may be closed by this pull request
github-merge-queue Bot pushed a commit that referenced this pull request Sep 10, 2025
# Description of Changes

Closes
[#2686](#2686).

Add support for listening using the [PG wire
protocol](https://www.postgresql.org/docs/current/protocol.html) so `pg`
clients could be used against the database.

# API and ABI breaking changes

The output of `duration` is changed to `rfc3339`, instead of the way is
made with `sats` because is what is done in `pg`, see note below.

# Expected complexity level and risk

2

~~There is open questions that are in the [ticket
#2686](#2686). Also
the crate used here require `RustTls`, so it could be good idea to
decide if~~:

* ~~Rewrite a big chunk of code to use `OpenSSL`~~
* ~~Move to `RustTls`
#1700
* ~~Pay for the extra compilation cost~~.

I open another port(`5433`) to listen for `pg` connections using `ssl`.
Need to be decided if this is the way or instead try to multi-plex the
current port for both protocols.

# Testing

Only manual testing so far. Solving the above questions allow me to
implement some unit tests. Also, not yet integrated into cloud for the
same reasons.

- [x] Adding some test for the binary encoding of special and primitive
types
- [x] Smoke test using `psql` that connect to the db instance and run
some queries
- [x] Manually inspect using a UI database explorer how infer the types,
some of this tools generate special widgets when displaying `json,
duration, etc`

---------

Co-authored-by: Noa <coolreader18@gmail.com>
@bfops
Copy link
Copy Markdown
Collaborator

bfops commented Oct 14, 2025

openssl is a bunch of my build time on Ubuntu as well, so I was curious how this PR affects total build time (after rm -rf target/*).

master:

real	6m20.941s
user	7m28.604s
sys		1m14.316s

This branch:

real	4m48.625s
user	6m54.506s
sys		1m0.312s

So a meaningful improvement for me!

I don't really love that this swaps one outside-of-cargo dependency for another on Windows, but I can't speak to which one is more imposing for Windows users.

@mamcx mamcx force-pushed the mamcx/openssl_no_more branch from 248f51f to f3d8ccc Compare October 17, 2025 21:10
@mamcx mamcx marked this pull request as draft October 17, 2025 21:11
@mamcx mamcx force-pushed the mamcx/openssl_no_more branch from f3d8ccc to be9fc55 Compare October 20, 2025 16:22
@mamcx mamcx force-pushed the mamcx/openssl_no_more branch from be9fc55 to 546bcf3 Compare October 20, 2025 17:24
mamcx added a commit to clockworklabs/jwks that referenced this pull request Oct 20, 2025
This was referenced Oct 20, 2025
mamcx added a commit to clockworklabs/jwks that referenced this pull request Oct 21, 2025
@bfops bfops marked this pull request as ready for review March 19, 2026 16:06
Copy link
Copy Markdown
Contributor

@clockwork-labs-bot clockwork-labs-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review: Remove openssl (#1700)

Summary: Replaces the openssl crate (with vendored openssl-src) with rcgen + p256 for key generation, and switches tokio-tungstenite/reqwest from native-tls to rustls. The motivation is clear: vendored OpenSSL is slow to compile, especially on Windows.

PEM Format Compatibility ✅

The critical question: do the new PEM outputs match what jsonwebtoken::DecodingKey::from_ec_pem() / EncodingKey::from_ec_pem() expect?

  • Public key: Both old (openssl::EcKey::public_key_to_pem() via PEM_write_bio_EC_PUBKEY) and new (rcgen::KeyPair::public_key_pem()) produce -----BEGIN PUBLIC KEY----- (SPKI format). ✅
  • Private key: Both old (PKey::private_key_to_pem_pkcs8()) and new (rcgen::KeyPair::serialize_pem()) produce -----BEGIN PRIVATE KEY----- (PKCS#8 format). ✅
  • Backward compatibility: Existing key files on disk are read by the unchanged JwtKeys::new() path, which passes PEM bytes directly to jsonwebtoken. Since the PEM tags are identical, existing keys will continue to work. ✅
  • Curve: Both use P-256 (Nid::X9_62_PRIME256V1 == PKCS_ECDSA_P256_SHA256). ✅

Swapped comments (cosmetic)

// Get the private key in PKCS#8 PEM format & write it.  // <-- says "private"
let public_key_bytes = key_pair.public_key_pem().into_bytes();  // <-- assigns public

// Get the public key in PEM format & write it.  // <-- says "public"
let private_key_bytes = key_pair.serialize_pem().into_bytes();  // <-- assigns private

The assignment is correct but the comments are swapped from the original and now misleading. Please swap them.

TLS backend change

  • tokio-tungstenite: native-tlsrustls
  • reqwest: Added rustls-tls feature, but native-tls is still a transitive dependency (via reqwest's default features). Consider whether you want to disable default features and use only rustls-tls to fully remove the native-tls dependency.

Test changes ✅

The to_jwk_json helper in token_validation.rs tests was updated from openssl to p256 for extracting EC point coordinates. The logic is equivalent and cleaner.

Missing test coverage

There are no tests for EcKeyPair::generate() or the roundtrip of generating keys → creating JwtKeys → signing a JWT → verifying the JWT. The existing tests in token_validation.rs exercise JwtKeys::generate() (which calls EcKeyPair::generate()) indirectly, but a direct unit test would be valuable. Suggested tests:

  1. Key generation roundtrip: Generate an EcKeyPair, convert to JwtKeys, sign a JWT, verify it with the public key.
  2. PEM format assertions: Generate keys and verify the PEM headers (BEGIN PUBLIC KEY, BEGIN PRIVATE KEY).
  3. Cross-library compatibility: Generate keys with the new code, verify the PEM can be parsed by jsonwebtoken (this is essentially what test 1 does).
  4. Write/read roundtrip: Write keys to temp files, read them back, verify they produce valid JwtKeys.

I can add these tests if you'd like.

Verdict

The core change is sound. PEM formats are compatible, the curve is correct, and existing key files will continue to work. The swapped comments should be fixed. The TLS backend change is a nice bonus.

- Fix misleading comments on public/private key generation
- Add 5 unit tests covering the key generation change:
  - PEM format headers are correct (BEGIN PUBLIC KEY / BEGIN PRIVATE KEY)
  - Sign/verify roundtrip with generated keys
  - Two generated key pairs are distinct
  - Cross-verification with wrong key fails
  - Write to disk / read back roundtrip
@bfops bfops marked this pull request as draft March 19, 2026 16:38
bfops and others added 3 commits March 19, 2026 09:42
…ub.com:clockworklabs/SpacetimeDB into mamcx/openssl_no_more
- Set default-features = false for reqwest in workspace Cargo.toml,
  keeping stream, json, rustls-tls, and http2 features
- Fix xtask-llm-benchmark to also disable reqwest default features
  (was re-enabling native-tls via Cargo feature unification)
- Remove native-tls version pin from Rust SDK (no longer needed
  since nothing depends on native-tls anymore)

This fully removes the native-tls -> openssl-sys dependency chain
from reqwest 0.12. The only remaining openssl-sys dependency is
from git2/libgit2-sys (unrelated to TLS).
Comment thread .github/workflows/ci.yml
cargo build -p v8
fi

# This step shouldn't be needed, but somehow we end up with caches that are missing librusty_v8.a.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added this since we now build in release mode here, and we started hitting this issue again.

I still have no idea why this happens since we no longer cache-on-failure, but.. /shrug.

@cloutiertyler cloutiertyler added possibly-stale close-stale-pr-create-issue Indicates that the PR is substantially out of date, and should become an issue to reimplement. labels Apr 13, 2026
@clockwork-labs-bot
Copy link
Copy Markdown
Contributor

Closing this stale PR in favor of #4833, which tracks reimplementing the work on top of current master. Keeping this PR around as historical context and source material.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

close-stale-pr-create-issue Indicates that the PR is substantially out of date, and should become an issue to reimplement. no runtime change This change does not affect the final binaries possibly-stale release-any To be landed in any release window

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optional **rustls** TLS backend for spacetimedb-sdk Remove dependency on openssl

8 participants