Академический Документы
Профессиональный Документы
Культура Документы
com.evintia.utils.*;
com.tradise.crypto.certificate.data.CertificateChain;
com.tradise.crypto.certificate.data.PrivateKeyCertificateChain;
com.tradise.crypto.certificate.data.impl.XmlCertificateChain;
com.tradise.crypto.certificate.status.OCSPService;
com.tradise.crypto.certificate.status.server.OCSPServerImpl;
com.tradise.crypto.exception.*;
com.tradise.crypto.signature.content.data.Content;
com.tradise.crypto.signature.content.data.DOMContent;
com.tradise.crypto.signature.content.data.impl.DOMContentImpl;
com.tradise.crypto.signature.data.SignatureCertificateChain;
com.tradise.crypto.signature.data.TimestampedSignatureCertificateChain;
com.tradise.crypto.signature.data.impl.SignedDataXMLDSig;
com.tradise.crypto.signature.data.impl.XMLSignatureCertificateChainImpl;
com.tradise.crypto.signature.timestamp.TimestampService;
com.tradise.crypto.signature.timestamp.data.TimestampResponder;
com.tradise.crypto.signature.utils.SignatureUtils;
java.io.*;
java.math.BigInteger;
java.security.MessageDigest;
java.security.UnrecoverableKeyException;
java.security.cert.X509Certificate;
java.text.ParseException;
java.text.SimpleDateFormat;
java.util.Date;
java.util.TimeZone;
java.util.logging.Level;
java.util.logging.Logger;
javax.security.auth.x500.X500Principal;
javax.xml.parsers.*;
org.apache.xml.security.Init;
org.apache.xml.security.algorithms.SignatureAlgorithm;
org.apache.xml.security.exceptions.XMLSecurityException;
org.apache.xml.security.keys.KeyInfo;
org.apache.xml.security.keys.content.X509Data;
org.apache.xml.security.signature.*;
org.apache.xml.security.transforms.Transforms;
org.apache.xml.security.utils.IdResolver;
org.apache.xml.security.utils.XMLUtils;
org.bouncycastle.util.encoders.Base64;
org.w3c.dom.*;
org.xml.sax.SAXException;
{
_$664 = (DOMContent)cont;
}
public void readContentFromStream(InputStream contentStream, String contentN
ame)
throws IOException
{
try
{
Document document = _$699(contentStream);
_$664 = new DOMContentImpl(document);
}
catch(IOException ioe)
{
throw ioe;
}
catch(Exception e)
{
ResourceUtils.getLogger().log(Level.INFO, "Could not read content fr
om stream", e);
throw new IOException(e.getMessage());
}
}
public void readSignatureFromStream(InputStream signatureStream)
throws IOException, BadFormatException
{
try
{
Document invoiceDoc = _$699(signatureStream);
Element sigElement = null;
_$647 = new XMLSignature(sigElement, "");
if(_$691)
{
Document clonedDoc = _$711(invoiceDoc);
Element clonedSigElement = null;
clonedSigElement.getParentNode().removeChild(clonedSigElement);
invoiceDoc = clonedDoc;
}
_$664 = new DOMContentImpl(invoiceDoc);
}
catch(IOException ioe)
{
throw ioe;
}
catch(Exception e)
{
ResourceUtils.getLogger().log(Level.INFO, "Could not read signature
from stream", e);
throw new BadFormatException(e);
}
}
public void readSignature(InputStream signatureStream)
throws IOException, BadFormatException
{
try
{
Document signDocument = _$699(signatureStream);
if(_$664 != null)
{
Document fullDocument;
if(_$691)
fullDocument = _$711();
else
fullDocument = _$664.getDocument();
_$719(signDocument.getDocumentElement(), fullDocument, true);
} else
{
_$647 = new XMLSignature(signDocument.getDocumentElement(), "");
}
}
catch(IOException ioe)
{
throw ioe;
}
catch(Exception e)
{
throw new BadFormatException(e);
}
}
public void readSignedData(Content sContent, InputStream signaturesStream)
throws IOException, BadFormatException
{
readContent(sContent);
readSignature(signaturesStream);
}
public void readSignatureFromStreams(InputStream contentStream, String conte
ntName, InputStream signaturesStream)
throws IOException, BadFormatException
{
readContentFromStream(contentStream, contentName);
readSignature(signaturesStream);
}
public void writeSignaturesTo(OutputStream out)
throws IOException
{
try
{
XmlUtils.serializeNode(_$647.getElement(), out);
}
catch(Exception e)
{
throw new IOException(e.getMessage());
}
}
public void writeRawSignedContentTo(OutputStream out)
throws IOException
{
writeSignedContentTo(out);
}
public void writeSignedContentTo(OutputStream out)
throws IOException
{
{
try
{
SignatureCertificateChain chain = _$755(_$647);
return (new SignatureCertificateChain[] {
chain
});
}
catch(XMLSecurityException xse)
{
ResourceUtils.getLogger().log(Level.WARNING, "Could not generate sig
nature chains", xse);
}
return new SignatureCertificateChain[0];
}
public Content getSignedContent()
{
return _$664;
}
/**
* @deprecated Method addSignature is deprecated
*/
public SignatureCertificateChain addSignature(PrivateKeyCertificateChain pri
vKeyCertStore, String password)
throws UnrecoverableKeyException
{
return addSimpleSignature(privKeyCertStore, password.toCharArray());
}
/**
* @deprecated Method addTimestampedSignature is deprecated
*/
public TimestampedSignatureCertificateChain addTimestampedSignature(PrivateK
eyCertificateChain privKeyCertStore, String password)
throws UnrecoverableKeyException, CommunicationException, BadFormatExcep
tion
{
throw new UnrecoverableKeyException("Time stamp not supported yet in XML
signatures");
}
/**
* @deprecated Method addTimestampedSignature is deprecated
*/
public TimestampedSignatureCertificateChain addTimestampedSignature(PrivateK
eyCertificateChain privKeyCertStore, String password, TimestampResponder tsRespo
nder)
throws UnrecoverableKeyException, CommunicationException, BadFormatExcep
tion
{
throw new UnrecoverableKeyException("Time stamp not supported yet in XML
signatures");
}
/**
xmlSig.addKeyInfo(certChain[0]);
xmlSig.getKeyInfo().setId("KeyInfo");
X509Data x509Data = xmlSig.getKeyInfo().itemX509Data(0);
xmlSig.getKeyInfo().addKeyValue(certChain[0].getPublicKey());
x509Data.addCertificate(certChain[0]);
_$804(privKeyCertStore, xmlSig, signatureId, "SignedProperties");
xmlSig.sign(privateKey);
return xmlSig;
}
private void _$804(PrivateKeyCertificateChain privKeyCertStore, XMLSignature
xmlSig, String signatureId, String signedPropsId)
throws XMLSignatureException
{
Document document = xmlSig.getDocument();
ObjectContainer container = new ObjectContainer(document);
Element qualPropsNode = document.createElementNS("http://uri.etsi.org/01
903/v1.3.2#", "etsi:QualifyingProperties");
qualPropsNode.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xad
es", "http://uri.etsi.org/01903/v1.3.2#");
Attr attr = document.createAttributeNS("", "Target");
attr.setValue((new StringBuilder()).append("#").append(signatureId).toSt
ring());
qualPropsNode.setAttributeNode(attr);
container.appendChild(qualPropsNode);
_$816(privKeyCertStore, document, qualPropsNode, signedPropsId);
xmlSig.appendObject(container);
}
private void _$816(PrivateKeyCertificateChain privKeyCertStore, Document doc
ument, Element qualifiedPropsNode, String signedPropsId)
{
Element signedPropsNode = document.createElementNS("http://uri.etsi.org/
01903/v1.3.2#", "etsi:SignedProperties");
signedPropsNode.setAttributeNS("#comprobante", "Id", signedPropsId);
IdResolver.registerElementById(signedPropsNode, signedPropsId);
qualifiedPropsNode.appendChild(signedPropsNode);
Element signedSignatureNode = document.createElementNS("http://uri.etsi.
org/01903/v1.3.2#", "etsi:SignedSignatureProperties");
signedPropsNode.appendChild(signedSignatureNode);
Element signedDataObjectPropNode = document.createElementNS("http://uri.
etsi.org/01903/v1.3.2#", "etsi:SignedDataObjectProperties");
signedPropsNode.appendChild(signedDataObjectPropNode);
Element signingTimeNode = document.createElementNS("http://uri.etsi.org/
01903/v1.3.2#", "etsi:SigningTime");
java.text.DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:m
m:ss'Z'");
TimeZone tzUTC = TimeZone.getTimeZone("Etc/UTC");
try
{
signingTimeNode.appendChild(document.createTextNode(DateTimeUtils.ge
tStringDate("yyyy-MM-dd'T'HH:mm:ss'Z'", new Date(), tzUTC)));
}
catch(ParseException ex)
{
throw new IllegalStateException(ex);
}
signedSignatureNode.appendChild(signingTimeNode);
_$833(privKeyCertStore, document, signedSignatureNode);
_$834(document, signedDataObjectPropNode);
}
public static void addCertRef(CertificateChain cert, Document document, Elem
ent parentNode, String uri)
{
Element certNode = document.createElementNS("http://uri.etsi.org/01903/v
1.3.2#", "xades:Cert");
if(uri != null)
{
Attr attr = document.createAttributeNS("", "URI");
attr.setValue(uri);
certNode.setAttributeNode(attr);
}
parentNode.appendChild(certNode);
Element certDigestNode = document.createElementNS("http://uri.etsi.org/0
1903/v1.3.2#", "xades:CertDigest");
certNode.appendChild(certDigestNode);
Element digestMethodNode = document.createElementNS("http://www.w3.org/2
000/09/xmldsig#", "ds:DigestMethod");
Attr attr = document.createAttributeNS("", "Algorithm");
attr.setValue("http://www.w3.org/2000/09/xmldsig#sha1");
digestMethodNode.setAttributeNode(attr);
certDigestNode.appendChild(digestMethodNode);
Element digestValueNode = document.createElementNS("http://www.w3.org/20
00/09/xmldsig#", "ds:DigestValue");
String digestValue = null;
try
{
digestValue = new String(Base64.encode(MessageDigest.getInstance("SH
A-1").digest(cert.getMainCertificate().getEncoded())));
}
catch(Exception ex)
{
throw new IllegalStateException(ex.getMessage());
}
digestValueNode.appendChild(document.createTextNode(digestValue));
certDigestNode.appendChild(digestValueNode);
Element issuerSerialNode = document.createElementNS("http://uri.etsi.org
/01903/v1.3.2#", "xades:IssuerSerial");
certNode.appendChild(issuerSerialNode);
Element issuerNameNode = document.createElementNS("http://www.w3.org/200
0/09/xmldsig#", "ds:X509IssuerName");
issuerNameNode.appendChild(document.createTextNode(cert.getIssuerCertifi
cateChain().getMainCertificate().getSubjectX500Principal().getName()));
issuerSerialNode.appendChild(issuerNameNode);
Element serialNumberNode = document.createElementNS("http://www.w3.org/2
000/09/xmldsig#", "ds:X509SerialNumber");
serialNumberNode.appendChild(document.createTextNode(cert.getMainCertifi
cate().getSerialNumber().toString()));
issuerSerialNode.appendChild(serialNumberNode);
}
private void _$833(PrivateKeyCertificateChain privKeyCertStore, Document doc
ument, Element signedPropsNode)
{
Element signingCertNode = document.createElementNS("http://uri.etsi.org/
01903/v1.3.2#", "etsi:SigningCertificate");
signedPropsNode.appendChild(signingCertNode);
addCertRef(privKeyCertStore, document, signingCertNode, null);
}
static
static
static
static
static
static
static
static
static
static
static
static
static
final
final
final
final
final
final
final
final
final
final
final
final
final
String
String
String
String
String
String
String
String
String
String
String
String
String
_$677
_$678
_$679
_$680
_$681
_$682
_$683
_$684
_$685
_$686
_$687
_$688
_$689
=
=
=
=
=
=
=
=
=
=
=
=
=
":";
"http://www.w3.org/2000/09/xmldsig#";
"ds";
"http://uri.etsi.org/01903/v1.3.2#";
"xades";
"xmlns:xades";
"//";
"[1]";
"//ds:Signature[1]";
"//xades:SignedProperties[1]";
"//ds:KeyInfo[1]";
"SignedProperties";
"KeyInfo";
private
private
private
private
static
{
Init.init();
}
}