-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
quic: add proper error codes & messages for QUIC failures #63198
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
Open
pimterry
wants to merge
1
commit into
nodejs:main
Choose a base branch
from
pimterry:fix-quic-error-codes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,14 @@ | ||
| #if HAVE_OPENSSL && HAVE_QUIC | ||
| #include "guard.h" | ||
| #ifndef OPENSSL_NO_QUIC | ||
| #include "data.h" | ||
| #include <env-inl.h> | ||
| #include <memory_tracker-inl.h> | ||
| #include <ngtcp2/ngtcp2.h> | ||
| #include <node_sockaddr-inl.h> | ||
| #include <openssl/ssl.h> | ||
| #include <string_bytes.h> | ||
| #include <v8.h> | ||
| #include "data.h" | ||
| #include "defs.h" | ||
| #include "util.h" | ||
|
|
||
|
|
@@ -346,6 +347,62 @@ std::optional<int> QuicError::get_crypto_error() const { | |
| return code() & ~NGTCP2_CRYPTO_ERROR; | ||
| } | ||
|
|
||
| const char* QuicError::name() const { | ||
| // CRYPTO_ERROR carries a TLS alert in its low byte (RFC 9001 sec. 4.8). | ||
| // OpenSSL's SSL_alert_desc_string_long owns a stable string for every | ||
| // alert it knows about; we filter out the "unknown" placeholder so the | ||
| // JS side can present `errorName` as undefined for unrecognised alerts. | ||
| if (auto alert = get_crypto_error()) { | ||
| const char* n = SSL_alert_desc_string_long(*alert); | ||
| if (n != nullptr && std::string_view(n) != "unknown") return n; | ||
| return nullptr; | ||
| } | ||
| // Named transport-layer error codes from RFC 9000 sec. 20.1 (and the | ||
| // RFC 9368 version-negotiation extension). Application error codes are | ||
| // opaque to QUIC, so we only decode for transport. | ||
| if (type() != Type::TRANSPORT) return nullptr; | ||
| switch (code()) { | ||
| case NGTCP2_NO_ERROR: | ||
| return "NO_ERROR"; | ||
| case NGTCP2_INTERNAL_ERROR: | ||
| return "INTERNAL_ERROR"; | ||
| case NGTCP2_CONNECTION_REFUSED: | ||
| return "CONNECTION_REFUSED"; | ||
| case NGTCP2_FLOW_CONTROL_ERROR: | ||
| return "FLOW_CONTROL_ERROR"; | ||
| case NGTCP2_STREAM_LIMIT_ERROR: | ||
| return "STREAM_LIMIT_ERROR"; | ||
| case NGTCP2_STREAM_STATE_ERROR: | ||
| return "STREAM_STATE_ERROR"; | ||
| case NGTCP2_FINAL_SIZE_ERROR: | ||
| return "FINAL_SIZE_ERROR"; | ||
| case NGTCP2_FRAME_ENCODING_ERROR: | ||
| return "FRAME_ENCODING_ERROR"; | ||
| case NGTCP2_TRANSPORT_PARAMETER_ERROR: | ||
| return "TRANSPORT_PARAMETER_ERROR"; | ||
| case NGTCP2_CONNECTION_ID_LIMIT_ERROR: | ||
| return "CONNECTION_ID_LIMIT_ERROR"; | ||
| case NGTCP2_PROTOCOL_VIOLATION: | ||
| return "PROTOCOL_VIOLATION"; | ||
| case NGTCP2_INVALID_TOKEN: | ||
| return "INVALID_TOKEN"; | ||
| case NGTCP2_APPLICATION_ERROR: | ||
| return "APPLICATION_ERROR"; | ||
| case NGTCP2_CRYPTO_BUFFER_EXCEEDED: | ||
| return "CRYPTO_BUFFER_EXCEEDED"; | ||
| case NGTCP2_KEY_UPDATE_ERROR: | ||
| return "KEY_UPDATE_ERROR"; | ||
| case NGTCP2_AEAD_LIMIT_REACHED: | ||
| return "AEAD_LIMIT_REACHED"; | ||
| case NGTCP2_NO_VIABLE_PATH: | ||
| return "NO_VIABLE_PATH"; | ||
| case NGTCP2_VERSION_NEGOTIATION_ERROR: | ||
| return "VERSION_NEGOTIATION_ERROR"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since this set is stable, we should just add them as strings on the quic |
||
| default: | ||
| return nullptr; | ||
| } | ||
| } | ||
|
|
||
| MaybeLocal<Value> QuicError::ToV8Value(Environment* env) const { | ||
| if ((type() == Type::TRANSPORT && code() == NGTCP2_NO_ERROR) || | ||
| (type() == Type::APPLICATION && code() == NGHTTP3_H3_NO_ERROR) || | ||
|
|
@@ -367,6 +424,7 @@ MaybeLocal<Value> QuicError::ToV8Value(Environment* env) const { | |
| type_str, | ||
| BigInt::NewFromUnsigned(env->isolate(), code()), | ||
| Undefined(env->isolate()), | ||
| Undefined(env->isolate()), | ||
| }; | ||
|
|
||
| // Note that per the QUIC specification, the reason, if present, is | ||
|
|
@@ -380,6 +438,15 @@ MaybeLocal<Value> QuicError::ToV8Value(Environment* env) const { | |
| return {}; | ||
| } | ||
|
|
||
| // Attach a human-readable name for known wire codes (RFC 9000 sec. 20.1 | ||
| // names and OpenSSL TLS alert descriptions for CRYPTO_ERROR). Unknown | ||
| // codes leave the slot as undefined. | ||
| if (const char* n = name()) { | ||
| if (!node::ToV8Value(env->context(), n).ToLocal(&argv[3])) { | ||
| return {}; | ||
| } | ||
| } | ||
|
|
||
| return Array::New(env->isolate(), argv, arraysize(argv)).As<Value>(); | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have the
QuicErrorobject, we should likely make use of it in here as well. Thecodecan remain the same. No need to change it in this PR but for consistency, any error that includes the QUIC error code should useQuicError