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/cms/signedData/CertListDemo.java 17 12.02.25 17:58 Dbratko $ 059 // $Revision: 17 $ 060 // 061 062 package demo.cms.signedData; 063 064 import iaik.cms.CMSCertList; 065 import iaik.security.provider.IAIK; 066 import iaik.x509.X509Certificate; 067 068 import java.io.FileInputStream; 069 import java.io.IOException; 070 071 import demo.DemoUtil; 072 073 /** 074 * Reads a CMS (PKCS#7) certifcate list from a file. 075 * <p> 076 * When starting the test, you have to specify 077 * the file name holding the <code>CMSCertList</code> to be parsed: 078 * <pre> 079 * java demo.cms.CertListDemo <file name> 080 * </pre> 081 * 082 * @see iaik.cms.CMSCertList 083 */ 084 public class CertListDemo { 085 086 /** 087 * Reads a CMS (PKCS#7) certificate chain from a file and dumps the certificates 088 * stored inside. 089 * <p> 090 * Usage: 091 * <p><code> 092 * java demo.cms.CertListDemo <file name> 093 * </code><p> 094 * 095 * @param arg the name of the file holding the certificate chain 096 */ 097 public static void main(String arg[]) { 098 099 IAIK.addAsJDK14Provider(true); 100 101 if (arg.length != 1) { 102 103 System.out.println("Usage: java demo.cms.CertListDemo <CMS-certificate-chain-file>"); 104 105 } else { 106 107 FileInputStream fis = null; 108 try { 109 fis = new FileInputStream(arg[0]); 110 CMSCertList cmsCertList = new CMSCertList(fis); 111 X509Certificate[] certs = cmsCertList.getX509Certificates(); 112 113 for (int i = 0; i < certs.length; i++) { 114 System.out.println(certs[i]); 115 } 116 117 } catch (Exception ex) { 118 System.out.println("Error reading certificates: "+ ex.toString()); 119 } finally { 120 if (fis != null) { 121 try { 122 fis.close(); 123 } catch (IOException ex) { 124 // ignore 125 } 126 } 127 } 128 129 } 130 System.out.println(); 131 DemoUtil.waitKey(); 132 } 133 }