Signing multiple objects?

Brad Cox bradjcox at gmail.com
Wed Nov 2 00:47:16 GMT 2011


Got it. My problem was confusing building with unmarshalling. May be
closing in on it.

The attachSamlAssertion method now fails in
the Signer.signObject(signature) call because signature.XMLSignature is
null.

ERROR 11691 main DisaBlueprintSamlProcessorTest.java:76 Exception
com.technica.xacml2.runtime.XacmlFault:
XMLObject does not have an XMLSignature instance, unable to compute
signature


Debugger shows XMLSignature variable is indeed null but the Signature
interface has no way to set it. SignatureImpl does, but not sure I should
use that and don't know what to set it to.


public void attachSamlAssertion(Document document)
 {
Element envelopeElmt = document.getDocumentElement();
try
 {
UnmarshallerFactory unmarshallerFactory =
Configuration.getUnmarshallerFactory();
 Unmarshaller unmarshaller =
unmarshallerFactory.getUnmarshaller(envelopeElmt);
XMLObject envelopeObj = unmarshaller.unmarshall(envelopeElmt);
 Envelope envelope = (Envelope) envelopeObj;
Header header = envelope.getHeader();
 Body body = envelope.getBody();

Security security = newSecurity();
 header.getUnknownXMLObjects().add(security);

Signature signature = newSignature();
 security.getUnknownXMLObjects().add(signature);

Timestamp timestamp = newTimeStamp();
 security.getUnknownXMLObjects().add(timestamp);

MessageID messageID = newMessageID();
 security.getUnknownXMLObjects().add(messageID);

Assertion assertion = newAssertion();
 security.getUnknownXMLObjects().add(assertion);

Signer.signObject(signature);
 }
catch (Exception e)
{
 throw new XacmlFault(e);
}
}

Here's how I'm building the signature:

public Signature newSignature()
 {
SignatureBuilder bldr = (SignatureBuilder)
xmlObjectBuilderFactory.getBuilder(Signature.DEFAULT_ELEMENT_NAME);
 Signature sig = (Signature) bldr.buildObject();
Credential credential = getCredential();
 sig.setSigningCredential(credential);
sig.setCanonicalizationAlgorithm(SignatureConstants.ALGO_ID_C14N_EXCL_OMIT_COMMENTS);
 sig.setSignatureAlgorithm(SignatureConstants.ALGO_ID_SIGNATURE_RSA_SHA1);

SecurityConfiguration secConfiguration =
Configuration.getGlobalSecurityConfiguration();
 NamedKeyInfoGeneratorManager namedKeyInfoGeneratorManager =
secConfiguration.getKeyInfoGeneratorManager();
KeyInfoGeneratorManager keyInfoGeneratorManager =
namedKeyInfoGeneratorManager.getDefaultManager();
 KeyInfoGeneratorFactory keyInfoGeneratorFactory =
keyInfoGeneratorManager.getFactory(credential);
KeyInfoGenerator keyInfoGenerator = keyInfoGeneratorFactory.newInstance();
 try
{
KeyInfo keyInfo = keyInfoGenerator.generate(credential);
 sig.setKeyInfo(keyInfo);
}
catch (SecurityException e)
 {
throw new XacmlFault(e);
}
 URIContentReference contentReference = new URIContentReference("");
contentReference.getTransforms().add(SignatureConstants.TRANSFORM_ENVELOPED_SIGNATURE);

contentReference.getTransforms().add(SignatureConstants.TRANSFORM_C14N_EXCL_OMIT_COMMENTS);
contentReference.setDigestAlgorithm(SignatureConstants.ALGO_ID_DIGEST_SHA1);
 sig.getContentReferences().add(contentReference);
return sig;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://shibboleth.net/pipermail/dev/attachments/20111101/4b5ae7ab/attachment.html 


More information about the dev mailing list