Improve code coverage for aaf cadi modules
[aaf/cadi.git] / aaf / src / src / main / java / com / att / cadi / cm / CmAgent.java
diff --git a/aaf/src/src/main/java/com/att/cadi/cm/CmAgent.java b/aaf/src/src/main/java/com/att/cadi/cm/CmAgent.java
deleted file mode 100644 (file)
index fe76082..0000000
+++ /dev/null
@@ -1,786 +0,0 @@
-/*******************************************************************************\r
- * ============LICENSE_START====================================================\r
- * * org.onap.aaf\r
- * * ===========================================================================\r
- * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
- * * ===========================================================================\r
- * * Licensed under the Apache License, Version 2.0 (the "License");\r
- * * you may not use this file except in compliance with the License.\r
- * * You may obtain a copy of the License at\r
- * * \r
- *  *      http://www.apache.org/licenses/LICENSE-2.0\r
- * * \r
- *  * Unless required by applicable law or agreed to in writing, software\r
- * * distributed under the License is distributed on an "AS IS" BASIS,\r
- * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * * See the License for the specific language governing permissions and\r
- * * limitations under the License.\r
- * * ============LICENSE_END====================================================\r
- * *\r
- * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
- * *\r
- ******************************************************************************/\r
-package com.att.cadi.cm;\r
-\r
-import java.io.BufferedReader;\r
-import java.io.File;\r
-import java.io.FileInputStream;\r
-import java.io.FileOutputStream;\r
-import java.io.IOException;\r
-import java.io.InputStreamReader;\r
-import java.net.InetAddress;\r
-import java.net.UnknownHostException;\r
-import java.security.KeyStore;\r
-import java.security.cert.X509Certificate;\r
-import java.util.ArrayDeque;\r
-import java.util.Deque;\r
-import java.util.GregorianCalendar;\r
-import java.util.HashMap;\r
-import java.util.Iterator;\r
-import java.util.Map;\r
-import java.util.Map.Entry;\r
-import java.util.Properties;\r
-\r
-import com.att.cadi.Access;\r
-import com.att.cadi.Symm;\r
-import com.att.cadi.aaf.client.ErrMessage;\r
-import com.att.cadi.aaf.v2_0.AAFCon;\r
-import com.att.cadi.aaf.v2_0.AAFConHttp;\r
-import com.att.cadi.client.EnvAccess;\r
-import com.att.cadi.client.Future;\r
-import com.att.cadi.config.Config;\r
-import com.att.cadi.http.HBasicAuthSS;\r
-import com.att.inno.env.Data.TYPE;\r
-import com.att.inno.env.Env;\r
-import com.att.inno.env.TimeTaken;\r
-import com.att.inno.env.Trans;\r
-import com.att.inno.env.util.Chrono;\r
-import com.att.inno.env.util.Split;\r
-import com.att.rosetta.env.RosettaDF;\r
-import com.att.rosetta.env.RosettaEnv;\r
-\r
-import certman.v1_0.Artifacts;\r
-import certman.v1_0.Artifacts.Artifact;\r
-import certman.v1_0.CertInfo;\r
-import certman.v1_0.CertificateRequest;\r
-\r
-public class CmAgent {\r
-       private static final String PRINT = "print";\r
-       private static final String FILE = "file";\r
-       private static final String PKCS12 = "pkcs12";\r
-       private static final String JKS = "jks";\r
-       private static final String SCRIPT="script";\r
-       \r
-       private static final String CM_VER = "1.0";\r
-       public static final int PASS_SIZE = 24;\r
-       private static int TIMEOUT;\r
-       \r
-       private static MyConsole cons;\r
-       \r
-       private static RosettaDF<CertificateRequest> reqDF;\r
-       private static RosettaDF<CertInfo> certDF;\r
-       private static RosettaDF<Artifacts> artifactsDF;\r
-       private static ErrMessage errMsg;\r
-       private static Map<String,PlaceArtifact> placeArtifact;\r
-       private static RosettaEnv env;\r
-\r
-       public static void main(String[] args) {\r
-               int exitCode = 0;\r
-               env = new RosettaEnv(Config.CADI_PROP_FILES,args);\r
-               Deque<String> cmds = new ArrayDeque<String>();\r
-               for(String p : args) {\r
-                       if(p.indexOf('=')<0) {\r
-                               cmds.add(p);\r
-                       }\r
-               }\r
-               \r
-               if(cmds.size()==0) {\r
-                       System.out.println("Usage: java -jar <cadi-aaf-*-full.jar> cmd [<tag=value>]*");\r
-                       System.out.println("   create   <mechID> [<machine>]");\r
-                       System.out.println("   read     <mechID> [<machine>]");\r
-                       System.out.println("   update   <mechID> [<machine>]");\r
-                       System.out.println("   delete   <mechID> [<machine>]");\r
-                       System.out.println("   copy     <mechID> <machine> <newmachine>[,<newmachine>]*");\r
-                       System.out.println("   place    <mechID> [<machine>]");\r
-                       System.out.println("   showpass <mechID> [<machine>]");\r
-                       System.out.println("   check    <mechID> [<machine>]");\r
-                       System.exit(1);\r
-               }\r
-               \r
-               TIMEOUT = Integer.parseInt(env.getProperty(Config.AAF_CONN_TIMEOUT, "5000"));\r
-               cons = TheConsole.implemented()?new TheConsole():new SubStandardConsole();\r
-\r
-               try {\r
-                       reqDF = env.newDataFactory(CertificateRequest.class);\r
-                       artifactsDF = env.newDataFactory(Artifacts.class);\r
-                       certDF = env.newDataFactory(CertInfo.class);\r
-                       errMsg = new ErrMessage(env);\r
-\r
-                       placeArtifact = new HashMap<String,PlaceArtifact>();\r
-                       placeArtifact.put(JKS, new PlaceArtifactInKeystore(JKS));\r
-                       placeArtifact.put(PKCS12, new PlaceArtifactInKeystore(PKCS12));\r
-                       placeArtifact.put(FILE, new PlaceArtifactInFiles());\r
-                       placeArtifact.put(PRINT, new PlaceArtifactOnStream(System.out));\r
-                       placeArtifact.put(SCRIPT, new PlaceArtifactScripts());\r
-                       \r
-                       Access access = new EnvAccess(env);\r
-                       Trans trans = env.newTrans();\r
-                       try {\r
-                               getProperty(env,false, Config.CM_URL,Config.CM_URL+": ");\r
-                               String str=env.getProperty(Config.CADI_ALIAS);\r
-                               if(str==null) { // ask for MechID pass\r
-                                       getProperty(env,false,Config.AAF_MECHID,"Your Identity: ");\r
-                                       getProperty(env,true,Config.AAF_MECHPASS,"Password: ");\r
-                               }\r
-                               AAFCon<?> aafcon = new AAFConHttp(access,Config.CM_URL);\r
-                                               \r
-                               String cmd = cmds.removeFirst();\r
-                               if("place".equals(cmd)) {\r
-                                       placeCerts(trans,aafcon,cmds);\r
-                               } else if("create".equals(cmd)) {\r
-                                       createArtifact(trans, aafcon,cmds);\r
-                               } else if("read".equals(cmd)) {\r
-                                       readArtifact(trans, aafcon, cmds);\r
-                               } else if("copy".equals(cmd)) {\r
-                                       copyArtifact(trans, aafcon, cmds);\r
-                               } else if("update".equals(cmd)) {\r
-                                       updateArtifact(trans, aafcon, cmds);\r
-                               } else if("delete".equals(cmd)) {\r
-                                       deleteArtifact(trans, aafcon, cmds);\r
-                               } else if("showpass".equals(cmd)) {\r
-                                       showPass(trans,aafcon,cmds);\r
-                               } else if("check".equals(cmd)) {\r
-                                       try {\r
-                                               exitCode = check(trans,aafcon,cmds);\r
-                                       } catch (Exception e) {\r
-                                               exitCode = 1;\r
-                                               throw e;\r
-                                       }\r
-                               } else {\r
-                                       cons.printf("Unknown command \"%s\"\n", cmd);\r
-                               }\r
-                       } finally {\r
-                               StringBuilder sb = new StringBuilder();\r
-                trans.auditTrail(4, sb, Trans.REMOTE);\r
-                if(sb.length()>0) {\r
-                       trans.info().log("Trans Info\n",sb);\r
-                }\r
-                       }\r
-               } catch (Exception e) {\r
-                       e.printStackTrace();\r
-               }\r
-               if(exitCode!=0) {\r
-                       System.exit(exitCode);\r
-               }\r
-       }\r
-\r
-       private static String getProperty(Env env, boolean secure, String tag, String prompt, Object ... def) {\r
-               String value;\r
-               if((value=env.getProperty(tag))==null) {\r
-                       if(secure) {\r
-                               value = new String(cons.readPassword(prompt, def));\r
-                       } else {\r
-                               value = cons.readLine(prompt,def).trim();\r
-                       }\r
-                       if(value!=null) {\r
-                               if(value.length()>0) {\r
-                                       env.setProperty(tag,value);\r
-                               } else if(def.length==1) {\r
-                                       value=def[0].toString();\r
-                                       env.setProperty(tag,value);\r
-                               }\r
-                       }\r
-               }\r
-               return value;\r
-       }\r
-\r
-       private interface MyConsole {\r
-               public String readLine(String fmt, Object ... args);\r
-               public char[] readPassword(String fmt, Object ... args);\r
-               public void printf(String fmt, Object ...args);\r
-       }\r
-\r
-       private static class TheConsole implements MyConsole {\r
-               @Override\r
-               public String readLine(String fmt, Object... args) {\r
-                       String rv = System.console().readLine(fmt, args);\r
-                       if(args.length>0 && args[0]!=null && rv.length()==0) {\r
-                               rv = args[0].toString();\r
-                       }\r
-                       return rv;\r
-               }\r
-\r
-               @Override\r
-               public char[] readPassword(String fmt, Object... args) {\r
-                       return System.console().readPassword(fmt, args);\r
-               }\r
-               \r
-               public static boolean implemented() {\r
-                       return System.console()!=null;\r
-               }\r
-\r
-               @Override\r
-               public void printf(String fmt, Object... args) {\r
-                       System.console().printf(fmt, args);\r
-               }\r
-       }\r
-       \r
-       // Substandard, because System.in doesn't do Passwords..\r
-       private static class SubStandardConsole implements MyConsole {\r
-               BufferedReader br = new BufferedReader(new InputStreamReader(System.in));\r
-               @Override\r
-               public String readLine(String fmt, Object... args) {\r
-                       String rv;\r
-                       try {\r
-                               System.out.printf(fmt,args);\r
-                               rv = br.readLine();\r
-                               if(args.length==1 && rv.length()==0) {\r
-                                       rv = args[0].toString();\r
-                               }\r
-                       } catch (IOException e) {\r
-                               System.err.println("uh oh...");\r
-                               rv = "";\r
-                       }\r
-                       return rv;\r
-               }\r
-\r
-               @Override\r
-               public char[] readPassword(String fmt, Object... args) {\r
-                       try {\r
-                               System.out.printf(fmt,args);\r
-                               return br.readLine().toCharArray();\r
-                       } catch (IOException e) {\r
-                               System.err.println("uh oh...");\r
-                               return new char[0];\r
-                       }\r
-               }\r
-\r
-               @Override\r
-               public void printf(String fmt, Object... args) {\r
-                       System.out.printf(fmt, args);\r
-               }\r
-       }\r
-\r
-//     private static class AutoData implements MyConsole {\r
-////           private Env env;\r
-//             private Map<String,String> data;\r
-//\r
-//             @Override\r
-//             public String readLine(String fmt, Object... args) {\r
-//                     String rv=data.get(fmt);\r
-//                     return rv==null?"":rv;\r
-//             }\r
-//\r
-//             @Override\r
-//             public char[] readPassword(String fmt, Object... args) {\r
-//                     String rv=data.get(fmt);\r
-//                     return rv==null?new char[0]:rv.toCharArray();\r
-//             }\r
-//             \r
-//             @Override\r
-//             public void printf(String fmt, Object... args) {\r
-//                     System.out.printf(fmt, args);\r
-//             }\r
-//\r
-//     }\r
-//     \r
-       private static String mechID(Deque<String> cmds) {\r
-               if(cmds.size()<1) {\r
-                       String alias = env.getProperty(Config.CADI_ALIAS);\r
-                       return alias!=null?alias:cons.readLine("MechID: ");\r
-               }\r
-               return cmds.removeFirst();      \r
-       }\r
-\r
-       private static String machine(Deque<String> cmds) throws UnknownHostException {\r
-               if(cmds.size()>0) {\r
-                       return cmds.removeFirst();\r
-               } else {\r
-                       String mach = env.getProperty(Config.HOSTNAME);\r
-                       return mach!=null?mach:InetAddress.getLocalHost().getHostName();\r
-               }\r
-       }\r
-\r
-       private static String[] machines(Deque<String> cmds)  {\r
-               String machines;\r
-               if(cmds.size()>0) {\r
-                       machines = cmds.removeFirst();\r
-               } else {\r
-                       machines = cons.readLine("Machines (sep by ','): ");\r
-               }\r
-               return Split.split(',', machines);\r
-       }\r
-\r
-       private static void createArtifact(Trans trans, AAFCon<?> aafcon, Deque<String> cmds) throws Exception {\r
-               String mechID = mechID(cmds);\r
-               String machine = machine(cmds);\r
-\r
-               Artifacts artifacts = new Artifacts();\r
-               Artifact arti = new Artifact();\r
-               artifacts.getArtifact().add(arti);\r
-               arti.setMechid(mechID!=null?mechID:cons.readLine("MechID: "));\r
-               arti.setMachine(machine!=null?machine:cons.readLine("Machine (%s): ",InetAddress.getLocalHost().getHostName()));\r
-               arti.setCa(cons.readLine("CA: (%s): ","aaf"));\r
-               \r
-               String resp = cons.readLine("Types [file,jks,pkcs12] (%s): ", "jks");\r
-               for(String s : Split.splitTrim(',', resp)) {\r
-                       arti.getType().add(s);\r
-               }\r
-               // Always do Script\r
-               if(!resp.contains(SCRIPT)) {\r
-                       arti.getType().add(SCRIPT);\r
-               }\r
-\r
-               // Note: Sponsor is set on Creation by CM\r
-               String configRootName = AAFCon.reverseDomain(arti.getMechid());\r
-               arti.setAppName(cons.readLine("AppName (%s): ",configRootName));\r
-               arti.setDir(cons.readLine("Directory (%s): ", System.getProperty("user.dir")));\r
-               arti.setOsUser(cons.readLine("OS User (%s): ", System.getProperty("user.name")));\r
-               arti.setRenewDays(Integer.parseInt(cons.readLine("Renewal Days (%s):", "30")));\r
-               arti.setNotification(toNotification(cons.readLine("Notification (mailto owner):", "")));\r
-               \r
-               TimeTaken tt = trans.start("Create Artifact", Env.REMOTE);\r
-               try {\r
-                       Future<Artifacts> future = aafcon.client(CM_VER).create("/cert/artifacts", artifactsDF, artifacts);\r
-                       if(future.get(TIMEOUT)) {\r
-                               trans.info().printf("Call to AAF Certman successful %s, %s",arti.getMechid(), arti.getMachine());\r
-                       } else {\r
-                               trans.error().printf("Call to AAF Certman failed, %s",\r
-                                       errMsg.toMsg(future));\r
-                       }\r
-               } finally {\r
-                       tt.done();\r
-               }\r
-       }\r
-\r
-       private static String toNotification(String notification) {\r
-               if(notification==null) {\r
-                       notification="";\r
-               } else if(notification.length()>0) {\r
-                       if(notification.indexOf(':')<0) {\r
-                               notification = "mailto:" + notification;\r
-                       }\r
-               }\r
-               return notification;\r
-       }\r
-       \r
-\r
-       private static void readArtifact(Trans trans, AAFCon<?> aafcon, Deque<String> cmds) throws Exception {\r
-               String mechID = mechID(cmds);\r
-               String machine = machine(cmds);\r
-\r
-               TimeTaken tt = trans.start("Read Artifact", Env.SUB);\r
-               try {\r
-                       Future<Artifacts> future = aafcon.client(CM_VER)\r
-                                       .read("/cert/artifacts/"+mechID+'/'+machine, artifactsDF);\r
-       \r
-                       if(future.get(TIMEOUT)) {\r
-                               boolean printed = false;\r
-                               for(Artifact a : future.value.getArtifact()) {\r
-                                       cons.printf("MechID:          %s\n",a.getMechid()); \r
-                                       cons.printf("  Sponsor:       %s\n",a.getSponsor()); \r
-                                       cons.printf("Machine:         %s\n",a.getMachine()); \r
-                                       cons.printf("CA:              %s\n",a.getCa()); \r
-                                       StringBuilder sb = new StringBuilder();\r
-                                       boolean first = true;\r
-                                       for(String t : a.getType()) {\r
-                                               if(first) {first=false;}\r
-                                               else{sb.append(',');}\r
-                                               sb.append(t);\r
-                                       }\r
-                                       cons.printf("Types:           %s\n",sb);\r
-                                       cons.printf("AppName:         %s\n",a.getAppName()); \r
-                                       cons.printf("Directory:       %s\n",a.getDir());\r
-                                       cons.printf("O/S User:        %s\n",a.getOsUser());\r
-                                       cons.printf("Renew Days:      %d\n",a.getRenewDays());\r
-                                       cons.printf("Notification     %s\n",a.getNotification());\r
-                                       printed = true;\r
-                               }\r
-                               if(!printed) {\r
-                                       cons.printf("Artifact for %s %s does not exist", mechID, machine);\r
-                               }\r
-                       } else {\r
-                               trans.error().log(errMsg.toMsg(future));\r
-                       }\r
-               } finally {\r
-                       tt.done();\r
-               }\r
-       }\r
-       \r
-       private static void copyArtifact(Trans trans, AAFCon<?> aafcon, Deque<String> cmds) throws Exception {\r
-               String mechID = mechID(cmds);\r
-               String machine = machine(cmds);\r
-               String[] newmachs = machines(cmds);\r
-               if(newmachs==null || newmachs == null) {\r
-                       trans.error().log("No machines listed to copy to");\r
-               } else {\r
-                       TimeTaken tt = trans.start("Copy Artifact", Env.REMOTE);\r
-                       try {\r
-                               Future<Artifacts> future = aafcon.client(CM_VER)\r
-                                               .read("/cert/artifacts/"+mechID+'/'+machine, artifactsDF);\r
-                       \r
-                               if(future.get(TIMEOUT)) {\r
-                                       boolean printed = false;\r
-                                       for(Artifact a : future.value.getArtifact()) {\r
-                                               for(String m : newmachs) {\r
-                                                       a.setMachine(m);\r
-                                                       Future<Artifacts> fup = aafcon.client(CM_VER).update("/cert/artifacts", artifactsDF, future.value);\r
-                                                       if(fup.get(TIMEOUT)) {\r
-                                                               trans.info().printf("Copy of %s %s successful to %s",mechID,machine,m);\r
-                                                       } else {\r
-                                                               trans.error().printf("Call to AAF Certman failed, %s",\r
-                                                                       errMsg.toMsg(fup));\r
-                                                       }\r
-       \r
-                                                       printed = true;\r
-                                               }\r
-                                       }\r
-                                       if(!printed) {\r
-                                               cons.printf("Artifact for %s %s does not exist", mechID, machine);\r
-                                       }\r
-                               } else {\r
-                                       trans.error().log(errMsg.toMsg(future));\r
-                               }\r
-                       } finally {\r
-                               tt.done();\r
-                       }\r
-               }\r
-       }\r
-\r
-       private static void updateArtifact(Trans trans, AAFCon<?> aafcon, Deque<String> cmds) throws Exception {\r
-               String mechID = mechID(cmds);\r
-               String machine = machine(cmds);\r
-\r
-               TimeTaken tt = trans.start("Update Artifact", Env.REMOTE);\r
-               try {\r
-                       Future<Artifacts> fread = aafcon.client(CM_VER)\r
-                                       .read("/cert/artifacts/"+mechID+'/'+machine, artifactsDF);\r
-       \r
-                       if(fread.get(TIMEOUT)) {\r
-                               Artifacts artifacts = new Artifacts();\r
-                               for(Artifact a : fread.value.getArtifact()) {\r
-                                       Artifact arti = new Artifact();\r
-                                       artifacts.getArtifact().add(arti);\r
-                                       \r
-                                       cons.printf("For %s on %s\n", a.getMechid(),a.getMachine());\r
-                                       arti.setMechid(a.getMechid());\r
-                                       arti.setMachine(a.getMachine());\r
-                                       arti.setCa(cons.readLine("CA: (%s): ",a.getCa()));\r
-                                       StringBuilder sb = new StringBuilder();\r
-                                       boolean first = true;\r
-                                       for(String t : a.getType()) {\r
-                                               if(first) {first=false;}\r
-                                               else{sb.append(',');}\r
-                                               sb.append(t);\r
-                                       }\r
-       \r
-                                       String resp = cons.readLine("Types [file,jks,pkcs12] (%s): ", sb);\r
-                                       for(String s : Split.splitTrim(',', resp)) {\r
-                                               arti.getType().add(s);\r
-                                       }\r
-                                       // Always do Script\r
-                                       if(!resp.contains(SCRIPT)) {\r
-                                               arti.getType().add(SCRIPT);\r
-                                       }\r
-\r
-                                       // Note: Sponsor is set on Creation by CM\r
-                                       arti.setAppName(cons.readLine("AppName (%s): ",a.getAppName()));\r
-                                       arti.setDir(cons.readLine("Directory (%s): ", a.getDir()));\r
-                                       arti.setOsUser(cons.readLine("OS User (%s): ", a.getOsUser()));\r
-                                       arti.setRenewDays(Integer.parseInt(cons.readLine("Renew Days (%s):", a.getRenewDays())));\r
-                                       arti.setNotification(toNotification(cons.readLine("Notification (%s):", a.getNotification())));\r
-       \r
-                               }\r
-                               if(artifacts.getArtifact().size()==0) {\r
-                                       cons.printf("Artifact for %s %s does not exist", mechID, machine);\r
-                               } else {\r
-                                       Future<Artifacts> fup = aafcon.client(CM_VER).update("/cert/artifacts", artifactsDF, artifacts);\r
-                                       if(fup.get(TIMEOUT)) {\r
-                                               trans.info().printf("Call to AAF Certman successful %s, %s",mechID,machine);\r
-                                       } else {\r
-                                               trans.error().printf("Call to AAF Certman failed, %s",\r
-                                                       errMsg.toMsg(fup));\r
-                                       }\r
-                               }\r
-                       } else {\r
-                               trans.error().printf("Call to AAF Certman failed, %s %s, %s",\r
-                                               errMsg.toMsg(fread),mechID,machine);\r
-                       }\r
-               } finally {\r
-                       tt.done();\r
-               }\r
-       }\r
-       \r
-       private static void deleteArtifact(Trans trans, AAFCon<?> aafcon, Deque<String> cmds) throws Exception {\r
-               String mechid = mechID(cmds);\r
-               String machine = mechID(cmds);\r
-               \r
-               TimeTaken tt = trans.start("Delete Artifact", Env.REMOTE);\r
-               try {\r
-                       Future<Void> future = aafcon.client(CM_VER)\r
-                                       .delete("/cert/artifacts/"+mechid+"/"+machine,"application/json" );\r
-       \r
-                       if(future.get(TIMEOUT)) {\r
-                               trans.info().printf("Call to AAF Certman successful %s, %s",mechid,machine);\r
-                       } else {\r
-                               trans.error().printf("Call to AAF Certman failed, %s %s, %s",\r
-                                       errMsg.toMsg(future),mechid,machine);\r
-                       }\r
-               } finally {\r
-                       tt.done();\r
-               }\r
-       }\r
-\r
-       \r
-\r
-       private static boolean placeCerts(Trans trans, AAFCon<?> aafcon, Deque<String> cmds) throws Exception {\r
-               boolean rv = false;\r
-               String mechID = mechID(cmds);\r
-               String machine = machine(cmds);\r
-               \r
-               TimeTaken tt = trans.start("Place Artifact", Env.REMOTE);\r
-               try {\r
-                       Future<Artifacts> acf = aafcon.client(CM_VER)\r
-                                       .read("/cert/artifacts/"+mechID+'/'+machine, artifactsDF);\r
-                       if(acf.get(TIMEOUT)) {\r
-                               // Have to wait for JDK 1.7 source...\r
-                               //switch(artifact.getType()) {\r
-                               if(acf.value.getArtifact()==null || acf.value.getArtifact().isEmpty()) {\r
-                                       cons.printf("There are no artifacts for %s %s", mechID, machine);\r
-                               } else {\r
-                                       for(Artifact a : acf.value.getArtifact()) {\r
-                                               CertificateRequest cr = new CertificateRequest();\r
-                                               cr.setMechid(a.getMechid());\r
-                                               cr.setSponsor(a.getSponsor());\r
-                                               cr.getFqdns().add(a.getMachine());\r
-                                               Future<String> f = aafcon.client(CM_VER)\r
-                                                               .setQueryParams("withTrust")\r
-                                                               .updateRespondString("/cert/" + a.getCa(),reqDF, cr);\r
-                                               if(f.get(TIMEOUT)) {\r
-                                                       CertInfo capi = certDF.newData().in(TYPE.JSON).load(f.body()).asObject();\r
-                                                       for(String type : a.getType()) {\r
-                                                               PlaceArtifact pa = placeArtifact.get(type);\r
-                                                               if(pa!=null) {\r
-                                                                       if(rv = pa.place(trans, capi, a)) {\r
-                                                                               notifyPlaced(a,rv);\r
-                                                                       }\r
-                                                               }\r
-                                                       }\r
-                                                       // Cover for the above multiple pass possibilities with some static Data, then clear per Artifact\r
-                                                       ArtifactDir.clear();\r
-                                               } else {\r
-                                                       trans.error().log(errMsg.toMsg(f));\r
-                                               }\r
-                                       }\r
-                               }\r
-                       } else {\r
-                               trans.error().log(errMsg.toMsg(acf));\r
-                       }\r
-               } finally {\r
-                       tt.done();\r
-               }\r
-               return rv;\r
-       }\r
-       \r
-       private static void notifyPlaced(Artifact a, boolean rv) {\r
-               \r
-               \r
-       }\r
-\r
-       private static void showPass(Trans trans, AAFCon<?> aafcon, Deque<String> cmds) throws Exception {\r
-               String mechID = mechID(cmds);\r
-               String machine = machine(cmds);\r
-\r
-               TimeTaken tt = trans.start("Show Password", Env.REMOTE);\r
-               try {\r
-                       Future<Artifacts> acf = aafcon.client(CM_VER)\r
-                                       .read("/cert/artifacts/"+mechID+'/'+machine, artifactsDF);\r
-                       if(acf.get(TIMEOUT)) {\r
-                               // Have to wait for JDK 1.7 source...\r
-                               //switch(artifact.getType()) {\r
-                               if(acf.value.getArtifact()==null || acf.value.getArtifact().isEmpty()) {\r
-                                       cons.printf("No Artifacts found for %s on %s", mechID, machine);\r
-                               } else {\r
-                                       String id = aafcon.defID();\r
-                                       boolean allowed;\r
-                                       for(Artifact a : acf.value.getArtifact()) {\r
-                                               allowed = id!=null && (id.equals(a.getSponsor()) ||\r
-                                                               (id.equals(a.getMechid()) \r
-                                                                               && aafcon.securityInfo().defSS.getClass().isAssignableFrom(HBasicAuthSS.class)));\r
-                                               if(!allowed) {\r
-                                                       Future<String> pf = aafcon.client(CM_VER).read("/cert/may/" + \r
-                                                                       a.getAppName() + ".certman|"+a.getCa()+"|showpass","*/*");\r
-                                                       if(pf.get(TIMEOUT)) {\r
-                                                               allowed = true;\r
-                                                       } else {\r
-                                                               trans.error().log(errMsg.toMsg(pf));\r
-                                                       }\r
-                                               }\r
-                                               if(allowed) {\r
-                                                       File dir = new File(a.getDir());\r
-                                                       Properties props = new Properties();\r
-                                                       FileInputStream fis = new FileInputStream(new File(dir,a.getAppName()+".props"));\r
-                                                       try {\r
-                                                               props.load(fis);\r
-                                                               fis.close();\r
-                                                               fis = new FileInputStream(new File(dir,a.getAppName()+".chal"));\r
-                                                               props.load(fis);\r
-                                                       } finally {\r
-                                                               fis.close();\r
-                                                       }\r
-                                                       \r
-                                                       File f = new File(dir,a.getAppName()+".keyfile");\r
-                                                       if(f.exists()) {\r
-                                                               Symm symm = Symm.obtain(f);\r
-                                                               \r
-                                                               for(Iterator<Entry<Object,Object>> iter = props.entrySet().iterator(); iter.hasNext();) {\r
-                                                                       Entry<Object,Object> en = iter.next();\r
-                                                                       if(en.getValue().toString().startsWith("enc:???")) {\r
-                                                                               System.out.printf("%s=%s\n", en.getKey(), symm.depass(en.getValue().toString()));\r
-                                                                       }\r
-                                                               }\r
-                                                       } else {\r
-                                                               trans.error().printf("%s.keyfile must exist to read passwords for %s on %s",\r
-                                                                               f.getCanonicalPath(),a.getMechid(), a.getMachine());\r
-                                                       }\r
-                                               }\r
-                                       }\r
-                               }\r
-                       } else {\r
-                               trans.error().log(errMsg.toMsg(acf));\r
-                       }\r
-               } finally {\r
-                       tt.done();\r
-               }\r
-\r
-       }\r
-       \r
-\r
-       /**\r
-        * Check returns Error Codes, so that Scripts can know what to do\r
-        * \r
-        *   0 - Check Complete, nothing to do\r
-        *   1 - General Error\r
-        *   2 - Error for specific Artifact - read check.msg\r
-        *   10 - Certificate Updated - check.msg is email content\r
-        *   \r
-        * @param trans\r
-        * @param aafcon\r
-        * @param cmds\r
-        * @return\r
-        * @throws Exception\r
-        */\r
-       private static int check(Trans trans, AAFCon<?> aafcon, Deque<String> cmds) throws Exception {\r
-               int exitCode=1;\r
-               String mechID = mechID(cmds);\r
-               String machine = machine(cmds);\r
-               \r
-               TimeTaken tt = trans.start("Check Certificate", Env.REMOTE);\r
-               try {\r
-               \r
-                       Future<Artifacts> acf = aafcon.client(CM_VER)\r
-                                       .read("/cert/artifacts/"+mechID+'/'+machine, artifactsDF);\r
-                       if(acf.get(TIMEOUT)) {\r
-                               // Have to wait for JDK 1.7 source...\r
-                               //switch(artifact.getType()) {\r
-                               if(acf.value.getArtifact()==null || acf.value.getArtifact().isEmpty()) {\r
-                                       cons.printf("No Artifacts found for %s on %s", mechID, machine);\r
-                               } else {\r
-                                       String id = aafcon.defID();\r
-                                       GregorianCalendar now = new GregorianCalendar();\r
-                                       for(Artifact a : acf.value.getArtifact()) {\r
-                                               if(id.equals(a.getMechid())) {\r
-                                                       File dir = new File(a.getDir());\r
-                                                       Properties props = new Properties();\r
-                                                       FileInputStream fis = new FileInputStream(new File(dir,a.getAppName()+".props"));\r
-                                                       try {\r
-                                                               props.load(fis);\r
-                                                       } finally {\r
-                                                               fis.close();\r
-                                                       }\r
-                                                       \r
-                                                       String prop;                                            \r
-                                                       File f;\r
-       \r
-                                                       if((prop=props.getProperty(Config.CADI_KEYFILE))==null ||\r
-                                                               !(f=new File(prop)).exists()) {\r
-                                                                       trans.error().printf("Keyfile must exist to check Certificates for %s on %s",\r
-                                                                               a.getMechid(), a.getMachine());\r
-                                                       } else {\r
-                                                               String ksf = props.getProperty(Config.CADI_KEYSTORE);\r
-                                                               String ksps = props.getProperty(Config.CADI_KEYSTORE_PASSWORD);\r
-                                                               if(ksf==null || ksps == null) {\r
-                                                                       trans.error().printf("Properties %s and %s must exist to check Certificates for %s on %s",\r
-                                                                                       Config.CADI_KEYSTORE, Config.CADI_KEYSTORE_PASSWORD,a.getMechid(), a.getMachine());\r
-                                                               } else {\r
-                                                                       KeyStore ks = KeyStore.getInstance("JKS");\r
-                                                                       Symm symm = Symm.obtain(f);\r
-                                                                       \r
-                                                                       fis = new FileInputStream(ksf);\r
-                                                                       try {\r
-                                                                               ks.load(fis,symm.depass(ksps).toCharArray());\r
-                                                                       } finally {\r
-                                                                               fis.close();\r
-                                                                       }\r
-                                                                       X509Certificate cert = (X509Certificate)ks.getCertificate(mechID);\r
-                                                                       String msg = null;\r
-\r
-                                                                       if(cert==null) {\r
-                                                                               msg = String.format("X509Certificate does not exist for %s on %s in %s",\r
-                                                                                               a.getMechid(), a.getMachine(), ksf);\r
-                                                                               trans.error().log(msg);\r
-                                                                               exitCode = 2;\r
-                                                                       } else {\r
-                                                                               GregorianCalendar renew = new GregorianCalendar();\r
-                                                                               renew.setTime(cert.getNotAfter());\r
-                                                                               renew.add(GregorianCalendar.DAY_OF_MONTH,-1*a.getRenewDays());\r
-                                                                               if(renew.after(now)) {\r
-                                                                                       msg = String.format("As of %s, X509Certificate for %s on %s, expiration %s is still within %d renewal days.\n", \r
-                                                                                                       Chrono.dateOnlyStamp(), a.getMechid(), a.getMachine(), cert.getNotAfter(),a.getRenewDays());\r
-                                                                                       trans.info().log(msg);\r
-                                                                                       exitCode = 0; // OK\r
-                                                                               } else {\r
-                                                                                       trans.info().printf("X509Certificate for %s on %s expiration, %s, needs Renewal.\n", \r
-                                                                                                       a.getMechid(), a.getMachine(),cert.getNotAfter());\r
-                                                                                       cmds.offerLast(mechID);\r
-                                                                                       cmds.offerLast(machine);\r
-                                                                                       if(placeCerts(trans,aafcon,cmds)) {\r
-                                                                                               msg = String.format("X509Certificate for %s on %s has been renewed. Ensure services using are refreshed.\n", \r
-                                                                                                               a.getMechid(), a.getMachine());\r
-                                                                                               exitCode = 10; // Refreshed\r
-                                                                                       } else {\r
-                                                                                               msg = String.format("X509Certificate for %s on %s attempted renewal, but failed. Immediate Investigation is required!\n", \r
-                                                                                                               a.getMechid(), a.getMachine());\r
-                                                                                               exitCode = 1; // Error Renewing\r
-                                                                                       }\r
-                                                                               }\r
-                                                                       }\r
-                                                                       if(msg!=null) {\r
-                                                                               FileOutputStream fos = new FileOutputStream(a.getDir()+'/'+a.getAppName()+".msg");\r
-                                                                               try {\r
-                                                                                       fos.write(msg.getBytes());\r
-                                                                               } finally {\r
-                                                                                       fos.close();\r
-                                                                               }\r
-                                                                       }\r
-                                                               }\r
-                                                               \r
-                                                       }\r
-                                               }\r
-                                       }\r
-                               }\r
-                       } else {\r
-                               trans.error().log(errMsg.toMsg(acf));\r
-                               exitCode=1;\r
-                       }\r
-               } finally {\r
-                       tt.done();\r
-               }\r
-               return exitCode;\r
-       }\r
-\r
-}\r
-                       \r
-               \r
-\r
-\r