Signing and validating using the same credential

Pascal Mainini mainp1 at bfh.ch
Thu Dec 4 13:44:38 EST 2014


Hi there

I'm having some troubles in signing and verifying an Assertion and an
AttributeQuery and thought, this would (hopefully) be the right place to
ask...

Signing looks like this in my code:

  Signature querySignature = (Signature)
buildXMLObject(Signature.DEFAULT_ELEMENT_NAME);
  querySignature.setSigningCredential(THE_CREDENTIAL);
  SecurityHelper.prepareSignatureParams(querySignature,  THE_CREDENTIAL,
null, null);
  query.setSignature(querySignature);
  Configuration.getMarshallerFactory().getMarshaller(query).marshall(query);
  Signer.signObject(querySignature);

I'm trying to validate like this:

  SignatureValidator signatureValidator = new
SignatureValidator(THE_CREDENTIAL);
  signatureValidator.validate(query.getSignature());

THE_CREDENTIAL is obtained from a Keystore with a single entry
consisting of a keypair with a private key as well as a certificate with
according public key:

  [...]
  X509Certificate certificate = (X509Certificate) pkEntry.getCertificate();
  BasicX509Credential credential = new BasicX509Credential();
  credential.setEntityCertificate(certificate);
  credential.setPublicKey(certificate.getPublicKey());
  credential.setPrivateKey(pkEntry.getPrivateKey());

I have tried various configurations with and without
setEntityCertificate as well as swapping in/out
setPublicKey/setPrivateKey depending on signing or validating with no
success at all, I always get the error:

"Signature did not validate against the credential's key"

I suppose there must be something wrong in my mind about how the
components work together and I would greatly appreciate any pointers.

Thanks in advance and kind regards,

Pascal


More information about the dev mailing list