Write/Read opensaml Assertion to/from XML file

Luis Rodríguez Fernández uo67113 at gmail.com
Wed Feb 1 08:20:06 GMT 2012


Hi Jose,


   1. Writing: you can do it "manually". See
   http://stackoverflow.com/questions/6681083/consume-samlresponse-token/9080912#9080912
   2. Signature:
      -   Sign:

public static String sign(String value, PrivateKey privateKey) throws
NoSuchAlgorithmException, InvalidKeyException, SignatureException {

// Create the signature
Signature signature = Signature.getInstance("SHA1withRSA");
signature.initSign(privateKey);
signature.update(value.getBytes());
byte[] signatureBytes = signature.sign();
 return (new BASE64Encoder())
.encodeBuffer(signatureBytes);
}


   - Validate:

                        // Retrieve the public key
FileInputStream inputStream = new FileInputStream("FederationPublicKey");
CertificateFactory cf = CertificateFactory.getInstance("X.509");
Certificate certificate = cf.generateCertificate(inputStream);
PublicKey publicKey = certificate.getPublicKey();

// Create the signature
Signature signature = Signature.getInstance("SHA1withRSA");
signature.initVerify(publicKey);
signature.update("SAMLRequest=...&SigAlg=...3rsa-sha1".getBytes());
if (signature.verify((new
BASE64Decoder()).decodeBuffer(signatureBase64encodedString.trim()))) {
System.out.println("Signature OK!!!");
} else {
System.out.println("Bad Signature!!!");
}


Hope it helps,

Luis

El 31 de enero de 2012 21:07, José Luis Hernández Ramos <
joseluishr1 at gmail.com> escribió:

> Hi all and thanks in advance,
>
> I have been looking for about the possibility of write and read an
> Assertion (in Java) but I have found only an example from shibboleth pages:
> https://wiki.shibboleth.net/confluence/display/OpenSAML/OSTwoUsrManJavaCreateFromXML
> and using the MetadataTest class. Is there any way in order to validate
> the signature in the assertion in a correct way after writing and reading
> the Assertion?
>
> Thanks again.
>
> Best regards,
> Jose.
>
> --
> To unsubscribe from this list send an email to
> dev-unsubscribe at shibboleth.net
>



-- 
"Los caminos del usuario son inescrutables…"

-- Rick Cook
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://shibboleth.net/pipermail/dev/attachments/20120201/d8ec934e/attachment.html 


More information about the dev mailing list