You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by co...@apache.org on 2011/12/06 11:24:32 UTC

svn commit: r1210847 [26/42] - in /webservices/wss4j/site: ./ apidocs/ apidocs/org/apache/ws/security/ apidocs/org/apache/ws/security/action/ apidocs/org/apache/ws/security/action/class-use/ apidocs/org/apache/ws/security/class-use/ apidocs/org/apache/...

Modified: webservices/wss4j/site/xref/org/apache/ws/security/components/crypto/Merlin.html
URL: http://svn.apache.org/viewvc/webservices/wss4j/site/xref/org/apache/ws/security/components/crypto/Merlin.html?rev=1210847&r1=1210846&r2=1210847&view=diff
==============================================================================
--- webservices/wss4j/site/xref/org/apache/ws/security/components/crypto/Merlin.html (original)
+++ webservices/wss4j/site/xref/org/apache/ws/security/components/crypto/Merlin.html Tue Dec  6 10:23:54 2011
@@ -854,552 +854,558 @@
 <a name="844" href="#844">844</a>                     WSSecurityException.FAILURE, <span class="jxr_string">"certpath"</span>,
 <a name="845" href="#845">845</a>                     <strong class="jxr_keyword">new</strong> Object[] { e.getMessage() }, e
 <a name="846" href="#846">846</a>                 );
-<a name="847" href="#847">847</a>         }
-<a name="848" href="#848">848</a>     }
-<a name="849" href="#849">849</a>     
-<a name="850" href="#850">850</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="851" href="#851">851</a> <em class="jxr_javadoccomment">     * Evaluate whether a given public key should be trusted.</em>
-<a name="852" href="#852">852</a> <em class="jxr_javadoccomment">     * </em>
-<a name="853" href="#853">853</a> <em class="jxr_javadoccomment">     * @param publicKey The PublicKey to be evaluated</em>
-<a name="854" href="#854">854</a> <em class="jxr_javadoccomment">     * @return whether the PublicKey parameter is trusted or not</em>
-<a name="855" href="#855">855</a> <em class="jxr_javadoccomment">     */</em>
-<a name="856" href="#856">856</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">boolean</strong> verifyTrust(PublicKey publicKey) <strong class="jxr_keyword">throws</strong> WSSecurityException {
-<a name="857" href="#857">857</a>         <em class="jxr_comment">//</em>
-<a name="858" href="#858">858</a>         <em class="jxr_comment">// If the public key is null, do not trust the signature</em>
-<a name="859" href="#859">859</a>         <em class="jxr_comment">//</em>
-<a name="860" href="#860">860</a>         <strong class="jxr_keyword">if</strong> (publicKey == <strong class="jxr_keyword">null</strong>) {
-<a name="861" href="#861">861</a>             <strong class="jxr_keyword">return</strong> false;
-<a name="862" href="#862">862</a>         }
-<a name="863" href="#863">863</a>         
-<a name="864" href="#864">864</a>         <em class="jxr_comment">//</em>
-<a name="865" href="#865">865</a>         <em class="jxr_comment">// Search the keystore for the transmitted public key (direct trust)</em>
-<a name="866" href="#866">866</a>         <em class="jxr_comment">//</em>
-<a name="867" href="#867">867</a>         <strong class="jxr_keyword">boolean</strong> trust = findPublicKeyInKeyStore(publicKey, keystore);
-<a name="868" href="#868">868</a>         <strong class="jxr_keyword">if</strong> (trust) {
-<a name="869" href="#869">869</a>             <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">true</strong>;
-<a name="870" href="#870">870</a>         } <strong class="jxr_keyword">else</strong> {
-<a name="871" href="#871">871</a>             <em class="jxr_comment">//</em>
-<a name="872" href="#872">872</a>             <em class="jxr_comment">// Now search the truststore for the transmitted public key (direct trust)</em>
-<a name="873" href="#873">873</a>             <em class="jxr_comment">//</em>
-<a name="874" href="#874">874</a>             trust = findPublicKeyInKeyStore(publicKey, truststore);
-<a name="875" href="#875">875</a>             <strong class="jxr_keyword">if</strong> (trust) {
-<a name="876" href="#876">876</a>                 <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">true</strong>;
-<a name="877" href="#877">877</a>             }
-<a name="878" href="#878">878</a>         }
-<a name="879" href="#879">879</a>         <strong class="jxr_keyword">return</strong> false;
-<a name="880" href="#880">880</a>     }
-<a name="881" href="#881">881</a>     
-<a name="882" href="#882">882</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="883" href="#883">883</a> <em class="jxr_javadoccomment">     * Get an X509 Certificate (chain) according to a given serial number and issuer string.</em>
-<a name="884" href="#884">884</a> <em class="jxr_javadoccomment">     *</em>
-<a name="885" href="#885">885</a> <em class="jxr_javadoccomment">     * @param issuer The Issuer String</em>
-<a name="886" href="#886">886</a> <em class="jxr_javadoccomment">     * @param serialNumber The serial number of the certificate</em>
-<a name="887" href="#887">887</a> <em class="jxr_javadoccomment">     * @return an X509 Certificate (chain) corresponding to the found certificate(s)</em>
-<a name="888" href="#888">888</a> <em class="jxr_javadoccomment">     * @throws WSSecurityException</em>
-<a name="889" href="#889">889</a> <em class="jxr_javadoccomment">     */</em>
-<a name="890" href="#890">890</a>     <strong class="jxr_keyword">private</strong> X509Certificate[] getX509Certificates(
-<a name="891" href="#891">891</a>         String issuer, 
-<a name="892" href="#892">892</a>         BigInteger serialNumber
-<a name="893" href="#893">893</a>     ) <strong class="jxr_keyword">throws</strong> <a href="../../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a> {
-<a name="894" href="#894">894</a>         <em class="jxr_comment">//</em>
-<a name="895" href="#895">895</a>         <em class="jxr_comment">// Convert the subject DN to a java X500Principal object first. This is to ensure</em>
-<a name="896" href="#896">896</a>         <em class="jxr_comment">// interop with a DN constructed from .NET, where e.g. it uses "S" instead of "ST".</em>
-<a name="897" href="#897">897</a>         <em class="jxr_comment">// Then convert it to a BouncyCastle X509Name, which will order the attributes of</em>
-<a name="898" href="#898">898</a>         <em class="jxr_comment">// the DN in a particular way (see WSS-168). If the conversion to an X500Principal</em>
-<a name="899" href="#899">899</a>         <em class="jxr_comment">// object fails (e.g. if the DN contains "E" instead of "EMAILADDRESS"), then fall</em>
-<a name="900" href="#900">900</a>         <em class="jxr_comment">// back on a direct conversion to a BC X509Name</em>
-<a name="901" href="#901">901</a>         <em class="jxr_comment">//</em>
-<a name="902" href="#902">902</a>         Object issuerName = <strong class="jxr_keyword">null</strong>;
-<a name="903" href="#903">903</a>         <strong class="jxr_keyword">try</strong> {
-<a name="904" href="#904">904</a>             X500Principal issuerRDN = <strong class="jxr_keyword">new</strong> X500Principal(issuer);
-<a name="905" href="#905">905</a>             issuerName = createBCX509Name(issuerRDN.getName());
-<a name="906" href="#906">906</a>         } <strong class="jxr_keyword">catch</strong> (java.lang.IllegalArgumentException ex) {
-<a name="907" href="#907">907</a>             issuerName = createBCX509Name(issuer);
-<a name="908" href="#908">908</a>         }
-<a name="909" href="#909">909</a>         Certificate[] certs = <strong class="jxr_keyword">null</strong>;
-<a name="910" href="#910">910</a>         <strong class="jxr_keyword">if</strong> (keystore != <strong class="jxr_keyword">null</strong>) {
-<a name="911" href="#911">911</a>             certs = getCertificates(issuerName, serialNumber, keystore);
-<a name="912" href="#912">912</a>         }
-<a name="913" href="#913">913</a> 
-<a name="914" href="#914">914</a>         <em class="jxr_comment">//If we can't find the issuer in the keystore then look at the truststore</em>
-<a name="915" href="#915">915</a>         <strong class="jxr_keyword">if</strong> ((certs == <strong class="jxr_keyword">null</strong> || certs.length == 0) &amp;&amp; truststore != <strong class="jxr_keyword">null</strong>) {
-<a name="916" href="#916">916</a>             certs = getCertificates(issuerName, serialNumber, truststore);
-<a name="917" href="#917">917</a>         }
-<a name="918" href="#918">918</a>         
-<a name="919" href="#919">919</a>         <strong class="jxr_keyword">if</strong> ((certs == <strong class="jxr_keyword">null</strong> || certs.length == 0)) {
-<a name="920" href="#920">920</a>             <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">null</strong>;
-<a name="921" href="#921">921</a>         }
-<a name="922" href="#922">922</a>         
-<a name="923" href="#923">923</a>         X509Certificate[] x509certs = <strong class="jxr_keyword">new</strong> X509Certificate[certs.length];
-<a name="924" href="#924">924</a>         <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i = 0; i &lt; certs.length; i++) {
-<a name="925" href="#925">925</a>             x509certs[i] = (X509Certificate) certs[i];
-<a name="926" href="#926">926</a>         }
-<a name="927" href="#927">927</a>         <strong class="jxr_keyword">return</strong> x509certs;
-<a name="928" href="#928">928</a>     }
-<a name="929" href="#929">929</a>     
-<a name="930" href="#930">930</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="931" href="#931">931</a> <em class="jxr_javadoccomment">     * Get an X509 Certificate (chain) of the X500Principal argument in the supplied KeyStore </em>
-<a name="932" href="#932">932</a> <em class="jxr_javadoccomment">     * @param subjectRDN either an X500Principal or a BouncyCastle X509Name instance.</em>
-<a name="933" href="#933">933</a> <em class="jxr_javadoccomment">     * @param store The KeyStore</em>
-<a name="934" href="#934">934</a> <em class="jxr_javadoccomment">     * @return an X509 Certificate (chain)</em>
-<a name="935" href="#935">935</a> <em class="jxr_javadoccomment">     * @throws WSSecurityException</em>
-<a name="936" href="#936">936</a> <em class="jxr_javadoccomment">     */</em>
-<a name="937" href="#937">937</a>     <strong class="jxr_keyword">private</strong> Certificate[] getCertificates(
-<a name="938" href="#938">938</a>         Object issuerRDN, 
-<a name="939" href="#939">939</a>         BigInteger serialNumber, 
-<a name="940" href="#940">940</a>         KeyStore store
-<a name="941" href="#941">941</a>     ) <strong class="jxr_keyword">throws</strong> <a href="../../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a> {
-<a name="942" href="#942">942</a>         <strong class="jxr_keyword">try</strong> {
-<a name="943" href="#943">943</a>             <strong class="jxr_keyword">for</strong> (Enumeration&lt;String&gt; e = store.aliases(); e.hasMoreElements();) {
-<a name="944" href="#944">944</a>                 String alias = e.nextElement();
-<a name="945" href="#945">945</a>                 Certificate cert = <strong class="jxr_keyword">null</strong>;
-<a name="946" href="#946">946</a>                 Certificate[] certs = store.getCertificateChain(alias);
-<a name="947" href="#947">947</a>                 <strong class="jxr_keyword">if</strong> (certs == <strong class="jxr_keyword">null</strong> || certs.length == 0) {
-<a name="948" href="#948">948</a>                     <em class="jxr_comment">// no cert chain, so lets check if getCertificate gives us a result.</em>
-<a name="949" href="#949">949</a>                     cert = store.getCertificate(alias);
-<a name="950" href="#950">950</a>                     <strong class="jxr_keyword">if</strong> (cert == <strong class="jxr_keyword">null</strong>) {
-<a name="951" href="#951">951</a>                         <strong class="jxr_keyword">continue</strong>;
-<a name="952" href="#952">952</a>                     }
-<a name="953" href="#953">953</a>                     certs = <strong class="jxr_keyword">new</strong> Certificate[]{cert};
-<a name="954" href="#954">954</a>                 } <strong class="jxr_keyword">else</strong> {
-<a name="955" href="#955">955</a>                     cert = certs[0];
-<a name="956" href="#956">956</a>                 }
-<a name="957" href="#957">957</a>                 <strong class="jxr_keyword">if</strong> (cert instanceof X509Certificate) {
-<a name="958" href="#958">958</a>                     X509Certificate x509cert = (X509Certificate) cert;
-<a name="959" href="#959">959</a>                     <strong class="jxr_keyword">if</strong> (x509cert.getSerialNumber().compareTo(serialNumber) == 0) {
-<a name="960" href="#960">960</a>                         Object certName = 
-<a name="961" href="#961">961</a>                             createBCX509Name(x509cert.getIssuerX500Principal().getName());
-<a name="962" href="#962">962</a>                         <strong class="jxr_keyword">if</strong> (certName.equals(issuerRDN)) {
-<a name="963" href="#963">963</a>                             <strong class="jxr_keyword">return</strong> certs;
-<a name="964" href="#964">964</a>                         }
-<a name="965" href="#965">965</a>                     }
-<a name="966" href="#966">966</a>                 }
-<a name="967" href="#967">967</a>             }
-<a name="968" href="#968">968</a>         } <strong class="jxr_keyword">catch</strong> (KeyStoreException e) {
-<a name="969" href="#969">969</a>             <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(
-<a name="970" href="#970">970</a>                 WSSecurityException.FAILURE, <span class="jxr_string">"keystore"</span>, <strong class="jxr_keyword">null</strong>, e
-<a name="971" href="#971">971</a>             );
-<a name="972" href="#972">972</a>         }
-<a name="973" href="#973">973</a>         <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">new</strong> Certificate[]{};
-<a name="974" href="#974">974</a>     }
-<a name="975" href="#975">975</a>     
-<a name="976" href="#976">976</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="977" href="#977">977</a> <em class="jxr_javadoccomment">     * Get an X509 Certificate (chain) according to a given Thumbprint.</em>
-<a name="978" href="#978">978</a> <em class="jxr_javadoccomment">     *</em>
-<a name="979" href="#979">979</a> <em class="jxr_javadoccomment">     * @param thumbprint The SHA1 thumbprint info bytes</em>
-<a name="980" href="#980">980</a> <em class="jxr_javadoccomment">     * @return the X509 Certificate (chain) that was found (can be null)</em>
-<a name="981" href="#981">981</a> <em class="jxr_javadoccomment">     * @throws WSSecurityException if problems during keystore handling or wrong certificate</em>
-<a name="982" href="#982">982</a> <em class="jxr_javadoccomment">     */</em>
-<a name="983" href="#983">983</a>     <strong class="jxr_keyword">private</strong> X509Certificate[] getX509Certificates(byte[] thumbprint) <strong class="jxr_keyword">throws</strong> WSSecurityException {
-<a name="984" href="#984">984</a>         MessageDigest sha = <strong class="jxr_keyword">null</strong>;
-<a name="985" href="#985">985</a>         
-<a name="986" href="#986">986</a>         <strong class="jxr_keyword">try</strong> {
-<a name="987" href="#987">987</a>             sha = MessageDigest.getInstance(<span class="jxr_string">"SHA1"</span>);
-<a name="988" href="#988">988</a>         } <strong class="jxr_keyword">catch</strong> (NoSuchAlgorithmException e) {
-<a name="989" href="#989">989</a>             <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(
-<a name="990" href="#990">990</a>                 WSSecurityException.FAILURE, <span class="jxr_string">"noSHA1availabe"</span>, <strong class="jxr_keyword">null</strong>, e
-<a name="991" href="#991">991</a>             );
-<a name="992" href="#992">992</a>         }
-<a name="993" href="#993">993</a>         Certificate[] certs = <strong class="jxr_keyword">null</strong>;
-<a name="994" href="#994">994</a>         <strong class="jxr_keyword">if</strong> (keystore != <strong class="jxr_keyword">null</strong>) {
-<a name="995" href="#995">995</a>             certs = getCertificates(thumbprint, keystore, sha);
-<a name="996" href="#996">996</a>         }
-<a name="997" href="#997">997</a> 
-<a name="998" href="#998">998</a>         <em class="jxr_comment">//If we can't find the issuer in the keystore then look at the truststore</em>
-<a name="999" href="#999">999</a>         <strong class="jxr_keyword">if</strong> ((certs == <strong class="jxr_keyword">null</strong> || certs.length == 0) &amp;&amp; truststore != <strong class="jxr_keyword">null</strong>) {
-<a name="1000" href="#1000">1000</a>             certs = getCertificates(thumbprint, truststore, sha);
-<a name="1001" href="#1001">1001</a>         }
-<a name="1002" href="#1002">1002</a>         
-<a name="1003" href="#1003">1003</a>         <strong class="jxr_keyword">if</strong> ((certs == <strong class="jxr_keyword">null</strong> || certs.length == 0)) {
-<a name="1004" href="#1004">1004</a>             <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">null</strong>;
-<a name="1005" href="#1005">1005</a>         }
-<a name="1006" href="#1006">1006</a>         
-<a name="1007" href="#1007">1007</a>         X509Certificate[] x509certs = <strong class="jxr_keyword">new</strong> X509Certificate[certs.length];
-<a name="1008" href="#1008">1008</a>         <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i = 0; i &lt; certs.length; i++) {
-<a name="1009" href="#1009">1009</a>             x509certs[i] = (X509Certificate) certs[i];
-<a name="1010" href="#1010">1010</a>         }
-<a name="1011" href="#1011">1011</a>         <strong class="jxr_keyword">return</strong> x509certs;
-<a name="1012" href="#1012">1012</a>     }
-<a name="1013" href="#1013">1013</a> 
-<a name="1014" href="#1014">1014</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="1015" href="#1015">1015</a> <em class="jxr_javadoccomment">     * Get an X509 Certificate (chain) of the X500Principal argument in the supplied KeyStore </em>
-<a name="1016" href="#1016">1016</a> <em class="jxr_javadoccomment">     * @param subjectRDN either an X500Principal or a BouncyCastle X509Name instance.</em>
-<a name="1017" href="#1017">1017</a> <em class="jxr_javadoccomment">     * @param store The KeyStore</em>
-<a name="1018" href="#1018">1018</a> <em class="jxr_javadoccomment">     * @return an X509 Certificate (chain)</em>
-<a name="1019" href="#1019">1019</a> <em class="jxr_javadoccomment">     * @throws WSSecurityException</em>
-<a name="1020" href="#1020">1020</a> <em class="jxr_javadoccomment">     */</em>
-<a name="1021" href="#1021">1021</a>     <strong class="jxr_keyword">private</strong> Certificate[] getCertificates(
-<a name="1022" href="#1022">1022</a>         byte[] thumbprint, 
-<a name="1023" href="#1023">1023</a>         KeyStore store,
-<a name="1024" href="#1024">1024</a>         MessageDigest sha
-<a name="1025" href="#1025">1025</a>     ) <strong class="jxr_keyword">throws</strong> <a href="../../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a> {
-<a name="1026" href="#1026">1026</a>         <strong class="jxr_keyword">try</strong> {
-<a name="1027" href="#1027">1027</a>             <strong class="jxr_keyword">for</strong> (Enumeration&lt;String&gt; e = store.aliases(); e.hasMoreElements();) {
-<a name="1028" href="#1028">1028</a>                 String alias = e.nextElement();
-<a name="1029" href="#1029">1029</a>                 Certificate cert = <strong class="jxr_keyword">null</strong>;
-<a name="1030" href="#1030">1030</a>                 Certificate[] certs = store.getCertificateChain(alias);
-<a name="1031" href="#1031">1031</a>                 <strong class="jxr_keyword">if</strong> (certs == <strong class="jxr_keyword">null</strong> || certs.length == 0) {
-<a name="1032" href="#1032">1032</a>                     <em class="jxr_comment">// no cert chain, so lets check if getCertificate gives us a result.</em>
-<a name="1033" href="#1033">1033</a>                     cert = store.getCertificate(alias);
-<a name="1034" href="#1034">1034</a>                     <strong class="jxr_keyword">if</strong> (cert == <strong class="jxr_keyword">null</strong>) {
-<a name="1035" href="#1035">1035</a>                         <strong class="jxr_keyword">continue</strong>;
-<a name="1036" href="#1036">1036</a>                     }
-<a name="1037" href="#1037">1037</a>                     certs = <strong class="jxr_keyword">new</strong> Certificate[]{cert};
-<a name="1038" href="#1038">1038</a>                 } <strong class="jxr_keyword">else</strong> {
-<a name="1039" href="#1039">1039</a>                     cert = certs[0];
-<a name="1040" href="#1040">1040</a>                 }
-<a name="1041" href="#1041">1041</a>                 <strong class="jxr_keyword">if</strong> (cert instanceof X509Certificate) {
-<a name="1042" href="#1042">1042</a>                     X509Certificate x509cert = (X509Certificate) cert;
-<a name="1043" href="#1043">1043</a>                     <strong class="jxr_keyword">try</strong> {
-<a name="1044" href="#1044">1044</a>                         sha.update(x509cert.getEncoded());
-<a name="1045" href="#1045">1045</a>                     } <strong class="jxr_keyword">catch</strong> (CertificateEncodingException ex) {
-<a name="1046" href="#1046">1046</a>                         <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(
-<a name="1047" href="#1047">1047</a>                             WSSecurityException.SECURITY_TOKEN_UNAVAILABLE, <span class="jxr_string">"encodeError"</span>,
-<a name="1048" href="#1048">1048</a>                             <strong class="jxr_keyword">null</strong>, ex
-<a name="1049" href="#1049">1049</a>                         );
-<a name="1050" href="#1050">1050</a>                     }
-<a name="1051" href="#1051">1051</a>                     byte[] data = sha.digest();
-<a name="1052" href="#1052">1052</a> 
-<a name="1053" href="#1053">1053</a>                     <strong class="jxr_keyword">if</strong> (Arrays.equals(data, thumbprint)) {
-<a name="1054" href="#1054">1054</a>                         <strong class="jxr_keyword">return</strong> certs;
-<a name="1055" href="#1055">1055</a>                     }
-<a name="1056" href="#1056">1056</a>                 }
-<a name="1057" href="#1057">1057</a>             }
-<a name="1058" href="#1058">1058</a>         } <strong class="jxr_keyword">catch</strong> (KeyStoreException e) {
-<a name="1059" href="#1059">1059</a>             <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(
-<a name="1060" href="#1060">1060</a>                 WSSecurityException.FAILURE, <span class="jxr_string">"keystore"</span>, <strong class="jxr_keyword">null</strong>, e
-<a name="1061" href="#1061">1061</a>             );
-<a name="1062" href="#1062">1062</a>         }
-<a name="1063" href="#1063">1063</a>         <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">new</strong> Certificate[]{};
-<a name="1064" href="#1064">1064</a>     }
-<a name="1065" href="#1065">1065</a>     
-<a name="1066" href="#1066">1066</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="1067" href="#1067">1067</a> <em class="jxr_javadoccomment">     * Get an X509 Certificate (chain) according to a given SubjectKeyIdentifier.</em>
-<a name="1068" href="#1068">1068</a> <em class="jxr_javadoccomment">     *</em>
-<a name="1069" href="#1069">1069</a> <em class="jxr_javadoccomment">     * @param skiBytes The SKI bytes</em>
-<a name="1070" href="#1070">1070</a> <em class="jxr_javadoccomment">     * @return the X509 certificate (chain) that was found (can be null)</em>
-<a name="1071" href="#1071">1071</a> <em class="jxr_javadoccomment">     */</em>
-<a name="1072" href="#1072">1072</a>     <strong class="jxr_keyword">private</strong> X509Certificate[] getX509CertificatesSKI(byte[] skiBytes) <strong class="jxr_keyword">throws</strong> WSSecurityException {
-<a name="1073" href="#1073">1073</a>         Certificate[] certs = <strong class="jxr_keyword">null</strong>;
-<a name="1074" href="#1074">1074</a>         <strong class="jxr_keyword">if</strong> (keystore != <strong class="jxr_keyword">null</strong>) {
-<a name="1075" href="#1075">1075</a>             certs = getCertificates(skiBytes, keystore);
-<a name="1076" href="#1076">1076</a>         }
-<a name="1077" href="#1077">1077</a> 
-<a name="1078" href="#1078">1078</a>         <em class="jxr_comment">//If we can't find the issuer in the keystore then look at the truststore</em>
-<a name="1079" href="#1079">1079</a>         <strong class="jxr_keyword">if</strong> ((certs == <strong class="jxr_keyword">null</strong> || certs.length == 0) &amp;&amp; truststore != <strong class="jxr_keyword">null</strong>) {
-<a name="1080" href="#1080">1080</a>             certs = getCertificates(skiBytes, truststore);
-<a name="1081" href="#1081">1081</a>         }
-<a name="1082" href="#1082">1082</a>         
-<a name="1083" href="#1083">1083</a>         <strong class="jxr_keyword">if</strong> ((certs == <strong class="jxr_keyword">null</strong> || certs.length == 0)) {
-<a name="1084" href="#1084">1084</a>             <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">null</strong>;
-<a name="1085" href="#1085">1085</a>         }
-<a name="1086" href="#1086">1086</a>         
-<a name="1087" href="#1087">1087</a>         X509Certificate[] x509certs = <strong class="jxr_keyword">new</strong> X509Certificate[certs.length];
-<a name="1088" href="#1088">1088</a>         <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i = 0; i &lt; certs.length; i++) {
-<a name="1089" href="#1089">1089</a>             x509certs[i] = (X509Certificate) certs[i];
-<a name="1090" href="#1090">1090</a>         }
-<a name="1091" href="#1091">1091</a>         <strong class="jxr_keyword">return</strong> x509certs;
-<a name="1092" href="#1092">1092</a>     }
-<a name="1093" href="#1093">1093</a>     
-<a name="1094" href="#1094">1094</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="1095" href="#1095">1095</a> <em class="jxr_javadoccomment">     * Get an X509 Certificate (chain) of the X500Principal argument in the supplied KeyStore </em>
-<a name="1096" href="#1096">1096</a> <em class="jxr_javadoccomment">     * @param subjectRDN either an X500Principal or a BouncyCastle X509Name instance.</em>
-<a name="1097" href="#1097">1097</a> <em class="jxr_javadoccomment">     * @param store The KeyStore</em>
-<a name="1098" href="#1098">1098</a> <em class="jxr_javadoccomment">     * @return an X509 Certificate (chain)</em>
-<a name="1099" href="#1099">1099</a> <em class="jxr_javadoccomment">     * @throws WSSecurityException</em>
-<a name="1100" href="#1100">1100</a> <em class="jxr_javadoccomment">     */</em>
-<a name="1101" href="#1101">1101</a>     <strong class="jxr_keyword">private</strong> Certificate[] getCertificates(
-<a name="1102" href="#1102">1102</a>         byte[] skiBytes, 
-<a name="1103" href="#1103">1103</a>         KeyStore store
-<a name="1104" href="#1104">1104</a>     ) <strong class="jxr_keyword">throws</strong> <a href="../../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a> {
-<a name="1105" href="#1105">1105</a>         <strong class="jxr_keyword">try</strong> {
-<a name="1106" href="#1106">1106</a>             <strong class="jxr_keyword">for</strong> (Enumeration&lt;String&gt; e = store.aliases(); e.hasMoreElements();) {
-<a name="1107" href="#1107">1107</a>                 String alias = e.nextElement();
-<a name="1108" href="#1108">1108</a>                 Certificate cert = <strong class="jxr_keyword">null</strong>;
-<a name="1109" href="#1109">1109</a>                 Certificate[] certs = store.getCertificateChain(alias);
-<a name="1110" href="#1110">1110</a>                 <strong class="jxr_keyword">if</strong> (certs == <strong class="jxr_keyword">null</strong> || certs.length == 0) {
-<a name="1111" href="#1111">1111</a>                     <em class="jxr_comment">// no cert chain, so lets check if getCertificate gives us a result.</em>
-<a name="1112" href="#1112">1112</a>                     cert = store.getCertificate(alias);
-<a name="1113" href="#1113">1113</a>                     <strong class="jxr_keyword">if</strong> (cert == <strong class="jxr_keyword">null</strong>) {
-<a name="1114" href="#1114">1114</a>                         <strong class="jxr_keyword">continue</strong>;
-<a name="1115" href="#1115">1115</a>                     }
-<a name="1116" href="#1116">1116</a>                     certs = <strong class="jxr_keyword">new</strong> Certificate[]{cert};
-<a name="1117" href="#1117">1117</a>                 } <strong class="jxr_keyword">else</strong> {
-<a name="1118" href="#1118">1118</a>                     cert = certs[0];
-<a name="1119" href="#1119">1119</a>                 }
-<a name="1120" href="#1120">1120</a>                 <strong class="jxr_keyword">if</strong> (cert instanceof X509Certificate) {
-<a name="1121" href="#1121">1121</a>                     X509Certificate x509cert = (X509Certificate) cert;
-<a name="1122" href="#1122">1122</a>                     byte[] data = getSKIBytesFromCert(x509cert);
-<a name="1123" href="#1123">1123</a>                     <strong class="jxr_keyword">if</strong> (data.length == skiBytes.length &amp;&amp; Arrays.equals(data, skiBytes)) {
-<a name="1124" href="#1124">1124</a>                         <strong class="jxr_keyword">return</strong> certs;
-<a name="1125" href="#1125">1125</a>                     }
-<a name="1126" href="#1126">1126</a>                 }
-<a name="1127" href="#1127">1127</a>             }
-<a name="1128" href="#1128">1128</a>         } <strong class="jxr_keyword">catch</strong> (KeyStoreException e) {
-<a name="1129" href="#1129">1129</a>             <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(
-<a name="1130" href="#1130">1130</a>                 WSSecurityException.FAILURE, <span class="jxr_string">"keystore"</span>, <strong class="jxr_keyword">null</strong>, e
-<a name="1131" href="#1131">1131</a>             );
-<a name="1132" href="#1132">1132</a>         }
-<a name="1133" href="#1133">1133</a>         <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">new</strong> Certificate[]{};
-<a name="1134" href="#1134">1134</a>     }
-<a name="1135" href="#1135">1135</a>     
-<a name="1136" href="#1136">1136</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="1137" href="#1137">1137</a> <em class="jxr_javadoccomment">     * Get an X509 Certificate (chain) according to a given DN of the subject of the certificate</em>
-<a name="1138" href="#1138">1138</a> <em class="jxr_javadoccomment">     *</em>
-<a name="1139" href="#1139">1139</a> <em class="jxr_javadoccomment">     * @param subjectDN The DN of subject to look for</em>
-<a name="1140" href="#1140">1140</a> <em class="jxr_javadoccomment">     * @return An X509 Certificate (chain) with the same DN as given in the parameters</em>
-<a name="1141" href="#1141">1141</a> <em class="jxr_javadoccomment">     * @throws WSSecurityException</em>
-<a name="1142" href="#1142">1142</a> <em class="jxr_javadoccomment">     */</em>
-<a name="1143" href="#1143">1143</a>     <strong class="jxr_keyword">private</strong> X509Certificate[] getX509CertificatesSubjectDN(String subjectDN) <strong class="jxr_keyword">throws</strong> WSSecurityException {
-<a name="1144" href="#1144">1144</a>         <em class="jxr_comment">//</em>
-<a name="1145" href="#1145">1145</a>         <em class="jxr_comment">// Convert the subject DN to a java X500Principal object first. This is to ensure</em>
-<a name="1146" href="#1146">1146</a>         <em class="jxr_comment">// interop with a DN constructed from .NET, where e.g. it uses "S" instead of "ST".</em>
-<a name="1147" href="#1147">1147</a>         <em class="jxr_comment">// Then convert it to a BouncyCastle X509Name, which will order the attributes of</em>
-<a name="1148" href="#1148">1148</a>         <em class="jxr_comment">// the DN in a particular way (see WSS-168). If the conversion to an X500Principal</em>
-<a name="1149" href="#1149">1149</a>         <em class="jxr_comment">// object fails (e.g. if the DN contains "E" instead of "EMAILADDRESS"), then fall</em>
-<a name="1150" href="#1150">1150</a>         <em class="jxr_comment">// back on a direct conversion to a BC X509Name</em>
-<a name="1151" href="#1151">1151</a>         <em class="jxr_comment">//</em>
-<a name="1152" href="#1152">1152</a>         Object subject;
-<a name="1153" href="#1153">1153</a>         <strong class="jxr_keyword">try</strong> {
-<a name="1154" href="#1154">1154</a>             X500Principal subjectRDN = <strong class="jxr_keyword">new</strong> X500Principal(subjectDN);
-<a name="1155" href="#1155">1155</a>             subject = createBCX509Name(subjectRDN.getName());
-<a name="1156" href="#1156">1156</a>         } <strong class="jxr_keyword">catch</strong> (java.lang.IllegalArgumentException ex) {
-<a name="1157" href="#1157">1157</a>             subject = createBCX509Name(subjectDN);
-<a name="1158" href="#1158">1158</a>         }
-<a name="1159" href="#1159">1159</a>         
-<a name="1160" href="#1160">1160</a>         Certificate[] certs = <strong class="jxr_keyword">null</strong>;
-<a name="1161" href="#1161">1161</a>         <strong class="jxr_keyword">if</strong> (keystore != <strong class="jxr_keyword">null</strong>) {
-<a name="1162" href="#1162">1162</a>             certs = getCertificates(subject, keystore);
-<a name="1163" href="#1163">1163</a>         }
-<a name="1164" href="#1164">1164</a> 
-<a name="1165" href="#1165">1165</a>         <em class="jxr_comment">//If we can't find the issuer in the keystore then look at the truststore</em>
-<a name="1166" href="#1166">1166</a>         <strong class="jxr_keyword">if</strong> ((certs == <strong class="jxr_keyword">null</strong> || certs.length == 0) &amp;&amp; truststore != <strong class="jxr_keyword">null</strong>) {
-<a name="1167" href="#1167">1167</a>             certs = getCertificates(subject, truststore);
-<a name="1168" href="#1168">1168</a>         }
-<a name="1169" href="#1169">1169</a>         
-<a name="1170" href="#1170">1170</a>         <strong class="jxr_keyword">if</strong> ((certs == <strong class="jxr_keyword">null</strong> || certs.length == 0)) {
-<a name="1171" href="#1171">1171</a>             <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">null</strong>;
-<a name="1172" href="#1172">1172</a>         }
-<a name="1173" href="#1173">1173</a>         
-<a name="1174" href="#1174">1174</a>         X509Certificate[] x509certs = <strong class="jxr_keyword">new</strong> X509Certificate[certs.length];
-<a name="1175" href="#1175">1175</a>         <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i = 0; i &lt; certs.length; i++) {
-<a name="1176" href="#1176">1176</a>             x509certs[i] = (X509Certificate) certs[i];
-<a name="1177" href="#1177">1177</a>         }
-<a name="1178" href="#1178">1178</a>         <strong class="jxr_keyword">return</strong> x509certs;
-<a name="1179" href="#1179">1179</a>     }
-<a name="1180" href="#1180">1180</a>     
-<a name="1181" href="#1181">1181</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="1182" href="#1182">1182</a> <em class="jxr_javadoccomment">     * Get an X509 Certificate (chain) that correspond to the identifier. For this implementation,</em>
-<a name="1183" href="#1183">1183</a> <em class="jxr_javadoccomment">     * the identifier corresponds to the KeyStore alias.</em>
-<a name="1184" href="#1184">1184</a> <em class="jxr_javadoccomment">     * </em>
-<a name="1185" href="#1185">1185</a> <em class="jxr_javadoccomment">     * @param identifier The identifier that corresponds to the returned certs</em>
-<a name="1186" href="#1186">1186</a> <em class="jxr_javadoccomment">     * @return an X509 Certificate (chain) that corresponds to the identifier</em>
-<a name="1187" href="#1187">1187</a> <em class="jxr_javadoccomment">     */</em>
-<a name="1188" href="#1188">1188</a>     <strong class="jxr_keyword">private</strong> X509Certificate[] getX509Certificates(String identifier) <strong class="jxr_keyword">throws</strong> WSSecurityException {
-<a name="1189" href="#1189">1189</a>         Certificate[] certs = <strong class="jxr_keyword">null</strong>;
-<a name="1190" href="#1190">1190</a>         <strong class="jxr_keyword">try</strong> {
-<a name="1191" href="#1191">1191</a>             <strong class="jxr_keyword">if</strong> (keystore != <strong class="jxr_keyword">null</strong>) {
-<a name="1192" href="#1192">1192</a>                 <em class="jxr_comment">// There's a chance that there can only be a set of trust stores</em>
-<a name="1193" href="#1193">1193</a>                 certs = keystore.getCertificateChain(identifier);
-<a name="1194" href="#1194">1194</a>                 <strong class="jxr_keyword">if</strong> (certs == <strong class="jxr_keyword">null</strong> || certs.length == 0) {
-<a name="1195" href="#1195">1195</a>                     <em class="jxr_comment">// no cert chain, so lets check if getCertificate gives us a result.</em>
-<a name="1196" href="#1196">1196</a>                     Certificate cert = keystore.getCertificate(identifier);
-<a name="1197" href="#1197">1197</a>                     <strong class="jxr_keyword">if</strong> (cert != <strong class="jxr_keyword">null</strong>) {
-<a name="1198" href="#1198">1198</a>                         certs = <strong class="jxr_keyword">new</strong> Certificate[]{cert};
-<a name="1199" href="#1199">1199</a>                     }
-<a name="1200" href="#1200">1200</a>                 }
-<a name="1201" href="#1201">1201</a>             }
-<a name="1202" href="#1202">1202</a> 
-<a name="1203" href="#1203">1203</a>             <strong class="jxr_keyword">if</strong> (certs == <strong class="jxr_keyword">null</strong> &amp;&amp; truststore != <strong class="jxr_keyword">null</strong>) {
-<a name="1204" href="#1204">1204</a>                 <em class="jxr_comment">// Now look into the trust stores</em>
-<a name="1205" href="#1205">1205</a>                 certs = truststore.getCertificateChain(identifier);
-<a name="1206" href="#1206">1206</a>                 <strong class="jxr_keyword">if</strong> (certs == <strong class="jxr_keyword">null</strong>) {
-<a name="1207" href="#1207">1207</a>                     Certificate cert = truststore.getCertificate(identifier);
-<a name="1208" href="#1208">1208</a>                     <strong class="jxr_keyword">if</strong> (cert != <strong class="jxr_keyword">null</strong>) {
-<a name="1209" href="#1209">1209</a>                         certs = <strong class="jxr_keyword">new</strong> Certificate[]{cert};
-<a name="1210" href="#1210">1210</a>                     }
-<a name="1211" href="#1211">1211</a>                 }
-<a name="1212" href="#1212">1212</a>             }
-<a name="1213" href="#1213">1213</a> 
-<a name="1214" href="#1214">1214</a>             <strong class="jxr_keyword">if</strong> (certs == <strong class="jxr_keyword">null</strong>) {
-<a name="1215" href="#1215">1215</a>                 <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">null</strong>;
-<a name="1216" href="#1216">1216</a>             }
-<a name="1217" href="#1217">1217</a>         } <strong class="jxr_keyword">catch</strong> (KeyStoreException e) {
-<a name="1218" href="#1218">1218</a>             <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(WSSecurityException.FAILURE, <span class="jxr_string">"keystore"</span>, <strong class="jxr_keyword">null</strong>, e);
-<a name="1219" href="#1219">1219</a>         }
-<a name="1220" href="#1220">1220</a> 
-<a name="1221" href="#1221">1221</a>         X509Certificate[] x509certs = <strong class="jxr_keyword">new</strong> X509Certificate[certs.length];
-<a name="1222" href="#1222">1222</a>         <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i = 0; i &lt; certs.length; i++) {
-<a name="1223" href="#1223">1223</a>             x509certs[i] = (X509Certificate) certs[i];
-<a name="1224" href="#1224">1224</a>         }
-<a name="1225" href="#1225">1225</a>         <strong class="jxr_keyword">return</strong> x509certs;
-<a name="1226" href="#1226">1226</a>     }
-<a name="1227" href="#1227">1227</a>     
-<a name="1228" href="#1228">1228</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="1229" href="#1229">1229</a> <em class="jxr_javadoccomment">     * Find the Public Key in a keystore. </em>
-<a name="1230" href="#1230">1230</a> <em class="jxr_javadoccomment">     */</em>
-<a name="1231" href="#1231">1231</a>     <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">boolean</strong> findPublicKeyInKeyStore(PublicKey publicKey, KeyStore keyStoreToSearch) {
-<a name="1232" href="#1232">1232</a>         <strong class="jxr_keyword">try</strong> {
-<a name="1233" href="#1233">1233</a>             <strong class="jxr_keyword">for</strong> (Enumeration&lt;String&gt; e = keyStoreToSearch.aliases(); e.hasMoreElements();) {
-<a name="1234" href="#1234">1234</a>                 String alias = e.nextElement();
-<a name="1235" href="#1235">1235</a>                 Certificate[] certs = keyStoreToSearch.getCertificateChain(alias);
-<a name="1236" href="#1236">1236</a>                 Certificate cert;
-<a name="1237" href="#1237">1237</a>                 <strong class="jxr_keyword">if</strong> (certs == <strong class="jxr_keyword">null</strong> || certs.length == 0) {
-<a name="1238" href="#1238">1238</a>                     <em class="jxr_comment">// no cert chain, so lets check if getCertificate gives us a result.</em>
-<a name="1239" href="#1239">1239</a>                     cert = keyStoreToSearch.getCertificate(alias);
-<a name="1240" href="#1240">1240</a>                     <strong class="jxr_keyword">if</strong> (cert == <strong class="jxr_keyword">null</strong>) {
-<a name="1241" href="#1241">1241</a>                         <strong class="jxr_keyword">continue</strong>;
-<a name="1242" href="#1242">1242</a>                     }
-<a name="1243" href="#1243">1243</a>                 } <strong class="jxr_keyword">else</strong> {
-<a name="1244" href="#1244">1244</a>                     cert = certs[0];
-<a name="1245" href="#1245">1245</a>                 }
-<a name="1246" href="#1246">1246</a>                 <strong class="jxr_keyword">if</strong> (!(cert instanceof X509Certificate)) {
-<a name="1247" href="#1247">1247</a>                     <strong class="jxr_keyword">continue</strong>;
-<a name="1248" href="#1248">1248</a>                 }
-<a name="1249" href="#1249">1249</a>                 X509Certificate x509cert = (X509Certificate) cert;
-<a name="1250" href="#1250">1250</a>                 <strong class="jxr_keyword">if</strong> (publicKey.equals(x509cert.getPublicKey())) {
-<a name="1251" href="#1251">1251</a>                     <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">true</strong>;
-<a name="1252" href="#1252">1252</a>                 }
-<a name="1253" href="#1253">1253</a>             }
-<a name="1254" href="#1254">1254</a>         } <strong class="jxr_keyword">catch</strong> (KeyStoreException e) {
-<a name="1255" href="#1255">1255</a>             <strong class="jxr_keyword">return</strong> false;
-<a name="1256" href="#1256">1256</a>         }
-<a name="1257" href="#1257">1257</a>         <strong class="jxr_keyword">return</strong> false;
-<a name="1258" href="#1258">1258</a>     }
-<a name="1259" href="#1259">1259</a>     
-<a name="1260" href="#1260">1260</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="1261" href="#1261">1261</a> <em class="jxr_javadoccomment">     * Get an X509 Certificate (chain) of the X500Principal argument in the supplied KeyStore </em>
-<a name="1262" href="#1262">1262</a> <em class="jxr_javadoccomment">     * @param subjectRDN either an X500Principal or a BouncyCastle X509Name instance.</em>
-<a name="1263" href="#1263">1263</a> <em class="jxr_javadoccomment">     * @param store The KeyStore</em>
-<a name="1264" href="#1264">1264</a> <em class="jxr_javadoccomment">     * @return an X509 Certificate (chain)</em>
-<a name="1265" href="#1265">1265</a> <em class="jxr_javadoccomment">     * @throws WSSecurityException</em>
-<a name="1266" href="#1266">1266</a> <em class="jxr_javadoccomment">     */</em>
-<a name="1267" href="#1267">1267</a>     <strong class="jxr_keyword">private</strong> Certificate[] getCertificates(Object subjectRDN, KeyStore store) 
-<a name="1268" href="#1268">1268</a>         <strong class="jxr_keyword">throws</strong> <a href="../../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a> {
-<a name="1269" href="#1269">1269</a>         <strong class="jxr_keyword">try</strong> {
-<a name="1270" href="#1270">1270</a>             <strong class="jxr_keyword">for</strong> (Enumeration&lt;String&gt; e = store.aliases(); e.hasMoreElements();) {
-<a name="1271" href="#1271">1271</a>                 String alias = e.nextElement();
-<a name="1272" href="#1272">1272</a>                 Certificate cert = <strong class="jxr_keyword">null</strong>;
-<a name="1273" href="#1273">1273</a>                 Certificate[] certs = store.getCertificateChain(alias);
-<a name="1274" href="#1274">1274</a>                 <strong class="jxr_keyword">if</strong> (certs == <strong class="jxr_keyword">null</strong> || certs.length == 0) {
-<a name="1275" href="#1275">1275</a>                     <em class="jxr_comment">// no cert chain, so lets check if getCertificate gives us a result.</em>
-<a name="1276" href="#1276">1276</a>                     cert = store.getCertificate(alias);
-<a name="1277" href="#1277">1277</a>                     <strong class="jxr_keyword">if</strong> (cert == <strong class="jxr_keyword">null</strong>) {
-<a name="1278" href="#1278">1278</a>                         <strong class="jxr_keyword">continue</strong>;
-<a name="1279" href="#1279">1279</a>                     }
-<a name="1280" href="#1280">1280</a>                     certs = <strong class="jxr_keyword">new</strong> Certificate[]{cert};
-<a name="1281" href="#1281">1281</a>                 } <strong class="jxr_keyword">else</strong> {
-<a name="1282" href="#1282">1282</a>                     cert = certs[0];
-<a name="1283" href="#1283">1283</a>                 }
-<a name="1284" href="#1284">1284</a>                 <strong class="jxr_keyword">if</strong> (cert instanceof X509Certificate) {
-<a name="1285" href="#1285">1285</a>                     X500Principal foundRDN = ((X509Certificate) cert).getSubjectX500Principal();
-<a name="1286" href="#1286">1286</a>                     Object certName = createBCX509Name(foundRDN.getName());
-<a name="1287" href="#1287">1287</a> 
-<a name="1288" href="#1288">1288</a>                     <strong class="jxr_keyword">if</strong> (subjectRDN.equals(certName)) {
-<a name="1289" href="#1289">1289</a>                         <strong class="jxr_keyword">return</strong> certs;
-<a name="1290" href="#1290">1290</a>                     }
-<a name="1291" href="#1291">1291</a>                 }
-<a name="1292" href="#1292">1292</a>             }
-<a name="1293" href="#1293">1293</a>         } <strong class="jxr_keyword">catch</strong> (KeyStoreException e) {
-<a name="1294" href="#1294">1294</a>             <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(
-<a name="1295" href="#1295">1295</a>                 WSSecurityException.FAILURE, <span class="jxr_string">"keystore"</span>, <strong class="jxr_keyword">null</strong>, e
-<a name="1296" href="#1296">1296</a>             );
-<a name="1297" href="#1297">1297</a>         }
-<a name="1298" href="#1298">1298</a>         <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">new</strong> Certificate[]{};
-<a name="1299" href="#1299">1299</a>     }
-<a name="1300" href="#1300">1300</a>     
-<a name="1301" href="#1301">1301</a>     <strong class="jxr_keyword">private</strong> <strong class="jxr_keyword">static</strong> String createKeyStoreErrorMessage(KeyStore keystore) <strong class="jxr_keyword">throws</strong> KeyStoreException {
-<a name="1302" href="#1302">1302</a>         Enumeration&lt;String&gt; aliases = keystore.aliases();
-<a name="1303" href="#1303">1303</a>         StringBuilder sb = <strong class="jxr_keyword">new</strong> StringBuilder(keystore.size() * 7);
-<a name="1304" href="#1304">1304</a>         <strong class="jxr_keyword">boolean</strong> firstAlias = <strong class="jxr_keyword">true</strong>;
-<a name="1305" href="#1305">1305</a>         <strong class="jxr_keyword">while</strong> (aliases.hasMoreElements()) {
-<a name="1306" href="#1306">1306</a>             <strong class="jxr_keyword">if</strong> (!firstAlias) {
-<a name="1307" href="#1307">1307</a>                 sb.append(<span class="jxr_string">", "</span>);
-<a name="1308" href="#1308">1308</a>             }
-<a name="1309" href="#1309">1309</a>             sb.append(aliases.nextElement());
-<a name="1310" href="#1310">1310</a>             firstAlias = false;
-<a name="1311" href="#1311">1311</a>         }
-<a name="1312" href="#1312">1312</a>         String msg = <span class="jxr_string">" in keystore of type ["</span> + keystore.getType()
-<a name="1313" href="#1313">1313</a>             + <span class="jxr_string">"] from provider ["</span> + keystore.getProvider()
-<a name="1314" href="#1314">1314</a>             + <span class="jxr_string">"] with size ["</span> + keystore.size() + <span class="jxr_string">"] and aliases: {"</span>
-<a name="1315" href="#1315">1315</a>             + sb.toString() + <span class="jxr_string">"}"</span>;
-<a name="1316" href="#1316">1316</a>         <strong class="jxr_keyword">return</strong> msg;
-<a name="1317" href="#1317">1317</a>     }
-<a name="1318" href="#1318">1318</a>     
-<a name="1319" href="#1319">1319</a>     <em class="jxr_javadoccomment">/**</em>
-<a name="1320" href="#1320">1320</a> <em class="jxr_javadoccomment">     * Get an implementation-specific identifier that corresponds to the X509Certificate. In</em>
-<a name="1321" href="#1321">1321</a> <em class="jxr_javadoccomment">     * this case, the identifier is the KeyStore alias.</em>
-<a name="1322" href="#1322">1322</a> <em class="jxr_javadoccomment">     * @param cert The X509Certificate corresponding to the returned identifier</em>
-<a name="1323" href="#1323">1323</a> <em class="jxr_javadoccomment">     * @param store The KeyStore to search</em>
-<a name="1324" href="#1324">1324</a> <em class="jxr_javadoccomment">     * @return An implementation-specific identifier that corresponds to the X509Certificate</em>
-<a name="1325" href="#1325">1325</a> <em class="jxr_javadoccomment">     */</em>
-<a name="1326" href="#1326">1326</a>     <strong class="jxr_keyword">private</strong> String getIdentifier(X509Certificate cert, KeyStore store)
-<a name="1327" href="#1327">1327</a>         <strong class="jxr_keyword">throws</strong> <a href="../../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a> {
-<a name="1328" href="#1328">1328</a>         <strong class="jxr_keyword">try</strong> {
-<a name="1329" href="#1329">1329</a>             <strong class="jxr_keyword">for</strong> (Enumeration&lt;String&gt; e = store.aliases(); e.hasMoreElements();) {
-<a name="1330" href="#1330">1330</a>                 String alias = e.nextElement();
-<a name="1331" href="#1331">1331</a>                 
-<a name="1332" href="#1332">1332</a>                 Certificate[] certs = store.getCertificateChain(alias);
-<a name="1333" href="#1333">1333</a>                 Certificate retrievedCert = <strong class="jxr_keyword">null</strong>;
-<a name="1334" href="#1334">1334</a>                 <strong class="jxr_keyword">if</strong> (certs == <strong class="jxr_keyword">null</strong> || certs.length == 0) {
-<a name="1335" href="#1335">1335</a>                     <em class="jxr_comment">// no cert chain, so lets check if getCertificate gives us a  result.</em>
-<a name="1336" href="#1336">1336</a>                     retrievedCert = store.getCertificate(alias);
-<a name="1337" href="#1337">1337</a>                     <strong class="jxr_keyword">if</strong> (retrievedCert == <strong class="jxr_keyword">null</strong>) {
-<a name="1338" href="#1338">1338</a>                         <strong class="jxr_keyword">continue</strong>;
-<a name="1339" href="#1339">1339</a>                     }
-<a name="1340" href="#1340">1340</a>                 } <strong class="jxr_keyword">else</strong> {
-<a name="1341" href="#1341">1341</a>                     retrievedCert = certs[0];
-<a name="1342" href="#1342">1342</a>                 }
-<a name="1343" href="#1343">1343</a>                 <strong class="jxr_keyword">if</strong> (!(retrievedCert instanceof X509Certificate)) {
-<a name="1344" href="#1344">1344</a>                     <strong class="jxr_keyword">continue</strong>;
-<a name="1345" href="#1345">1345</a>                 }
-<a name="1346" href="#1346">1346</a>                 <strong class="jxr_keyword">if</strong> (retrievedCert != <strong class="jxr_keyword">null</strong> &amp;&amp; retrievedCert.equals(cert)) {
-<a name="1347" href="#1347">1347</a>                     <strong class="jxr_keyword">return</strong> alias;
+<a name="847" href="#847">847</a>         } <strong class="jxr_keyword">catch</strong> (NullPointerException e) {
+<a name="848" href="#848">848</a>                 <em class="jxr_comment">// NPE thrown by JDK 1.7 for one of the test cases</em>
+<a name="849" href="#849">849</a>                 <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(
+<a name="850" href="#850">850</a>                     WSSecurityException.FAILURE, <span class="jxr_string">"certpath"</span>,
+<a name="851" href="#851">851</a>                     <strong class="jxr_keyword">new</strong> Object[] { e.getMessage() }, e
+<a name="852" href="#852">852</a>                 );
+<a name="853" href="#853">853</a>         }
+<a name="854" href="#854">854</a>     }
+<a name="855" href="#855">855</a>     
+<a name="856" href="#856">856</a>     <em class="jxr_javadoccomment">/**</em>
+<a name="857" href="#857">857</a> <em class="jxr_javadoccomment">     * Evaluate whether a given public key should be trusted.</em>
+<a name="858" href="#858">858</a> <em class="jxr_javadoccomment">     * </em>
+<a name="859" href="#859">859</a> <em class="jxr_javadoccomment">     * @param publicKey The PublicKey to be evaluated</em>
+<a name="860" href="#860">860</a> <em class="jxr_javadoccomment">     * @return whether the PublicKey parameter is trusted or not</em>
+<a name="861" href="#861">861</a> <em class="jxr_javadoccomment">     */</em>
+<a name="862" href="#862">862</a>     <strong class="jxr_keyword">public</strong> <strong class="jxr_keyword">boolean</strong> verifyTrust(PublicKey publicKey) <strong class="jxr_keyword">throws</strong> WSSecurityException {
+<a name="863" href="#863">863</a>         <em class="jxr_comment">//</em>
+<a name="864" href="#864">864</a>         <em class="jxr_comment">// If the public key is null, do not trust the signature</em>
+<a name="865" href="#865">865</a>         <em class="jxr_comment">//</em>
+<a name="866" href="#866">866</a>         <strong class="jxr_keyword">if</strong> (publicKey == <strong class="jxr_keyword">null</strong>) {
+<a name="867" href="#867">867</a>             <strong class="jxr_keyword">return</strong> false;
+<a name="868" href="#868">868</a>         }
+<a name="869" href="#869">869</a>         
+<a name="870" href="#870">870</a>         <em class="jxr_comment">//</em>
+<a name="871" href="#871">871</a>         <em class="jxr_comment">// Search the keystore for the transmitted public key (direct trust)</em>
+<a name="872" href="#872">872</a>         <em class="jxr_comment">//</em>
+<a name="873" href="#873">873</a>         <strong class="jxr_keyword">boolean</strong> trust = findPublicKeyInKeyStore(publicKey, keystore);
+<a name="874" href="#874">874</a>         <strong class="jxr_keyword">if</strong> (trust) {
+<a name="875" href="#875">875</a>             <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">true</strong>;
+<a name="876" href="#876">876</a>         } <strong class="jxr_keyword">else</strong> {
+<a name="877" href="#877">877</a>             <em class="jxr_comment">//</em>
+<a name="878" href="#878">878</a>             <em class="jxr_comment">// Now search the truststore for the transmitted public key (direct trust)</em>
+<a name="879" href="#879">879</a>             <em class="jxr_comment">//</em>
+<a name="880" href="#880">880</a>             trust = findPublicKeyInKeyStore(publicKey, truststore);
+<a name="881" href="#881">881</a>             <strong class="jxr_keyword">if</strong> (trust) {
+<a name="882" href="#882">882</a>                 <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">true</strong>;
+<a name="883" href="#883">883</a>             }
+<a name="884" href="#884">884</a>         }
+<a name="885" href="#885">885</a>         <strong class="jxr_keyword">return</strong> false;
+<a name="886" href="#886">886</a>     }
+<a name="887" href="#887">887</a>     
+<a name="888" href="#888">888</a>     <em class="jxr_javadoccomment">/**</em>
+<a name="889" href="#889">889</a> <em class="jxr_javadoccomment">     * Get an X509 Certificate (chain) according to a given serial number and issuer string.</em>
+<a name="890" href="#890">890</a> <em class="jxr_javadoccomment">     *</em>
+<a name="891" href="#891">891</a> <em class="jxr_javadoccomment">     * @param issuer The Issuer String</em>
+<a name="892" href="#892">892</a> <em class="jxr_javadoccomment">     * @param serialNumber The serial number of the certificate</em>
+<a name="893" href="#893">893</a> <em class="jxr_javadoccomment">     * @return an X509 Certificate (chain) corresponding to the found certificate(s)</em>
+<a name="894" href="#894">894</a> <em class="jxr_javadoccomment">     * @throws WSSecurityException</em>
+<a name="895" href="#895">895</a> <em class="jxr_javadoccomment">     */</em>
+<a name="896" href="#896">896</a>     <strong class="jxr_keyword">private</strong> X509Certificate[] getX509Certificates(
+<a name="897" href="#897">897</a>         String issuer, 
+<a name="898" href="#898">898</a>         BigInteger serialNumber
+<a name="899" href="#899">899</a>     ) <strong class="jxr_keyword">throws</strong> <a href="../../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a> {
+<a name="900" href="#900">900</a>         <em class="jxr_comment">//</em>
+<a name="901" href="#901">901</a>         <em class="jxr_comment">// Convert the subject DN to a java X500Principal object first. This is to ensure</em>
+<a name="902" href="#902">902</a>         <em class="jxr_comment">// interop with a DN constructed from .NET, where e.g. it uses "S" instead of "ST".</em>
+<a name="903" href="#903">903</a>         <em class="jxr_comment">// Then convert it to a BouncyCastle X509Name, which will order the attributes of</em>
+<a name="904" href="#904">904</a>         <em class="jxr_comment">// the DN in a particular way (see WSS-168). If the conversion to an X500Principal</em>
+<a name="905" href="#905">905</a>         <em class="jxr_comment">// object fails (e.g. if the DN contains "E" instead of "EMAILADDRESS"), then fall</em>
+<a name="906" href="#906">906</a>         <em class="jxr_comment">// back on a direct conversion to a BC X509Name</em>
+<a name="907" href="#907">907</a>         <em class="jxr_comment">//</em>
+<a name="908" href="#908">908</a>         Object issuerName = <strong class="jxr_keyword">null</strong>;
+<a name="909" href="#909">909</a>         <strong class="jxr_keyword">try</strong> {
+<a name="910" href="#910">910</a>             X500Principal issuerRDN = <strong class="jxr_keyword">new</strong> X500Principal(issuer);
+<a name="911" href="#911">911</a>             issuerName = createBCX509Name(issuerRDN.getName());
+<a name="912" href="#912">912</a>         } <strong class="jxr_keyword">catch</strong> (java.lang.IllegalArgumentException ex) {
+<a name="913" href="#913">913</a>             issuerName = createBCX509Name(issuer);
+<a name="914" href="#914">914</a>         }
+<a name="915" href="#915">915</a>         Certificate[] certs = <strong class="jxr_keyword">null</strong>;
+<a name="916" href="#916">916</a>         <strong class="jxr_keyword">if</strong> (keystore != <strong class="jxr_keyword">null</strong>) {
+<a name="917" href="#917">917</a>             certs = getCertificates(issuerName, serialNumber, keystore);
+<a name="918" href="#918">918</a>         }
+<a name="919" href="#919">919</a> 
+<a name="920" href="#920">920</a>         <em class="jxr_comment">//If we can't find the issuer in the keystore then look at the truststore</em>
+<a name="921" href="#921">921</a>         <strong class="jxr_keyword">if</strong> ((certs == <strong class="jxr_keyword">null</strong> || certs.length == 0) &amp;&amp; truststore != <strong class="jxr_keyword">null</strong>) {
+<a name="922" href="#922">922</a>             certs = getCertificates(issuerName, serialNumber, truststore);
+<a name="923" href="#923">923</a>         }
+<a name="924" href="#924">924</a>         
+<a name="925" href="#925">925</a>         <strong class="jxr_keyword">if</strong> ((certs == <strong class="jxr_keyword">null</strong> || certs.length == 0)) {
+<a name="926" href="#926">926</a>             <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">null</strong>;
+<a name="927" href="#927">927</a>         }
+<a name="928" href="#928">928</a>         
+<a name="929" href="#929">929</a>         X509Certificate[] x509certs = <strong class="jxr_keyword">new</strong> X509Certificate[certs.length];
+<a name="930" href="#930">930</a>         <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i = 0; i &lt; certs.length; i++) {
+<a name="931" href="#931">931</a>             x509certs[i] = (X509Certificate) certs[i];
+<a name="932" href="#932">932</a>         }
+<a name="933" href="#933">933</a>         <strong class="jxr_keyword">return</strong> x509certs;
+<a name="934" href="#934">934</a>     }
+<a name="935" href="#935">935</a>     
+<a name="936" href="#936">936</a>     <em class="jxr_javadoccomment">/**</em>
+<a name="937" href="#937">937</a> <em class="jxr_javadoccomment">     * Get an X509 Certificate (chain) of the X500Principal argument in the supplied KeyStore </em>
+<a name="938" href="#938">938</a> <em class="jxr_javadoccomment">     * @param subjectRDN either an X500Principal or a BouncyCastle X509Name instance.</em>
+<a name="939" href="#939">939</a> <em class="jxr_javadoccomment">     * @param store The KeyStore</em>
+<a name="940" href="#940">940</a> <em class="jxr_javadoccomment">     * @return an X509 Certificate (chain)</em>
+<a name="941" href="#941">941</a> <em class="jxr_javadoccomment">     * @throws WSSecurityException</em>
+<a name="942" href="#942">942</a> <em class="jxr_javadoccomment">     */</em>
+<a name="943" href="#943">943</a>     <strong class="jxr_keyword">private</strong> Certificate[] getCertificates(
+<a name="944" href="#944">944</a>         Object issuerRDN, 
+<a name="945" href="#945">945</a>         BigInteger serialNumber, 
+<a name="946" href="#946">946</a>         KeyStore store
+<a name="947" href="#947">947</a>     ) <strong class="jxr_keyword">throws</strong> <a href="../../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a> {
+<a name="948" href="#948">948</a>         <strong class="jxr_keyword">try</strong> {
+<a name="949" href="#949">949</a>             <strong class="jxr_keyword">for</strong> (Enumeration&lt;String&gt; e = store.aliases(); e.hasMoreElements();) {
+<a name="950" href="#950">950</a>                 String alias = e.nextElement();
+<a name="951" href="#951">951</a>                 Certificate cert = <strong class="jxr_keyword">null</strong>;
+<a name="952" href="#952">952</a>                 Certificate[] certs = store.getCertificateChain(alias);
+<a name="953" href="#953">953</a>                 <strong class="jxr_keyword">if</strong> (certs == <strong class="jxr_keyword">null</strong> || certs.length == 0) {
+<a name="954" href="#954">954</a>                     <em class="jxr_comment">// no cert chain, so lets check if getCertificate gives us a result.</em>
+<a name="955" href="#955">955</a>                     cert = store.getCertificate(alias);
+<a name="956" href="#956">956</a>                     <strong class="jxr_keyword">if</strong> (cert == <strong class="jxr_keyword">null</strong>) {
+<a name="957" href="#957">957</a>                         <strong class="jxr_keyword">continue</strong>;
+<a name="958" href="#958">958</a>                     }
+<a name="959" href="#959">959</a>                     certs = <strong class="jxr_keyword">new</strong> Certificate[]{cert};
+<a name="960" href="#960">960</a>                 } <strong class="jxr_keyword">else</strong> {
+<a name="961" href="#961">961</a>                     cert = certs[0];
+<a name="962" href="#962">962</a>                 }
+<a name="963" href="#963">963</a>                 <strong class="jxr_keyword">if</strong> (cert instanceof X509Certificate) {
+<a name="964" href="#964">964</a>                     X509Certificate x509cert = (X509Certificate) cert;
+<a name="965" href="#965">965</a>                     <strong class="jxr_keyword">if</strong> (x509cert.getSerialNumber().compareTo(serialNumber) == 0) {
+<a name="966" href="#966">966</a>                         Object certName = 
+<a name="967" href="#967">967</a>                             createBCX509Name(x509cert.getIssuerX500Principal().getName());
+<a name="968" href="#968">968</a>                         <strong class="jxr_keyword">if</strong> (certName.equals(issuerRDN)) {
+<a name="969" href="#969">969</a>                             <strong class="jxr_keyword">return</strong> certs;
+<a name="970" href="#970">970</a>                         }
+<a name="971" href="#971">971</a>                     }
+<a name="972" href="#972">972</a>                 }
+<a name="973" href="#973">973</a>             }
+<a name="974" href="#974">974</a>         } <strong class="jxr_keyword">catch</strong> (KeyStoreException e) {
+<a name="975" href="#975">975</a>             <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(
+<a name="976" href="#976">976</a>                 WSSecurityException.FAILURE, <span class="jxr_string">"keystore"</span>, <strong class="jxr_keyword">null</strong>, e
+<a name="977" href="#977">977</a>             );
+<a name="978" href="#978">978</a>         }
+<a name="979" href="#979">979</a>         <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">new</strong> Certificate[]{};
+<a name="980" href="#980">980</a>     }
+<a name="981" href="#981">981</a>     
+<a name="982" href="#982">982</a>     <em class="jxr_javadoccomment">/**</em>
+<a name="983" href="#983">983</a> <em class="jxr_javadoccomment">     * Get an X509 Certificate (chain) according to a given Thumbprint.</em>
+<a name="984" href="#984">984</a> <em class="jxr_javadoccomment">     *</em>
+<a name="985" href="#985">985</a> <em class="jxr_javadoccomment">     * @param thumbprint The SHA1 thumbprint info bytes</em>
+<a name="986" href="#986">986</a> <em class="jxr_javadoccomment">     * @return the X509 Certificate (chain) that was found (can be null)</em>
+<a name="987" href="#987">987</a> <em class="jxr_javadoccomment">     * @throws WSSecurityException if problems during keystore handling or wrong certificate</em>
+<a name="988" href="#988">988</a> <em class="jxr_javadoccomment">     */</em>
+<a name="989" href="#989">989</a>     <strong class="jxr_keyword">private</strong> X509Certificate[] getX509Certificates(byte[] thumbprint) <strong class="jxr_keyword">throws</strong> WSSecurityException {
+<a name="990" href="#990">990</a>         MessageDigest sha = <strong class="jxr_keyword">null</strong>;
+<a name="991" href="#991">991</a>         
+<a name="992" href="#992">992</a>         <strong class="jxr_keyword">try</strong> {
+<a name="993" href="#993">993</a>             sha = MessageDigest.getInstance(<span class="jxr_string">"SHA1"</span>);
+<a name="994" href="#994">994</a>         } <strong class="jxr_keyword">catch</strong> (NoSuchAlgorithmException e) {
+<a name="995" href="#995">995</a>             <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(
+<a name="996" href="#996">996</a>                 WSSecurityException.FAILURE, <span class="jxr_string">"noSHA1availabe"</span>, <strong class="jxr_keyword">null</strong>, e
+<a name="997" href="#997">997</a>             );
+<a name="998" href="#998">998</a>         }
+<a name="999" href="#999">999</a>         Certificate[] certs = <strong class="jxr_keyword">null</strong>;
+<a name="1000" href="#1000">1000</a>         <strong class="jxr_keyword">if</strong> (keystore != <strong class="jxr_keyword">null</strong>) {
+<a name="1001" href="#1001">1001</a>             certs = getCertificates(thumbprint, keystore, sha);
+<a name="1002" href="#1002">1002</a>         }
+<a name="1003" href="#1003">1003</a> 
+<a name="1004" href="#1004">1004</a>         <em class="jxr_comment">//If we can't find the issuer in the keystore then look at the truststore</em>
+<a name="1005" href="#1005">1005</a>         <strong class="jxr_keyword">if</strong> ((certs == <strong class="jxr_keyword">null</strong> || certs.length == 0) &amp;&amp; truststore != <strong class="jxr_keyword">null</strong>) {
+<a name="1006" href="#1006">1006</a>             certs = getCertificates(thumbprint, truststore, sha);
+<a name="1007" href="#1007">1007</a>         }
+<a name="1008" href="#1008">1008</a>         
+<a name="1009" href="#1009">1009</a>         <strong class="jxr_keyword">if</strong> ((certs == <strong class="jxr_keyword">null</strong> || certs.length == 0)) {
+<a name="1010" href="#1010">1010</a>             <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">null</strong>;
+<a name="1011" href="#1011">1011</a>         }
+<a name="1012" href="#1012">1012</a>         
+<a name="1013" href="#1013">1013</a>         X509Certificate[] x509certs = <strong class="jxr_keyword">new</strong> X509Certificate[certs.length];
+<a name="1014" href="#1014">1014</a>         <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i = 0; i &lt; certs.length; i++) {
+<a name="1015" href="#1015">1015</a>             x509certs[i] = (X509Certificate) certs[i];
+<a name="1016" href="#1016">1016</a>         }
+<a name="1017" href="#1017">1017</a>         <strong class="jxr_keyword">return</strong> x509certs;
+<a name="1018" href="#1018">1018</a>     }
+<a name="1019" href="#1019">1019</a> 
+<a name="1020" href="#1020">1020</a>     <em class="jxr_javadoccomment">/**</em>
+<a name="1021" href="#1021">1021</a> <em class="jxr_javadoccomment">     * Get an X509 Certificate (chain) of the X500Principal argument in the supplied KeyStore </em>
+<a name="1022" href="#1022">1022</a> <em class="jxr_javadoccomment">     * @param subjectRDN either an X500Principal or a BouncyCastle X509Name instance.</em>
+<a name="1023" href="#1023">1023</a> <em class="jxr_javadoccomment">     * @param store The KeyStore</em>
+<a name="1024" href="#1024">1024</a> <em class="jxr_javadoccomment">     * @return an X509 Certificate (chain)</em>
+<a name="1025" href="#1025">1025</a> <em class="jxr_javadoccomment">     * @throws WSSecurityException</em>
+<a name="1026" href="#1026">1026</a> <em class="jxr_javadoccomment">     */</em>
+<a name="1027" href="#1027">1027</a>     <strong class="jxr_keyword">private</strong> Certificate[] getCertificates(
+<a name="1028" href="#1028">1028</a>         byte[] thumbprint, 
+<a name="1029" href="#1029">1029</a>         KeyStore store,
+<a name="1030" href="#1030">1030</a>         MessageDigest sha
+<a name="1031" href="#1031">1031</a>     ) <strong class="jxr_keyword">throws</strong> <a href="../../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a> {
+<a name="1032" href="#1032">1032</a>         <strong class="jxr_keyword">try</strong> {
+<a name="1033" href="#1033">1033</a>             <strong class="jxr_keyword">for</strong> (Enumeration&lt;String&gt; e = store.aliases(); e.hasMoreElements();) {
+<a name="1034" href="#1034">1034</a>                 String alias = e.nextElement();
+<a name="1035" href="#1035">1035</a>                 Certificate cert = <strong class="jxr_keyword">null</strong>;
+<a name="1036" href="#1036">1036</a>                 Certificate[] certs = store.getCertificateChain(alias);
+<a name="1037" href="#1037">1037</a>                 <strong class="jxr_keyword">if</strong> (certs == <strong class="jxr_keyword">null</strong> || certs.length == 0) {
+<a name="1038" href="#1038">1038</a>                     <em class="jxr_comment">// no cert chain, so lets check if getCertificate gives us a result.</em>
+<a name="1039" href="#1039">1039</a>                     cert = store.getCertificate(alias);
+<a name="1040" href="#1040">1040</a>                     <strong class="jxr_keyword">if</strong> (cert == <strong class="jxr_keyword">null</strong>) {
+<a name="1041" href="#1041">1041</a>                         <strong class="jxr_keyword">continue</strong>;
+<a name="1042" href="#1042">1042</a>                     }
+<a name="1043" href="#1043">1043</a>                     certs = <strong class="jxr_keyword">new</strong> Certificate[]{cert};
+<a name="1044" href="#1044">1044</a>                 } <strong class="jxr_keyword">else</strong> {
+<a name="1045" href="#1045">1045</a>                     cert = certs[0];
+<a name="1046" href="#1046">1046</a>                 }
+<a name="1047" href="#1047">1047</a>                 <strong class="jxr_keyword">if</strong> (cert instanceof X509Certificate) {
+<a name="1048" href="#1048">1048</a>                     X509Certificate x509cert = (X509Certificate) cert;
+<a name="1049" href="#1049">1049</a>                     <strong class="jxr_keyword">try</strong> {
+<a name="1050" href="#1050">1050</a>                         sha.update(x509cert.getEncoded());
+<a name="1051" href="#1051">1051</a>                     } <strong class="jxr_keyword">catch</strong> (CertificateEncodingException ex) {
+<a name="1052" href="#1052">1052</a>                         <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(
+<a name="1053" href="#1053">1053</a>                             WSSecurityException.SECURITY_TOKEN_UNAVAILABLE, <span class="jxr_string">"encodeError"</span>,
+<a name="1054" href="#1054">1054</a>                             <strong class="jxr_keyword">null</strong>, ex
+<a name="1055" href="#1055">1055</a>                         );
+<a name="1056" href="#1056">1056</a>                     }
+<a name="1057" href="#1057">1057</a>                     byte[] data = sha.digest();
+<a name="1058" href="#1058">1058</a> 
+<a name="1059" href="#1059">1059</a>                     <strong class="jxr_keyword">if</strong> (Arrays.equals(data, thumbprint)) {
+<a name="1060" href="#1060">1060</a>                         <strong class="jxr_keyword">return</strong> certs;
+<a name="1061" href="#1061">1061</a>                     }
+<a name="1062" href="#1062">1062</a>                 }
+<a name="1063" href="#1063">1063</a>             }
+<a name="1064" href="#1064">1064</a>         } <strong class="jxr_keyword">catch</strong> (KeyStoreException e) {
+<a name="1065" href="#1065">1065</a>             <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(
+<a name="1066" href="#1066">1066</a>                 WSSecurityException.FAILURE, <span class="jxr_string">"keystore"</span>, <strong class="jxr_keyword">null</strong>, e
+<a name="1067" href="#1067">1067</a>             );
+<a name="1068" href="#1068">1068</a>         }
+<a name="1069" href="#1069">1069</a>         <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">new</strong> Certificate[]{};
+<a name="1070" href="#1070">1070</a>     }
+<a name="1071" href="#1071">1071</a>     
+<a name="1072" href="#1072">1072</a>     <em class="jxr_javadoccomment">/**</em>
+<a name="1073" href="#1073">1073</a> <em class="jxr_javadoccomment">     * Get an X509 Certificate (chain) according to a given SubjectKeyIdentifier.</em>
+<a name="1074" href="#1074">1074</a> <em class="jxr_javadoccomment">     *</em>
+<a name="1075" href="#1075">1075</a> <em class="jxr_javadoccomment">     * @param skiBytes The SKI bytes</em>
+<a name="1076" href="#1076">1076</a> <em class="jxr_javadoccomment">     * @return the X509 certificate (chain) that was found (can be null)</em>
+<a name="1077" href="#1077">1077</a> <em class="jxr_javadoccomment">     */</em>
+<a name="1078" href="#1078">1078</a>     <strong class="jxr_keyword">private</strong> X509Certificate[] getX509CertificatesSKI(byte[] skiBytes) <strong class="jxr_keyword">throws</strong> WSSecurityException {
+<a name="1079" href="#1079">1079</a>         Certificate[] certs = <strong class="jxr_keyword">null</strong>;
+<a name="1080" href="#1080">1080</a>         <strong class="jxr_keyword">if</strong> (keystore != <strong class="jxr_keyword">null</strong>) {
+<a name="1081" href="#1081">1081</a>             certs = getCertificates(skiBytes, keystore);
+<a name="1082" href="#1082">1082</a>         }
+<a name="1083" href="#1083">1083</a> 
+<a name="1084" href="#1084">1084</a>         <em class="jxr_comment">//If we can't find the issuer in the keystore then look at the truststore</em>
+<a name="1085" href="#1085">1085</a>         <strong class="jxr_keyword">if</strong> ((certs == <strong class="jxr_keyword">null</strong> || certs.length == 0) &amp;&amp; truststore != <strong class="jxr_keyword">null</strong>) {
+<a name="1086" href="#1086">1086</a>             certs = getCertificates(skiBytes, truststore);
+<a name="1087" href="#1087">1087</a>         }
+<a name="1088" href="#1088">1088</a>         
+<a name="1089" href="#1089">1089</a>         <strong class="jxr_keyword">if</strong> ((certs == <strong class="jxr_keyword">null</strong> || certs.length == 0)) {
+<a name="1090" href="#1090">1090</a>             <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">null</strong>;
+<a name="1091" href="#1091">1091</a>         }
+<a name="1092" href="#1092">1092</a>         
+<a name="1093" href="#1093">1093</a>         X509Certificate[] x509certs = <strong class="jxr_keyword">new</strong> X509Certificate[certs.length];
+<a name="1094" href="#1094">1094</a>         <strong class="jxr_keyword">for</strong> (<strong class="jxr_keyword">int</strong> i = 0; i &lt; certs.length; i++) {
+<a name="1095" href="#1095">1095</a>             x509certs[i] = (X509Certificate) certs[i];
+<a name="1096" href="#1096">1096</a>         }
+<a name="1097" href="#1097">1097</a>         <strong class="jxr_keyword">return</strong> x509certs;
+<a name="1098" href="#1098">1098</a>     }
+<a name="1099" href="#1099">1099</a>     
+<a name="1100" href="#1100">1100</a>     <em class="jxr_javadoccomment">/**</em>
+<a name="1101" href="#1101">1101</a> <em class="jxr_javadoccomment">     * Get an X509 Certificate (chain) of the X500Principal argument in the supplied KeyStore </em>
+<a name="1102" href="#1102">1102</a> <em class="jxr_javadoccomment">     * @param subjectRDN either an X500Principal or a BouncyCastle X509Name instance.</em>
+<a name="1103" href="#1103">1103</a> <em class="jxr_javadoccomment">     * @param store The KeyStore</em>
+<a name="1104" href="#1104">1104</a> <em class="jxr_javadoccomment">     * @return an X509 Certificate (chain)</em>
+<a name="1105" href="#1105">1105</a> <em class="jxr_javadoccomment">     * @throws WSSecurityException</em>
+<a name="1106" href="#1106">1106</a> <em class="jxr_javadoccomment">     */</em>
+<a name="1107" href="#1107">1107</a>     <strong class="jxr_keyword">private</strong> Certificate[] getCertificates(
+<a name="1108" href="#1108">1108</a>         byte[] skiBytes, 
+<a name="1109" href="#1109">1109</a>         KeyStore store
+<a name="1110" href="#1110">1110</a>     ) <strong class="jxr_keyword">throws</strong> <a href="../../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a> {
+<a name="1111" href="#1111">1111</a>         <strong class="jxr_keyword">try</strong> {
+<a name="1112" href="#1112">1112</a>             <strong class="jxr_keyword">for</strong> (Enumeration&lt;String&gt; e = store.aliases(); e.hasMoreElements();) {
+<a name="1113" href="#1113">1113</a>                 String alias = e.nextElement();
+<a name="1114" href="#1114">1114</a>                 Certificate cert = <strong class="jxr_keyword">null</strong>;
+<a name="1115" href="#1115">1115</a>                 Certificate[] certs = store.getCertificateChain(alias);
+<a name="1116" href="#1116">1116</a>                 <strong class="jxr_keyword">if</strong> (certs == <strong class="jxr_keyword">null</strong> || certs.length == 0) {
+<a name="1117" href="#1117">1117</a>                     <em class="jxr_comment">// no cert chain, so lets check if getCertificate gives us a result.</em>
+<a name="1118" href="#1118">1118</a>                     cert = store.getCertificate(alias);
+<a name="1119" href="#1119">1119</a>                     <strong class="jxr_keyword">if</strong> (cert == <strong class="jxr_keyword">null</strong>) {
+<a name="1120" href="#1120">1120</a>                         <strong class="jxr_keyword">continue</strong>;
+<a name="1121" href="#1121">1121</a>                     }
+<a name="1122" href="#1122">1122</a>                     certs = <strong class="jxr_keyword">new</strong> Certificate[]{cert};
+<a name="1123" href="#1123">1123</a>                 } <strong class="jxr_keyword">else</strong> {
+<a name="1124" href="#1124">1124</a>                     cert = certs[0];
+<a name="1125" href="#1125">1125</a>                 }
+<a name="1126" href="#1126">1126</a>                 <strong class="jxr_keyword">if</strong> (cert instanceof X509Certificate) {
+<a name="1127" href="#1127">1127</a>                     X509Certificate x509cert = (X509Certificate) cert;
+<a name="1128" href="#1128">1128</a>                     byte[] data = getSKIBytesFromCert(x509cert);
+<a name="1129" href="#1129">1129</a>                     <strong class="jxr_keyword">if</strong> (data.length == skiBytes.length &amp;&amp; Arrays.equals(data, skiBytes)) {
+<a name="1130" href="#1130">1130</a>                         <strong class="jxr_keyword">return</strong> certs;
+<a name="1131" href="#1131">1131</a>                     }
+<a name="1132" href="#1132">1132</a>                 }
+<a name="1133" href="#1133">1133</a>             }
+<a name="1134" href="#1134">1134</a>         } <strong class="jxr_keyword">catch</strong> (KeyStoreException e) {
+<a name="1135" href="#1135">1135</a>             <strong class="jxr_keyword">throw</strong> <strong class="jxr_keyword">new</strong> <a href="../../../../../../org/apache/ws/security/WSSecurityException.html">WSSecurityException</a>(
+<a name="1136" href="#1136">1136</a>                 WSSecurityException.FAILURE, <span class="jxr_string">"keystore"</span>, <strong class="jxr_keyword">null</strong>, e
+<a name="1137" href="#1137">1137</a>             );
+<a name="1138" href="#1138">1138</a>         }
+<a name="1139" href="#1139">1139</a>         <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">new</strong> Certificate[]{};
+<a name="1140" href="#1140">1140</a>     }
+<a name="1141" href="#1141">1141</a>     
+<a name="1142" href="#1142">1142</a>     <em class="jxr_javadoccomment">/**</em>
+<a name="1143" href="#1143">1143</a> <em class="jxr_javadoccomment">     * Get an X509 Certificate (chain) according to a given DN of the subject of the certificate</em>
+<a name="1144" href="#1144">1144</a> <em class="jxr_javadoccomment">     *</em>
+<a name="1145" href="#1145">1145</a> <em class="jxr_javadoccomment">     * @param subjectDN The DN of subject to look for</em>
+<a name="1146" href="#1146">1146</a> <em class="jxr_javadoccomment">     * @return An X509 Certificate (chain) with the same DN as given in the parameters</em>
+<a name="1147" href="#1147">1147</a> <em class="jxr_javadoccomment">     * @throws WSSecurityException</em>
+<a name="1148" href="#1148">1148</a> <em class="jxr_javadoccomment">     */</em>
+<a name="1149" href="#1149">1149</a>     <strong class="jxr_keyword">private</strong> X509Certificate[] getX509CertificatesSubjectDN(String subjectDN) <strong class="jxr_keyword">throws</strong> WSSecurityException {
+<a name="1150" href="#1150">1150</a>         <em class="jxr_comment">//</em>
+<a name="1151" href="#1151">1151</a>         <em class="jxr_comment">// Convert the subject DN to a java X500Principal object first. This is to ensure</em>
+<a name="1152" href="#1152">1152</a>         <em class="jxr_comment">// interop with a DN constructed from .NET, where e.g. it uses "S" instead of "ST".</em>
+<a name="1153" href="#1153">1153</a>         <em class="jxr_comment">// Then convert it to a BouncyCastle X509Name, which will order the attributes of</em>
+<a name="1154" href="#1154">1154</a>         <em class="jxr_comment">// the DN in a particular way (see WSS-168). If the conversion to an X500Principal</em>
+<a name="1155" href="#1155">1155</a>         <em class="jxr_comment">// object fails (e.g. if the DN contains "E" instead of "EMAILADDRESS"), then fall</em>
+<a name="1156" href="#1156">1156</a>         <em class="jxr_comment">// back on a direct conversion to a BC X509Name</em>
+<a name="1157" href="#1157">1157</a>         <em class="jxr_comment">//</em>
+<a name="1158" href="#1158">1158</a>         Object subject;
+<a name="1159" href="#1159">1159</a>         <strong class="jxr_keyword">try</strong> {
+<a name="1160" href="#1160">1160</a>             X500Principal subjectRDN = <strong class="jxr_keyword">new</strong> X500Principal(subjectDN);
+<a name="1161" href="#1161">1161</a>             subject = createBCX509Name(subjectRDN.getName());
+<a name="1162" href="#1162">1162</a>         } <strong class="jxr_keyword">catch</strong> (java.lang.IllegalArgumentException ex) {
+<a name="1163" href="#1163">1163</a>             subject = createBCX509Name(subjectDN);
+<a name="1164" href="#1164">1164</a>         }
+<a name="1165" href="#1165">1165</a>         
+<a name="1166" href="#1166">1166</a>         Certificate[] certs = <strong class="jxr_keyword">null</strong>;
+<a name="1167" href="#1167">1167</a>         <strong class="jxr_keyword">if</strong> (keystore != <strong class="jxr_keyword">null</strong>) {
+<a name="1168" href="#1168">1168</a>             certs = getCertificates(subject, keystore);
+<a name="1169" href="#1169">1169</a>         }
+<a name="1170" href="#1170">1170</a> 
+<a name="1171" href="#1171">1171</a>         <em class="jxr_comment">//If we can't find the issuer in the keystore then look at the truststore</em>
+<a name="1172" href="#1172">1172</a>         <strong class="jxr_keyword">if</strong> ((certs == <strong class="jxr_keyword">null</strong> || certs.length == 0) &amp;&amp; truststore != <strong class="jxr_keyword">null</strong>) {
+<a name="1173" href="#1173">1173</a>             certs = getCertificates(subject, truststore);
+<a name="1174" href="#1174">1174</a>         }
+<a name="1175" href="#1175">1175</a>         
+<a name="1176" href="#1176">1176</a>         <strong class="jxr_keyword">if</strong> ((certs == <strong class="jxr_keyword">null</strong> || certs.length == 0)) {
+<a name="1177" href="#1177">1177</a>             <strong class="jxr_keyword">return</strong> <strong class="jxr_keyword">null</strong>;
+<a name="1178" href="#1178">1178</a>         }
+<a name="1179" href="#1179">1179</a>         
+<a name="1180" href="#1180">1180</a>         X509Certificate[] x509certs = <strong class="jxr_keyword">new</strong> X509Certificate[certs.length];

[... 266 lines stripped ...]