001// Copyright (C) 2002 IAIK 002// https://sic.tech/ 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// This source is provided for inspection purposes and recompilation only, 011// unless specified differently in a contract with IAIK. This source has to 012// be kept in strict confidence and must not be disclosed to any third party 013// under any circumstances. Redistribution in source and binary forms, with 014// or without modification, are <not> permitted in any case! 015// 016// THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 017// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 018// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 019// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 020// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 021// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 022// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 023// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 024// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 025// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 026// SUCH DAMAGE. 027// 028// $Header: /IAIK-CMS/current/src/demo/smime/ecc/SimpleSMimeV4EdDemo.java 5 12.02.25 17:59 Dbratko $ 029// $Revision: 5 $ 030// 031 032package demo.smime.ecc; 033 034import demo.DemoSMimeUtil; 035import demo.DemoUtil; 036import demo.cms.ecc.ECCDemoUtil; 037import demo.cms.ecc.keystore.CMSEccKeyStore; 038import iaik.asn1.structures.AlgorithmID; 039import iaik.utils.KeyAndCertificate; 040import iaik.x509.X509Certificate; 041 042/** 043 * This class demonstrates the usage of the IAIK S/MIME implementation. It shows how to create 044 * signed and/or (authenticated) encrypted S/MIMEv4 messages using Ed keys and how to parse them 045 * and verify the signatures and decrypt the content, respectively. 046 * <p> 047 * This demo uses one set of cryptographic algorithms. A demo that uses several combinations of algorithms 048 * is shown in {@link SMimeV4EccDemo SMimeV4EccDemo}. 049 * <p> 050 * Additionally to <code>iaik_cms.jar</code> you also must have 051 * <code>iaik_jce_(full).jar</code> (IAIK-JCE, <a href = 052 * "https://sic.tech/products/core-crypto-toolkits/jca-jce/" target="_blank"> 053 * https://sic.tech/products/core-crypto-toolkits/jca-jce/</a>), 054 * and <code>iaik_eccelarate.jar</code> (IAIK-ECCelerate<sup><small>TM</small></sup>, <a href = 055 * "https://sic.tech/products/core-crypto-toolkits/eccelerate/" target="_blank"> 056 * https://sic.tech/products/core-crypto-toolkits/eccelerate/</a>) 057 * in your classpath. 058 * <p> 059 * To run this demo the following packages are required: 060 * <ul> 061 * <li> 062 * <code>iaik_cms.jar</code> 063 * </li> 064 * <li> 065 * <code>iaik_jce(_full).jar</code> (<a href="https://sic.tech/products/core-crypto-toolkits/jca-jce/" target="_blank">IAIK-JCE Core Crypto Library</a>). 066 * </li> 067 * <li> 068 * <code>iaik_eccelerate.jar</code> (<a href="https://sic.tech/products/core-crypto-toolkits/eccelerate/" target="_blank">IAIK ECC Library</a>). 069 * </li> 070 * <li> 071 * <a href="https://jakarta.ee/specifications/mail/" target="_blank">Jakarta</a>/<a href="https://eclipse-ee4j.github.io/angus-mail/" target="_blank">Angus</a> Mail 072 * </li> 073 * <li> 074 * <a href="https://jakarta.ee/specifications/activation/" target="_blank">Jakarta Activation Framework</a> 075 * </li> 076 * </ul> 077 */ 078public class SimpleSMimeV4EdDemo extends SimpleSMimeV4EcDemo { 079 080 /** 081 * Default constructor. 082 */ 083 public SimpleSMimeV4EdDemo() { 084 085 System.out.println(); 086 System.out.println("********************************************************************************************"); 087 System.out.println("* SimpleSMimeV4EdDemo demo *"); 088 System.out.println("* (shows how to create and parse (verify, decrypt) signed and encrypted S/MIMEv4 messages) *"); 089 System.out.println("********************************************************************************************"); 090 System.out.println(); 091 092 } 093 094 /** 095 * Gets signing key and certificate. 096 * 097 * @return signing key and certificate 098 */ 099 protected KeyAndCertificate getSignerKeyAndCert() { 100 return new KeyAndCertificate( 101 CMSEccKeyStore.getPrivateKey(CMSEccKeyStore.ECDSA, 102 CMSEccKeyStore.SZ_ED25519), 103 CMSEccKeyStore.getCertificateChain(CMSEccKeyStore.ECDSA, 104 CMSEccKeyStore.SZ_ED25519)); 105 } 106 107 /** 108 * Gets the digest algorithm used for signing. 109 * 110 * @return the digest algorithm 111 */ 112 protected AlgorithmID getDigestAlgorithm() { 113 return AlgorithmID.sha512; 114 } 115 116 /** 117 * Gets the signature algorithm. 118 * 119 * @return the signature algorithm 120 */ 121 protected AlgorithmID getSignatureAlgorithm() { 122 return AlgorithmID.ed25519; 123 } 124 125 /** 126 * Gets the recipient certificates. 127 * 128 * @return the certificates of the recipients 129 */ 130 protected X509Certificate[] getRecipientCerts() { 131 X509Certificate[] recipientCerts = { 132 CMSEccKeyStore.getCertificateChain(CMSEccKeyStore.ECDH, 133 CMSEccKeyStore.SZ_X25519)[0], 134 CMSEccKeyStore.getCertificateChain(CMSEccKeyStore.ECDH, 135 CMSEccKeyStore.SZ_X448)[0], 136 }; 137 return recipientCerts; 138 } 139 140 141 142 /** 143 * The main method. 144 */ 145 public static void main(String[] argv) throws Exception { 146 147 DemoSMimeUtil.initDemos(); 148 // add ECC provider 149 ECCDemoUtil.installIaikEccProvider(); 150 151 (new SimpleSMimeV4EdDemo()).start(); 152 System.out.println("\nReady!"); 153 DemoUtil.waitKey(); 154 } 155}