Package net.shibboleth.metadata.dom.impl
Class XMLSignatureSigner
java.lang.Object
net.shibboleth.metadata.dom.impl.XMLSignatureSigner
A class that encapsulates the various stages in signing an XML document.
This implementation is not thread safe, but can be used sequentially to sign a number of different documents.
As an adjunct to an XMLSignatureSigningStage instance, it snapshots its
parameters during construction so that they can be used without synchronization
during operation.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final StringCanonicalization algorithm to use.private final List<X509Certificate>Certificate chain, with end entity certificate as element 0, to be included with the signature.CRLs to be included with the signature.private final booleanWhether to debug digest operations by logging the pre-digest data stream.private final StringDigest algorithm used.Names of attributes to treat as ID attributes for signature referencing.private final booleanWhether key names should be included in the signature's KeyInfo.private final booleanWhether the public key should be included in the signature's KeyInfo.private final booleanWhether the certificates chain should be included in the signature's KeyInfo.private final booleanWhether the CRLs should be included in the signature's KeyInfo.private final booleanWhether the end-entity certificate's issuer and serial number should be included in the signature's KeyInfo.private final booleanWhether the end-entity certificate's subject name should be included in the signature's KeyInfo.Inclusive prefix list used with exclusive canonicalization.private final KeyInfoFactoryFactory used to create KeyInfo objects.Explicit names to associate with the given signing key.private final org.slf4j.LoggerLogger provided by the calling class.private final PrivateKeyPrivate key used to sign data.private final PublicKeyPublic key associated with the given private key.private final booleanWhether to remove CR characters from generated signatures.private final StringSignature algorithm used.private final XMLSignatureFactoryFactory used to create XML signature objects. -
Constructor Summary
ConstructorsConstructorDescriptionXMLSignatureSigner(XMLSignatureSigningStage stage, org.slf4j.Logger logger) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddKeyNames(List<XMLStructure> keyInfoItems) Adds key names to the KeyInfo, if key names are to be included.protected voidaddKeyValue(List<XMLStructure> keyInfoItems) Adds raw key values to the KeyInfo if key values are to be included.protected voidaddX509Data(List<XMLStructure> keyInfoItems) Adds X509 data (subject names, certificates, CRLs, and Issuer/Serial) set to be included, into the key info.protected KeyInfoBuilds the KeyInfo element to be included in the signature.protected ReferencebuildSignatureReference(Element target) Builds the references to the signed content.protected SignedInfobuildSignedInfo(Element target) Gets the descriptor of signed content.protected StringgetElementId(Element target) Determines the ID for the element to be signed.private voidremoveCRsFromNamedChildren(Element signature, String elementName) Remove any CRs from the text content of named child elements.voidSign an individual item.
-
Field Details
-
log
@Nonnull private final org.slf4j.Logger logLogger provided by the calling class. -
privKey
Private key used to sign data. -
publicKey
Public key associated with the given private key. -
inclusivePrefixList
Inclusive prefix list used with exclusive canonicalization. -
idAttributeNames
Names of attributes to treat as ID attributes for signature referencing. Default value: list containing the non-namespace-qualified attributes 'ID', 'Id', 'id' -
keyNames
Explicit names to associate with the given signing key. -
certificates
Certificate chain, with end entity certificate as element 0, to be included with the signature. -
crls
CRLs to be included with the signature. -
includeKeyNames
private final boolean includeKeyNamesWhether key names should be included in the signature's KeyInfo. -
includeKeyValue
private final boolean includeKeyValueWhether the public key should be included in the signature's KeyInfo. -
includeX509SubjectName
private final boolean includeX509SubjectNameWhether the end-entity certificate's subject name should be included in the signature's KeyInfo. -
includeX509Certificates
private final boolean includeX509CertificatesWhether the certificates chain should be included in the signature's KeyInfo. -
includeX509Crls
private final boolean includeX509CrlsWhether the CRLs should be included in the signature's KeyInfo. -
includeX509IssuerSerial
private final boolean includeX509IssuerSerialWhether the end-entity certificate's issuer and serial number should be included in the signature's KeyInfo. -
debugPreDigest
private final boolean debugPreDigestWhether to debug digest operations by logging the pre-digest data stream. -
removingCRsFromSignature
private final boolean removingCRsFromSignatureWhether to remove CR characters from generated signatures. -
c14nAlgo
Canonicalization algorithm to use. This is determined from thec14nExclusiveandc14nWithCommentsproperties. -
sigAlgo
Signature algorithm used. -
digestAlgo
Digest algorithm used. -
xmlSigFactory
Factory used to create XML signature objects. -
keyInfoFactory
Factory used to create KeyInfo objects.
-
-
Constructor Details
-
XMLSignatureSigner
public XMLSignatureSigner(@Nonnull XMLSignatureSigningStage stage, @Nonnull org.slf4j.Logger logger) Constructor.- Parameters:
stage- theXMLSignatureSigningStagewe are acting as an adjunct tologger- the logger for the calling stage
-
-
Method Details
-
sign
Sign an individual item.- Parameters:
item- theItemto sign- Throws:
StageProcessingException- if an error occurs preventing the signature from being made
-
buildSignedInfo
@Nonnull protected SignedInfo buildSignedInfo(@Nonnull Element target) throws StageProcessingException Gets the descriptor of signed content.- Parameters:
target- the element that will be signed- Returns:
- signed content descriptor
- Throws:
StageProcessingException- thrown if there is a problem creating the signed content descriptor
-
buildSignatureReference
@Nonnull protected Reference buildSignatureReference(@Nonnull Element target) throws StageProcessingException Builds the references to the signed content.- Parameters:
target- the element to be signed- Returns:
- reference to signed content
- Throws:
StageProcessingException- thrown if there is a problem creating the reference to the element
-
getElementId
Determines the ID for the element to be signed. To determine the ID first, all the element attributes are inspected, if one matches the providedidAttributeNamesthen the value of the attribute is used as the ID value. If no ID attribute names are given, or none of the given ones match, and one or more of the attributes is marked as an ID attribute (i.e.Attr.isId()is true), then the value of one of those attributes is used.- Parameters:
target- an element to be referenced by the signature- Returns:
- the ID value for the element, or null
-
buildKeyInfo
Builds the KeyInfo element to be included in the signature.- Returns:
- KeyInfo element to be included in the signature
- Throws:
StageProcessingException- thrown if there is a problem creating the KeyInfo descriptor
-
addKeyNames
protected void addKeyNames(@Nonnull @NonnullElements @Live List<XMLStructure> keyInfoItems) throws StageProcessingException Adds key names to the KeyInfo, if key names are to be included.- Parameters:
keyInfoItems- collector for KeyInfo children- Throws:
StageProcessingException- thrown if there is a problem creating the KeyName content
-
addKeyValue
protected void addKeyValue(@Nonnull @NonnullElements @Live List<XMLStructure> keyInfoItems) throws StageProcessingException Adds raw key values to the KeyInfo if key values are to be included.- Parameters:
keyInfoItems- collector for KeyInfo children- Throws:
StageProcessingException- thrown if there is a problem creating the KeyValue content
-
addX509Data
Adds X509 data (subject names, certificates, CRLs, and Issuer/Serial) set to be included, into the key info.- Parameters:
keyInfoItems- collector for KeyInfo children
-
removeCRsFromNamedChildren
Remove any CRs from the text content of named child elements.- Parameters:
signature- TheSignatureelement to process.elementName- The element name within the XML DSIG namespace to look for.
-