return edt;
}
private SecurityHeaderElement createSignature(final PublicKey pubKey,final Key signingKey,final SAMLToken samlToken,final NamespaceContextEx nsContext)throws WSTrustException{
try{
final JAXBSignatureFactory signatureFactory = JAXBSignatureFactory.newInstance();
final C14NMethodParameterSpec spec = null;
final CanonicalizationMethod canonicalMethod =
signatureFactory.newCanonicalizationMethod(CanonicalizationMethod.EXCLUSIVE,spec);
DigestMethod digestMethod;
digestMethod = signatureFactory.newDigestMethod(DigestMethod.SHA1, null);
SignatureMethod signatureMethod;
signatureMethod = signatureFactory.newSignatureMethod(SignatureMethod.RSA_SHA1, null);
//Note : Signature algorithm parameters null for now , fix me.
final ArrayList<Transform> transformList = new ArrayList<Transform>();
Transform tr1;
tr1 = signatureFactory.newTransform(Transform.ENVELOPED, (TransformParameterSpec) null);
Transform tr2;
tr2 = signatureFactory.newTransform(CanonicalizationMethod.EXCLUSIVE, (TransformParameterSpec) null);
transformList.add(tr1);
transformList.add(tr2);
final String uri = "#" + "uuid-" + UUID.randomUUID().toString();
final Reference ref = signatureFactory.newReference(uri,digestMethod,transformList, null, null);
// Create the SignedInfo
final SignedInfo signedInfo = signatureFactory.newSignedInfo(canonicalMethod,signatureMethod,Collections.singletonList(ref));
KeyValue keyValue;
//kv = kif.newKeyValue(pubKey);
if (pubKey instanceof java.security.interfaces.DSAPublicKey) {
DSAKeyValue dsa = null;
final DSAPublicKey key = (DSAPublicKey)pubKey;
final byte[] paramP = key.getParams().getP().toByteArray();
final byte[] paramQ = key.getParams().getQ().toByteArray();
final byte[] paramG = key.getParams().getG().toByteArray();
final byte[] paramY = key.getY().toByteArray();
dsa = signatureFactory.newDSAKeyValue(paramP,paramQ,paramG,paramY,null,null,null);
keyValue = signatureFactory.newKeyValue(Collections.singletonList(dsa));
} else if (pubKey instanceof java.security.interfaces.RSAPublicKey) {
RSAKeyValue rsa = null;
final RSAPublicKey key = (RSAPublicKey)pubKey;
rsa = signatureFactory.newRSAKeyValue(key.getModulus().toByteArray(),key.getPublicExponent().toByteArray());
keyValue = signatureFactory.newKeyValue(Collections.singletonList(rsa));
}else{
throw new WSTrustException("Unsupported PublicKey");
}
// Create a KeyInfo and add the KeyValue to it
final javax.xml.crypto.dsig.keyinfo.KeyInfo keyInfo = signatureFactory.newKeyInfo(Collections.singletonList(keyValue));
final JAXBSignContext signContext = new JAXBSignContext(signingKey);
final SSEData data = null;
signContext.setURIDereferencer(new DSigResolver(data));
final com.sun.xml.ws.security.opt.crypto.dsig.Signature signature = (Signature) signatureFactory.newXMLSignature(signedInfo,keyInfo);
final JAXBSignatureHeaderElement jhe = new JAXBSignatureHeaderElement(signature,soapVersion,(XMLSignContext)signContext);
return new EnvelopedSignedMessageHeader(samlToken,(com.sun.xml.ws.security.opt.crypto.dsig.Reference) ref, jhe,nsContext);
// } catch (KeyException ex) {
// ex.printStackTrace();
// throw new WSTrustException("Unable to create sign SAML Assertion",ex);