001 // Copyright (C) 2002 IAIK 002 // https://jce.iaik.tugraz.at 003 // 004 // Copyright (C) 2003 - 2025 Stiftung Secure Information and 005 // Communication Technologies SIC 006 // https://sic.tech 007 // 008 // All rights reserved. 009 // 010 // Redistribution and use in source and binary forms, with or without 011 // modification, are permitted provided that the following conditions 012 // are met: 013 // 1. Redistributions of source code must retain the above copyright 014 // notice, this list of conditions and the following disclaimer. 015 // 2. Redistributions in binary form must reproduce the above copyright 016 // notice, this list of conditions and the following disclaimer in the 017 // documentation and/or other materials provided with the distribution. 018 // 019 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 020 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 021 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 022 // ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 023 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 024 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 025 // OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 026 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 027 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 028 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 029 // SUCH DAMAGE. 030 031 // Copyright (C) 2002 IAIK 032 // https://sic.tech/ 033 // 034 // Copyright (C) 2003 - 2025 Stiftung Secure Information and 035 // Communication Technologies SIC 036 // https://sic.tech/ 037 // 038 // All rights reserved. 039 // 040 // This source is provided for inspection purposes and recompilation only, 041 // unless specified differently in a contract with IAIK. This source has to 042 // be kept in strict confidence and must not be disclosed to any third party 043 // under any circumstances. Redistribution in source and binary forms, with 044 // or without modification, are <not> permitted in any case! 045 // 046 // THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 047 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 048 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 049 // ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 050 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 051 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 052 // OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 053 // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 054 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 055 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 056 // SUCH DAMAGE. 057 // 058 // $Header: /IAIK-CMS/current/src/demo/DemoAll.java 64 12.02.25 17:58 Dbratko $ 059 // $Revision: 64 $ 060 // 061 062 package demo; 063 064 import java.io.File; 065 import java.io.IOException; 066 067 import demo.cms.authEnvelopedData.AuthEnvelopedDataDemo; 068 import demo.cms.authEnvelopedData.AuthEnvelopedDataOutputStreamDemo; 069 import demo.cms.authenticatedData.AuthenticatedDataDemo; 070 import demo.cms.authenticatedData.AuthenticatedDataOutputStreamDemo; 071 import demo.cms.authenticatedData.HMACwith3DESAuthenticatedDataDemo; 072 import demo.cms.authenticatedData.HMACwithAESAuthenticatedDataDemo; 073 import demo.cms.basic.CMSDemo; 074 import demo.cms.compressedData.CompressedDataDemo; 075 import demo.cms.compressedData.CompressedDataOutputStreamDemo; 076 import demo.cms.data.DataDemo; 077 import demo.cms.digestedData.DigestedDataDemo; 078 import demo.cms.digestedData.DigestedDataOutputStreamDemo; 079 import demo.cms.ecc.ECCDemoUtil; 080 import demo.cms.ecc.EckaEGAuthEnvelopedDataDemo; 081 import demo.cms.encryptedData.EncryptedDataDemo; 082 import demo.cms.encryptedData.EncryptedDataOutputStreamDemo; 083 import demo.cms.envelopedData.ArcFourEnvelopedDataDemo; 084 import demo.cms.envelopedData.CAST128EnvelopedDataDemo; 085 import demo.cms.envelopedData.EncryptedContentInfoDemo; 086 import demo.cms.envelopedData.EnvelopedDataDemo; 087 import demo.cms.envelopedData.EnvelopedDataDemoAEAD; 088 import demo.cms.envelopedData.EnvelopedDataOutputStreamDemo; 089 import demo.cms.envelopedData.ExplicitEnvelopedDataDemo; 090 import demo.cms.envelopedData.OaepEnvelopedDataDemo; 091 import demo.cms.envelopedData.RC2EnvelopedDataDemo; 092 import demo.cms.pkcs7cms.PKCS7CMSDataDemo; 093 import demo.cms.pkcs7cms.PKCS7CMSDigestedDataDemo; 094 import demo.cms.pkcs7cms.PKCS7CMSEncryptedContentInfoDemo; 095 import demo.cms.pkcs7cms.PKCS7CMSEncryptedDataDemo; 096 import demo.cms.pkcs7cms.PKCS7CMSEnvelopedDataDemo; 097 import demo.cms.pkcs7cms.PKCS7CMSSignedDataDemo; 098 import demo.cms.signedAndEnvelopedData.SignedAndEnvelopedDataDemo; 099 import demo.cms.signedData.CounterSignatureDemo; 100 import demo.cms.signedData.PssSignedDataDemo; 101 import demo.cms.signedData.SignedDataDemo; 102 import demo.cms.signedData.SignedDataDemoWithAdditionalSignerInfo; 103 import demo.cms.signedData.SignedDataInOutStreamDemoWithAdditionalSignerInfo; 104 import demo.cms.signedData.SignedDataOutputStreamDemo; 105 import demo.cms.signedData.SignedDataStreamDemoWithAdditionalSignerInfo; 106 import demo.keystore.CMSKeyStoreConstants; 107 import demo.keystore.SetupCMSKeyStore; 108 import demo.smime.basic.BinarySignedDemo; 109 import demo.smime.basic.CMSStreamDemo; 110 import demo.smime.basic.ProcessMessageDemo; 111 import demo.smime.basic.SMimeDemo; 112 import demo.smime.basic.SMimeEnvelopedDemoAEAD; 113 import demo.smime.basic.SMimeV3Demo; 114 import demo.smime.basic.SMimeV4Demo; 115 import demo.smime.ecc.SMimeV4BrainpoolDemo; 116 import demo.smime.ess.MLADemo; 117 import demo.smime.ess.SignedReceiptDemo; 118 import demo.smime.ess.SigningCertificateDemo; 119 import demo.smime.ess.TripleWrappingDemo; 120 import iaik.asn1.structures.AlgorithmID; 121 import iaik.cms.SecurityProvider; 122 import iaik.cms.Utils; 123 124 /** 125 * This class runs all available demos. 126 */ 127 public class DemoAll implements CMSKeyStoreConstants { 128 129 /** 130 * Start all tests. 131 */ 132 public void start() throws Exception { 133 134 File keystore = new File(CMSKeyStoreConstants.KS_FILENAME); 135 if (!keystore.exists()) { 136 System.out.println("Can't find '"+CMSKeyStoreConstants.KS_FILENAME+"'!"); 137 System.out.println("Create new keystore..."); 138 139 SetupCMSKeyStore.start(); 140 } 141 142 String jdkVersion = (String) System.getProperty("java.version"); 143 144 // cms demos 145 (new CMSDemo()).start(); 146 (new DataDemo()).start(); 147 (new DigestedDataDemo()).start(); 148 (new EncryptedDataDemo()).start(); 149 if (Utils.isClassAvailable("iaik.security.dh.ESDHPublicKey")) { 150 // require ESDH 151 (new EnvelopedDataDemo()).start(); 152 if ((jdkVersion != null) && (jdkVersion.compareTo("1.7") >= 0)) { 153 // EnvelopedData with GCM only available for JDK versions >= 1.7 154 (new EnvelopedDataDemoAEAD()).start(); 155 } 156 (new ExplicitEnvelopedDataDemo()).start(); 157 if (DemoUtil.getIaikProviderVersion() >= 3.12) { 158 (new AuthenticatedDataDemo()).start(); 159 (new HMACwith3DESAuthenticatedDataDemo()).start(); 160 (new HMACwithAESAuthenticatedDataDemo()).start(); 161 } 162 if (DemoUtil.getIaikProviderVersion() >= 3.14) { 163 (new demo.cms.envelopedData.AESEnvelopedDataDemo()).start(); 164 (new EnvelopedDataDemo((AlgorithmID)AlgorithmID.aes192_CBC.clone(), 165 (AlgorithmID)AlgorithmID.cms_aes192_wrap.clone(), 166 192)).start(); 167 (new EnvelopedDataDemo((AlgorithmID)AlgorithmID.aes256_CBC.clone(), 168 (AlgorithmID)AlgorithmID.cms_aes256_wrap.clone(), 169 256)).start(); 170 171 (new demo.cms.envelopedData.ExplicitAESEnvelopedDataDemo()).start(); 172 (new ExplicitEnvelopedDataDemo((AlgorithmID)AlgorithmID.aes192_CBC.clone(), 173 (AlgorithmID)AlgorithmID.cms_aes192_wrap.clone(), 174 192)).start(); 175 (new ExplicitEnvelopedDataDemo((AlgorithmID)AlgorithmID.aes256_CBC.clone(), 176 (AlgorithmID)AlgorithmID.cms_aes256_wrap.clone(), 177 256)).start(); 178 } 179 if (DemoUtil.getIaikProviderVersion() > 3.18) { 180 (new demo.cms.envelopedData.CamelliaEnvelopedDataDemo()).start(); 181 (new EnvelopedDataDemo((AlgorithmID)AlgorithmID.camellia192_CBC.clone(), 182 (AlgorithmID)AlgorithmID.cms_camellia192_wrap.clone(), 183 192)).start(); 184 (new EnvelopedDataDemo((AlgorithmID)AlgorithmID.camellia256_CBC.clone(), 185 (AlgorithmID)AlgorithmID.cms_camellia256_wrap.clone(), 186 256)).start(); 187 188 (new ExplicitEnvelopedDataDemo((AlgorithmID)AlgorithmID.camellia128_CBC.clone(), 189 (AlgorithmID)AlgorithmID.cms_camellia128_wrap.clone(), 190 128)).start(); 191 (new ExplicitEnvelopedDataDemo((AlgorithmID)AlgorithmID.camellia192_CBC.clone(), 192 (AlgorithmID)AlgorithmID.cms_camellia192_wrap.clone(), 193 192)).start(); 194 (new ExplicitEnvelopedDataDemo((AlgorithmID)AlgorithmID.camellia256_CBC.clone(), 195 (AlgorithmID)AlgorithmID.cms_camellia256_wrap.clone(), 196 256)).start(); 197 198 199 (new demo.cms.authenticatedData.HMACwithAESAuthenticatedDataDemo()).start(); 200 } 201 } 202 (new SignedDataDemo()).start(); 203 (new CompressedDataDemo()).start(); 204 (new EncryptedContentInfoDemo()).start(); 205 (new SignedAndEnvelopedDataDemo()).start(); 206 (new CAST128EnvelopedDataDemo()).start(); 207 (new RC2EnvelopedDataDemo()).start(); 208 (new ArcFourEnvelopedDataDemo()).start(); 209 210 // run separatly since stores encryption result to a file 211 //(new FileEncryptionDemo()).start(); 212 213 (new PKCS7CMSDataDemo()).start(); 214 (new PKCS7CMSDigestedDataDemo()).start(); 215 (new PKCS7CMSEncryptedDataDemo()).start(); 216 (new PKCS7CMSEnvelopedDataDemo()).start(); 217 (new PKCS7CMSSignedDataDemo()).start(); 218 (new PKCS7CMSEncryptedContentInfoDemo()).start(); 219 (new PssSignedDataDemo()).start(); 220 (new OaepEnvelopedDataDemo()).start(); 221 (new SignedDataDemoWithAdditionalSignerInfo()).start(); 222 (new SignedDataStreamDemoWithAdditionalSignerInfo()).start(); 223 if (DemoUtil.getIaikProviderVersion() >= 3.16) { 224 (new SignedDataInOutStreamDemoWithAdditionalSignerInfo()).start(); 225 } 226 (new CounterSignatureDemo()).start(); 227 (new EnvelopedDataOutputStreamDemo()).start(); 228 (new SignedDataOutputStreamDemo()).start(); 229 (new EncryptedDataOutputStreamDemo()).start(); 230 (new DigestedDataOutputStreamDemo()).start(); 231 if (Utils.isClassAvailable("iaik.security.dh.ESDHPublicKey")) { 232 if (DemoUtil.getIaikProviderVersion() >= 3.12) { 233 (new AuthenticatedDataOutputStreamDemo()).start(); 234 } 235 if (DemoUtil.getIaikProviderVersion() >= 3.17) { 236 (new AuthEnvelopedDataDemo()).start(); 237 (new AuthEnvelopedDataOutputStreamDemo()).start(); 238 } 239 } 240 (new CompressedDataOutputStreamDemo()).start(); 241 242 if (Utils.isClassAvailable("iaik.security.dh.ESDHPublicKey")) { 243 // requires ESDH 244 (new CMSStreamDemo()).start(); 245 } 246 247 // smime demos 248 (new SMimeDemo()).start(); 249 if (Utils.isClassAvailable("iaik.security.dh.ESDHPublicKey")) { 250 // requires ESDH 251 (new SMimeV3Demo()).start(); 252 (new SMimeV4Demo()).start(); 253 } 254 if ((jdkVersion != null) && (jdkVersion.compareTo("1.7") >= 0)) { 255 // S/MIME EnvelopedData with GCM only available for JDK versions >= 1.7 256 (new SMimeEnvelopedDemoAEAD()).start(); 257 } 258 if (DemoUtil.getIaikProviderVersion() > 3.18) { 259 (new demo.smime.basic.SMimeCamelliaDemo()).start(); 260 (new demo.smime.basic.SMimeV3CamelliaDemo()).start(); 261 } 262 (new ProcessMessageDemo()).start(); 263 (new BinarySignedDemo()).start(); 264 265 // run separatly because it creates big (temporary) files 266 // (new BigSMimeMailDemo()).start(); 267 268 (new SigningCertificateDemo()).start(); 269 (new TripleWrappingDemo()).start(); 270 (new SignedReceiptDemo()).start(); 271 272 // run separatly (uses Swing Dialog) 273 // 274 // if (Utils.isClassAvailable("javax.swing.JOptionPane")) { 275 // (new SecurityLabelDemo()).start(); 276 // } 277 278 (new MLADemo()).start(); 279 280 281 // TSP demos (the IAIK TSP library must be in the classpath) 282 if ((Utils.isClassAvailable("iaik.tsp.TimeStampReq")) && (DemoUtil.getIaikProviderVersion() >= 3.14) ) { 283 (new demo.cms.tsp.TimeStampDemo()).start(); 284 } 285 286 // ECC demos (IAIK ECC provider must be in the classpath) 287 if ((Utils.isClassAvailable("iaik.security.ecc.provider.ECCProvider")) || 288 (Utils.isClassAvailable("iaik.security.ec.provider.ECCelerate"))) { 289 // add ECC provider 290 SecurityProvider securityProvider = ECCDemoUtil.installIaikEccProvider(); 291 // CMS 292 (new demo.cms.ecc.ECDSASignedDataDemo()).start(); 293 (new demo.cms.ecc.ECDSASignedDataOutputStreamDemo()).start(); 294 (new demo.cms.ecc.ECDHEnvelopedDataDemo()).start(); 295 if (DemoUtil.getIaikProviderVersion() >= 5.4) { 296 (new EckaEGAuthEnvelopedDataDemo()).start(); 297 } 298 if ((securityProvider.getClass().getName().equals("iaik.cms.ecc.ECCelerateProvider")) && 299 (ECCDemoUtil.getECCelerateVersion() > 6.02)) { 300 (new demo.cms.ecc.EdDSASignedDataDemo()).start(); 301 (new demo.cms.ecc.EdDSASignedDataOutputStreamDemo()).start(); 302 (new demo.cms.ecc.EdDHEnvelopedDataDemo()).start(); 303 (new demo.cms.ecc.EdDHAuthEnvelopedDataDemo()).start(); 304 (new demo.cms.ecc.EdDHAuthenticatedDataDemo()).start(); 305 } 306 // S/MIME 307 (new demo.smime.ecc.SMimeEccDemo()).start(); 308 if (DemoUtil.getIaikProviderVersion() > 3.13) { 309 (new demo.smime.ecc.SMimeEccSuiteBDemo()).start(); 310 } 311 if ((securityProvider.getClass().getName().equals("iaik.cms.ecc.ECCelerateProvider")) && 312 (DemoUtil.getIaikProviderVersion() > 5.62) && 313 (ECCDemoUtil.getECCelerateVersion() > 6.1)) { 314 (new demo.smime.ecc.SMimeV4EccDemo()).start(); 315 (new demo.smime.ecc.SimpleSMimeV4EcDemo()).start(); 316 (new demo.smime.ecc.SimpleSMimeV4EdDemo()).start(); 317 if ((jdkVersion != null) && (jdkVersion.compareTo("1.7") >= 0)) { 318 // EnvelopedData with GCM only available for JDK versions >= 1.7 319 (new SMimeV4BrainpoolDemo()).start(); 320 } 321 322 } 323 } 324 325 } 326 327 /** 328 * Performs all tests. 329 */ 330 public static void main(String arg[]) throws IOException { 331 332 DemoSMimeUtil.initDemos(); 333 334 try { 335 (new DemoAll()).start(); 336 System.out.println("All demos O.K.!!!"); 337 } catch(Exception ex) { 338 System.out.println("There were errors: " + ex.toString()); 339 ex.printStackTrace(); 340 } 341 342 // DemoUtil.waitKey(); 343 344 345 } 346 }