Skip to content
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

Handle certificates mentioned in HTTP connection during local entry deployment. #2243

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

chathuranga-jayanath-99

Purpose

Certificates specified in the HTTP connector connection need to be loaded into the respective JKS during the local entry deployment. Following this, the PassThroughHttpSSLSender have to be reloaded with the updated SSLContext.

@@ -0,0 +1,9 @@
package org.apache.synapse.transport.dynamicconfigurations;
Copy link
Member

Choose a reason for hiding this comment

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

Shall we add the license headers?

Copy link
Member

Choose a reason for hiding this comment

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

Please check other places as well.

File certificateFile = new File(certificateFilePath);
String certificateAlias = certificateFile.getName().split("\\.")[0];
try {
FileInputStream certificateFileInputStream = FileUtils.openInputStream(new File(certificateFilePath));
Copy link
Member

Choose a reason for hiding this comment

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

Shall we use try block with resources to close the stream automatically? Relevant to other input/output streams.

sslSenderTrustStoreHolder.setKeyStore(sslSenderTrustStore);
KeyStoreReloaderHolder.getInstance().reloadAllKeyStores();
} catch (CertificateException | IOException | KeyStoreException | NoSuchAlgorithmException e) {
throw new RuntimeException(e);
Copy link
Member

Choose a reason for hiding this comment

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

Rather than throwing a generic runtime exception, shall we add a more descriptive message?

ex: ("Failed to load certificate file to trust store", e)

Comment on lines +138 to +141
FileInputStream fileInputStream = new FileInputStream(sslSenderTrustStoreHolder.getLocation());
InputStream dest = IOUtils.toBufferedInputStream(fileInputStream);
fileInputStream.close();
sslSenderTrustStore.load(dest, sslSenderTrustStoreHolder.getPassword().toCharArray());
Copy link
Member

@Bhashinee Bhashinee Dec 2, 2024

Choose a reason for hiding this comment

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

Do we need these redundant truststore loads as we do it in line 145?

Choose a reason for hiding this comment

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

Yes. They represent 2 things. First load is to load the certificate to the JKS and the second load is used to load the new JKS and create a new connection.

try {
keyStoreLoader.loadKeyStore(transportOutDescription);
} catch (AxisFault e) {
throw new RuntimeException(e);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we throwing a runtime exception here? instead throw an AxisFault with a proper message.

public void testGetInstance() {
SslSenderTrustStoreHolder instance = SslSenderTrustStoreHolder.getInstance();
SslSenderTrustStoreHolder instance2 = SslSenderTrustStoreHolder.getInstance();
Assert.assertEquals(instance, instance2);
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add an assert message here.

@@ -79,6 +102,66 @@ public String deploySynapseArtifact(OMElement artifactConfig, String fileName,
return null;
}

private void handleHttpConnectorCertificates(OMElement element) throws DeploymentException {
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn;t have to be specific to http connector right? If so shall we change the method name?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants