1 /** 2 * Licensed to the Apache Software Foundation (ASF) under one 3 * or more contributor license agreements. See the NOTICE file 4 * distributed with this work for additional information 5 * regarding copyright ownership. The ASF licenses this file 6 * to you under the Apache License, Version 2.0 (the 7 * "License"); you may not use this file except in compliance 8 * with the License. You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, 13 * software distributed under the License is distributed on an 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 * KIND, either express or implied. See the License for the 16 * specific language governing permissions and limitations 17 * under the License. 18 */ 19 package org.apache.xml.security.test.interop; 20 21 import java.io.File; 22 23 import org.apache.xml.security.test.utils.resolver.OfflineResolver; 24 import org.apache.xml.security.utils.JavaUtils; 25 import org.apache.xml.security.utils.resolver.ResourceResolverSpi; 26 27 28 /** 29 * This test is to ensure interoperability with the examples provided by the IBM 30 * XML Security Suite. They have to be located in the directory 31 * <CODE>data/com/ibm/xss4j-20030127/</CODE>. 32 * <BR /> 33 * For license issues, the vectors are not included in the distibution. See 34 * <A HREF="../../../../../../../interop.html">the interop page</A> for more on this. 35 * 36 * @see <A HREF="http://www.alphaworks.ibm.com/tech/xmlsecuritysuite">The IBM alphaWorks Website</A> 37 */ 38 /* 39 * To make interop against the IBM xss4j examples, download the 40 * XSS4j from http://www.alphaworks.ibm.com/tech/xmlsecuritysuite 41 * and extract the test signatures from 42 * xss4j-20030127.zip#/xss4j/data/dsig 43 * in the directory 44 * data/com/ibm/xss4j-20030127/ 45 * then the interop test is performed against these values, too. 46 */ 47 public class IBMTest extends InteropTestBase { 48 49 /** {@link org.apache.commons.logging} logging facility */ 50 static org.apache.commons.logging.Log log = 51 org.apache.commons.logging.LogFactory.getLog(IBMTest.class.getName()); 52 53 /** Field kentsDir */ 54 static final String kentsDir = "data/com/ibm/xss4j-20030127/"; 55 56 static { org.apache.xml.security.Init.init()57 org.apache.xml.security.Init.init(); 58 } 59 60 private boolean runTests = false; 61 62 /** 63 * Constructor IBMTest 64 * 65 * @param Name_ 66 */ IBMTest()67 public IBMTest() { 68 super(); 69 String filename = "src/test/resources/com/ibm/xss4j-20011029/enveloped-rsa.sig"; 70 File f = new File(filename); 71 if (f.exists()) { 72 runTests = true; 73 } 74 } 75 76 /** 77 * Method test_enveloping_hmac 78 * 79 * @throws Exception 80 */ 81 @org.junit.Test test_enveloping_hmac()82 public void test_enveloping_hmac() throws Exception { 83 if (!runTests) { 84 return; 85 } 86 String filename = kentsDir + "enveloping-hmac.sig"; 87 ResourceResolverSpi resolver = new OfflineResolver(); 88 boolean followManifests = false; 89 byte[] hmacKey = JavaUtils.getBytesFromFile(kentsDir + "enveloping-hmac.key"); 90 boolean verify = false; 91 92 try { 93 verify = this.verifyHMAC(filename, resolver, followManifests, hmacKey); 94 } catch (RuntimeException ex) { 95 log.error("Verification crashed for " + filename); 96 throw ex; 97 } 98 99 if (!verify) { 100 log.error("Verification failed for " + filename); 101 } 102 103 assertTrue(filename, verify); 104 } 105 106 /** 107 * Method test_detached_dsa 108 * 109 * @throws Exception 110 */ 111 @org.junit.Test test_detached_dsa()112 public void test_detached_dsa() throws Exception { 113 if (!runTests) { 114 return; 115 } 116 String filename = kentsDir + "detached-dsa.sig"; 117 ResourceResolverSpi resolver = new OfflineResolver(); 118 boolean followManifests = false; 119 boolean verify = false; 120 121 try { 122 verify = this.verify(filename, resolver, followManifests); 123 } catch (RuntimeException ex) { 124 log.error("Verification crashed for " + filename); 125 throw ex; 126 } 127 128 if (!verify) { 129 log.error("Verification failed for " + filename); 130 } 131 132 assertTrue(filename, verify); 133 } 134 135 /** 136 * Method test_detached_rsa 137 * 138 * @throws Exception 139 */ 140 @org.junit.Test test_detached_rsa()141 public void test_detached_rsa() throws Exception { 142 if (!runTests) { 143 return; 144 } 145 String filename = kentsDir + "detached-rsa.sig"; 146 ResourceResolverSpi resolver = new OfflineResolver(); 147 boolean followManifests = false; 148 boolean verify = false; 149 150 try { 151 verify = this.verify(filename, resolver, followManifests); 152 } catch (RuntimeException ex) { 153 log.error("Verification crashed for " + filename); 154 throw ex; 155 } 156 157 if (!verify) { 158 log.error("Verification failed for " + filename); 159 } 160 161 assertTrue(filename, verify); 162 } 163 164 /** 165 * Method test_enveloped_dsa 166 * 167 * @throws Exception 168 */ 169 @org.junit.Test test_enveloped_dsa()170 public void test_enveloped_dsa() throws Exception { 171 if (!runTests) { 172 return; 173 } 174 String filename = kentsDir + "enveloped-dsa.sig"; 175 ResourceResolverSpi resolver = null; 176 boolean followManifests = false; 177 boolean verify = false; 178 179 try { 180 verify = this.verify(filename, resolver, followManifests); 181 } catch (RuntimeException ex) { 182 log.error("Verification crashed for " + filename); 183 throw ex; 184 } 185 186 if (!verify) { 187 log.error("Verification failed for " + filename); 188 } 189 190 assertTrue(filename, verify); 191 } 192 193 /** 194 * Method test_enveloped_rsa 195 * 196 * @throws Exception 197 */ 198 @org.junit.Test test_enveloped_rsa()199 public void test_enveloped_rsa() throws Exception { 200 if (!runTests) { 201 return; 202 } 203 String filename = kentsDir + "enveloped-rsa.sig"; 204 ResourceResolverSpi resolver = null; 205 boolean followManifests = false; 206 boolean verify = false; 207 208 try { 209 verify = this.verify(filename, resolver, followManifests); 210 } catch (RuntimeException ex) { 211 log.error("Verification crashed for " + filename); 212 throw ex; 213 } 214 215 if (!verify) { 216 log.error("Verification failed for " + filename); 217 } 218 219 assertTrue(filename, verify); 220 } 221 222 /** 223 * Method test_enveloping_dsa 224 * 225 * @throws Exception 226 */ 227 @org.junit.Test test_enveloping_dsa()228 public void test_enveloping_dsa() throws Exception { 229 if (!runTests) { 230 return; 231 } 232 String filename = kentsDir + "enveloping-dsa.sig"; 233 ResourceResolverSpi resolver = null; 234 boolean followManifests = false; 235 boolean verify = false; 236 237 try { 238 verify = this.verify(filename, resolver, followManifests); 239 } catch (RuntimeException ex) { 240 log.error("Verification crashed for " + filename); 241 throw ex; 242 } 243 244 if (!verify) { 245 log.error("Verification failed for " + filename); 246 } 247 248 assertTrue(filename, verify); 249 } 250 251 /** 252 * Method test_enveloping_rsa 253 * 254 * @throws Exception 255 */ 256 @org.junit.Test test_enveloping_rsa()257 public void test_enveloping_rsa() throws Exception { 258 if (!runTests) { 259 return; 260 } 261 String filename = kentsDir + "enveloping-rsa.sig"; 262 ResourceResolverSpi resolver = null; 263 boolean followManifests = false; 264 boolean verify = false; 265 266 try { 267 verify = this.verify(filename, resolver, followManifests); 268 } catch (RuntimeException ex) { 269 log.error("Verification crashed for " + filename); 270 throw ex; 271 } 272 273 if (!verify) { 274 log.error("Verification failed for " + filename); 275 } 276 277 assertTrue(filename, verify); 278 } 279 280 /** 281 * Method test_enveloping_dsa_soaped_broken 282 * 283 * @throws Exception 284 */ 285 @org.junit.Test test_enveloping_dsa_soaped_broken()286 public void test_enveloping_dsa_soaped_broken() throws Exception { 287 if (!runTests) { 288 return; 289 } 290 String filename = kentsDir + "enveloping-dsa-soaped-broken.sig"; 291 if (!new File(filename).exists() ) { 292 System.err.println("Couldn't find: " + filename + " and couldn't do the test"); 293 return; 294 } 295 ResourceResolverSpi resolver = null; 296 boolean followManifests = false; 297 boolean verify = true; 298 299 try { 300 verify = this.verify(filename, resolver, followManifests); 301 } catch (RuntimeException ex) { 302 log.error("Verification crashed for " + filename); 303 throw ex; 304 } 305 306 if (verify) { 307 log.error("Verification failed for " + filename + ", had to be broken but was successful"); 308 } 309 310 assertTrue(filename, !verify); 311 } 312 313 /** 314 * Method test_enveloping_exclusive 315 * 316 * @throws Exception 317 * $todo$ implement exclusive-c14n 318 */ 319 @org.junit.Ignore _not_active_test_enveloping_exclusive()320 public void _not_active_test_enveloping_exclusive() throws Exception { 321 // exclusive c14n not supported yet 322 } 323 324 /** 325 * Method test_enveloping_exclusive_soaped 326 * 327 * @throws Exception 328 * $todo$ implement exclusive-c14n 329 */ 330 @org.junit.Ignore _not_active_test_enveloping_exclusive_soaped()331 public void _not_active_test_enveloping_exclusive_soaped() throws Exception { 332 // exclusive c14n not supported yet 333 } 334 335 } 336