-
Notifications
You must be signed in to change notification settings - Fork 64
feat: Add jks to supported formats #6153
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
emincihangeri
wants to merge
14
commits into
main
Choose a base branch
from
support-jks
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
Show all changes
14 commits
Select commit
Hold shift + click to select a range
81852dc
feat: Add jks to supported formats
7426a58
chore: Test jks format
7ba444e
Merge branch 'main' into support-jks
emincihangeri 9eafa68
chore: Update changeset
091ebc5
Changes from lint:fix
e90a58d
chore: Create mock data for test
880f322
Merge branch 'main' into support-jks
emincihangeri d14c340
Changes from lint:fix
b3c06e4
Merge branch 'main' into support-jks
KavithaSiva be8b05c
chore: Clean
5c00441
Merge branch 'main' into support-jks
emincihangeri 056a996
Changes from lint:fix
3311cd4
Update packages/connectivity/src/http-agent/http-agent.ts
emincihangeri e20bfc9
Changes from lint:fix
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@sap-cloud-sdk/connectivity': minor | ||
| --- | ||
|
|
||
| [New Functionality] Support certificates in JKS format for `ClientCertificateAuthentication`. |
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,6 +1,7 @@ | ||||||
| import { readFile } from 'fs/promises'; | ||||||
| import http from 'http'; | ||||||
| import https from 'https'; | ||||||
| import * as jks from 'jks-js'; | ||||||
| import { createLogger, last } from '@sap-cloud-sdk/util'; | ||||||
| /* Careful the proxy imports cause circular dependencies if imported from scp directly */ | ||||||
| // eslint-disable-next-line import/no-internal-modules | ||||||
|
|
@@ -132,6 +133,33 @@ function getKeyStoreOptions(destination: Destination): | |||||
|
|
||||||
| const certBuffer = Buffer.from(certificate.content, 'base64'); | ||||||
|
|
||||||
| if ( | ||||||
| getFormat(certificate) === 'jks' || | ||||||
| getFormat(certificate) === 'keystore' | ||||||
| ) { | ||||||
| if (!destination.keyStorePassword) { | ||||||
| throw Error('Keystore password is required for JKS format'); | ||||||
| } | ||||||
| const pemKeystore = jks.toPem(certBuffer, destination.keyStorePassword); | ||||||
| const aliases = Object.keys(pemKeystore); | ||||||
| if (aliases.length === 0) { | ||||||
| throw Error('No entries found in JKS keystore'); | ||||||
| } | ||||||
| if (aliases.length > 1) { | ||||||
| throw Error( | ||||||
| 'Multiple entries found in JKS keystore; only a single entry is supported' | ||||||
| ); | ||||||
| } | ||||||
| const alias = aliases[0]; // Use first alias | ||||||
emincihangeri marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| const entry = pemKeystore[alias]; | ||||||
| if (!entry.cert || !entry.key) { | ||||||
| throw Error('Invalid JKS entry: missing cert or key'); | ||||||
| } | ||||||
| return { | ||||||
| cert: Buffer.from(entry.cert, 'utf8'), | ||||||
| key: Buffer.from(entry.key, 'utf8') | ||||||
| }; | ||||||
| } | ||||||
| // if the format is pem, the key and certificate needs to be passed separately | ||||||
| // it could be required to separate the string into two parts, but this seems to work as well | ||||||
| if (getFormat(certificate) === 'pem') { | ||||||
|
|
@@ -207,7 +235,7 @@ function mtlsIsEnabled(destination: Destination) { | |||||
| /* | ||||||
| The node client supports only these store formats https://nodejs.org/api/tls.html#tlscreatesecurecontextoptions. | ||||||
| */ | ||||||
| const supportedCertificateFormats = ['p12', 'pfx', 'pem']; | ||||||
| const supportedCertificateFormats = ['p12', 'pfx', 'pem', 'jks']; | ||||||
|
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. Not completely sure, but I think this can be listed there too now:
Suggested change
|
||||||
|
|
||||||
| function isSupportedFormat(format: string | undefined): boolean { | ||||||
| return !!format && supportedCertificateFormats.includes(format); | ||||||
|
|
||||||
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.
AFAICT this is optional and removing it might help with the most recent update by the user.