-
Notifications
You must be signed in to change notification settings - Fork 51
Fix #462: verify Thrift TLS server certificate by default [PECOBLR-3837][SEC-20280] #463
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
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
055fc81
Fix #462: verify Thrift TLS server certificate by default
msrathore-db 2dad965
Merge remote-tracking branch 'origin/main' into fix/issue-462-thrift-…
msrathore-db b28ee14
fix(ci): clear security-scan CVE findings
msrathore-db ecee476
ai: apply changes for #463 (4 review threads)
peco-engineer-bot[bot] 18ee36f
ai: apply changes for #463 (1 review thread)
peco-engineer-bot[bot] 81ce468
ai: apply changes for #463 (1 review thread)
peco-engineer-bot[bot] 884c76f
ai: apply changes for #463 (1 review thread)
peco-engineer-bot[bot] 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import HiveDriverError from '../errors/HiveDriverError'; | ||
|
|
||
| /** | ||
| * Normalise a PEM input (`string` or `Buffer`) accepted on the public surface | ||
| * into a `Buffer`. Does a light, ordered BEGIN…END sanity check so a | ||
| * truncated/headerless/DER blob (or a stray page that merely contains the | ||
| * literals out of order, e.g. a proxy-intercept page) is rejected here rather | ||
| * than surfacing as an opaque TLS handshake error further down. The bytes are | ||
| * NOT fully parsed in JS — that is deferred to the TLS stack, which returns a | ||
| * meaningful error on a malformed PEM/key. | ||
| * | ||
| * `kind` selects the expected block: `'certificate'` matches a `CERTIFICATE` | ||
| * block; `'private key'` matches any `… PRIVATE KEY` block (PKCS#8 `PRIVATE | ||
| * KEY`, PKCS#1 `RSA PRIVATE KEY`, SEC1 `EC PRIVATE KEY`). | ||
| * | ||
| * `backendLabel` prefixes the error message so the caller (e.g. `DBSQLClient` | ||
| * on the Thrift path, `kernel backend` on the kernel path) is named accurately. | ||
| * | ||
| * Throws `HiveDriverError` when the value is empty or (for strings) lacks the | ||
| * expected PEM header. | ||
| */ | ||
| export default function normalizePemBytes( | ||
| value: Buffer | string, | ||
| optionName: string, | ||
| kind: 'certificate' | 'private key', | ||
| backendLabel: string, | ||
| ): Buffer { | ||
| if (typeof value === 'string') { | ||
| const re = | ||
| kind === 'certificate' | ||
| ? /-----BEGIN CERTIFICATE-----[\s\S]+?-----END CERTIFICATE-----/ | ||
| : /-----BEGIN [A-Z0-9 ]*PRIVATE KEY-----[\s\S]+?-----END [A-Z0-9 ]*PRIVATE KEY-----/; | ||
| if (!re.test(value)) { | ||
| const expected = | ||
| kind === 'certificate' | ||
| ? "a '-----BEGIN CERTIFICATE-----' … '-----END CERTIFICATE-----' block" | ||
| : "a 'BEGIN … PRIVATE KEY' / 'END … PRIVATE KEY' PEM block (PKCS#8, PKCS#1, or SEC1)"; | ||
| throw new HiveDriverError( | ||
| `${backendLabel}: \`${optionName}\` string does not look like a PEM ${kind} (expected ${expected}). ` + | ||
| 'Pass PEM text or a Buffer of PEM bytes.', | ||
| ); | ||
| } | ||
| return Buffer.from(value, 'utf8'); | ||
| } | ||
| if (Buffer.isBuffer(value)) { | ||
| if (value.length === 0) { | ||
| throw new HiveDriverError(`${backendLabel}: \`${optionName}\` Buffer is empty.`); | ||
| } | ||
| return value; | ||
| } | ||
| throw new HiveDriverError(`${backendLabel}: \`${optionName}\` must be a PEM string or a Buffer.`); | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.