/** * Constructs an {@link XMLSignature} from the given signature object. * * @param signature the signature * * @return the constructed XMLSignature */ protected XMLSignature buildSignature(Signature signature) { log.debug("Creating XMLSignature object"); return ((SignatureImpl) signature).getXMLSignature(); }
/** {@inheritDoc} */ public SignatureImpl buildObject(String namespaceURI, String localName, String namespacePrefix) { return new SignatureImpl(namespaceURI, localName, namespacePrefix); } }
/** {@inheritDoc} */ public void setSignatureAlgorithm(String newAlgorithm) { signatureAlgorithm = prepareForAssignment(signatureAlgorithm, newAlgorithm); }
/** {@inheritDoc} */ public Signature unmarshall(Element signatureElement) throws UnmarshallingException { log.debug("Starting to unmarshall Apache XML-Security-based SignatureImpl element"); SignatureImpl signature = new SignatureImpl(signatureElement.getNamespaceURI(), signatureElement.getLocalName(), signatureElement.getPrefix()); try { log.debug("Constructing Apache XMLSignature object"); XMLSignature xmlSignature = new XMLSignature(signatureElement, ""); SignedInfo signedInfo = xmlSignature.getSignedInfo(); log.debug("Adding canonicalization and signing algorithms, and HMAC output length to Signature"); signature.setCanonicalizationAlgorithm(signedInfo.getCanonicalizationMethodURI()); signature.setSignatureAlgorithm(signedInfo.getSignatureMethodURI()); signature.setHMACOutputLength(getHMACOutputLengthValue(signedInfo.getSignatureMethodElement())); org.apache.xml.security.keys.KeyInfo xmlSecKeyInfo = xmlSignature.getKeyInfo(); if (xmlSecKeyInfo != null) { log.debug("Adding KeyInfo to Signature"); Unmarshaller unmarshaller = Configuration.getUnmarshallerFactory().getUnmarshaller( xmlSecKeyInfo.getElement()); KeyInfo keyInfo = (KeyInfo) unmarshaller.unmarshall(xmlSecKeyInfo.getElement()); signature.setKeyInfo(keyInfo); } signature.setXMLSignature(xmlSignature); signature.setDOM(signatureElement); return signature; } catch (XMLSecurityException e) { log.error("Error constructing Apache XMLSignature instance from Signature element: {}", e.getMessage()); throw new UnmarshallingException("Unable to unmarshall Signature with Apache XMLSignature", e); } }
/** * Validate an instance of {@link SignatureImpl}, which is in turn based on underlying Apache XML Security * <code>XMLSignature</code> instance. * * @param sigImpl the signature implementation object to validate * @throws ValidationException thrown if the signature is not valid with respect to the profile */ protected void validateSignatureImpl(SignatureImpl sigImpl) throws ValidationException { if (sigImpl.getXMLSignature() == null) { log.error("SignatureImpl did not contain the an Apache XMLSignature child"); throw new ValidationException("Apache XMLSignature does not exist on SignatureImpl"); } XMLSignature apacheSig = sigImpl.getXMLSignature(); if (!(sigImpl.getParent() instanceof SignableSAMLObject)) { log.error("Signature is not an immedidate child of a SignableSAMLObject"); throw new ValidationException("Signature is not an immediate child of a SignableSAMLObject."); } SignableSAMLObject signableObject = (SignableSAMLObject) sigImpl.getParent(); Reference ref = validateReference(apacheSig); String uri = ref.getURI(); validateReferenceURI(uri, signableObject); validateTransforms(ref); validateObjectChildren(apacheSig); }
((SignatureImpl) signature).setXMLSignature(dsig); signature.setDOM(signatureElement); signature.releaseParentDOM(true);
/** {@inheritDoc} */ public Signature unmarshall(Element signatureElement) throws UnmarshallingException { log.debug("Starting to unmarshall Apache XML-Security-based SignatureImpl element"); SignatureImpl signature = new SignatureImpl(signatureElement.getNamespaceURI(), signatureElement.getLocalName(), signatureElement.getPrefix()); try { log.debug("Constructing Apache XMLSignature object"); XMLSignature xmlSignature = new XMLSignature(signatureElement, ""); SignedInfo signedInfo = xmlSignature.getSignedInfo(); log.debug("Adding canonicalization and signing algorithms, and HMAC output length to Signature"); signature.setCanonicalizationAlgorithm(signedInfo.getCanonicalizationMethodURI()); signature.setSignatureAlgorithm(signedInfo.getSignatureMethodURI()); signature.setHMACOutputLength(getHMACOutputLengthValue(signedInfo.getSignatureMethodElement())); org.apache.xml.security.keys.KeyInfo xmlSecKeyInfo = xmlSignature.getKeyInfo(); if (xmlSecKeyInfo != null) { log.debug("Adding KeyInfo to Signature"); Unmarshaller unmarshaller = Configuration.getUnmarshallerFactory().getUnmarshaller( xmlSecKeyInfo.getElement()); KeyInfo keyInfo = (KeyInfo) unmarshaller.unmarshall(xmlSecKeyInfo.getElement()); signature.setKeyInfo(keyInfo); } signature.setXMLSignature(xmlSignature); signature.setDOM(signatureElement); return signature; } catch (XMLSecurityException e) { log.error("Error constructing Apache XMLSignature instance from Signature element: {}", e.getMessage()); throw new UnmarshallingException("Unable to unmarshall Signature with Apache XMLSignature", e); } }
((SignatureImpl) signature).setXMLSignature(dsig); signature.setDOM(signatureElement); signature.releaseParentDOM(true);
/** {@inheritDoc} */ public void setHMACOutputLength(Integer length) { hmacOutputLength = prepareForAssignment(hmacOutputLength, length); }
/** * Constructs an {@link XMLSignature} from the given signature object. * * @param signature the signature * * @return the constructed XMLSignature */ protected XMLSignature buildSignature(Signature signature) { log.debug("Creating XMLSignature object"); return ((SignatureImpl) signature).getXMLSignature(); }
/** {@inheritDoc} */ public SignatureImpl buildObject(String namespaceURI, String localName, String namespacePrefix) { return new SignatureImpl(namespaceURI, localName, namespacePrefix); } }
/** * Set the Apache XML Security signature instance held by this object. * * @param signature an Apache XML Security signature object */ public void setXMLSignature(XMLSignature signature) { xmlSignature = prepareForAssignment(xmlSignature, signature); } }
/** * Signs a single XMLObject. * * @param signature the signature to computer the signature on * @throws SignatureException thrown if there is an error computing the signature */ public static void signObject(Signature signature) throws SignatureException { Logger log = getLogger(); try { XMLSignature xmlSignature = ((SignatureImpl) signature).getXMLSignature(); if (xmlSignature == null) { log.error("Unable to compute signature, Signature XMLObject does not have the XMLSignature " + "created during marshalling."); throw new SignatureException("XMLObject does not have an XMLSignature instance, unable to compute signature"); } log.debug("Computing signature over XMLSignature object"); xmlSignature.sign(SecurityHelper.extractSigningKey(signature.getSigningCredential())); } catch (XMLSecurityException e) { log.error("An error occured computing the digital signature", e); throw new SignatureException("Signature computation error", e); } }
/** * Set the Apache XML Security signature instance held by this object. * * @param signature an Apache XML Security signature object */ public void setXMLSignature(XMLSignature signature) { xmlSignature = prepareForAssignment(xmlSignature, signature); } }
/** * Signs a single XMLObject. * * @param signature the signature to computer the signature on * @throws SignatureException thrown if there is an error computing the signature */ public static void signObject(Signature signature) throws SignatureException { Logger log = getLogger(); try { XMLSignature xmlSignature = ((SignatureImpl) signature).getXMLSignature(); if (xmlSignature == null) { log.error("Unable to compute signature, Signature XMLObject does not have the XMLSignature " + "created during marshalling."); throw new SignatureException("XMLObject does not have an XMLSignature instance, unable to compute signature"); } log.debug("Computing signature over XMLSignature object"); xmlSignature.sign(SecurityHelper.extractSigningKey(signature.getSigningCredential())); } catch (XMLSecurityException e) { log.error("An error occured computing the digital signature", e); throw new SignatureException("Signature computation error", e); } }
/** {@inheritDoc} */ public void setSignatureAlgorithm(String newAlgorithm) { signatureAlgorithm = prepareForAssignment(signatureAlgorithm, newAlgorithm); }
/** {@inheritDoc} */ public void setSigningCredential(Credential newCredential) { signingCredential = prepareForAssignment(signingCredential, newCredential); }
/** {@inheritDoc} */ public void setKeyInfo(KeyInfo newKeyInfo) { keyInfo = prepareForAssignment(keyInfo, newKeyInfo); }
/** {@inheritDoc} */ public void setSigningCredential(Credential newCredential) { signingCredential = prepareForAssignment(signingCredential, newCredential); }
/** {@inheritDoc} */ public void setKeyInfo(KeyInfo newKeyInfo) { keyInfo = prepareForAssignment(keyInfo, newKeyInfo); }