1 13 14 package org.ejbca.ui.cli; 15 16 import java.io.BufferedReader ; 17 import java.io.FileOutputStream ; 18 import java.io.InputStreamReader ; 19 20 25 public class CaExportCACommand extends BaseCaAdminCommand { 26 31 public CaExportCACommand(String [] args) { 32 super(args); 33 } 34 35 41 public void execute() throws IllegalAdminCommandException, ErrorAdminCommandException { 42 String signatureKeyAlias = "SignatureKeyAlias"; 43 String encryptionKeyAlias = "EncryptionKeyAlias"; 44 if (args.length < 3) { 45 String msg = "Usage: CA exportca <CA name> <pkcs12 file> [<signature_key_alias>] [<encryption_key_alias>]\n" + 46 "Default values for signature_key_alias is \"" + signatureKeyAlias + "\" and encryption_key_alias" + 47 " is \"" + encryptionKeyAlias + "\"."; 48 throw new IllegalAdminCommandException(msg); 49 } 50 try { 51 String caName = args[1]; 52 String p12file = args[2]; 53 if ( args.length > 3 ) { 54 signatureKeyAlias = args[3]; 55 } 56 if ( args.length > 4 ) { 57 encryptionKeyAlias = args[4]; 58 } 59 System.out.print("Enter keystore password: "); 60 String kspwd = new BufferedReader (new InputStreamReader (System.in)).readLine(); 61 62 if ( !getCAAdminSessionRemote().isKeyStorePassword(administrator, kspwd) ) { 63 throw new IllegalArgumentException ("Keystore password does not match user-supplied password."); 64 } 65 byte[] keyStoreBytes = getCAAdminSessionRemote().exportCAKeyStore(administrator, caName, kspwd.toCharArray(), kspwd.toCharArray(), signatureKeyAlias, encryptionKeyAlias); 66 FileOutputStream fos = new FileOutputStream (p12file); 67 fos.write(keyStoreBytes); 68 fos.close(); 69 } catch (ErrorAdminCommandException e) { 70 throw e; 71 } catch (Exception e) { 72 throw new ErrorAdminCommandException(e); 73 } 74 } } 76 | Popular Tags |