Update of /cvsroot/ebxmlms/ebxmlms/src/hk/hku/cecid/phoenix/message/packaging
In directory sc8-pr-cvs1:/tmp/cvs-serv15660
Modified Files:
Tag: b0931
EbxmlMessage.java PKISignatureImpl.java Signature.java
Log Message:
Bug fix for digital signature.
Index: EbxmlMessage.java
===================================================================
RCS file: /cvsroot/ebxmlms/ebxmlms/src/hk/hku/cecid/phoenix/message/packaging/EbxmlMessage.java,v
retrieving revision 1.24.2.6
retrieving revision 1.24.2.7
diff -C2 -d -r1.24.2.6 -r1.24.2.7
*** EbxmlMessage.java 17 Jul 2003 09:41:59 -0000 1.24.2.6
--- EbxmlMessage.java 26 Jul 2003 15:17:33 -0000 1.24.2.7
***************
*** 160,163 ****
--- 160,167 ----
private final ArrayList payloadContainers;
+ private int soapMessageFileOffset;
+
+ private int soapMessageLength;
+
/**
* Optional file name in which the message is persisted.
***************
*** 254,257 ****
--- 258,263 ----
saveChanges();
+ soapMessageFileOffset = 0;
+ soapMessageLength = 0;
filename = null;
messageOrder = null;
***************
*** 907,912 ****
CertResolver certResolver)
throws SOAPException, SignatureException {
! Signature signature = Signature.newInstance(this);
! return signature.verify(password, keyStoreLocation, certResolver);
}
--- 913,933 ----
CertResolver certResolver)
throws SOAPException, SignatureException {
! boolean result = true;
! Iterator i = headerContainer.getSignatures();
! if (i.hasNext()) {
! while (i.hasNext()) {
! Signature sig = (Signature) i.next();
! Signature signature = Signature.newInstance
! (this, sig.soapEnvelope, sig.getSOAPElement());
! result = result && signature.verify
! (password, keyStoreLocation, certResolver);
! }
! }
! else {
! throw new SignatureException("No <" + Signature.
! NAMESPACE_PREFIX_DS + ":" + Signature.ELEMENT_SIGNATURE +
! "> element is found to be verified!");
! }
! return result;
}
***************
*** 1192,1195 ****
--- 1213,1228 ----
return null;
+ }
+
+ public void setSOAPMessageFileOffset(int offset, int length) {
+ soapMessageFileOffset = offset;
+ soapMessageLength = length;
+ }
+
+ public int[] getSOAPMessageFileOffset() {
+ int[] offset = new int[2];
+ offset[0] = soapMessageFileOffset;
+ offset[1] = soapMessageLength;
+ return offset;
}
Index: PKISignatureImpl.java
===================================================================
RCS file: /cvsroot/ebxmlms/ebxmlms/src/hk/hku/cecid/phoenix/message/packaging/PKISignatureImpl.java,v
retrieving revision 1.3.2.4
retrieving revision 1.3.2.5
diff -C2 -d -r1.3.2.4 -r1.3.2.5
*** PKISignatureImpl.java 5 May 2003 08:39:21 -0000 1.3.2.4
--- PKISignatureImpl.java 26 Jul 2003 15:17:33 -0000 1.3.2.5
***************
*** 76,81 ****
import hk.hku.cecid.phoenix.pki.SignException;
import hk.hku.cecid.phoenix.pki.VerifyException;
! import java.io.ByteArrayInputStream;
! import java.io.ByteArrayOutputStream;
import java.security.PrivateKey;
import java.security.PublicKey;
--- 76,80 ----
import hk.hku.cecid.phoenix.pki.SignException;
import hk.hku.cecid.phoenix.pki.VerifyException;
! import java.io.*;
import java.security.PrivateKey;
import java.security.PublicKey;
***************
*** 114,121 ****
}
! PKISignatureImpl(SOAPEnvelope soapEnvelope, SOAPElement soapElement)
! throws SOAPException {
super(soapEnvelope, soapElement);
! this.ebxmlMessage = null;
}
--- 113,120 ----
}
! PKISignatureImpl(EbxmlMessage ebxmlMessage, SOAPEnvelope soapEnvelope,
! SOAPElement soapElement) throws SOAPException {
super(soapEnvelope, soapElement);
! this.ebxmlMessage = ebxmlMessage;
}
***************
*** 236,246 ****
throws SignatureException {
try {
- final SOAPPart soapPart = ebxmlMessage.getSOAPMessage().
- getSOAPPart();
- DocumentResult docResult = new DocumentResult();
- TransformerFactory.newInstance().newTransformer().
- transform(soapPart.getContent(), docResult);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
! (new XMLWriter(baos)).write(docResult.getDocument());
DocumentBuilderFactory factory = DocumentBuilderFactory.
newInstance();
--- 235,270 ----
throws SignatureException {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
! String fileName = ebxmlMessage.getFileName();
! if (fileName != null) {
! FileInputStream fis = new FileInputStream(fileName);
! int skipped = ebxmlMessage.getSOAPMessageFileOffset()[0];
! byte[] buffer = new byte[skipped];
! if (skipped > 0) {
! fis.read(buffer, 0, skipped);
! }
! int length = 0;
! for (int c = fis.read() ; c != -1 &&
! length < ebxmlMessage.getSOAPMessageFileOffset()[1] ;
! c = fis.read()) {
! baos.write(c);
! length++;
! }
! if (length != ebxmlMessage.getSOAPMessageFileOffset()[1]) {
! throw new VerifyException(ebxmlMessage.
! getSOAPMessageFileOffset()[1] + " bytes should be " +
! "read from <" + fileName + "> but only " + length +
! " bytes are successfully read");
! }
! fis.close();
! }
! else {
! final SOAPPart soapPart = ebxmlMessage.getSOAPMessage().
! getSOAPPart();
! DocumentResult docResult = new DocumentResult();
! TransformerFactory.newInstance().newTransformer().
! transform(soapPart.getContent(), docResult);
! (new XMLWriter(baos)).write(docResult.getDocument());
! }
DocumentBuilderFactory factory = DocumentBuilderFactory.
newInstance();
***************
*** 249,257 ****
final Document soapPartDocument = factory.newDocumentBuilder().
parse(new ByteArrayInputStream(baos.toByteArray()));
- final String soapHeaderName = soapPart.getEnvelope().getHeader().
- getElementName().getLocalName();
- final Element soapHeader = (Element) soapPartDocument.
- getElementsByTagNameNS(NAMESPACE_URI_SOAP_ENVELOPE,
- soapHeaderName).item(0);
ApacheXMLDSigner signature = new ApacheXMLDSigner();
--- 273,276 ----
***************
*** 326,330 ****
if (!name.equals(nsPrefix + NAMESPACE_PREFIX_DS) &&
! !name.equals(XML_NS_DECL_PREFIX)) {
addedChild.addAttribute(soapEnvelope.
createName(name), value);
--- 345,349 ----
if (!name.equals(nsPrefix + NAMESPACE_PREFIX_DS) &&
! !name.startsWith(XML_NS_DECL_PREFIX)) {
addedChild.addAttribute(soapEnvelope.
createName(name), value);
Index: Signature.java
===================================================================
RCS file: /cvsroot/ebxmlms/ebxmlms/src/hk/hku/cecid/phoenix/message/packaging/Signature.java,v
retrieving revision 1.4.4.3
retrieving revision 1.4.4.4
diff -C2 -d -r1.4.4.3 -r1.4.4.4
*** Signature.java 5 May 2003 08:39:21 -0000 1.4.4.3
--- Signature.java 26 Jul 2003 15:17:33 -0000 1.4.4.4
***************
*** 349,353 ****
static Signature newInstance(SOAPEnvelope soapEnvelope,
SOAPElement soapElement) throws SOAPException {
! return new PKISignatureImpl(soapEnvelope, soapElement);
}
--- 349,359 ----
static Signature newInstance(SOAPEnvelope soapEnvelope,
SOAPElement soapElement) throws SOAPException {
! return new PKISignatureImpl(null, soapEnvelope, soapElement);
! }
!
! static Signature newInstance(EbxmlMessage ebxmlMessage,
! SOAPEnvelope soapEnvelope, SOAPElement soapElement)
! throws SOAPException {
! return new PKISignatureImpl(ebxmlMessage, soapEnvelope, soapElement);
}
|