[WSS4J] Using trusted Certs with wss4j
Jason Essington <[email protected]> Mon, 26 Jan 2004 17:31:22 -0700
| Newsgroups | gmane.text.xml.wss4j |
|---|---|
| Message-ID | <[email protected]> |
I just tried to encrypt a message today using a trusted certificate
(rather than a keypair) and the crypto engine (Merlin) pitched an NPE.
The problem seems to stem from the getCertificates(String alias)
method. when the WSEncryptBody calls the crypto.getCertificates()
method with an alias that belongs to a self signed trusted certificate
(cert that has been exported, sans the private key, from another
keystore and imported into the one being used) the method returns null.
the root cause is KeyStore.getCertificateChain() in the case of a self
signed trusted certificate only KeyStore.getCertificate() seems to
return a certificate.
I solved the problem this way (in Merlin):
public X509Certificate[] getCertificates(String alias) throws
Exception {
for (Enumeration enum = keystore.aliases();
enum.hasMoreElements();) {
String elem = (String) enum.nextElement();
}
certs = keystore.getCertificateChain(alias);
if (certs == null || certs.length == 0) {
Certificate cert = keystore.getCertificate(alias);
// no cert chain, so lets check if getCertificate gives us a
result.
if (cert != null) {
certs = new Certificate [] {cert};
}
else {
return null;
}
}
X509Certificate[] x509certs = new X509Certificate[certs.length];
for (int i = 0; i < certs.length; i++) {
x509certs[i] = (X509Certificate) certs[i];
}
return x509certs;
}
But I am not sure if that's the best solution to this problem.
This little change does allow me to encrypt (on the sending side) and
authenticate Signatures (on the receiving side) messages where the
keystore for the respective action contains a trusted certificate
rather than a keypair.
-jason
-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn