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
Support for multiple certificate keystores accessed by identifier.
uhurusurfa committed Nov 26, 2024
commit b28524ad41e2430f5e79f7a5521b6c8a9fd68f87
2 changes: 1 addition & 1 deletion Server/src/main/java/CheckCertificate.java
Original file line number Diff line number Diff line change
@@ -221,7 +221,7 @@ public int CheckCertStore(String host, int port, String uri, String targetKeySto

private void checkUsingApacheHttp(String host, int port, String uri, String targetKeyStore, String keyStorePwd) throws Exception {
System.out.println("Trying using Apache HTTP Client...");
Map<String, String> httpOptions = new HashMap<String, String>();
Map<String, Object> httpOptions = new HashMap<String, Object>();
if (auth_user != null) {
httpOptions.put(HTTPUtil.PARAM_HTTP_USER, auth_user);
httpOptions.put(HTTPUtil.PARAM_HTTP_PWD, auth_pwd);
2 changes: 1 addition & 1 deletion Server/src/main/java/org/openas2/Session.java
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ public interface Session {
* @see CertificateFactory
* @see Component
*/
CertificateFactory getCertificateFactory() throws ComponentNotFoundException;
CertificateFactory getCertificateFactory(String componentID) throws ComponentNotFoundException;

/**
* Gets the <code>Component</code> currently registered with an ID
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ public abstract class AliasedCertCommand extends BaseCommand {
public CommandResult execute(Object[] params) {

try {
CertificateFactory certFx = getSession().getCertificateFactory();
CertificateFactory certFx = getSession().getCertificateFactory(CertificateFactory.COMPID_AS2_CERTIFICATE_FACTORY);

if (certFx instanceof AliasedCertificateFactory) {
return execute((AliasedCertificateFactory) certFx, params);
5 changes: 4 additions & 1 deletion Server/src/main/java/org/openas2/cmd/XMLCommandRegistry.java
Original file line number Diff line number Diff line change
@@ -63,7 +63,10 @@ public void refresh() throws OpenAS2Exception {

protected void loadCommand(Node node, MultiCommand parent) throws OpenAS2Exception {
Command cmd = (Command) XMLUtil.getComponent(node, getSession());

if (cmd == null) {
// Must be disabled so do nothing
return;
}
if (parent != null) {
parent.getCommands().add(cmd);
} else {
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.openas2.cert.AliasedCertificateFactory;
import org.openas2.cert.CertificateFactory;
import org.openas2.cmd.CommandResult;
import org.openas2.cmd.processor.RestCommandProcessor;

@@ -225,7 +226,7 @@ private CommandResult importCertificateByStream(String itemId, MultivaluedMap<St
params.add("importbystream");
params.add(itemId);
String payload = formParams.getFirst("data");
AliasedCertificateFactory certFx = (AliasedCertificateFactory) getProcessor().getSession().getCertificateFactory();
AliasedCertificateFactory certFx = (AliasedCertificateFactory) getProcessor().getSession().getCertificateFactory(CertificateFactory.COMPID_AS2_CERTIFICATE_FACTORY);
ByteArrayInputStream bais = new ByteArrayInputStream(Base64.getDecoder().decode(payload));

java.security.cert.CertificateFactory cf = java.security.cert.CertificateFactory.getInstance("X.509");
Original file line number Diff line number Diff line change
@@ -311,7 +311,7 @@ protected AS2Message createMessage(Socket s) {
}

protected String decryptAndVerify(AS2Message msg) throws OpenAS2Exception {
CertificateFactory certFx = getModule().getSession().getCertificateFactory();
CertificateFactory certFx = getModule().getSession().getCertificateFactory(CertificateFactory.COMPID_AS2_CERTIFICATE_FACTORY);
ICryptoHelper ch;
String mic = null;

@@ -633,7 +633,7 @@ public void createMDNData(Session session, MessageMDN mdn, String micAlg, String
reportPart.setHeader(MimeUtil.MIME_CONTENT_TYPE_KEY, unfoldHeaders?MimeUtility.unfold(reportMultiPart.getContentType()):reportMultiPart.getContentType());
// Sign the data if needed
if (signatureProtocol != null) {
CertificateFactory certFx = session.getCertificateFactory();
CertificateFactory certFx = session.getCertificateFactory(CertificateFactory.COMPID_AS2_CERTIFICATE_FACTORY);

try {
// The receiver of the original message is the sender of the MDN - sign with the receivers private key
Original file line number Diff line number Diff line change
@@ -102,7 +102,7 @@ public boolean healthcheck(List<String> failures) {
if (logger.isTraceEnabled()) {
logger.trace("Helthcheck about to try URL: " + urlString);
}
Map<String, String> options = new HashMap<String, String>();
Map<String, Object> options = new HashMap<String, Object>();
options.put(HTTPUtil.HTTP_PROP_OVERRIDE_SSL_CHECKS, "true");
ResponseWrapper rw = HTTPUtil.execRequest(HTTPUtil.Method.GET, urlString, null, null, null, options, 0L, false);
if (200 != rw.getStatusCode()) {
Original file line number Diff line number Diff line change
@@ -183,7 +183,7 @@ private void sendMessage(String url, Message msg, MimeBodyPart securedData) thro
logger.info("Connecting to: " + url + msg.getLogMsgID());
}

Map<String, String> httpOptions = getHttpOptions();
Map<String, Object> httpOptions = getHttpOptions();
httpOptions.put(HTTPUtil.PARAM_HTTP_USER, msg.getPartnership().getAttribute(HTTPUtil.PARAM_HTTP_USER));
httpOptions.put(HTTPUtil.PARAM_HTTP_PWD, msg.getPartnership().getAttribute(HTTPUtil.PARAM_HTTP_PWD));
long maxSize = msg.getPartnership().getNoChunkedMaxSize();
@@ -331,7 +331,7 @@ protected MimeBodyPart secure(Message msg) throws Exception {
dataBP = AS2Util.getCryptoHelper().compress(msg, dataBP, compressionType, contentTxfrEncoding);
}
// Encrypt and/or sign the data if requested
CertificateFactory certFx = getSession().getCertificateFactory();
CertificateFactory certFx = getSession().getCertificateFactory(CertificateFactory.COMPID_AS2_CERTIFICATE_FACTORY);

// Sign the data if requested
if (sign) {
Original file line number Diff line number Diff line change
@@ -142,7 +142,7 @@ private boolean sendAsyncMDN(MessageMDN mdn, String url, DispositionType disposi
logger.debug("ASYNC MDN attempting connection to: " + url + mdn.getMessage().getLogMsgID());
}
long maxSize = msg.getPartnership().getNoChunkedMaxSize();
Map<String, String> httpOptions = getHttpOptions();
Map<String, Object> httpOptions = getHttpOptions();
httpOptions.put(HTTPUtil.PARAM_HTTP_USER, msg.getPartnership().getAttribute(HTTPUtil.PARAM_HTTP_USER));
httpOptions.put(HTTPUtil.PARAM_HTTP_PWD, msg.getPartnership().getAttribute(HTTPUtil.PARAM_HTTP_PWD));
// Convert the MimebodyPart to a string so we know how big it is to set Content-Length
Original file line number Diff line number Diff line change
@@ -105,7 +105,7 @@ public static void main(String[] args) {
session.getPartnershipFactory().updatePartnership(msg, true);
msg.updateMessageID();

CertificateFactory certFx = session.getCertificateFactory();
CertificateFactory certFx = session.getCertificateFactory(CertificateFactory.COMPID_AS2_CERTIFICATE_FACTORY);
String x509_alias = msg.getPartnership().getAlias(Partnership.PTYPE_SENDER);
X509Certificate senderCert = certFx.getCertificate(x509_alias);

13 changes: 10 additions & 3 deletions Server/src/main/java/org/openas2/util/AS2Util.java
Original file line number Diff line number Diff line change
@@ -54,13 +54,20 @@ public static ICryptoHelper getCryptoHelper() throws Exception {

public static String generateMessageID(Message msg, boolean isMDN) throws InvalidParameterException {
String idFormat = null;
CompositeParameters params = new CompositeParameters(false).add("date", new DateParameters()).add("msg", new MessageParameters(msg)).add("rand", new RandomParameters());
CompositeParameters params = new CompositeParameters(
false).add("date",
new DateParameters()).add("msg",
new MessageParameters(msg)).add("rand",new RandomParameters()
);
if (isMDN) {
params.add("mdn", new MessageMDNParameters(msg.getMDN()));
idFormat = msg.getPartnership().getAttributeOrProperty(Properties.AS2_MDN_MESSAGE_ID_FORMAT, null);
}
if (idFormat == null) {
idFormat = msg.getPartnership().getAttributeOrProperty(Properties.AS2_MESSAGE_ID_FORMAT, "<OPENAS2-$date.ddMMyyyyHHmmssZ$-$rand.UUID$@$msg.sender.as2_id$_$msg.receiver.as2_id$>");
idFormat = msg.getPartnership().getAttributeOrProperty(
Properties.AS2_MESSAGE_ID_FORMAT,
"<OPENAS2-$date.ddMMyyyyHHmmssZ$-$rand.UUID$@$msg.sender.as2_id$_$msg.receiver.as2_id$>"
);
}
String id = ParameterParser.parse(idFormat, params);
// RFC822 requires enclosing message in <> but AS2 spec provides for this to be
@@ -497,7 +504,7 @@ public static boolean processMDN(AS2Message msg, byte[] data, OutputStream out,
logger.error(msg.getLogMsg(), e1);
return AS2Util.resend(session, sourceClass, SenderModule.DO_SEND, msg, new OpenAS2Exception(e1), true, false);
}
CertificateFactory cFx = session.getCertificateFactory();
CertificateFactory cFx = session.getCertificateFactory(CertificateFactory.COMPID_AS2_CERTIFICATE_FACTORY);
String x509_alias = mdn.getPartnership().getAlias(Partnership.PTYPE_RECEIVER);
X509Certificate senderCert = cFx.getCertificate(x509_alias);

2 changes: 1 addition & 1 deletion Server/src/test/java/org/openas2/app/BaseServerSetup.java
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@
import org.openas2.util.Properties;


public class BaserServerSetup {
public class BaseServerSetup {
private static final TestResource RESOURCE = TestResource.forGroup("SingleServerTest");
static String myCompanyOid = "MyCompany_OID";
static String myPartnerOid = "PartnerA_OID";