crypto: add crypto::GetSSLCtx API for addon access to OpenSSL contexts#62254
crypto: add crypto::GetSSLCtx API for addon access to OpenSSL contexts#62254pimterry wants to merge 2 commits intonodejs:mainfrom
Conversation
|
Review requested:
|
This intended to replace usage of the unsupported _external field, offering an official API for native addons to access OpenSSL directly while reducing the JS API and internal field exposure.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #62254 +/- ##
==========================================
- Coverage 89.66% 89.66% -0.01%
==========================================
Files 676 676
Lines 206500 206572 +72
Branches 39539 39555 +16
==========================================
+ Hits 185168 185231 +63
+ Misses 13463 13459 -4
- Partials 7869 7882 +13
🚀 New features to boost your workflow:
|
| @@ -0,0 +1,52 @@ | |||
| #include <node.h> | |||
| #include <openssl/ssl.h> | |||
There was a problem hiding this comment.
You probably need OpenSSL-available guards here as well, but I think CI will tell whether that's the case
There was a problem hiding this comment.
I think it probably doesn't, and the other openssl addons test don't. I think this is covered by the binding build config.
| if (!value.As<v8::Object>() | ||
| ->Get(context, FIXED_ONE_BYTE_STRING(env->isolate(), "context")) | ||
| .ToLocal(&inner)) { | ||
| return nullptr; |
There was a problem hiding this comment.
This should be in a try/catch, right?
There was a problem hiding this comment.
Good point - done. Just swallowing the error here, which is a bit debatable, but this API currently just consistently returns null for other cases where no context is available and that seems reasonable for the native addon use case, so I'm inclined to keep it simple.
Once upon a time (#20237) we attempted to remove the
secureContext.context._externalfield which exposes OpenSSL contexts. This was later reverted (#21711) because it turns out there are external native addons which do want to integrate with Node's OpenSSL, and were using this JS API as it's currently the only way to do so.At the time, @sam-github said:
I think this makes a lot of sense. I'm in the process of building a native addon myself that needs access to OpenSSL contexts (user-space solution for #41112). I'd like to do this properly, without having to awkwardly hook onto internals like this.
This PR does that: creating a new
node::crypto::GetSSLCtxnative API, so C++ addons can access the OpenSSL context directly. With this in place, we could potentially drop_externalentirely from the JS API (and maybe even.context) in some future major bump. Naming is intended to match the SSL_CTX type and OpenSSL SSL_CTX_... APIs etc, but open to bikeshedding that further.This API itself should be easy to keep stable as OpenSSL changes, but obviously SSL_CTX won't be stable as it has APIs that will change as we upgrade OpenSSL versions etc. I think that's fine, there's clearly no real avoiding that and addons using this will have to be able to deal with OpenSSL changes like this appropriately. Reasonable given that it's a native-only API imo.