Class XadesSignature
java.lang.Object
br.ufsc.labsec.signature.conformanceVerifier.xades.XadesSignature
- All Implemented Interfaces:
Signature<Element>, GenericXadesSignature, SignatureObject
- Direct Known Subclasses:
CounterSignature
Esta classe representa uma assinatura do tipo XAdES.
Implementa
GenericXadesSignature.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected ElementO nodo XML da assinaturaprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected Dateprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected DocumentO documento de assinatura -
Constructor Summary
ConstructorsConstructorDescriptionXadesSignature(Document xml, Element signature, XadesSignatureContainer xadesSignatureContainer) Constrói uma assinatura XAdES a partir da representação DOM do documento XML assinado, e do elemento que representa a assinatura no documento. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddUnsignedAttribute(SignatureAttribute<Element> attribute) Adiciona um atributo à lista de atributos não-assinadosstatic voidaddX509DataContent(Collection<Certificate> certificates, Collection<X509CRL> crls, X509Data x509Data) Adiciona os certificados e CRLs, presentes na estrutura X509Data, nas listas dadasprotected org.bouncycastle.cms.SignerIdbuildSignerIdentifier(X500Principal issuerName, BigInteger serialNumber) Constrói um objeto da classeSignerId.protected voidcalculateArchiveTimeStampHashValue(OutputStream octetStream, Time time) Passos para cálculo do hash do carimbo do tempo de arquivamento, conforme o documento ETSI TS 101 903 V1.4.1 (2009-06) seção 8.2.1Retorna o identificador do algoritmo de assinatura (OID) utilizado na assinatura.byte[]getArchiveTimeStampHashValue(String hashAlgorithmName) Calcula o valor de hash do carimbo de tempo de arquivamentobyte[]getArchiveTimeStampHashValue(String hashAlgorithmName, Time time) Calcula o valor de hash do carimbo de tempo de arquivamentoRetorna a lista de atributos presente na assinatura.Retorna os certificados da estrutura KeyInfoRetorna o contêiner da assinatura XAdESRetorna uma lista de contra-assinaturagetCrls()Retorna as CRLs da assinaturagetEncodedAttribute(String attributeId) Retorna o primeiro atributo da assinaturagetEncodedAttribute(String attributeId, Integer index) Retorna o atributo correspondente ao identificador dadoInforma em qualElementespecifico está a representação da assinaturagetSignaturePolicyHashValue(SignaturePolicyInterface signaturePolicyInterface) Retorna o valor de hash no nodo da política de assinaturagetSignaturePolicyIdentifier(SignaturePolicyInterface signaturePolicyInterface) Retorna o identificador da política de assinaturagetSignaturePolicyUri(SignaturePolicyInterface signaturePolicyInterface) Retorna a URI da política de assinaturaObtém o valor do atributo Id da tag SignatureValuebyte[]getSignatureValueHash(String algorithm) Retorna o valor de hash da assinaturaRetorna a lista de atributos assinadosRetorna o certificado do assinanteRetorna o nome do assinanteRetorna a lista de atributos não-assinadosgetXml()Retorna a assinatura em forma deDocumentpara que se possa navegar por ela mais livremente.inthashCode()booleanhasImpliedPolicy(SignaturePolicyInterface signaturePolicyInterface) protected booleanhasSigningCertificate(CounterSignature counterSignature) Verifica se existe a propriedade SigningCertificate na contra assinaturabooleanhasValidKeyInfo(List<Reference> references, DOMValidateContext validateContext) Verifica se o estado do ds:KeyInfo permite a ausência de um XAdES:SignedProperties na assinaturabooleanhasValidKeyInfoElement(X509Certificate signerCertificate) booleanisArchiveTimeStampHashValue(String hashAlgorithmName, Time time, byte[] expected) booleanVerifica se a assinatura Xades é do tipo envelopada por meio da URI da w3 dentro dos nodos com a tag TransformbooleanVerifica se o conteúdo assinado é externobooleanisSignatureValueHashValid(String algorithm, byte[] expected) voidremoveUnsignedAttribute(String attributeId, int index) Remove o nodo do atributo não-assinado no arquivovoidreplaceUnsignedAttribute(SignatureAttribute<Element> attribute, int index) Substitui um atributo não-assinadobyte[]resolveAttributeContentToBeHashed(List<String> mandatoryAttrs, List<String> optionalAttrs, String namespace, String target, boolean withSignature) voidsetTimeReference(Date timeReference) booleanverify(X509Certificate signerCertificate, SignatureReport sigReport, boolean isComplete, boolean isIcpBr) Verifica a assinatura XAdES baseado no documento(http://www.w3.org/TR/XAdES/) e anexa ao report.
-
Field Details
-
SIGNED_SIGNATURE_PROPERTIES
- See Also:
-
COLON
- See Also:
-
UNSIGNED_PROPERTIES
- See Also:
-
XADES_COUNTER_SIGNATURE
- See Also:
-
SIGNING_CERTIFICATE
- See Also:
-
SIGNED_PROPERTIES
- See Also:
-
DOM
- See Also:
-
XADES_ARCHIVE_TIME_STAMP
- See Also:
-
REFERENCE
- See Also:
-
SPURI
- See Also:
-
SIG_POLICY_QUALIFIERS
- See Also:
-
SIGNED_INFO
- See Also:
-
KEY_INFO
- See Also:
-
ID
- See Also:
-
SIGNATURE
- See Also:
-
COUNTER_SIGNATURE
- See Also:
-
SIGNATURE_VALUE
- See Also:
-
OBJECT
- See Also:
-
QUALIFYING_PROPERTIES
- See Also:
-
SIGNATURE_TIME_STAMP
- See Also:
-
COMPLETE_CERTIFICATE_REFS
- See Also:
-
COMPLETE_CERTIFICATE_REFSV2
- See Also:
-
COMPLETE_REVOCATION_REFS
- See Also:
-
ATTRIBUTE_CERTIFICATE_REFS
- See Also:
-
ATTRIBUTE_CERTIFICATE_REFSV2
- See Also:
-
ATTRIBUTE_REVOCATION_REFS
- See Also:
-
TYPE
- See Also:
-
SIGNATURE_POLICY_IDENTIFIER
- See Also:
-
UNSIGNED_DATA_OBJECT_PROPERTIES
- See Also:
-
UNSIGNED_SIGNATURE_PROPERTIES
- See Also:
-
SIGNED_DATA_OBJECT_PROPERTIES
- See Also:
-
REVOCATION_VALUES
- See Also:
-
CERTIFICATE_VALUES
- See Also:
-
ATTR_AUTHORITIES_CERT_VALUES
- See Also:
-
ATTRIBUTE_REVOCATION_VALUES
- See Also:
-
xml
O documento de assinatura -
signatureElement
O nodo XML da assinatura -
timeReference
-
-
Constructor Details
-
XadesSignature
public XadesSignature(Document xml, Element signature, XadesSignatureContainer xadesSignatureContainer) Constrói uma assinatura XAdES a partir da representação DOM do documento XML assinado, e do elemento que representa a assinatura no documento.- Parameters:
xml- A representação DOM de um documento XMLsignature- O elemento que representa a assinatura no documentoxadesSignatureContainer- O contêiner de assinatura XAdES
-
-
Method Details
-
setTimeReference
-
getTimeReference
-
hashCode
-
getSignatureElement
-
getSignatureMethod
- Throws:
SignatureException
-
hasValidKeyInfo
Verifica se o estado do ds:KeyInfo permite a ausência de um XAdES:SignedProperties na assinatura- Parameters:
references- Lista de referências do SignedInfovalidateContext- Contexto contendo assinatura e chave pública de verificação- Returns:
- Verdadeiro se permite a ausência, falso se exige a presença do XAdES:SignedProperties
-
getAlgorithmFromSignature
-
verify
public boolean verify(X509Certificate signerCertificate, SignatureReport sigReport, boolean isComplete, boolean isIcpBr) throws VerificationException Verifica a assinatura XAdES baseado no documento(http://www.w3.org/TR/XAdES/) e anexa ao report.- Specified by:
verifyin interfaceGenericXadesSignature- Parameters:
signerCertificate- O certificado do signatáriosigReport- O relátorio da assinaturaisComplete- Se o relatório deve ser completo ou simplesisIcpBr- Se a cadeia de certificados é Icp-BR para fazer ExtensionsReport- Returns:
- Indica se a assinatura XAdES está de acordo com os padrões do documento (http://www.w3.org/TR/XAdES/)
- Throws:
VerificationException- Exceção em caso de erro durante a verificação
-
getXml
Retorna a assinatura em forma deDocumentpara que se possa navegar por ela mais livremente. Obs.: A referência interna é passada, por isso se for causado algum erro na assinatura através do document, esse erros posteriomente aparecerão dentro doXadesSignaturetambém.- Returns:
- A assinatura na representação DOM
-
getAttributeList
Retorna a lista de atributos presente na assinatura.- Specified by:
getAttributeListin interfaceSignature<Element>- Returns:
- A lista de atributos na assinatura
-
getSignedAttributeList
-
getUnsignedAttributeList
-
getEncodedAttribute
public Element getEncodedAttribute(String attributeId, Integer index) throws SignatureAttributeNotFoundException Retorna o atributo correspondente ao identificador dado- Specified by:
getEncodedAttributein interfaceSignature<Element>- Parameters:
attributeId- O identificador do atributoindex- O índice do atributo- Returns:
- O atributo correspondente ao identificador dado
- Throws:
SignatureAttributeNotFoundException- Exceção caso o atributo não seja encontrado
-
getSignatureContainer
-
getEncodedAttribute
Retorna o primeiro atributo da assinatura- Specified by:
getEncodedAttributein interfaceGenericXadesSignature- Parameters:
attributeId- O identificador do atributo- Returns:
- O primeiro atributo da assinatura
- Throws:
SignatureAttributeNotFoundException- atributo não encontrado
-
hasImpliedPolicy
-
getSignaturePolicyIdentifier
Retorna o identificador da política de assinatura- Specified by:
getSignaturePolicyIdentifierin interfaceGenericXadesSignature- Returns:
- O identificador da política de assinatura
-
isExternalSignedData
public boolean isExternalSignedData()Verifica se o conteúdo assinado é externo- Specified by:
isExternalSignedDatain interfaceGenericXadesSignature- Returns:
- Indica se o conteúdo assinado é externo
-
getSignatureValueHash
public byte[] getSignatureValueHash(String algorithm) throws PbadException, NoSuchAlgorithmException Retorna o valor de hash da assinatura- Specified by:
getSignatureValueHashin interfaceGenericXadesSignature- Parameters:
algorithm- O algoritmo a ser utilizado para o cálculo de hash- Returns:
- Array de bytes com valor de hash da assinatura
- Throws:
PbadException- Exceção em caso de erro no cálculoNoSuchAlgorithmException
-
isSignatureValueHashValid
- Throws:
PbadException
-
addUnsignedAttribute
public void addUnsignedAttribute(SignatureAttribute<Element> attribute) throws SignatureAttributeException Adiciona um atributo à lista de atributos não-assinados- Specified by:
addUnsignedAttributein interfaceSignature<Element>- Parameters:
attribute- O atributo a ser adicionado- Throws:
DOMException- Exceção em caso de erro na estrutura do XMLSignatureAttributeException- Exceção em caso de erro no atributo
-
replaceUnsignedAttribute
public void replaceUnsignedAttribute(SignatureAttribute<Element> attribute, int index) throws SignatureAttributeException Description copied from interface:SignatureSubstitui um atributo não-assinado- Specified by:
replaceUnsignedAttributein interfaceSignature<Element>- Parameters:
attribute- atributo a ser substituídoindex- índice do atributo a ser substituído- Throws:
SignatureAttributeException
-
getCounterSignatures
Retorna uma lista de contra-assinatura- Specified by:
getCounterSignaturesin interfaceSignature<Element>- Returns:
- A lista de contra-assinaturas
-
buildSignerIdentifier
protected org.bouncycastle.cms.SignerId buildSignerIdentifier(X500Principal issuerName, BigInteger serialNumber) Constrói um objeto da classeSignerId.- Parameters:
issuerName- Nome do emissor do certificadoserialNumber- Número do serial do certificado- Returns:
- O
SignerIdgerado
-
hasSigningCertificate
Verifica se existe a propriedade SigningCertificate na contra assinatura- Parameters:
counterSignature- A contra assinatura- Returns:
- Indica se existe a propriedade SigningCertificate
-
getSignatureValueAttribute
Obtém o valor do atributo Id da tag SignatureValue- Returns:
- Valor do atributo Id da tag SignatureValue
-
getSignaturePolicyUri
Retorna a URI da política de assinatura- Specified by:
getSignaturePolicyUriin interfaceGenericXadesSignature- Returns:
- A URI da política de assinatura
-
getSignaturePolicyHashValue
Retorna o valor de hash no nodo da política de assinatura- Specified by:
getSignaturePolicyHashValuein interfaceGenericXadesSignature- Returns:
- O hash da política de assinatura
-
removeUnsignedAttribute
public void removeUnsignedAttribute(String attributeId, int index) throws SignatureAttributeException Remove o nodo do atributo não-assinado no arquivo- Parameters:
attributeId- O identificador do atributo a ser removidoindex- O índice do atributo- Throws:
SignatureAttributeException- Exceção caso o atributo não seja encontrado
-
getArchiveTimeStampHashValue
Calcula o valor de hash do carimbo de tempo de arquivamento- Specified by:
getArchiveTimeStampHashValuein interfaceGenericXadesSignature- Parameters:
hashAlgorithmName- O algoritmo a ser utilizado no cálculo- Returns:
- O valor de hash do carimbo
- Throws:
PbadException- Exceção em caso de erro na canonização
-
getArchiveTimeStampHashValue
public byte[] getArchiveTimeStampHashValue(String hashAlgorithmName, Time time) throws PbadException Calcula o valor de hash do carimbo de tempo de arquivamento- Specified by:
getArchiveTimeStampHashValuein interfaceGenericXadesSignature- Parameters:
hashAlgorithmName- O algoritmo a ser utilizado no cálculotime- O horário do carimbo- Returns:
- O valor de hash do carimbo
- Throws:
PbadException- Exceção em caso de erro na canonização
-
isArchiveTimeStampHashValue
public boolean isArchiveTimeStampHashValue(String hashAlgorithmName, Time time, byte[] expected) throws PbadException - Throws:
PbadException
-
calculateArchiveTimeStampHashValue
protected void calculateArchiveTimeStampHashValue(OutputStream octetStream, Time time) throws CanonicalizationException, SignatureAttributeException Passos para cálculo do hash do carimbo do tempo de arquivamento, conforme o documento ETSI TS 101 903 V1.4.1 (2009-06) seção 8.2.1- Parameters:
octetStream- Onde está sendo escrito os bytes contatenados do hashtime- A data do carimbo do tempo- Throws:
SignatureAttributeException- Exceção em caso de erro nos atributos da assinaturaEncodingException- Exceção em caso de erro na canonizaçãoCanonicalizationException
-
getContainer
Retorna o contêiner da assinatura XAdES- Specified by:
getContainerin interfaceGenericXadesSignature- Returns:
- O contêiner da assinatura XAdES
-
getSigningCertificate
Retorna o certificado do assinante- Returns:
- O certificado do assinante
-
getCertificatesAtKeyInfo
Retorna os certificados da estrutura KeyInfo- Returns:
- Os certificados da estrutura KeyInfo ou nulo em caso de erro
-
getCrls
Retorna as CRLs da assinatura- Returns:
- As CRLs da assinatura
- Throws:
CRLException- Exceção em caso de erro na manipulação das CRLs
-
addX509DataContent
public static void addX509DataContent(Collection<Certificate> certificates, Collection<X509CRL> crls, X509Data x509Data) Adiciona os certificados e CRLs, presentes na estrutura X509Data, nas listas dadas- Parameters:
certificates- A lista de certificadoscrls- A lista de CRLsx509Data- A estrutura X509Data
-
getSubjectName
-
isEnveloped
public boolean isEnveloped()Verifica se a assinatura Xades é do tipo envelopada por meio da URI da w3 dentro dos nodos com a tag Transform- Returns:
- se ela é envelopada
-
getFormat
-
hasValidKeyInfoElement
-
resolveAttributeContentToBeHashed
public byte[] resolveAttributeContentToBeHashed(List<String> mandatoryAttrs, List<String> optionalAttrs, String namespace, String target, boolean withSignature) throws PbadException - Throws:
PbadException
-
getAlgorithmOid
Retorna o identificador do algoritmo de assinatura (OID) utilizado na assinatura.- Specified by:
getAlgorithmOidin interfaceSignature<Element>- Returns:
- Uma string contendo o OID do algoritmo de assinatura.
-