Skip to content

Commit

Permalink
Merge pull request #9 from OpenAS2/dev
Browse files Browse the repository at this point in the history
Async MDN fix, resend retry count implementation, signed MIC calculation fix, improved handling of errors and numerous other bug fixes
  • Loading branch information
pete-gilchrist committed Nov 15, 2015
2 parents aba3712 + d034289 commit 7a352af
Show file tree
Hide file tree
Showing 31 changed files with 660 additions and 453 deletions.
15 changes: 10 additions & 5 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
OpenAS2 Server
Version 1.3.4
Version 1.3.5
RELEASE NOTES

The OpenAS2 project is pleased to announce the release of OpenAS2 1.3.4
The OpenAS2 project is pleased to announce the release of OpenAS2 1.3.5

The release download file is: OpenAS2Server-1.3.4.zip
The release download file is: OpenAS2Server-1.3.5.zip
The zip file contains a PDF document providing information on installing and using the application.

This release is an enhancement release:
- add SHA224, SHA256, SHA384 and SHA512 encryption algorithms
This release is an enahncement and bugfix release:
- fix handling of file streams to ensure file handle is always closed
- fix async MDN functionality
- fix calculation of MIC when content is signed and compressed
- improved logic handling sending of MDN errors and HTTP responses
- add compiler option to build file to ensure java 1.5 compatibility
- add ability to control number of resend attempts

Java 1.5 or later is required.

Expand Down
6 changes: 5 additions & 1 deletion Remote/src/org/openas2/remote/OpenAS2Servlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@
*/
public class OpenAS2Servlet extends HttpServlet {

SocketLogging sl = null;
/**
*
*/
private static final long serialVersionUID = -625641001873163537L;
SocketLogging sl = null;
LogGetter lg = null;
ByteArrayOutputStream baos = null;
int logPort;
Expand Down
3 changes: 3 additions & 0 deletions Server/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<!-- Java sources -->
<property name="src.dir" location="${basedir}/src" />

<property name="ant.build.javac.source" value="1.5" />
<property name="ant.build.javac.target" value="1.5" />

<!-- Java classes -->
<property name="build.dir" location="${basedir}/build" />
<property name="lib.dir" location="${basedir}/lib" />
Expand Down
5 changes: 3 additions & 2 deletions Server/config/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@

<processor classname="org.openas2.processor.DefaultProcessor"
pendingMDN="%home%/../data/pendingMDN3"
pendingMDNinfo="%home%/../data/pendinginfoMDN3">
pendingMDNinfo="%home%/../data/pendinginfoMDN3"
resend_max_retries="10">


<module classname="org.openas2.processor.sender.AS2SenderModule">
Expand All @@ -57,7 +58,7 @@
delimiters="-."
sendfilename="true"
format="sender.as2_id, receiver.as2_id, attributes.fileid"
mimetype="application/EDI-X12"/>
mimetype="application/EDI-X12" />

<module classname="org.openas2.processor.receiver.AS2DirectoryPollingModule"
outboxdir="%home%/../data/toOpenAS2A/"
Expand Down
1 change: 1 addition & 0 deletions Server/config/partnerships.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<attribute name="as2_mdn_options" value="signed-receipt-protocol=optional, pkcs7-signature; signed-receipt-micalg=optional, SHA1"/>
<attribute name="encrypt" value="3DES"/>
<attribute name="sign" value="MD5"/>
<attribute name="resend_max_retries" value="3"/>
</partnership>

<partnership name="OpenAS2B-to-OpenAS2A">
Expand Down
Binary file not shown.
Binary file modified Server/lib/openas2-server.jar
Binary file not shown.
1 change: 1 addition & 0 deletions Server/src/org/openas2/OpenAS2Exception.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@ public void terminate() {
}

protected void log(boolean terminated) {
logger.error("Error occurred:: " + this.getMessage() + "\n Sources: "+ this.getSources(), this);
}
}
2 changes: 1 addition & 1 deletion Server/src/org/openas2/Session.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
public interface Session {
/** Official OpenAS2 release version */
public static final String VERSION = "1.3.4";
public static final String VERSION = "1.3.5";

/** Official OpenAS2 title */
public static final String TITLE = "OpenAS2 v" + VERSION;
Expand Down
40 changes: 32 additions & 8 deletions Server/src/org/openas2/lib/helper/BCCryptoHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,10 @@
import org.bouncycastle.asn1.pkcs.PKCSObjectIdentifiers;
import org.bouncycastle.asn1.pkcs.PrivateKeyInfo;
import org.bouncycastle.asn1.x500.X500Name;
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
import org.bouncycastle.cert.X509CertificateHolder;
import org.bouncycastle.cms.CMSAlgorithm;
import org.bouncycastle.cms.CMSException;
import org.bouncycastle.cms.KeyTransRecipientId;
import org.bouncycastle.cms.KeyTransRecipientInformation;
import org.bouncycastle.cms.Recipient;
import org.bouncycastle.cms.RecipientId;
import org.bouncycastle.cms.RecipientInformation;
import org.bouncycastle.cms.RecipientInformationStore;
import org.bouncycastle.cms.SignerInfoGenerator;
Expand All @@ -54,7 +50,6 @@
import org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoGeneratorBuilder;
import org.bouncycastle.cms.jcajce.JcaSimpleSignerInfoVerifierBuilder;
import org.bouncycastle.cms.jcajce.JceCMSContentEncryptorBuilder;
import org.bouncycastle.cms.jcajce.JceKeyTransRecipientId;
import org.bouncycastle.cms.jcajce.JceKeyTransRecipientInfoGenerator;
import org.bouncycastle.crypto.util.PrivateKeyFactory;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
Expand All @@ -64,7 +59,6 @@
import org.bouncycastle.mail.smime.SMIMESigned;
import org.bouncycastle.mail.smime.SMIMESignedGenerator;
import org.bouncycastle.mail.smime.SMIMEUtil;
import org.bouncycastle.operator.DefaultSignatureAlgorithmIdentifierFinder;
import org.bouncycastle.operator.OperatorCreationException;
import org.bouncycastle.operator.OutputEncryptor;
import org.bouncycastle.util.encoders.Base64;
Expand Down Expand Up @@ -99,6 +93,34 @@ public boolean isSigned(MimeBodyPart part) throws MessagingException {
return baseType.equalsIgnoreCase("multipart/signed");
}

public boolean isCompressed(MimeBodyPart part) throws MessagingException {
ContentType contentType = new ContentType(part.getContentType());
String baseType = contentType.getBaseType().toLowerCase();

if (logger.isTraceEnabled())
{
try
{
logger.trace("Compression check. MIME Base Content-Type:" + contentType.getBaseType());
logger.trace("Compression check. SMIME-TYPE:" + contentType.getParameter("smime-type"));
logger.trace("Compressed MIME msg AFTER COMPRESSION Content-Disposition:" + part.getDisposition());
} catch (MessagingException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
if (baseType.equalsIgnoreCase("application/pkcs7-mime")) {
String smimeType = contentType.getParameter("smime-type");
boolean checkResult = (smimeType != null) && smimeType.equalsIgnoreCase("compressed-data");
if (!checkResult && logger.isDebugEnabled())
logger.debug("Check for compressed data failed on SMIME content type: " + smimeType);
return (checkResult);
}
if (logger.isDebugEnabled()) logger.debug("Check for compressed data failed on BASE content type: " + baseType);
return false;
}

public String calculateMIC(MimeBodyPart part, String digest, boolean includeHeaders)
throws GeneralSecurityException, MessagingException, IOException {
String micAlg = convertAlgorithm(digest, true);
Expand Down Expand Up @@ -165,7 +187,8 @@ public MimeBodyPart decrypt(MimeBodyPart part, Certificate cert, Key key)

// Get the recipient object for decryption
if (logger.isDebugEnabled())
logger.debug("Extracted X500 info:: PRINCIPAL : " + x509Cert.getIssuerX500Principal() + " :: NAME : " + x509Cert.getIssuerX500Principal().getName());
logger.debug("Extracted X500 info:: PRINCIPAL : " + x509Cert.getIssuerX500Principal()
+ " :: NAME : " + x509Cert.getIssuerX500Principal().getName());

X500Name x500Name = new X500Name(x509Cert.getIssuerX500Principal().getName());
KeyTransRecipientId certRecId = new KeyTransRecipientId(x500Name,x509Cert.getSerialNumber());
Expand All @@ -191,7 +214,8 @@ public MimeBodyPart decrypt(MimeBodyPart part, Certificate cert, Key key)
if (certRecId.match(recipientInfo) && !foundRecipient) {
foundRecipient = true;
// byte[] decryptedData = recipientInfo.getContent(new JceKeyTransEnvelopedRecipient((PrivateKey)key).setProvider("BC"));
byte[] decryptedData = recipientInfo.getContent(new BcRSAKeyTransEnvelopedRecipient(PrivateKeyFactory.createKey(PrivateKeyInfo.getInstance(key.getEncoded()))));
byte[] decryptedData = recipientInfo.getContent(
new BcRSAKeyTransEnvelopedRecipient(PrivateKeyFactory.createKey(PrivateKeyInfo.getInstance(key.getEncoded()))));

return SMIMEUtil.toMimeBodyPart(decryptedData);
}
Expand Down
2 changes: 2 additions & 0 deletions Server/src/org/openas2/lib/helper/ICryptoHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public interface ICryptoHelper {

boolean isSigned(MimeBodyPart part) throws Exception;

boolean isCompressed(MimeBodyPart part) throws Exception;

String calculateMIC(MimeBodyPart part, String digest, boolean includeHeaders) throws Exception;

MimeBodyPart decrypt(MimeBodyPart part, Certificate cert, Key key) throws Exception;
Expand Down
17 changes: 17 additions & 0 deletions Server/src/org/openas2/message/BaseMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,28 @@ public abstract class BaseMessage implements Message {
private String compressionType = ICryptoHelper.COMPRESSION_NONE;
private boolean rxdMsgWasSigned = false;
private boolean rxdMsgWasEncrypted = false;
private Map<Object, Object> options = new HashMap<Object, Object>();

public BaseMessage() {
super();
}


public Map<Object, Object> getOptions() {
if (options == null) {
options = new HashMap<Object, Object>();
}
return options;
}

public void setOption(Object key, Object value) {
getOptions().put(key, value);
}

public Object getOption(Object key) {
return getOptions().get(key);
}

public void setAttribute(String key, String value) {
getAttributes().put(key, value);
}
Expand Down
6 changes: 6 additions & 0 deletions Server/src/org/openas2/message/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ public interface Message extends Serializable {

public static final String SMIME_TYPE_COMPRESSED_DATA = "smime-type=compressed-data";

public Map<Object, Object> getOptions();

public void setOption(Object key, Object value);

public Object getOption(Object key);

public void setAttribute(String key, String value);

public String getAttribute(String key);
Expand Down
1 change: 0 additions & 1 deletion Server/src/org/openas2/params/CompositeParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openas2.processor.receiver.AS2MDNReceiverHandler;


public class CompositeParameters extends ParameterParser {
Expand Down
1 change: 1 addition & 0 deletions Server/src/org/openas2/partner/AS2Partnership.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ public interface AS2Partnership {
public static final String PA_AS2_MDN_OPTIONS = "as2_mdn_options"; // Requested options for returned MDN
public static final String PA_AS2_RECEIPT_OPTION = "as2_receipt_option"; // URL destination for an async MDN
public static final String PA_MESSAGEID = "messageid"; // format to use for message-id if not default
public static final String PA_RESEND_MAX_RETRIES = "resend_max_retries"; // format to use for message-id if not default
}
10 changes: 9 additions & 1 deletion Server/src/org/openas2/processor/DefaultProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openas2.OpenAS2Exception;
import org.openas2.message.Message;


public class DefaultProcessor extends BaseProcessor {
private List<ProcessorModule> modules;
private Log logger = LogFactory.getLog(DefaultProcessor.class.getSimpleName());

public List<ProcessorModule> getActiveModules() {
List<ProcessorModule> activeMods = new ArrayList<ProcessorModule>();
Expand Down Expand Up @@ -47,6 +49,11 @@ public void handle(String action, Message msg, Map<Object, Object> options)
ProcessorException pex = null;
boolean moduleFound = false;

if (logger.isDebugEnabled())
{
logger.debug("Processor searching for module handler for action: " + action);
}

while (moduleIt.hasNext()) {
module = (ProcessorModule) moduleIt.next();

Expand All @@ -66,6 +73,7 @@ public void handle(String action, Message msg, Map<Object, Object> options)
if (pex != null) {
throw pex;
} else if (!moduleFound) {
logger.error("No handler found for action: " + action);
throw new NoModuleException(action, msg, options);
}
}
Expand Down
Loading

0 comments on commit 7a352af

Please sign in to comment.