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

Self Signed Certificates Refactor and Unit Test #404

Merged
merged 35 commits into from
Dec 5, 2024
Merged
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
3b02a19
Fix iterating over properties using incorrect source map.
uhurusurfa Nov 24, 2024
1a6186a
Fix the spelling on the class name for Base[r]ServerSetup
uhurusurfa Nov 26, 2024
b28524a
Support for multiple certificate keystores accessed by identifier.
uhurusurfa Nov 26, 2024
1b8c7e9
Support passing the self signed trust store into the HTTP context
uhurusurfa Nov 26, 2024
374c7cd
Add new properties for trust store and update test configs.
uhurusurfa Nov 26, 2024
1a3684f
Fix case when user does not choose a response.
uhurusurfa Nov 26, 2024
14eef8e
Add support for importing certs within the certificate factory.
uhurusurfa Nov 26, 2024
5e82422
Add identifiers for certificate factories.
uhurusurfa Nov 26, 2024
8f936ad
Support multiple certificate factories
uhurusurfa Nov 26, 2024
d165ab2
Refactor self signed certificate handling so that trust store is managed
uhurusurfa Nov 26, 2024
cc4fdfd
Fix deprecation warnings
uhurusurfa Nov 26, 2024
802b8b2
Standardise on config.dir property key
uhurusurfa Nov 26, 2024
f06a90f
Add new properties
uhurusurfa Nov 26, 2024
c5cada6
Fix tests failing after certificate factory changes
uhurusurfa Nov 26, 2024
503a22a
Upgrade packages to fix warnings
uhurusurfa Nov 28, 2024
16ede91
Remove unused imports
uhurusurfa Nov 28, 2024
1176c12
Support an "enabled" attribute on the component nodes
uhurusurfa Nov 28, 2024
c73257c
Make a standalone class for ENV replacement so it is reusable for
uhurusurfa Nov 28, 2024
d043876
Upgrade to 4.1.0
uhurusurfa Nov 28, 2024
400095e
Release notes for 4.1.0
uhurusurfa Nov 28, 2024
5f1cdce
Update dependencies to latest
uhurusurfa Nov 28, 2024
e2d3fbc
Prevent using milestone releases
uhurusurfa Nov 28, 2024
8dee6a0
Allow Healthcheck module to be fully configured by properties
uhurusurfa Nov 28, 2024
4778cc2
Removed all XML based config examples as part of move to properties.
uhurusurfa Nov 28, 2024
57704ab
Make methods public to failitate testing.
uhurusurfa Dec 4, 2024
c06cab4
Enhancements to support extended testing
uhurusurfa Dec 4, 2024
1368a08
Unit testing Self Signed Certificates for SSL
uhurusurfa Dec 4, 2024
325ecb0
Add properties to make modules fully configurable by props.
uhurusurfa Dec 4, 2024
762b340
Refactoring the AS2Message name
uhurusurfa Dec 4, 2024
8a1848e
Ensure self signed KeyManagers are in SSL Context
uhurusurfa Dec 4, 2024
6334921
Support PKCS12 certificate store for SSL certificates.
uhurusurfa Dec 4, 2024
d6643d9
Support certificate generation
uhurusurfa Dec 4, 2024
7059818
Update release notes
uhurusurfa Dec 4, 2024
4b84dca
Merge branch 'master' of https://github.com/OpenAS2/OpenAs2App.git into
uhurusurfa Dec 4, 2024
d5a3798
Cater for Windows mess with backslashes in file path when rendering as
uhurusurfa Dec 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Make a standalone class for ENV replacement so it is reusable for
property loading
uhurusurfa committed Nov 28, 2024
commit c73257c9ec69a785f4360e54702911c7784ba5c1
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package org.openas2.lib.util;

import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.openas2.OpenAS2Exception;


/**
* Supports replacing strings containing environment variable references wiht he value of the env var.
*/
public class StringEnvVarReplacer {
private static final Pattern ENV_VAR_PATTERN = Pattern.compile("\\$ENV\\{([^\\}]++)\\}");
private Map<String, String> envVars;
private final String HOME_DIR_PLACEHOLDER = "%home%";
private String appHomeDir = null;

public StringEnvVarReplacer() {
super();
this.envVars = System.getenv();
}

public StringEnvVarReplacer(Map<String, String> env_vars) {
super();
this.envVars = env_vars;
}

public void setEnvVarMap(Map<String, String> envVarMap) {
this.envVars = envVarMap;
}

public void setAppHomeDir(String appHomeDir) {
this.appHomeDir = appHomeDir;
}

public String replace(String input) throws OpenAS2Exception {
if (this.appHomeDir != null) {
input = input.replace(this.HOME_DIR_PLACEHOLDER, this.appHomeDir);
}
StringBuffer strBuf = new StringBuffer();
Matcher matcher = ENV_VAR_PATTERN.matcher(input);
while (matcher.find()) {
String key = matcher.group(1);
String value = envVars.get(key);

if (value == null) {
throw new OpenAS2Exception("Missing environment variable for replacement: " + matcher.group() + " Using key: " + key);
} else {
matcher.appendReplacement(strBuf, Matcher.quoteReplacement(value));
}
}
matcher.appendTail(strBuf);

return strBuf.toString();
}

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package org.openas2.lib.xml;

import org.openas2.OpenAS2Exception;
import org.openas2.lib.util.StringEnvVarReplacer;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.AttributesImpl;
import org.xml.sax.helpers.XMLFilterImpl;

import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
* Supports replacing XML element properties with system environment variables.
* An XML handler to support replacing XML element properties with system environment variables.
* Support for system properties is provided in the AS2Util.attributeEnhancer method
*
*/
@@ -23,32 +22,32 @@ public void endElement(String uri, String localName, String qName) throws SAXExc
super.endElement(uri, localName, qName);
}

private static final Pattern ENV_VAR_PATTERN = Pattern.compile("\\$ENV\\{([^\\}]++)\\}");
private final Map<String, String> env_vars;
private final String HOME_DIR_PLACEHOLDER = "%home%";
@SuppressWarnings("unused")
private String appHomeDir = null;
private final StringEnvVarReplacer envVarReplacer = new StringEnvVarReplacer();

public PropertyReplacementFilter() {
super();
this.env_vars = System.getenv();
envVarReplacer.setEnvVarMap(System.getenv());
}

public PropertyReplacementFilter(Map<String, String> env_vars) {
public PropertyReplacementFilter(Map<String, String> envVars) {
super();
this.env_vars = env_vars;
envVarReplacer.setEnvVarMap(envVars);
}

public PropertyReplacementFilter(XMLReader parent) {
this(parent, System.getenv());
}

public PropertyReplacementFilter(XMLReader parent, Map<String, String> env_vars) {
public PropertyReplacementFilter(XMLReader parent, Map<String, String> envVars) {
super(parent);
this.env_vars = env_vars;
envVarReplacer.setEnvVarMap(envVars);
}

public void setAppHomeDir(String appHomeDir) {
this.appHomeDir = appHomeDir;
envVarReplacer.setAppHomeDir(appHomeDir);
}

/**
@@ -58,7 +57,12 @@ public void setAppHomeDir(String appHomeDir) {
*/
@Override
public void characters(char[] data, int start, int length) throws SAXException {
char[] value = this.replace(String.copyValueOf(data, start, length)).toCharArray();
char[] value;
try {
value = envVarReplacer.replace(String.copyValueOf(data, start, length)).toCharArray();
} catch (OpenAS2Exception e) {
throw new SAXException(e);
}
super.characters(value, 0, value.length);
}

@@ -74,31 +78,13 @@ public void startElement(String uri, String localName, String qName, Attributes

int length = attributes.getLength();
for (int i = 0; i < length; ++i) {
attributes.setValue(i, this.replace(attributes.getValue(i)));
}

super.startElement(uri, localName, qName, attributes);
}

private String replace(String input) throws SAXException {
if (this.appHomeDir != null) {
input = input.replace(this.HOME_DIR_PLACEHOLDER, this.appHomeDir);
}
StringBuffer strBuf = new StringBuffer();
Matcher matcher = ENV_VAR_PATTERN.matcher(input);
while (matcher.find()) {
String key = matcher.group(1);
String value = env_vars.get(key);

if (value == null) {
throw new SAXException("Missing environment variable for replacement: " + matcher.group() + " Using key: " + key);
} else {
matcher.appendReplacement(strBuf, Matcher.quoteReplacement(value));
try {
attributes.setValue(i, envVarReplacer.replace(attributes.getValue(i)));
} catch (OpenAS2Exception e) {
throw new SAXException(e);
}
}
matcher.appendTail(strBuf);

return strBuf.toString();
super.startElement(uri, localName, qName, attributes);
}

}