1 /*
2  * @(#) $Id: WSSVerify.java,v 1.2 2003/07/08 08:13:52 pankaj Exp $
3  *
4  * Copyright (c) 2002-03 by Pankaj Kumar (http://www.pankaj-k.net). 
5  * All rights reserved.
6  *
7  * The license governing the use of this file can be found in the 
8  * root directory of the containing software.
9  */
10
11import java.io.FileInputStream;
12import org.w3c.dom.Document;
13
14import com.verisign.xmlsig.VerifyingKey;
15import com.verisign.xmlsig.VerifyingKeyFactory;
16import com.verisign.messaging.WSSecurity;
17import com.verisign.messaging.MessageValidity;
18import com.verisign.xpath.XPath;
19import org.xmltrustcenter.verifier.TrustVerifier;
20import org.xmltrustcenter.verifier.X509TrustVerifier;
21
22public class WSSVerify {
23    public static void main(String[] args) throws Exception {
24        if (args.length < 1){
25            System.out.println("Usage:: java WSSVerify <inp-file>");
26            return;
27        }
28        String datafile = args[0];
29
30        String keystore = "my.keystore";
31        String storepass = "changeit";
32        String kstype = "JCEKS";
33
34        System.out.println("Verifying SOAP data in file \"" + datafile + "\" using trusted certs");
35        System.out.println("in keystore \"" + keystore + "\" ...");
36
37        FileInputStream fis = new FileInputStream(keystore);
38        java.security.KeyStore ks = java.security.KeyStore.getInstance(kstype);
39        ks.load(fis, storepass.toCharArray());
40
41        Document doc = XmlUtility.readXML(datafile);
42        TrustVerifier verifier = new X509TrustVerifier(ks);
43
44        WSSecurity wss = new WSSecurity();
45        MessageValidity[] resa = wss.verify(doc, verifier, null);
46
47        for (int i = 0; i < resa.length; i++){
48            System.out.println("result[" + i + "] = " + resa[i].isValid());
49        }
50    }
51}