-// } else if (sso.lastModified() > (System.currentTimeMillis() - EIGHT_HOURS)) {
-// for(String tag : new String[] {Config.AAF_APPPASS,Config.CADI_KEYSTORE_PASSWORD,Config.CADI_KEY_PASSWORD}) {
-// access.getProperties().remove(tag);
-// diskprops.remove(tag);
-// }
-// touchDiskprops=true;
- }
-
- String keyfile = access.getProperty(Config.CADI_KEYFILE); // in case its CertificateMan props
- if (keyfile == null) {
- access.setProperty(Config.CADI_KEYFILE, dot_aaf_kf.getAbsolutePath());
- addProp(Config.CADI_KEYFILE,dot_aaf_kf.getAbsolutePath());
- }
-
-
- String alias, appID;
- alias = access.getProperty(Config.CADI_ALIAS);
- if(alias==null) {
- appID = access.getProperty(Config.AAF_APPID);
- user=appID;
- } else {
- user=alias;
- appID=null;
- }
-
- if(appID!=null && access.getProperty(Config.AAF_APPPASS)==null) {
- char[] password = cons.readPassword("Password for %s: ", appID);
- String app_pass = access.encrypt(new String(password));
- access.setProperty(Config.AAF_APPPASS,app_pass);
- diskprops.setProperty(Config.AAF_APPPASS, app_pass);
- }
-
- String keystore=access.getProperty(Config.CADI_KEYSTORE);
- String keystore_pass=access.getProperty(Config.CADI_KEYSTORE_PASSWORD);
-
- if(user==null || (alias!=null && (keystore==null || keystore_pass==null))) {
- String select = null;
- String name;
- for (File tsf : dot_aaf.listFiles()) {
- name = tsf.getName();
- if (!name.contains("trust") && (name.endsWith(".jks") || name.endsWith(".p12"))) {
- setLogDefault();
- select = cons.readLine("Use %s for Identity? (y/n): ",tsf.getName());
- if("y".equalsIgnoreCase(select)) {
- keystore = tsf.getCanonicalPath();
- access.setProperty(Config.CADI_KEYSTORE, keystore);
- addProp(Config.CADI_KEYSTORE, keystore);
- char[] password = cons.readPassword("Keystore Password: ");
- encrypted_pass= access.encrypt(new String(password));
- access.setProperty(Config.CADI_KEYSTORE_PASSWORD, encrypted_pass);
- addProp(Config.CADI_KEYSTORE_PASSWORD, encrypted_pass);
-
- // TODO READ Aliases out of Keystore?
- user = alias = cons.readLine("Keystore alias: ");
- access.setProperty(Config.CADI_ALIAS, user);
- addProp(Config.CADI_ALIAS, user);
- break;
- }
- }
- }
- if(alias==null) {
- user = appID = cons.readLine(Config.AAF_APPID + ": ");
- access.setProperty(Config.AAF_APPID, appID);
- addProp(Config.AAF_APPID, appID);
- char[] password = cons.readPassword(Config.AAF_APPPASS + ": ");
- encrypted_pass= access.encrypt(new String(password));
- access.setProperty(Config.AAF_APPPASS, encrypted_pass);
- addProp(Config.AAF_APPPASS, encrypted_pass);
- }
- } else {
- encrypted_pass = access.getProperty(Config.CADI_KEYSTORE_PASSWORD);
- if(encrypted_pass == null) {
- keystore_pass = null;
- encrypted_pass = access.getProperty(Config.AAF_APPPASS);
- } else {
- keystore_pass = encrypted_pass;
- }
- }
-
-
- if (alias!=null) {
- use_X509 = true;
- } else {
- use_X509 = false;
- Symm decryptor = Symm.obtain(dot_aaf_kf);
- if (user == null) {
- if (sso.exists()) {
- String cm_url = access.getProperty(Config.CM_URL); // SSO might overwrite...
- FileInputStream fos = new FileInputStream(sso);
- try {
- access.load(fos);
- user = access.getProperty(Config.AAF_APPID);
- encrypted_pass = access.getProperty(Config.AAF_APPPASS);
- // decrypt with .aaf, and re-encrypt with regular Keyfile
- access.setProperty(Config.AAF_APPPASS,
- access.encrypt(decryptor.depass(encrypted_pass)));
- if (cm_url != null) { //Command line CM_URL Overwrites ssofile.
- access.setProperty(Config.CM_URL, cm_url);
- }
- } finally {
- fos.close();
- }
- } else {
- diskprops = new Properties();
- String realm = Config.getDefaultRealm();
- // Turn on Console Sysout
- System.setOut(System.out);
- user = cons.readLine("aaf_id(%s@%s): ", System.getProperty("user.name"), realm);
- if (user == null) {
- user = System.getProperty("user.name") + '@' + realm;
- } else if (user.length() == 0) { //
- user = System.getProperty("user.name") + '@' + realm;
- } else if ((user.indexOf('@') < 0) && (realm != null)) {
- user = user + '@' + realm;
- }
- access.setProperty(Config.AAF_APPID, user);
- diskprops.setProperty(Config.AAF_APPID, user);
- encrypted_pass = new String(cons.readPassword("aaf_password: "));
- System.setOut(os);
- encrypted_pass = Symm.ENC + decryptor.enpass(encrypted_pass);
- access.setProperty(Config.AAF_APPPASS, encrypted_pass);
- diskprops.setProperty(Config.AAF_APPPASS, encrypted_pass);
- diskprops.setProperty(Config.CADI_KEYFILE, access.getProperty(Config.CADI_KEYFILE));
- }
- }
- }
- if (user == null) {
- err = new StringBuilder("Add -D" + Config.AAF_APPID + "=<id> ");
- }
-
- if (encrypted_pass == null && alias == null) {
- if (err == null) {
- err = new StringBuilder();
- } else {
- err.append("and ");
- }
- err.append("-D" + Config.AAF_APPPASS + "=<passwd> ");
- }
-
- String locateUrl = access.getProperty(Config.AAF_LOCATE_URL);
- if(locateUrl==null) {
- locateUrl=AAFSSO.cons.readLine("AAF Locator URL=https://");
- if(locateUrl==null || locateUrl.length()==0) {
- err = new StringBuilder(Config.AAF_LOCATE_URL);
- err.append(" is required.");
- ok = false;
- return;
- } else {
- locateUrl="https://"+locateUrl;
- }
- access.setProperty(Config.AAF_LOCATE_URL, locateUrl);
- addProp(Config.AAF_LOCATE_URL, locateUrl);
- }
-
- String aafUrl = "https://AAF_LOCATE_URL/AAF_NS.service:2.0";
- access.setProperty(Config.AAF_URL, aafUrl);
- access.setProperty(Config.CM_URL, "https://AAF_LOCATE_URL/AAF_NS.cm:2.0");
- String cadiLatitude = access.getProperty(Config.CADI_LATITUDE);
- if(cadiLatitude==null) {
- System.out.println("# If you do not know your Global Coordinates, we suggest bing.com/maps");
- cadiLatitude=AAFSSO.cons.readLine("cadi_latitude[0.000]=");
- if(cadiLatitude==null || cadiLatitude.isEmpty()) {
- cadiLatitude="0.000";
- }
- access.setProperty(Config.CADI_LATITUDE, cadiLatitude);
- addProp(Config.CADI_LATITUDE, cadiLatitude);
-
- }
- String cadiLongitude = access.getProperty(Config.CADI_LONGITUDE);
- if(cadiLongitude==null) {
- cadiLongitude=AAFSSO.cons.readLine("cadi_longitude[0.000]=");
- if(cadiLongitude==null || cadiLongitude.isEmpty()) {
- cadiLongitude="0.000";
- }
- access.setProperty(Config.CADI_LONGITUDE, cadiLongitude);
- addProp(Config.CADI_LONGITUDE, cadiLongitude);
- }
-
- String cadi_truststore = access.getProperty(Config.CADI_TRUSTSTORE);
- if(cadi_truststore==null) {
- String name;
- String select;
- for (File tsf : dot_aaf.listFiles()) {
- name = tsf.getName();
- if (name.contains("trust") &&
- (name.endsWith(".jks") || name.endsWith(".p12"))) {
- select = cons.readLine("Use %s for TrustStore? (y/n):",tsf.getName());
- if("y".equalsIgnoreCase(select)) {
- cadi_truststore=tsf.getCanonicalPath();
- access.setProperty(Config.CADI_TRUSTSTORE, cadi_truststore);
- addProp(Config.CADI_TRUSTSTORE, cadi_truststore);
- break;
- }
- }
- }
- }
- if(cadi_truststore!=null) {
- if(cadi_truststore.indexOf(File.separatorChar)<0) {
- cadi_truststore=dot_aaf.getPath()+File.separator+cadi_truststore;
- }
- String cadi_truststore_password = access.getProperty(Config.CADI_TRUSTSTORE_PASSWORD);
- if(cadi_truststore_password==null) {
- cadi_truststore_password=AAFSSO.cons.readLine("cadi_truststore_password[%s]=","changeit");
- cadi_truststore_password = access.encrypt(cadi_truststore_password);
- access.setProperty(Config.CADI_TRUSTSTORE_PASSWORD, cadi_truststore_password);
- addProp(Config.CADI_TRUSTSTORE_PASSWORD, cadi_truststore_password);
- }
- }
- ok = err==null;
- }
- writeFiles();
- }
+// } else if (sso.lastModified() > (System.currentTimeMillis() - EIGHT_HOURS)) {
+// for (String tag : new String[] {Config.AAF_APPPASS,Config.CADI_KEYSTORE_PASSWORD,Config.CADI_KEY_PASSWORD}) {
+// access.getProperties().remove(tag);
+// diskprops.remove(tag);
+// }
+// touchDiskprops=true;
+ }
+
+ String keyfile = access.getProperty(Config.CADI_KEYFILE); // in case its CertificateMan props
+ if (keyfile == null) {
+ access.setProperty(Config.CADI_KEYFILE, dot_aaf_kf.getAbsolutePath());
+ addProp(Config.CADI_KEYFILE,dot_aaf_kf.getAbsolutePath());
+ }
+
+
+ String alias, appID;
+ alias = access.getProperty(Config.CADI_ALIAS);
+ if (alias==null) {
+ appID = access.getProperty(Config.AAF_APPID);
+ user=appID;
+ } else {
+ user=alias;
+ appID=null;
+ }
+
+ if (appID!=null) {
+ diskprops.setProperty(Config.AAF_APPID,appID);
+ if( access.getProperty(Config.AAF_APPPASS)==null) {
+ char[] password = cons.readPassword("Password for %s: ", appID);
+ if(password.length>0) {
+ String app_pass = access.encrypt(new String(password));
+ access.setProperty(Config.AAF_APPPASS,app_pass);
+ diskprops.setProperty(Config.AAF_APPPASS,app_pass);
+ }
+ }
+ }
+
+ String keystore=access.getProperty(Config.CADI_KEYSTORE);
+ String keystore_pass=access.getProperty(Config.CADI_KEYSTORE_PASSWORD);
+
+ if (user==null || (alias!=null && (keystore==null || keystore_pass==null))) {
+ String select = null;
+ String name;
+ for (File tsf : dot_aaf.listFiles()) {
+ name = tsf.getName();
+ if (!name.contains("trust") && (name.endsWith(".jks") || name.endsWith(".p12"))) {
+ setLogDefault();
+ select = cons.readLine("Use %s for Identity? (y/n): ",tsf.getName());
+ if ("y".equalsIgnoreCase(select)) {
+ keystore = tsf.getCanonicalPath();
+ access.setProperty(Config.CADI_KEYSTORE, keystore);
+ addProp(Config.CADI_KEYSTORE, keystore);
+ char[] password = cons.readPassword("Keystore Password: ");
+ encrypted_pass= access.encrypt(new String(password));
+ access.setProperty(Config.CADI_KEYSTORE_PASSWORD, encrypted_pass);
+ addProp(Config.CADI_KEYSTORE_PASSWORD, encrypted_pass);
+
+ // TODO READ Aliases out of Keystore?
+ user = alias = cons.readLine("Keystore alias: ");
+ access.setProperty(Config.CADI_ALIAS, user);
+ addProp(Config.CADI_ALIAS, user);
+ break;
+ }
+ }
+ }
+ if (alias==null) {
+ user = appID = cons.readLine(Config.AAF_APPID + ": ");
+ access.setProperty(Config.AAF_APPID, appID);
+ addProp(Config.AAF_APPID, appID);
+ char[] password = cons.readPassword(Config.AAF_APPPASS + ": ");
+ encrypted_pass= access.encrypt(new String(password));
+ access.setProperty(Config.AAF_APPPASS, encrypted_pass);
+ addProp(Config.AAF_APPPASS, encrypted_pass);
+ }
+ } else {
+ encrypted_pass = access.getProperty(Config.CADI_KEYSTORE_PASSWORD);
+ if (encrypted_pass == null) {
+ keystore_pass = null;
+ encrypted_pass = access.getProperty(Config.AAF_APPPASS);
+ } else {
+ keystore_pass = encrypted_pass;
+ }
+ }
+
+
+ if (alias!=null) {
+ use_X509 = true;
+ } else {
+ use_X509 = false;
+ Symm decryptor = ArtifactDir.getSymm(dot_aaf_kf);
+ if (user == null) {
+ if (sso.exists()) {
+ String cm_url = access.getProperty(Config.AAF_URL_CM); // SSO might overwrite...
+ FileInputStream fos = new FileInputStream(sso);
+ try {
+ access.load(fos);
+ user = access.getProperty(Config.AAF_APPID);
+ encrypted_pass = access.getProperty(Config.AAF_APPPASS);
+ // decrypt with .aaf, and re-encrypt with regular Keyfile
+ access.setProperty(Config.AAF_APPPASS,
+ access.encrypt(decryptor.depass(encrypted_pass)));
+ if (cm_url != null) { //Command line CM_URL Overwrites ssofile.
+ access.setProperty(Config.AAF_URL_CM, cm_url);
+ }
+ } finally {
+ fos.close();
+ }
+ } else {
+ diskprops = new Properties();
+ String realm = Config.getDefaultRealm();
+ // Turn on Console Sysout
+ System.setOut(System.out);
+ user = cons.readLine("aaf_id(%s@%s): ", System.getProperty("user.name"), realm);
+ if (user == null) {
+ user = System.getProperty("user.name") + '@' + realm;
+ } else if (user.length() == 0) { //
+ user = System.getProperty("user.name") + '@' + realm;
+ } else if ((user.indexOf('@') < 0) && (realm != null)) {
+ user = user + '@' + realm;
+ }
+ access.setProperty(Config.AAF_APPID, user);
+ diskprops.setProperty(Config.AAF_APPID, user);
+ encrypted_pass = new String(cons.readPassword("aaf_password: "));
+ System.setOut(os);
+ encrypted_pass = Symm.ENC + decryptor.enpass(encrypted_pass);
+ access.setProperty(Config.AAF_APPPASS, encrypted_pass);
+ diskprops.setProperty(Config.AAF_APPPASS, encrypted_pass);
+ diskprops.setProperty(Config.CADI_KEYFILE, access.getProperty(Config.CADI_KEYFILE));
+ }
+ }
+ }
+ if (user == null) {
+ err = new StringBuilder("Add -D" + Config.AAF_APPID + "=<id> ");
+ }
+
+ if (encrypted_pass == null && alias == null) {
+ if (err == null) {
+ err = new StringBuilder();
+ } else {
+ err.append("and ");
+ }
+ err.append("-D" + Config.AAF_APPPASS + "=<passwd> ");
+ }
+
+ String locateUrl = access.getProperty(Config.AAF_LOCATE_URL);
+ if (locateUrl==null) {
+ locateUrl=AAFSSO.cons.readLine("AAF Locator URL=https://");
+ if (locateUrl==null || locateUrl.length()==0) {
+ err = new StringBuilder(Config.AAF_LOCATE_URL);
+ err.append(" is required.");
+ ok = false;
+ return;
+ } else {
+ locateUrl="https://"+locateUrl;
+ }
+ access.setProperty(Config.AAF_LOCATE_URL, locateUrl);
+ addProp(Config.AAF_LOCATE_URL, locateUrl);
+ }
+
+ final String apiVersion = access.getProperty(Config.AAF_API_VERSION, Config.AAF_DEFAULT_API_VERSION);
+ final String aaf_root_ns = access.getProperty(Config.AAF_ROOT_NS);
+ String locateRoot;
+ if(aaf_root_ns==null) {
+ locateRoot=Defaults.AAF_ROOT;
+ } else {
+ locateRoot = Defaults.AAF_LOCATE_CONST + "/%CNS." + aaf_root_ns;
+ }
+ if(access.getProperty(Config.AAF_URL)==null) {
+
+ access.setProperty(Config.AAF_URL, locateRoot+".service:"+apiVersion);
+ }
+ if(access.getProperty(Config.AAF_URL_CM)==null) {
+ access.setProperty(Config.AAF_URL_CM, locateRoot+".cm:"+apiVersion);
+ }
+ String cadiLatitude = access.getProperty(Config.CADI_LATITUDE);
+ if (cadiLatitude==null) {
+ System.out.println("# If you do not know your Global Coordinates, we suggest bing.com/maps");
+ cadiLatitude=AAFSSO.cons.readLine("cadi_latitude[0.000]=");
+ if (cadiLatitude==null || cadiLatitude.isEmpty()) {
+ cadiLatitude="0.000";
+ }
+ access.setProperty(Config.CADI_LATITUDE, cadiLatitude);
+ addProp(Config.CADI_LATITUDE, cadiLatitude);
+
+ }
+ String cadiLongitude = access.getProperty(Config.CADI_LONGITUDE);
+ if (cadiLongitude==null) {
+ cadiLongitude=AAFSSO.cons.readLine("cadi_longitude[0.000]=");
+ if (cadiLongitude==null || cadiLongitude.isEmpty()) {
+ cadiLongitude="0.000";
+ }
+ access.setProperty(Config.CADI_LONGITUDE, cadiLongitude);
+ addProp(Config.CADI_LONGITUDE, cadiLongitude);
+ }
+
+ String cadi_truststore = access.getProperty(Config.CADI_TRUSTSTORE);
+ if (cadi_truststore==null) {
+ String name;
+ String select;
+ for (File tsf : dot_aaf.listFiles()) {
+ name = tsf.getName();
+ if (name.contains("trust") &&
+ (name.endsWith(".jks") || name.endsWith(".p12"))) {
+ select = cons.readLine("Use %s for TrustStore? (y/n):",tsf.getName());
+ if ("y".equalsIgnoreCase(select)) {
+ cadi_truststore=tsf.getCanonicalPath();
+ access.setProperty(Config.CADI_TRUSTSTORE, cadi_truststore);
+ addProp(Config.CADI_TRUSTSTORE, cadi_truststore);
+ break;
+ }
+ }
+ }
+ }
+ if (cadi_truststore!=null) {
+ if (cadi_truststore.indexOf(File.separatorChar)<0) {
+ cadi_truststore=dot_aaf.getPath()+File.separator+cadi_truststore;
+ }
+ String cadi_truststore_password = access.getProperty(Config.CADI_TRUSTSTORE_PASSWORD);
+ if (cadi_truststore_password==null) {
+ cadi_truststore_password=AAFSSO.cons.readLine("cadi_truststore_password[%s]=","changeit");
+ cadi_truststore_password = access.encrypt(cadi_truststore_password);
+ access.setProperty(Config.CADI_TRUSTSTORE_PASSWORD, cadi_truststore_password);
+ addProp(Config.CADI_TRUSTSTORE_PASSWORD, cadi_truststore_password);
+ }
+ }
+ ok = err==null;
+ }
+ writeFiles();
+ }