PageRenderTime 61ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/pki-core-9.0.21/base/silent/src/common/AutoInstaller.java

#
Java | 2461 lines | 1797 code | 432 blank | 232 comment | 181 complexity | 40377d981c0c94c94baf17b1ad5270a5 MD5 | raw file
Possible License(s): GPL-2.0
  1. // --- BEGIN COPYRIGHT BLOCK ---
  2. // This program is free software; you can redistribute it and/or modify
  3. // it under the terms of the GNU General Public License as published by
  4. // the Free Software Foundation; version 2 of the License.
  5. //
  6. // This program is distributed in the hope that it will be useful,
  7. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  8. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  9. // GNU General Public License for more details.
  10. //
  11. // You should have received a copy of the GNU General Public License along
  12. // with this program; if not, write to the Free Software Foundation, Inc.,
  13. // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  14. //
  15. // (C) 2007 Red Hat, Inc.
  16. // All rights reserved.
  17. // --- END COPYRIGHT BLOCK ---
  18. import java.net.*;
  19. import java.io.*;
  20. import java.util.*;
  21. /**
  22. * CMS Test Framework.
  23. * Use this class to Configure a CA, RA,DRM,OCSP and SubCA subsystem.
  24. * This simulartes the installation wizard functions and helps to configure a CMS subsystem.
  25. */
  26. public class AutoInstaller {
  27. private static Properties props = null;
  28. // Admin Server and InternalDB varialbes
  29. private String adminDomain, adminID, adminPWD, adminPort, machineName, host, serverID, instanceID, serverRoot, sieURL, dbConnPort, dbConnHost, dbInstanceName, dbPassword, dbLDAPauthDN, dbmode, ldapServerDB;
  30. // CMS Subsystem info
  31. private String certAdminName, certAdminUid, certAdminPWD, kra, subsystems, ca, ra, ocsp, remoteKRA, wirelessSupport, eeHttpPort, eeHttpsPort, agentHttpsPort, radminHttpsPort, tokenName, tokenPWD, certType, keyType, keyLength, SingleSignOnPWD, subjectName, aki, isCA, ski, sslCABit, objectSigningCABit, mailCABit, hashType, caOComponent, certValidityDays, signingCert, tks;
  32. // CA info
  33. private String caHostname, caPortnum, caTimeout, caEEPort, enpropfile, cdir, tokenpwd, CAadminId, CAadminPwd, CAcertnickname, caAgentPortnum, cloneInstanceId;
  34. // Program variables
  35. private int i;
  36. private String configURL, deamonURL, certInstID;
  37. private String inputLine;
  38. private boolean st = false;
  39. private String postQuery = null;
  40. private String propFileName;
  41. private StringBuffer spage = new StringBuffer();
  42. // 4.5 server String CERTtokenName="Internal Key Storage Token";
  43. private String CERTtokenName = "internal";
  44. private String certRequestStr = null, ssl_clientcert = "true";
  45. private String raSigningCert = null;
  46. private String kraTransportCert = null;
  47. private boolean subca = false;
  48. // / Constructors
  49. public AutoInstaller() {}
  50. /**
  51. * Constructor . Takes parameter Server Root .
  52. */
  53. public AutoInstaller(String sr) {
  54. serverRoot = sr;
  55. }
  56. // Set InternalDBVInfo
  57. /**
  58. * Set Internal Database Information . Takes parameters internaldatabase hostname, internaldatabase port, internaldatabase name, internaldatabase binddn, internaldatabase password
  59. */
  60. public void setInternalDBInfo(String dbh, String dbp, String dbname, String dbdn, String dbpswd) {
  61. dbConnPort = dbp;
  62. dbConnHost = dbh;
  63. dbInstanceName = dbname;
  64. dbPassword = dbpswd;
  65. dbLDAPauthDN = dbdn;
  66. dbmode = "local";
  67. ldapServerDB = "userRoot";
  68. }
  69. // Create Password file
  70. private boolean CreatePasswordFile() {
  71. String s = "internal: " + SingleSignOnPWD;
  72. OutputStream f0 = null;
  73. try {
  74. f0 = new FileOutputStream(
  75. serverRoot + "/" + instanceID + "/config/password.conf");
  76. f0.write(s.getBytes());
  77. f0.close();
  78. return true;
  79. } catch (Exception e) {
  80. System.out.println("exception " + e.getMessage());
  81. try {
  82. if (f0 != null) f0.close();
  83. } catch (IOException ioe) {
  84. System.out.println("IO Exception: " + ioe.getMessage());
  85. }
  86. return false;
  87. }
  88. }
  89. private boolean BackupConfigFile() {
  90. FileInputStream f1 = null;
  91. OutputStream f2 = null;
  92. try {
  93. f1 = new FileInputStream(
  94. serverRoot + "/" + instanceID + "/config/CS.cfg");
  95. int size = f1.available();
  96. byte b[] = new byte[size];
  97. if (f1.read(b) != b.length) {
  98. f1.close();
  99. return false;
  100. }
  101. f2 = new FileOutputStream(
  102. serverRoot + "/" + instanceID + "/config/CS.cfg.org");
  103. f2.write(b);
  104. f1.close();
  105. f2.close();
  106. return true;
  107. } catch (Exception e) {
  108. System.out.println("exception " + e.getMessage());
  109. try {
  110. if (f1 != null) f1.close();
  111. } catch (IOException ioe) {
  112. System.out.println("IO Exception: " + ioe.getMessage());
  113. }
  114. try {
  115. if (f2 != null) f2.close();
  116. } catch (IOException ioe) {
  117. System.out.println("IO Exception: " + ioe.getMessage());
  118. }
  119. return false;
  120. }
  121. }
  122. // Get RaSigning Cert
  123. public String getRASigningCert() {
  124. return raSigningCert;
  125. }
  126. // Get KRATransportCert
  127. public String getKRATransportCert() {
  128. return kraTransportCert;
  129. }
  130. // Set Admin Server Info
  131. /**
  132. * Set Admin Server Information . Takes parameters : hostname, adminserver portnumber , adminId , adminPassword
  133. */
  134. public void setAdminInfo(String h, String p, String adDN, String id, String adpwd) {
  135. adminDomain = adDN;
  136. adminID = id;
  137. adminPWD = adpwd;
  138. adminPort = p;
  139. host = h;
  140. }
  141. // Set CA Server Info
  142. /**
  143. * Set CA server Information . Takes parametrers :CAhostname, CAEEPORT, CAAGENTPORT , CAAdminUID, CAAdminPassword
  144. */
  145. public void setCAInfo(String cah, String caeep, String caagp, String caaduid, String caadpwd) {
  146. caHostname = cah;
  147. caPortnum = caagp;
  148. caTimeout = "30";
  149. caEEPort = caeep;
  150. CAadminId = caaduid;
  151. CAadminPwd = caadpwd;
  152. caAgentPortnum = caagp;
  153. }
  154. // Set ClientDB Info;
  155. /**
  156. * Sets Client Database information . Takes paramters : certdbdir, certdbpasswd, certnickanme
  157. */
  158. public void setClientDBInfo(String cd, String pwd, String nickname) {
  159. cdir = cd;
  160. tokenpwd = pwd;
  161. CAcertnickname = nickname;
  162. }
  163. // Is this Internal or any hardware token and its password;
  164. /**
  165. * Set token info . Takes paramter "Internal" and tokenpasswd
  166. */
  167. public void setTokenInfo(String t, String tp) {
  168. tokenName = t;
  169. tokenPWD = tp;
  170. }
  171. // Set Subsystem Information for Configuring
  172. /**
  173. * Takes parameters - sID- ServerID e.x cert1, sRoot- ServerRootK kT- keyType "RSA/DSA" , kL - keylength (1024.2048) , cVD- certificate validity dates e.g 365 for 1 year, sdn - subsystems dn, sAdp - subsystem's Admin port, sAgp - subsystems's Agentport,seSP- subsystem's ee SSL port , sep- Subsystems ee port.
  174. */
  175. public void setSubSystemInfo(String sID, String sRoot, String kT, String kL, String hT, String cVD, String sdn, String sAdP, String sAgP, String seSP, String seP) {
  176. serverID = sID;
  177. instanceID = "cert-" + sID;
  178. keyType = kT;
  179. keyLength = kL;
  180. hashType = hT;
  181. certValidityDays = cVD;
  182. eeHttpPort = seP;
  183. eeHttpsPort = seSP;
  184. agentHttpsPort = sAgP;
  185. radminHttpsPort = sAdP;
  186. subjectName = sdn;
  187. caOComponent = "test";
  188. }
  189. // // Configure CMS Subsystems
  190. /**
  191. * Confiures a CA Subsystem .Takes parameter : adminSubjectDN, adminUID, AdminPasswd, SingleSignonPasswd
  192. */
  193. public boolean ConfigureCA(String adn, String aduid, String adp, String ssonpwd) {
  194. certAdminName = adn;
  195. certAdminUid = aduid;
  196. certAdminPWD = adp;
  197. SingleSignOnPWD = ssonpwd;
  198. signingCert = "caSigningCert";
  199. certType = signingCert;
  200. subsystems = "ca";
  201. ca = "true";
  202. kra = "false";
  203. ra = "false";
  204. ocsp = "false";
  205. remoteKRA = "false";
  206. wirelessSupport = "false";
  207. aki = "true";
  208. isCA = "true";
  209. ski = "true";
  210. sslCABit = "true";
  211. objectSigningCABit = "true";
  212. mailCABit = "true";
  213. if (ConfCA()) {
  214. CreatePasswordFile();
  215. BackupConfigFile();
  216. return true;
  217. }
  218. return false;
  219. }
  220. public boolean ConfigureTKS(String adn, String aduid, String adp, String ssonpwd) {
  221. certAdminName = adn;
  222. certAdminUid = aduid;
  223. certAdminPWD = adp;
  224. SingleSignOnPWD = ssonpwd;
  225. signingCert = "raSigningCert";
  226. certType = signingCert;
  227. subsystems = "tks";
  228. ra = "false";
  229. tks = "true";
  230. kra = "false";
  231. ca = "false";
  232. ocsp = "false";
  233. remoteKRA = "false";
  234. wirelessSupport = "false";
  235. aki = "true";
  236. isCA = "false";
  237. ski = "true";
  238. sslCABit = "true";
  239. objectSigningCABit = "true";
  240. mailCABit = "true";
  241. if (ConfTKS()) {
  242. CreatePasswordFile();
  243. BackupConfigFile();
  244. return true;
  245. }
  246. return false;
  247. }
  248. private boolean ConfTKS() {
  249. // Start Configuring
  250. // Step 1. Start Deamon
  251. if (!startDeamon()) {
  252. System.out.println(
  253. "Configuring Cert Instance: Unable to start deamon");
  254. return false;
  255. }
  256. // Sometimes it takes time to start deamon so wait for few seconds
  257. try {
  258. System.out.println("going to sleep for 10 seconds");
  259. Thread.sleep(10000);
  260. } catch (InterruptedException ie) {
  261. System.out.println("sleep exection");
  262. }
  263. // Step 1a: Initialize Token ( Changed in 6.0)jjj
  264. if (!initializePWD()) {
  265. System.out.println(
  266. "Configuring Cert Instance: error initializing pwd token");
  267. return false;
  268. }
  269. // Step 2. Configure Internal DB
  270. if (!configInternalDB()) {
  271. System.out.println(
  272. "Configuring Cert Instance: error configuring internal db");
  273. return false;
  274. }
  275. // Step 3. Create Admin Values
  276. if (!createAdminValues()) {
  277. System.out.println(
  278. "Configuring Cert Instance: error configuring admin values ");
  279. return false;
  280. }
  281. // Step 4. SubSystems
  282. if (!selectSubSystem()) {
  283. System.out.println(
  284. "Configuring Cert Instance: error selecting subsystems");
  285. return false;
  286. }
  287. // Step 5. Network Configuration
  288. if (!networkConfig()) {
  289. System.out.println(
  290. "Configuring Cert Instance: error configuring network ports ");
  291. return false;
  292. }
  293. // Create a SSL signing cert
  294. Date tmpdate = new Date();
  295. certType = "serverCert";
  296. subjectName = "CN=" + host + "." + adminDomain + ",OU=ssltest"
  297. + tmpdate.getTime() + ",O=SSL,C=US";
  298. keyLength = "512";
  299. keyType = "RSA";
  300. String mtokenPWD = tokenPWD;
  301. tokenPWD = "";
  302. ssl_clientcert = "false";
  303. signingCert = "server";
  304. if (!initializeToken()) {
  305. System.out.println(
  306. "Configuring Cert Instance: error initializing token");
  307. return false;
  308. }
  309. // Step 8 : keyLenth
  310. if (!keyLength()) {
  311. System.out.println(
  312. "Configuring Cert Instance: error configuring KeyLength");
  313. return false;
  314. }
  315. // Step 9 : CheckDN
  316. if (!checkDN()) {
  317. System.out.println(
  318. "Configuring Cert Instance: error checking deamon");
  319. return false;
  320. }
  321. // Step 10 :
  322. if (!certRequest(false)) {
  323. System.out.println(
  324. "Configuring Cert Instance: error creating Request");
  325. return false;
  326. }
  327. // After creating ssl cert
  328. tokenPWD = mtokenPWD;
  329. // Step 11
  330. if (!singleSignON()) {
  331. System.out.println(
  332. "Configuring Cert Instance: error setting up singlesignon");
  333. return false;
  334. }
  335. // Step 11
  336. if (!doMisc()) {
  337. System.out.println(
  338. "Configuring Cert Instance: error setting up miscell");
  339. return false;
  340. }
  341. // Step 12
  342. if (!exitDeamon()) {
  343. System.out.println(
  344. "Configuring Cert Instance: Unable to exit deamon");
  345. return false;
  346. }
  347. return true;
  348. }
  349. /**
  350. * Confiures a RA Subsystem .Takes parameter : adminSubjectDN, adminUID, AdminPasswd, SingleSignonPasswd
  351. */
  352. public boolean ConfigureRA(String adn, String aduid, String adp, String ssonpwd) {
  353. certAdminName = adn;
  354. certAdminUid = aduid;
  355. certAdminPWD = adp;
  356. SingleSignOnPWD = ssonpwd;
  357. signingCert = "raSigningCert";
  358. certType = signingCert;
  359. subsystems = "ra";
  360. ra = "true";
  361. kra = "false";
  362. ca = "false";
  363. ocsp = "false";
  364. remoteKRA = "false";
  365. wirelessSupport = "false";
  366. aki = "true";
  367. isCA = "true";
  368. ski = "true";
  369. sslCABit = "true";
  370. objectSigningCABit = "true";
  371. mailCABit = "true";
  372. if (ConfRA()) {
  373. CreatePasswordFile();
  374. BackupConfigFile();
  375. return true;
  376. }
  377. return false;
  378. }
  379. /**
  380. * Confiures a OCSP Subsystem .Takes parameter : adminSubjectDN, adminUID, AdminPasswd, SingleSignonPasswd
  381. */
  382. public boolean ConfigureOCSP(String adn, String aduid, String adp, String ssonpwd) {
  383. certAdminName = adn;
  384. certAdminUid = aduid;
  385. certAdminPWD = adp;
  386. SingleSignOnPWD = ssonpwd;
  387. signingCert = "ocspSigningCert";
  388. certType = signingCert;
  389. subsystems = "ocsp";
  390. ocsp = "true";
  391. kra = "false";
  392. ra = "false";
  393. ca = "false";
  394. remoteKRA = "false";
  395. wirelessSupport = "false";
  396. aki = "true";
  397. isCA = "true";
  398. ski = "true";
  399. sslCABit = "true";
  400. objectSigningCABit = "true";
  401. mailCABit = "true";
  402. if (ConfOCSP()) {
  403. CreatePasswordFile();
  404. BackupConfigFile();
  405. return true;
  406. }
  407. return false;
  408. }
  409. /**
  410. * Confiures a KRA Subsystem .Takes parameter : adminSubjectDN, adminUID, AdminPasswd, SingleSignonPasswd
  411. */
  412. public boolean ConfigureKRA(String adn, String aduid, String adp, String ssonpwd) {
  413. certAdminName = adn;
  414. certAdminUid = aduid;
  415. certAdminPWD = adp;
  416. SingleSignOnPWD = ssonpwd;
  417. signingCert = "kraTransportCert";
  418. certType = signingCert;
  419. subsystems = "kra";
  420. kra = "true";
  421. ca = "false";
  422. ra = "false";
  423. ocsp = "false";
  424. remoteKRA = "false";
  425. wirelessSupport = "false";
  426. aki = "true";
  427. isCA = "true";
  428. ski = "true";
  429. sslCABit = "true";
  430. objectSigningCABit = "true";
  431. mailCABit = "true";
  432. if (ConfKRA()) {
  433. CreatePasswordFile();
  434. BackupConfigFile();
  435. return true;
  436. }
  437. return false;
  438. }
  439. /**
  440. * Confiures a SubCA Subsystem .Takes parameter : adminSubjectDN, adminUID, AdminPasswd, SingleSignonPasswd
  441. */
  442. public boolean ConfigureSubCA(String adn, String aduid, String adp, String ssonpwd) {
  443. certAdminName = adn;
  444. certAdminUid = aduid;
  445. certAdminPWD = adp;
  446. SingleSignOnPWD = ssonpwd;
  447. subca = true;
  448. signingCert = "caSigningCert";
  449. certType = signingCert;
  450. subsystems = "ca";
  451. ca = "true";
  452. kra = "false";
  453. ra = "false";
  454. ocsp = "false";
  455. remoteKRA = "false";
  456. wirelessSupport = "false";
  457. aki = "true";
  458. isCA = "true";
  459. ski = "true";
  460. sslCABit = "true";
  461. objectSigningCABit = "true";
  462. mailCABit = "true";
  463. if (ConfSubCA()) {
  464. CreatePasswordFile();
  465. BackupConfigFile();
  466. return true;
  467. }
  468. return false;
  469. }
  470. // ////////////////////////////////////////////////////////
  471. private void getProperties(String filePath) throws Exception {
  472. FileInputStream fis = null;
  473. try {
  474. fis = new FileInputStream(filePath);
  475. props = new Properties();
  476. props.load(fis);
  477. System.out.println("Reading Properties file successful");
  478. } catch (Exception e) {
  479. System.out.println("exception " + e.getMessage());
  480. }
  481. try {
  482. if (fis != null) fis.close();
  483. } catch (IOException ioe) {
  484. System.out.println("IO Exception: " + ioe.getMessage());
  485. }
  486. }
  487. private void setPropFile(String fileName) {
  488. propFileName = fileName;
  489. }
  490. private void setConfigURL() {
  491. configURL = "/" + instanceID + "/Tasks/Operation/config-cert";
  492. }
  493. private void setDeamonURL() {
  494. deamonURL = "/" + instanceID + "/Tasks/Operation/start-daemon";
  495. }
  496. private void setPostQueryString(String querystring) {
  497. postQuery = querystring;
  498. }
  499. private boolean Connect(String myStringUrl) {
  500. // / This functions connects to the URL and POST HTTP Request .
  501. // It compares with NMC_STATUS and return the status.
  502. System.out.println(myStringUrl);
  503. st = false;
  504. PostQuery sm = new PostQuery(myStringUrl, adminID, adminPWD, postQuery);
  505. boolean st = sm.Send();
  506. spage = sm.getPage();
  507. return st;
  508. }
  509. private boolean startDeamon() {
  510. // Set StringURL to connect , set the query string and Connect .Get the result
  511. System.out.println("Log Info - configuring Cert Instance : Start Deamon");
  512. setDeamonURL();
  513. String myStringUrl = "http://" + host + "." + adminDomain + ":"
  514. + adminPort + deamonURL;
  515. System.out.println("Log Info -" + myStringUrl);
  516. String query = "instanceID=" + URLEncoder.encode(instanceID);
  517. query += "&AdminUsername=" + URLEncoder.encode(adminID);
  518. query += "&AdminUserPassword=" + URLEncoder.encode(adminPWD);
  519. setPostQueryString(query);
  520. return Connect(myStringUrl);
  521. }
  522. private boolean configInternalDB() {
  523. System.out.println(
  524. "Log Info - configuring Cert Instance : configureInternalDB");
  525. setConfigURL();
  526. String myStringUrl = "http://" + host + ":" + adminPort + configURL;
  527. System.out.println(myStringUrl);
  528. String query = "serverRoot=" + URLEncoder.encode(serverRoot);
  529. query += "&instanceID=" + URLEncoder.encode(instanceID);
  530. query += "&adminUID=" + URLEncoder.encode(adminID);
  531. query += "&opType=" + URLEncoder.encode("OP_MODIFY");
  532. query += "&taskID=" + URLEncoder.encode("createInternalDB");
  533. query += "&AdminUserPassword=" + URLEncoder.encode(adminPWD);
  534. query += "&host=" + URLEncoder.encode(host);
  535. query += "&internaldb.ldapconn.host=" + URLEncoder.encode(dbConnHost);
  536. query += "&internaldb.ldapconn.port=" + URLEncoder.encode(dbConnPort);
  537. query += "&internaldb.ldapauth.bindDN="
  538. + URLEncoder.encode(dbLDAPauthDN);
  539. query += "&db.instanceName=" + URLEncoder.encode(dbInstanceName);
  540. query += "&db.password=" + URLEncoder.encode(dbPassword);
  541. query += "&adminDomain=" + URLEncoder.encode(adminDomain);
  542. query += "&db.mode=" + URLEncoder.encode(dbmode);
  543. query += "&ldapServerDB=" + URLEncoder.encode(ldapServerDB);
  544. query += "&cmsSeed=0";
  545. // logging
  546. setPostQueryString(query);
  547. return Connect(myStringUrl);
  548. }
  549. private boolean createAdminValues() {
  550. System.out.println("configuring Cert Instance : configureAdmin");
  551. setConfigURL();
  552. String myStringUrl = "http://" + host + ":" + adminPort + configURL;
  553. System.out.println(myStringUrl);
  554. String query = "serverRoot=" + URLEncoder.encode(serverRoot);
  555. query += "&";
  556. query += "instanceID=" + URLEncoder.encode(instanceID);
  557. query += "&AdminUserPassword=" + URLEncoder.encode(adminPWD);
  558. query += "&cert.admin.name=" + URLEncoder.encode(certAdminName);
  559. query += "&cert.admin.uid=" + URLEncoder.encode(certAdminUid);
  560. query += "&cert.admin.passwd=" + URLEncoder.encode(certAdminPWD);
  561. query += "&db.password=" + URLEncoder.encode(dbPassword);
  562. query += "&opType=" + URLEncoder.encode("OP_MODIFY");
  563. query += "&taskID=" + URLEncoder.encode("setupAdmin");
  564. query += "&cmsSeed=0";
  565. setPostQueryString(query);
  566. return Connect(myStringUrl);
  567. }
  568. private boolean selectSubSystem() {
  569. System.out.println("configuring Cert Instance : SubSystems");
  570. setConfigURL();
  571. String myStringUrl = "http://" + host + ":" + adminPort + configURL;
  572. System.out.println(myStringUrl);
  573. String query = "serverRoot=" + URLEncoder.encode(serverRoot);
  574. query += "&";
  575. query += "instanceID=" + URLEncoder.encode(instanceID);
  576. query += "&AdminUserPassword=" + URLEncoder.encode(adminPWD);
  577. query += "&db.password=" + URLEncoder.encode(dbPassword);
  578. query += "&internaldb.ldapauth.bindDN="
  579. + URLEncoder.encode(dbLDAPauthDN);
  580. query += "&kra=" + URLEncoder.encode(kra);
  581. query += "&subsystems=" + URLEncoder.encode(subsystems);
  582. query += "&ca=" + URLEncoder.encode(ca);
  583. query += "&ra=" + URLEncoder.encode(ra);
  584. query += "&ocsp=" + URLEncoder.encode(ocsp);
  585. query += "&remoteKRA=" + URLEncoder.encode(remoteKRA);
  586. query += "&wirelessSupport=" + URLEncoder.encode(wirelessSupport);
  587. query += "&opType=" + URLEncoder.encode("OP_MODIFY");
  588. query += "&taskID=" + URLEncoder.encode("selectSubsystems");
  589. query += "&cmsSeed=0";
  590. if (subsystems.equals("ca")) {
  591. query += "&internaldb.ldapconn.host="
  592. + URLEncoder.encode(dbConnHost);
  593. query += "&internaldb.ldapconn.port="
  594. + URLEncoder.encode(dbConnPort);
  595. }
  596. if (subsystems.equals("ra")) {
  597. query += "&caHostname=" + caHostname;
  598. query += "&caPortnum=" + caPortnum;
  599. query += "&caTimeout=" + caTimeout;
  600. }
  601. if (subsystems.equals("tks")) {
  602. query += "&tks=true";
  603. }
  604. setPostQueryString(query);
  605. return Connect(myStringUrl);
  606. }
  607. private boolean taskCloneMaster() {
  608. System.out.println("configuring Cert Instance : taskCloneMaster");
  609. setConfigURL();
  610. String myStringUrl = "http://" + host + ":" + adminPort + configURL;
  611. System.out.println(myStringUrl);
  612. String query = "serverRoot=" + URLEncoder.encode(serverRoot);
  613. query += "&";
  614. query += "&claPortnumEE=" + URLEncoder.encode(caEEPort);
  615. query += "&claPortnum=" + URLEncoder.encode(caAgentPortnum);
  616. query += "&claHostname=" + URLEncoder.encode(caHostname);
  617. query += "&ra=false";
  618. query += "&ca=true";
  619. query += "&kra=false";
  620. query += "&subsystems=ca";
  621. query += "&cloning=true";
  622. query += "&cloningInstance=" + URLEncoder.encode(cloneInstanceId);
  623. query += "&claTimeout=" + URLEncoder.encode("60");
  624. query += "&internaldb.ldapauth.bindDN="
  625. + URLEncoder.encode(dbLDAPauthDN);
  626. query += "&AdminUserPassword=" + URLEncoder.encode(adminPWD);
  627. query += "&db.password=" + URLEncoder.encode(dbPassword);
  628. query += "&instanceID=" + URLEncoder.encode(instanceID);
  629. query += "&opType=" + URLEncoder.encode("OP_MODIFY");
  630. query += "&taskID=" + URLEncoder.encode("taskCloneMaster");
  631. query += "&cmsSeed=0";
  632. setPostQueryString(query);
  633. return Connect(myStringUrl);
  634. }
  635. private boolean taskCloning() {
  636. System.out.println("configuring Cert Instance : taskCloning");
  637. setConfigURL();
  638. String myStringUrl = "http://" + host + ":" + adminPort + configURL;
  639. System.out.println(myStringUrl);
  640. String query = "serverRoot=" + URLEncoder.encode(serverRoot);
  641. query += "&";
  642. query += "&cloneTokenPasswd=" + URLEncoder.encode(dbPassword);
  643. query += "&cloneTokenName=" + URLEncoder.encode("internal");
  644. query += "&cloningInstance=" + URLEncoder.encode(cloneInstanceId);
  645. query += "&cloneSameMachine=true";
  646. query += "&AdminUserPassword=" + URLEncoder.encode(adminPWD);
  647. query += "&certType=" + URLEncoder.encode(certType);
  648. query += "&instanceID=" + URLEncoder.encode(instanceID);
  649. query += "&opType=" + URLEncoder.encode("OP_MODIFY");
  650. query += "&taskID=" + URLEncoder.encode("taskCloning");
  651. query += "&cmsSeed=0";
  652. setPostQueryString(query);
  653. return Connect(myStringUrl);
  654. }
  655. private boolean setSerial(String start, String end) {
  656. System.out.println("configuring Cert Instance : setCASerial");
  657. setConfigURL();
  658. String myStringUrl = "http://" + host + ":" + adminPort + configURL;
  659. System.out.println(myStringUrl);
  660. String query = "serverRoot=" + URLEncoder.encode(serverRoot);
  661. query += "&";
  662. query += "instanceID=" + URLEncoder.encode(instanceID);
  663. query += "&db.password=" + URLEncoder.encode(dbPassword);
  664. query += "&caSerialNumber=" + URLEncoder.encode(start);
  665. query += "&caEndSerialNumber=" + URLEncoder.encode(end);
  666. query += "&opType=" + URLEncoder.encode("OP_MODIFY");
  667. query += "&taskID=" + URLEncoder.encode("setCASerial");
  668. query += "&cmsSeed=0";
  669. setPostQueryString(query);
  670. return Connect(myStringUrl);
  671. }
  672. private boolean setOCSP() {
  673. System.out.println("configuring Cert Instance : setOCSP");
  674. setConfigURL();
  675. String myStringUrl = "http://" + host + ":" + adminPort + configURL;
  676. System.out.println(myStringUrl);
  677. String query = "serverRoot=" + URLEncoder.encode(serverRoot);
  678. query += "&";
  679. query += "instanceID=" + URLEncoder.encode(instanceID);
  680. query += "&CAOCSPService=" + URLEncoder.encode("true");
  681. query += "&opType=" + URLEncoder.encode("OP_MODIFY");
  682. query += "&taskID=" + URLEncoder.encode("addOCSPService");
  683. query += "&cmsSeed=0";
  684. setPostQueryString(query);
  685. return Connect(myStringUrl);
  686. }
  687. private boolean networkConfig() {
  688. System.out.println("configuring Cert Instance : Network Config");
  689. setConfigURL();
  690. String myStringUrl = "http://" + host + ":" + adminPort + configURL;
  691. System.out.println(myStringUrl);
  692. String query = "AdminUserPassword=" + URLEncoder.encode(adminPWD);
  693. query += "&";
  694. query += "instanceID=" + URLEncoder.encode(instanceID);
  695. if (subsystems.equals("kra")) {
  696. query += "&agentGateway.https.port="
  697. + URLEncoder.encode(agentHttpsPort);
  698. query += "&radm.https.port=" + URLEncoder.encode(radminHttpsPort);
  699. query += "&eePortsEnable=" + URLEncoder.encode("false");
  700. } else {
  701. query += "&eeGateway.http.port=" + URLEncoder.encode(eeHttpPort);
  702. query += "&eeGateway.https.port=" + URLEncoder.encode(eeHttpsPort);
  703. query += "&agentGateway.https.port="
  704. + URLEncoder.encode(agentHttpsPort);
  705. query += "&radm.https.port=" + URLEncoder.encode(radminHttpsPort);
  706. query += "&eePortsEnable=" + URLEncoder.encode("true");
  707. query += "&eeGateway.http.enable=" + URLEncoder.encode("true");
  708. }
  709. query += "&opType=" + URLEncoder.encode("OP_MODIFY");
  710. query += "&taskID=" + URLEncoder.encode("configureNetwork");
  711. query += "&cmsSeed=0";
  712. setPostQueryString(query);
  713. return Connect(myStringUrl);
  714. }
  715. private boolean serverMigration() {
  716. System.out.println("configuring Cert Instance : Server migration");
  717. setConfigURL();
  718. String myStringUrl = "http://" + host + ":" + adminPort + configURL;
  719. System.out.println(myStringUrl);
  720. String query = "AdminUserPassword=" + URLEncoder.encode(adminPWD);
  721. query += "&";
  722. query += "instanceID=" + URLEncoder.encode(instanceID);
  723. query += "&migrationEnable=" + URLEncoder.encode("false");
  724. query += "&opType=" + URLEncoder.encode("OP_MODIFY");
  725. query += "&taskID=" + URLEncoder.encode("migration");
  726. query += "&cmsSeed=0";
  727. setPostQueryString(query);
  728. return Connect(myStringUrl);
  729. }
  730. private boolean initializePWD() {
  731. System.out.println("configuring Cert Instance : Initialize token");
  732. setConfigURL();
  733. String myStringUrl = "http://" + host + ":" + adminPort + configURL;
  734. System.out.println(myStringUrl);
  735. String query = "AdminUserPassword=" + URLEncoder.encode(adminPWD);
  736. query += "&";
  737. query += "instanceID=" + URLEncoder.encode(instanceID);
  738. query += "&serverRoot=" + URLEncoder.encode(serverRoot);
  739. query += "&tokenName=" + URLEncoder.encode(tokenName);
  740. query += "&tokenPasswd=" + URLEncoder.encode(tokenPWD);
  741. query += "&opType=" + URLEncoder.encode("OP_MODIFY");
  742. query += "&taskID=" + URLEncoder.encode("initToken");
  743. query += "&cmsSeed=0";
  744. setPostQueryString(query);
  745. return Connect(myStringUrl);
  746. }
  747. private boolean initializeToken() {
  748. System.out.println("configuring Cert Instance : Initialize token");
  749. setConfigURL();
  750. String myStringUrl = "http://" + host + ":" + adminPort + configURL;
  751. System.out.println(myStringUrl);
  752. String query = "AdminUserPassword=" + URLEncoder.encode(adminPWD);
  753. query += "&";
  754. query += "instanceID=" + URLEncoder.encode(instanceID);
  755. query += "&serverRoot=" + URLEncoder.encode(serverRoot);
  756. query += "&tokenName=" + URLEncoder.encode(tokenName);
  757. query += "&tokenPasswd=" + URLEncoder.encode(tokenPWD);
  758. query += "&certType=" + URLEncoder.encode(certType);
  759. query += "&keyType=" + URLEncoder.encode(keyType);
  760. query += "&keyLength=" + URLEncoder.encode(keyLength);
  761. query += "&sopPasswd=" + URLEncoder.encode(SingleSignOnPWD);
  762. query += "&opType=" + URLEncoder.encode("OP_MODIFY");
  763. query += "&taskID=" + URLEncoder.encode("initToken");
  764. query += "&cmsSeed=0";
  765. setPostQueryString(query);
  766. return Connect(myStringUrl);
  767. }
  768. private boolean keyLength() {
  769. System.out.println("configuring Cert Instance : Check Key length");
  770. setConfigURL();
  771. String myStringUrl = "http://" + host + ":" + adminPort + configURL;
  772. System.out.println(myStringUrl);
  773. String query = "AdminUserPassword=" + URLEncoder.encode(adminPWD);
  774. query += "&";
  775. query += "instanceID=" + URLEncoder.encode(instanceID);
  776. query += "&serverRoot=" + URLEncoder.encode(serverRoot);
  777. query += "&tokenName=" + URLEncoder.encode(tokenName);
  778. query += "&tokenPasswd=" + URLEncoder.encode(tokenPWD);
  779. query += "&certType=" + URLEncoder.encode(certType);
  780. query += "&keyType=" + URLEncoder.encode(keyType);
  781. query += "&keyLength=" + URLEncoder.encode(keyLength);
  782. query += "&sopPasswd=" + URLEncoder.encode(SingleSignOnPWD);
  783. query += "&opType=" + URLEncoder.encode("OP_MODIFY");
  784. query += "&taskID=" + URLEncoder.encode("checkKeyLength");
  785. query += "&cmsSeed=0";
  786. setPostQueryString(query);
  787. return Connect(myStringUrl);
  788. }
  789. private boolean checkDN() {
  790. System.out.println("configuring Cert Instance : Check DN");
  791. setConfigURL();
  792. String myStringUrl = "http://" + host + ":" + adminPort + configURL;
  793. System.out.println(myStringUrl);
  794. String query = "AdminUserPassword=" + URLEncoder.encode(adminPWD);
  795. query += "&";
  796. query += "instanceID=" + URLEncoder.encode(instanceID);
  797. query += "&certType=" + URLEncoder.encode(certType);
  798. query += "&subjectName=" + URLEncoder.encode(subjectName);
  799. query += "&opType=" + URLEncoder.encode("OP_MODIFY");
  800. query += "&taskID=" + URLEncoder.encode("checkDN");
  801. query += "&cmsSeed=0";
  802. setPostQueryString(query);
  803. return Connect(myStringUrl);
  804. }
  805. private String normalize(String s) {
  806. String val = "";
  807. for (int i = 0; i < s.length(); i++) {
  808. if ((s.charAt(i) == '\\') && (s.charAt(i + 1) == 'n')) {
  809. i++;
  810. continue;
  811. } else if ((s.charAt(i) == '\\') && (s.charAt(i + 1) == 'r')) {
  812. i++;
  813. continue;
  814. } else if (s.charAt(i) == '"') {
  815. continue;
  816. }
  817. val += s.charAt(i);
  818. }
  819. return val;
  820. }
  821. private String pkcs7Convertcert(String s) {
  822. String val = "";
  823. int len = s.length();
  824. for (int i = 0; i < len; i = i + 64) {
  825. if (i + 64 < len) {
  826. val = val + s.substring(i, i + 64) + "\n";
  827. } else {
  828. val = val + s.substring(i, len);
  829. }
  830. }
  831. return val;
  832. }
  833. private boolean certRequest(boolean trustM) {
  834. // This function prepares a Certificate Request.
  835. // Submits it to the CA
  836. // Approves the request.
  837. // And then installs it
  838. System.out.println("configuring Cert Instance : cert Request");
  839. setConfigURL();
  840. String myStringUrl = "http://" + host + ":" + adminPort + configURL;
  841. System.out.println(myStringUrl);
  842. String query = "AdminUserPassword=" + URLEncoder.encode(adminPWD);
  843. query += "&";
  844. query += "instanceID=" + URLEncoder.encode(instanceID);
  845. query += "&certType=" + URLEncoder.encode(certType);
  846. query += "&subjectName=" + URLEncoder.encode(subjectName);
  847. query += "&keyType=" + URLEncoder.encode(keyType);
  848. query += "&keyLength=" + URLEncoder.encode(keyLength);
  849. query += "&tokenName=" + URLEncoder.encode(CERTtokenName);
  850. if (subca) {
  851. query += "&sslCABit=true";
  852. query += "&objectSigningCABit=true";
  853. query += "&wirelessSupport=false";
  854. query += "&mailCABit=true";
  855. query += "&isCA=true";
  856. query += "&ski=true";
  857. query += "&aki=true";
  858. query += "&keyUsage=true";
  859. query += "&caSigningCertReqFormat=PKCS10";
  860. }
  861. if (subsystems.equals("ra")) {
  862. query += "&aki=" + URLEncoder.encode(aki);
  863. query += "&keyUsage=" + URLEncoder.encode("true");
  864. query += "&signing_cert=" + signingCert;
  865. }
  866. if (certType.equals("serverCert")) {
  867. query += "&sslServerBit=" + URLEncoder.encode("true");
  868. query += "&sslClientBit=" + URLEncoder.encode("true");
  869. query += "&serverCertReqFormat=PKCS10";
  870. } else {
  871. if (subsystems.equals("ra")) {
  872. query += "&sslClientBit=" + URLEncoder.encode("true");
  873. query += "&raSigningCertReqFormat=PKCS10";
  874. }
  875. if (subsystems.equals("ocsp")) {
  876. query += "&ocspSigningCertReqFormat=PKCS10";
  877. }
  878. if (subsystems.equals("kra")) {
  879. // added keyUsage
  880. query += "&keyUsage=" + URLEncoder.encode("true");
  881. // added URLEncoder
  882. query += "&aki=" + URLEncoder.encode(aki);
  883. query += "&kraTransportCertReqFormat=PKCS10";
  884. }
  885. }
  886. query += "&opType=" + URLEncoder.encode("OP_MODIFY");
  887. query += "&taskID=" + URLEncoder.encode("certRequest");
  888. query += "&caHostname=" + caHostname;
  889. query += "&caEEPort=" + caEEPort;
  890. query += "&cmsSeed=0";
  891. setPostQueryString(query);
  892. if (!Connect(myStringUrl)) {
  893. System.out.println("Error :certRequest");
  894. return false;
  895. }
  896. String res = spage.toString();
  897. certRequestStr = res.substring(
  898. res.indexOf("certReq: ") + "certReq: ".length(),
  899. res.indexOf("-----END NEW CERTIFICATE REQUEST-----"));
  900. certRequestStr += "-----END NEW CERTIFICATE REQUEST-----";
  901. int ReqId = 0;
  902. UserEnroll e = new UserEnroll(caHostname, caEEPort, subjectName, "test",
  903. "test", null, "test", "test", cdir, tokenpwd, ssl_clientcert,
  904. keyLength, keyType, null, null, signingCert);
  905. e.setpkcs10Request(certRequestStr);
  906. if (e.Enroll()) {
  907. ReqId = e.getRequestId();
  908. } else {
  909. System.out.println("Request was not successful");
  910. return false;
  911. }
  912. String trm;
  913. if (trustM) {
  914. trm = "true";
  915. } else {
  916. trm = "false";
  917. }
  918. Request r = new Request(caHostname, caAgentPortnum, CAadminId,
  919. CAadminPwd, CAcertnickname, cdir, tokenpwd, getString(ReqId),
  920. null, null, "approve", "enrollment", "showWaiting", null, trm);
  921. if (r.ApproveRequests(getString(ReqId)) <= -1) {
  922. System.out.println(
  923. "Error : Agent request approval was not successful");
  924. return false;
  925. }
  926. System.out.println("configuring Cert Instance : req Success");
  927. // Checking to see if request is approved.
  928. setConfigURL();
  929. myStringUrl = "http://" + host + ":" + adminPort + configURL;
  930. System.out.println(myStringUrl);
  931. query = "AdminUserPassword=" + URLEncoder.encode(adminPWD);
  932. query += "&";
  933. query += "instanceID=" + URLEncoder.encode(instanceID);
  934. query += "&certType=" + URLEncoder.encode(certType);
  935. if (certType.equals("serverCert")) {
  936. query += "&serverCertReqID=" + ReqId;
  937. } else {
  938. query += "&raSigningCertReqID=" + ReqId;
  939. }
  940. query += "&serverRoot=" + URLEncoder.encode(serverRoot);
  941. query += "&caEEPort=" + caEEPort;
  942. query += "&caHostname=" + host;
  943. query += "&caEEType=https";
  944. query += "&opType=" + URLEncoder.encode("OP_MODIFY");
  945. query += "&taskID=" + URLEncoder.encode("reqSuccess");
  946. query += "&cmsSeed=0";
  947. setPostQueryString(query);
  948. if (Connect(myStringUrl)) {
  949. checkRequest cr = new checkRequest(caHostname, caEEPort, cdir,
  950. tokenpwd, getString(ReqId), null, null);
  951. if (cr.checkRequestStatus()) {
  952. String cert = cr.getpkcs7ChainCert();
  953. String certtmp = pkcs7Convertcert(cert);
  954. certtmp = normalize(certtmp);
  955. cert = "-----BEGIN CERTIFICATE-----" + "\n" + certtmp + "\n"
  956. + "-----END CERTIFICATE-----\n";
  957. // install cert
  958. System.out.println(
  959. "configuring Cert Instance : install cert :" + cert);
  960. setConfigURL();
  961. myStringUrl = "http://" + host + ":" + adminPort + configURL;
  962. System.out.println(myStringUrl);
  963. query = "AdminUserPassword=" + URLEncoder.encode(adminPWD);
  964. query += "&";
  965. query += "instanceID=" + URLEncoder.encode(instanceID);
  966. query += "&certType=" + URLEncoder.encode(certType);
  967. query += "&db.password=" + URLEncoder.encode(dbPassword);
  968. if (certType.equals("raSigningCert")) {
  969. query += "&nickname="
  970. + URLEncoder.encode(certType + " " + instanceID);
  971. raSigningCert = "-----BEGIN CERTIFICATE-----" + "\n"
  972. + cr.getCert() + "\n"
  973. + "-----END CERTIFICATE-----\n";
  974. }
  975. if (certType.equals("kraTransportCert")) {
  976. ComCrypto cCrypto = new ComCrypto();
  977. kraTransportCert = cCrypto.normalize(cr.getCert());
  978. }
  979. if (certType.equals("serverCert")) {
  980. query += "&nickname="
  981. + URLEncoder.encode("Server-Cert" + " " + instanceID);
  982. }
  983. if (certType.equals("ocspSigningCert")) {
  984. query += "&nickname="
  985. + URLEncoder.encode(certType + " " + instanceID);
  986. }
  987. query += "&pkcs10=" + URLEncoder.encode(cert);
  988. query += "&opType=" + URLEncoder.encode("OP_MODIFY");
  989. query += "&taskID=" + URLEncoder.encode("installCert");
  990. query += "&cmsSeed=0";
  991. setPostQueryString(query);
  992. return(Connect(myStringUrl));
  993. }
  994. } else {
  995. System.out.println("Error: Request is not approved");
  996. return false;
  997. }
  998. return true;
  999. }
  1000. private String getString(int m) {
  1001. Integer x = new Integer(m);
  1002. String s = x.toString();
  1003. return s;
  1004. }
  1005. private boolean createCert() {
  1006. System.out.println("configuring Cert Instance : Create Cert");
  1007. // clauclate the validity dates for the cert.
  1008. GregorianCalendar begin = new GregorianCalendar();
  1009. GregorianCalendar end = new GregorianCalendar();
  1010. Integer days = new Integer(certValidityDays);
  1011. end.add(GregorianCalendar.DATE, days.intValue());
  1012. setConfigURL();
  1013. String myStringUrl = "http://" + host + ":" + adminPort + configURL;
  1014. System.out.println(myStringUrl);
  1015. String query = "AdminUserPassword=" + URLEncoder.encode(adminPWD);
  1016. query += "&";
  1017. query += "instanceID=" + URLEncoder.encode(instanceID);
  1018. query += "&serverRoot=" + URLEncoder.encode(serverRoot);
  1019. query += "&db.password=" + URLEncoder.encode(dbPassword);
  1020. query += "&subjectName=" + URLEncoder.encode(subjectName);
  1021. query += "&certType=" + URLEncoder.encode(certType);
  1022. query += "&beginYear="
  1023. + URLEncoder.encode(getString(begin.get(GregorianCalendar.YEAR)));
  1024. query += "&beginMonth="
  1025. + URLEncoder.encode(
  1026. getString(begin.get(GregorianCalendar.MONTH)));
  1027. query += "&beginDate="
  1028. + URLEncoder.encode(getString(begin.get(GregorianCalendar.DATE)));
  1029. query += "&beginHour="
  1030. + URLEncoder.encode(getString(begin.get(GregorianCalendar.HOUR)));
  1031. query += "&beginMin="
  1032. + URLEncoder.encode(
  1033. getString(begin.get(GregorianCalendar.MINUTE)));
  1034. query += "&beginSec="
  1035. + URLEncoder.encode(
  1036. getString(begin.get(GregorianCalendar.SECOND)));
  1037. query += "&afterYear="
  1038. + URLEncoder.encode(getString(end.get(GregorianCalendar.YEAR)));
  1039. query += "&afterMonth="
  1040. + URLEncoder.encode(getString(end.get(GregorianCalendar.MONTH)));
  1041. query += "&afterDate="
  1042. + URLEncoder.encode(getString(end.get(GregorianCalendar.DATE)));
  1043. query += "&afterHour="
  1044. + URLEncoder.encode(getString(end.get(GregorianCalendar.HOUR)));
  1045. query += "&afterMin="
  1046. + URLEncoder.encode(getString(end.get(GregorianCalendar.MINUTE)));
  1047. query += "&afterSec="
  1048. + URLEncoder.encode(getString(end.get(GregorianCalendar.SECOND)));
  1049. query += "&keyType=" + URLEncoder.encode(keyType);
  1050. query += "&keyLength=" + URLEncoder.encode(keyLength);
  1051. query += "&certLen=" + URLEncoder.encode("-1");
  1052. query += "&tokenName=" + URLEncoder.encode(CERTtokenName);
  1053. query += "&aki=" + URLEncoder.encode(aki);
  1054. query += "&keyUsage=" + URLEncoder.encode("true");
  1055. if (certType.equals("serverCert")) {
  1056. query += "&sslServerBit=" + URLEncoder.encode("true");
  1057. query += "&sslClientBit=" + URLEncoder.encode("true");
  1058. } else {
  1059. query += "&caOComponent=" + URLEncoder.encode(caOComponent);
  1060. query += "&caCComponent=" + URLEncoder.encode("us");
  1061. query += "&isCA=" + URLEncoder.encode(isCA);
  1062. query += "&ski=" + URLEncoder.encode(ski);
  1063. query += "&tokenPasswd=" + URLEncoder.encode(tokenPWD);
  1064. query += "&sslCABit=" + URLEncoder.encode(sslCABit);
  1065. query += "&mailCABit=" + URLEncoder.encode(mailCABit);
  1066. query += "&objectSigningCABit="
  1067. + URLEncoder.encode(objectSigningCABit);
  1068. }
  1069. query += "&hashType=" + URLEncoder.encode(hashType);
  1070. query += "&sopPasswd=" + URLEncoder.encode(SingleSignOnPWD);
  1071. query += "&wirelessSupport=" + URLEncoder.encode("false");
  1072. query += "&opType=" + URLEncoder.encode("OP_MODIFY");
  1073. query += "&taskID=" + URLEncoder.encode("createCert");
  1074. query += "&cmsSeed=0";
  1075. setPostQueryString(query);
  1076. return Connect(myStringUrl);
  1077. }
  1078. private boolean singleSignON() {
  1079. System.out.println("configuring Cert Instance : Single Signon");
  1080. setConfigURL();
  1081. String myStringUrl = "http://" + host + ":" + adminPort + configURL;
  1082. System.out.println(myStringUrl);
  1083. String PWTags = "Internal:Internal LDAP Database:singlesignon";
  1084. String query = "AdminUserPassword=" + URLEncoder.encode(adminPWD);
  1085. query += "&";
  1086. query += "instanceID=" + URLEncoder.encode(instanceID);
  1087. query += "&serverRoot=" + URLEncoder.encode(serverRoot);
  1088. // query += "&singleSignonPwd=" + URLEncoder.encode(SingleSignOnPWD);
  1089. query += "&singleSignonPWTags=" + URLEncoder.encode(PWTags);
  1090. query += "&Internal=" + URLEncoder.encode(tokenPWD);
  1091. query += "&Internal LDAP Database=" + URLEncoder.encode(dbPassword);
  1092. query += "&pwcTokenname=" + URLEncoder.encode("internal");
  1093. query += "&singlesignon=" + URLEncoder.encode(tokenPWD);
  1094. query += "&opType=" + URLEncoder.encode("OP_MODIFY");
  1095. query += "&taskID=" + URLEncoder.encode("singleSignon");
  1096. query += "&cmsSeed=0";
  1097. setPostQueryString(query);
  1098. return Connect(myStringUrl);
  1099. }
  1100. private boolean doMisc() {
  1101. System.out.println("configuring Cert Instance : do Miscell");
  1102. setConfigURL();
  1103. String myStringUrl = "http://" + host + ":" + adminPort + configURL;
  1104. System.out.println(myStringUrl);
  1105. String PWTags = "Internal:Internal LDAP Database:singlesignon";
  1106. String query = "AdminUserPassword=" + URLEncoder.encode(adminPWD);
  1107. query += "&";
  1108. query += "instanceID=" + URLEncoder.encode(instanceID);
  1109. query += "&serverRoot=" + URLEncoder.encode(serverRoot);
  1110. query += "&singleSignonPwd=" + URLEncoder.encode(SingleSignOnPWD);
  1111. query += "&singleSignonPWTags=" + URLEncoder.encode(PWTags);
  1112. query += "&Internal=" + URLEncoder.encode(tokenPWD);
  1113. query += "&Internal LDAP Database=" + URLEncoder.encode(dbPassword);
  1114. query += "&singlesignon=" + URLEncoder.encode(tokenPWD);
  1115. query += "&deletePasswdConf=false";
  1116. query += "&opType=" + URLEncoder.encode("OP_MODIFY");
  1117. query += "&taskID=" + URLEncoder.encode("doMiscStuffs");
  1118. query += "&cmsSeed=0";
  1119. setPostQueryString(query);
  1120. return Connect(myStringUrl);
  1121. }
  1122. private boolean exitDeamon() {
  1123. System.out.println("configuring Cert Instance : Exit Deamon");
  1124. setDeamonURL();
  1125. String myStringUrl = "http://" + host + ":" + adminPort + configURL;
  1126. System.out.println(myStringUrl);
  1127. String query = "AdminUserPassword=" + URLEncoder.encode(adminPWD);
  1128. query += "&";
  1129. query += "instanceID=" + URLEncoder.encode(instanceID);
  1130. query += "&serverRoot=" + URLEncoder.encode(serverRoot);
  1131. query += "&opType=" + URLEncoder.encode("OP_MODIFY");
  1132. query += "&taskID=" + URLEncoder.encode("exit");
  1133. query += "&cmsSeed=0";
  1134. setPostQueryString(query);
  1135. return Connect(myStringUrl);
  1136. }
  1137. private boolean ConfOCSP() {
  1138. // Step 1. Start Deamon
  1139. if (!startDeamon()) {
  1140. System.out.println(
  1141. "Configuring Cert Instance: Unable to start deamon");
  1142. return false;
  1143. }
  1144. // Sometimes it takes time to start deamon so wait for few seconds
  1145. try {
  1146. System.out.println("going to sleep for 10 seconds");
  1147. Thread.sleep(10000);
  1148. } catch (InterruptedException ie) {
  1149. System.out.println("sleep exection");
  1150. }
  1151. // Step 1a: Initialize Token ( Changed in 6.0)jjj
  1152. if (!initializePWD()) {
  1153. System.out.println(
  1154. "Configuring Cert Instance: error initializing pwd token");
  1155. return false;
  1156. }
  1157. // Step 2. Configure Internal DB
  1158. if (!configInternalDB()) {
  1159. System.out.println(
  1160. "Configuring Cert Instance: error configuring internal db");
  1161. return false;
  1162. }
  1163. // Step 3. Create Admin Values
  1164. if (!createAdminValues()) {
  1165. System.out.println(
  1166. "Configuring Cert Instance: error configuring admin values ");
  1167. return false;
  1168. }
  1169. // Step 4. SubSystems
  1170. if (!selectSubSystem()) {
  1171. System.out.println(
  1172. "Configuring Cert Instance: error selecting subsystems");
  1173. return false;
  1174. }
  1175. // Step 5. Network Configuration
  1176. if (!networkConfig()) {
  1177. System.out.println(
  1178. "Configuring Cert Instance: error configuring network ports ");
  1179. return false;
  1180. }
  1181. // Step 6: Initialize Token This has been moved to step 1a
  1182. if (!initializeToken()) {
  1183. System.out.println(
  1184. "Configuring Cert Instance: error initializing token");
  1185. return false;
  1186. }
  1187. // Step 7 : keyLenth
  1188. if (!keyLength()) {
  1189. System.out.println(
  1190. "Configuring Cert Instance: error configuring KeyLength");
  1191. return false;
  1192. }
  1193. // Step 8 : CheckDN
  1194. if (!checkDN()) {
  1195. System.out.println(
  1196. "Configuring Cert Instance: error checking deamon");
  1197. return false;
  1198. }
  1199. // Step 9 : certRequest and Install
  1200. if (!certRequest(false)) {
  1201. System.out.println("Configuring Cert Instance: error getting cert");
  1202. return false;
  1203. }
  1204. // Create a SSL signing cert
  1205. Date tmpdate = new Date();
  1206. certType = "serverCert";
  1207. subjectName = "CN=" + host + "." + adminDomain + ",OU=ssltest"
  1208. + tmpdate.getTime() + ",O=SSL,C=US";
  1209. keyLength = "512";
  1210. keyType = "RSA";
  1211. String mtokenPWD = tokenPWD;
  1212. tokenPWD = "";
  1213. ssl_clientcert = "false";
  1214. signingCert = "server";
  1215. if (!initializeToken()) {
  1216. System.out.println(
  1217. "Configuring Cert Instance: error initializing token");
  1218. return false;
  1219. }
  1220. // Step 8 : keyLenth
  1221. if (!keyLength()) {
  1222. System.out.println(
  1223. "Configuring Cert Instance: error configuring KeyLength");
  1224. return false;
  1225. }
  1226. // Step 9 : CheckDN
  1227. if (!checkDN()) {
  1228. System.out.println(
  1229. "Configuring Cert Instance: error checking deamon");
  1230. return false;
  1231. }
  1232. // Step 10 :
  1233. if (!certRequest(false)) {
  1234. System.out.println(
  1235. "Configuring Cert Instance: error creating Request");
  1236. return false;
  1237. }
  1238. // After creating ssl cert
  1239. tokenPWD = mtokenPWD;
  1240. // Step 11
  1241. if (!singleSignON()) {
  1242. System.out.println(
  1243. "Configuring Cert Instance: error setting up singlesignon");
  1244. return false;
  1245. }
  1246. // Step 11
  1247. if (!doMisc()) {
  1248. System.out.println(
  1249. "Configuring Cert Instance: error setting up miscell");
  1250. return false;
  1251. }
  1252. // Step 12
  1253. if (!exitDeamon()) {
  1254. System.out.println(
  1255. "Configuring Cert Instance: Unable to exit deamon");
  1256. return false;
  1257. }
  1258. return true;
  1259. }
  1260. private boolean setupStorageKey() {
  1261. System.out.println("configuring Cert Instance : Storage Key");
  1262. setConfigURL();
  1263. String myStringUrl = "http://" + host + ":" + adminPort + configURL;
  1264. System.out.println(myStringUrl);
  1265. String query = "AdminUserPassword=" + URLEncoder.encode(adminPWD);
  1266. query += "&";
  1267. query += "instanceID=" + URLEncoder.encode(instanceID);
  1268. query += "&serverRoot=" + URLEncoder.encode(serverRoot);
  1269. query += "&opType=" + URLEncoder.encode("OP_MODIFY");
  1270. query += "&taskID=" + URLEncoder.encode("storageKey");
  1271. query += "&tokenName=" + URLEncoder.encode("Internal");
  1272. query += "&tokenPasswd=" + URLEncoder.encode("");
  1273. query += "&keyLength=" + URLEncoder.encode("512");
  1274. query += "&cmsSeed=0";
  1275. setPostQueryString(query);
  1276. return Connect(myStringUrl);
  1277. }
  1278. private boolean setupKRAAgents() {
  1279. System.out.println("configuring Cert Instance : KRA Agents");
  1280. setConfigURL();
  1281. String myStringUrl = "http://" + host + ":" + adminPort + configURL;
  1282. System.out.println(myStringUrl);
  1283. String query = "AdminUserPassword=" + URLEncoder.encode(adminPWD);
  1284. query += "&";
  1285. query += "instanceID=" + URLEncoder.encode(instanceID);
  1286. query += "&serverRoot=" + URLEncoder.encode(serverRoot);
  1287. query += "&opType=" + URLEncoder.encode("OP_MODIFY");
  1288. query += "&taskID=" + URLEncoder.encode("agents");
  1289. query += "&n=" + URLEncoder.encode("3");
  1290. query += "&m=" + URLEncoder.encode("2");
  1291. query += "&uid2=" + URLEncoder.encode("agent3");
  1292. query += "&uid0=" + URLEncoder.encode("agent1");
  1293. query += "&uid1=" + URLEncoder.encode("agent2");
  1294. query += "&pwd1=" + URLEncoder.encode("netscape");
  1295. query += "&pwd2=" + URLEncoder.encode("netscape");
  1296. query += "&pwd0=" + URLEncoder.encode("netscape");
  1297. query += "&cmsSeed=0";
  1298. setPostQueryString(query);
  1299. return Connect(myStringUrl);
  1300. }
  1301. private boolean ConfRA() {
  1302. // Start Configuring
  1303. // Step 1. Start Deamon
  1304. if (!startDeamon()) {
  1305. System.out.println(
  1306. "Configuring Cert Instance: Unable to start deamon");
  1307. return false;
  1308. }
  1309. // Sometimes it takes time to start deamon so wait for few seconds
  1310. try {
  1311. System.out.println("going to sleep for 10 seconds");
  1312. Thread.sleep(10000);
  1313. } catch (InterruptedException ie) {
  1314. System.out.println("sleep exection");
  1315. }
  1316. // Step 1a: Initialize Token ( Changed in 6.0)jjj
  1317. if (!initializePWD()) {
  1318. System.out.println(
  1319. "Configuring Cert Instance: error initializing pwd token");
  1320. return false;
  1321. }
  1322. // Step 2. Configure Internal DB
  1323. if (!configInternalDB()) {
  1324. System.out.println(
  1325. "Configuring Cert Instance: error configuring internal db");
  1326. return false;
  1327. }
  1328. // Step 3. Create Admin Values
  1329. if (!createAdminValues()) {
  1330. System.out.println(
  1331. "Configuring Cert Instance: error configuring admin values ");
  1332. return false;
  1333. }
  1334. // Step 4. SubSystems
  1335. if (!selectSubSystem()) {
  1336. System.out.println(
  1337. "Configuring Cert Instance: error selecting subsystems");
  1338. return false;
  1339. }
  1340. // Step 5. Network Configuration
  1341. if (!networkConfig()) {
  1342. System.out.println(
  1343. "Configuring Cert Instance: error configuring network ports ");
  1344. return false;
  1345. }
  1346. // Step 6: Initialize Token This has been moved to step 1a
  1347. if (!initializeToken()) {
  1348. System.out.println(
  1349. "Configuring Cert Instance: error initializing token");
  1350. return false;
  1351. }
  1352. // Step 7 : keyLenth
  1353. if (!keyLength()) {
  1354. System.out.println(
  1355. "Configuring Cert Instance: error configuring KeyLength");
  1356. return false;
  1357. }
  1358. // Step 8 : CheckDN
  1359. if (!checkDN()) {
  1360. System.out.println(
  1361. "Configuring Cert Instance: error checking deamon");
  1362. return false;
  1363. }
  1364. // Step 9 : certRequest and Install i.e approve the request as a trusted manager
  1365. if (!certRequest(true)) {
  1366. System.out.println("Configuring Cert Instance: error getting cert");
  1367. return false;
  1368. }
  1369. // Create a SSL signing cert
  1370. Date tmpdate = new Date();
  1371. certType = "serverCert";
  1372. subjectName = "CN=" + host + "." + adminDomain + ",OU=ssltest"
  1373. + tmpdate.getTime() + ",O=SSL,C=US";
  1374. keyLength = "512";
  1375. keyType = "RSA";
  1376. String mtokenPWD = tokenPWD;
  1377. tokenPWD = "";
  1378. ssl_clientcert = "false";
  1379. signingCert = "server";
  1380. if (!initializeToken()) {
  1381. System.out.println(
  1382. "Configuring Cert Instance: error initializing token");
  1383. return false;
  1384. }
  1385. // Step 8 : keyLenth
  1386. if (!keyLength()) {
  1387. System.out.println(
  1388. "Configuring Cert Instance: error configuring KeyLength");
  1389. return false;
  1390. }
  1391. // Step 9 : CheckDN
  1392. if (!checkDN()) {
  1393. System.out.println(
  1394. "Configuring Cert Instance: error checking deamon");
  1395. return false;
  1396. }
  1397. // Step 10 :
  1398. if (!certRequest(false)) {
  1399. System.out.println(
  1400. "Configuring Cert Instance: error creating Request");
  1401. return false;
  1402. }
  1403. // After creating ssl cert
  1404. tokenPWD = mtokenPWD;
  1405. // Step 11
  1406. if (!singleSignON()) {
  1407. System.out.println(
  1408. "Configuring Cert Instance: error setting up singlesignon");
  1409. return false;
  1410. }
  1411. // Step 11
  1412. if (!doMisc()) {
  1413. System.out.println(
  1414. "Configuring Cert Instance: error setting up miscell");
  1415. return false;
  1416. }
  1417. // Step 12
  1418. if (!exitDeamon()) {
  1419. System.out.println(
  1420. "Configuring Cert Instance: Unable to exit deamon");
  1421. return false;
  1422. }
  1423. return true;
  1424. }
  1425. private boolean ConfKRA() {
  1426. // Start Configuring
  1427. // Step 1. Start Deamon
  1428. if (!startDeamon()) {
  1429. System.out.println(
  1430. "Configuring Cert Instance: Unable to start deamon");
  1431. return false;
  1432. }
  1433. // Sometimes it takes time to start deamon so wait for few seconds
  1434. try {
  1435. System.out.println("going to sleep for 10 seconds");
  1436. Thread.sleep(10000);
  1437. } catch (InterruptedException ie) {
  1438. System.out.println("sleep exection");
  1439. }
  1440. // Step 1a: Initialize Token ( Changed in 6.0)jjj
  1441. if (!initializePWD()) {
  1442. System.out.println(
  1443. "Configuring Cert Instance: error initializing pwd token");
  1444. return false;
  1445. }
  1446. // Step 2. Configure Internal DB
  1447. if (!configInternalDB()) {
  1448. System.out.println(
  1449. "Configuring Cert Instance: error configuring internal db");
  1450. return false;
  1451. }
  1452. // Step 3. Create Admin Values
  1453. if (!createAdminValues()) {
  1454. System.out.println(
  1455. "Configuring Cert Instance: error configuring admin values ");
  1456. return false;
  1457. }
  1458. // Step 4. SubSystems
  1459. if (!selectSubSystem()) {
  1460. System.out.println(
  1461. "Configuring Cert Instance: error selecting subsystems");
  1462. return false;
  1463. }
  1464. // Step 5. Network Configuration
  1465. if (!networkConfig()) {
  1466. System.out.println(
  1467. "Configuring Cert Instance: error configuring network ports ");
  1468. return false;
  1469. }
  1470. // Step 6: Initialize Token This has been moved to step 1a
  1471. if (!initializeToken()) {
  1472. System.out.println(
  1473. "Configuring Cert Instance: error initializing token");
  1474. return false;
  1475. }
  1476. // Step 7 : keyLenth
  1477. if (!keyLength()) {
  1478. System.out.println(
  1479. "Configuring Cert Instance: error configuring KeyLength");
  1480. return false;
  1481. }
  1482. // Step 8 : CheckDN
  1483. if (!checkDN()) {
  1484. System.out.println(
  1485. "Configuring Cert Instance: error checking deamon");
  1486. return false;
  1487. }
  1488. // Step 9 : certRequest and Install i.e approve the request as a trusted manager
  1489. if (!certRequest(true)) {
  1490. System.out.println("Configuring Cert Instance: error getting cert");
  1491. return false;
  1492. }
  1493. if (!setupStorageKey()) {
  1494. System.out.println(
  1495. "Configuring Cert Instance: error configuring storage key");
  1496. return false;
  1497. }
  1498. // no need to do this from 7.1 due to new acl based key recovery
  1499. /*
  1500. if (!setupKRAAgents())
  1501. { System.out.println("Configuring Cert Instance: error configuring storage key"); return false;}
  1502. */
  1503. // Create a SSL signing cert
  1504. Date tmpdate = new Date();
  1505. certType = "serverCert";
  1506. subjectName = "CN=" + host + "." + adminDomain + ",OU=ssltest"
  1507. + tmpdate.getTime() + ",O=SSL,C=US";
  1508. keyLength = "512";
  1509. keyType = "RSA";
  1510. String mtokenPWD = tokenPWD;
  1511. tokenPWD = "";
  1512. ssl_clientcert = "false";
  1513. signingCert = "server";
  1514. if (!initializeToken()) {
  1515. System.out.println(
  1516. "Configuring Cert Instance: error initializing token");
  1517. return false;
  1518. }
  1519. // Step 8 : keyLenth
  1520. if (!keyLength()) {
  1521. System.out.println(
  1522. "Configuring Cert Instance: error configuring KeyLength");
  1523. return false;
  1524. }
  1525. // Step 9 : CheckDN
  1526. if (!checkDN()) {
  1527. System.out.println(
  1528. "Configuring Cert Instance: error checking deamon");
  1529. return false;
  1530. }
  1531. // Step 10 :
  1532. if (!certRequest(false)) {
  1533. System.out.println(
  1534. "Configuring Cert Instance: error creating Request");
  1535. return false;
  1536. }
  1537. // After creating ssl cert
  1538. tokenPWD = mtokenPWD;
  1539. // Step 11
  1540. if (!singleSignON()) {
  1541. System.out.println(
  1542. "Configuring Cert Instance: error setting up singlesignon");
  1543. return false;
  1544. }
  1545. // Step 11
  1546. if (!doMisc()) {
  1547. System.out.println(
  1548. "Configuring Cert Instance: error setting up miscell");
  1549. return false;
  1550. }
  1551. // Step 12
  1552. if (!exitDeamon()) {
  1553. System.out.println(
  1554. "Configuring Cert Instance: Unable to exit deamon");
  1555. return false;
  1556. }
  1557. return true;
  1558. }
  1559. // /// Sub CA configuration
  1560. private boolean ConfSubCA() {
  1561. // Start Configuring
  1562. // Step 1. Start Deamon
  1563. if (!startDeamon()) {
  1564. System.out.println(
  1565. "Configuring Cert Instance: Unable to start deamon");
  1566. return false;
  1567. }
  1568. // Sometimes it takes time to start deamon so wait for few seconds
  1569. try {
  1570. System.out.println("going to sleep for 10 seconds");
  1571. Thread.sleep(10000);
  1572. } catch (InterruptedException ie) {
  1573. System.out.println("sleep exection");
  1574. }
  1575. // Step 1a: Initialize Token ( Changed in 6.0)jjj
  1576. if (!initializePWD()) {
  1577. System.out.println(
  1578. "Configuring Cert Instance: error initializing pwd token");
  1579. return false;
  1580. }
  1581. // Step 2. Configure Internal DB
  1582. if (!configInternalDB()) {
  1583. System.out.println(
  1584. "Configuring Cert Instance: error configuring internal db");
  1585. return false;
  1586. }
  1587. // Step 3. Create Admin Values
  1588. if (!createAdminValues()) {
  1589. System.out.println(
  1590. "Configuring Cert Instance: error configuring admin values ");
  1591. return false;
  1592. }
  1593. // Step 4. SubSystems
  1594. if (!selectSubSystem()) {
  1595. System.out.println(
  1596. "Configuring Cert Instance: error selecting subsystems");
  1597. return false;
  1598. }
  1599. // Step 5. Network Configuration
  1600. if (!networkConfig()) {
  1601. System.out.println(
  1602. "Configuring Cert Instance: error configuring network ports ");
  1603. return false;
  1604. }
  1605. // Step 6: Initialize Token This has been moved to step 1a
  1606. if (!initializeToken()) {
  1607. System.out.println(
  1608. "Configuring Cert Instance: error initializing token");
  1609. return false;
  1610. }
  1611. // Step 7 : keyLenth
  1612. if (!keyLength()) {
  1613. System.out.println(
  1614. "Configuring Cert Instance: error configuring KeyLength");
  1615. return false;
  1616. }
  1617. // Step 8 : CheckDN
  1618. if (!checkDN()) {
  1619. System.out.println(
  1620. "Configuring Cert Instance: error checking deamon");
  1621. return false;
  1622. }
  1623. // Step 9 : certRequest and Install i.e approve the request as a trusted manager
  1624. if (!certRequest(false)) {
  1625. System.out.println("Configuring Cert Instance: error getting cert");
  1626. return false;
  1627. }
  1628. // Create a SSL signing cert
  1629. Date tmpdate = new Date();
  1630. certType = "serverCert";
  1631. subjectName = "CN=" + host + "." + adminDomain + ",OU=ssltest"
  1632. + tmpdate.getTime() + ",O=SSL,C=US";
  1633. keyLength = "512";
  1634. keyType = "RSA";
  1635. String mtokenPWD = tokenPWD;
  1636. tokenPWD = "";
  1637. ssl_clientcert = "false";
  1638. signingCert = "server";
  1639. if (!initializeToken()) {
  1640. System.out.println(
  1641. "Configuring Cert Instance: error initializing token");
  1642. return false;
  1643. }
  1644. // Step 8 : keyLenth
  1645. if (!keyLength()) {
  1646. System.out.println(
  1647. "Configuring Cert Instance: error configuring KeyLength");
  1648. return false;
  1649. }
  1650. // Step 9 : CheckDN
  1651. if (!checkDN()) {
  1652. System.out.println(
  1653. "Configuring Cert Instance: error checking deamon");
  1654. return false;
  1655. }
  1656. // Step 10 :
  1657. if (!certRequest(false)) {
  1658. System.out.println(
  1659. "Configuring Cert Instance: error creating Request");
  1660. return false;
  1661. }
  1662. // After creating ssl cert
  1663. tokenPWD = mtokenPWD;
  1664. // Step 11
  1665. if (!singleSignON()) {
  1666. System.out.println(
  1667. "Configuring Cert Instance: error setting up singlesignon");
  1668. return false;
  1669. }
  1670. // Step 11
  1671. if (!doMisc()) {
  1672. System.out.println(
  1673. "Configuring Cert Instance: error setting up miscell");
  1674. return false;
  1675. }
  1676. // Step 12
  1677. if (!exitDeamon()) {
  1678. System.out.println(
  1679. "Configuring Cert Instance: Unable to exit deamon");
  1680. return false;
  1681. }
  1682. return true;
  1683. }
  1684. // / CA
  1685. // org
  1686. private boolean ConfCA() {
  1687. // Start Configuring
  1688. // Step 1. Start Deamon
  1689. if (!startDeamon()) {
  1690. System.out.println(
  1691. "Configuring Cert Instance: Unable to start deamon");
  1692. return false;
  1693. }
  1694. // Sometimes it takes time to start deamon so wait for few seconds
  1695. try {
  1696. System.out.println("going to sleep for 10 seconds");
  1697. Thread.sleep(10000);
  1698. } catch (InterruptedException ie) {
  1699. System.out.println("sleep exection");
  1700. }
  1701. // Step 1a: Initialize Token ( Changed in 6.0)jjj
  1702. if (!initializePWD()) {
  1703. System.out.println(
  1704. "Configuring Cert Instance: error initializing pwd token");
  1705. return false;
  1706. }
  1707. // Step 2. Configure Internal DB
  1708. if (!configInternalDB()) {
  1709. System.out.println(
  1710. "Configuring Cert Instance: error configuring internal db");
  1711. return false;
  1712. }
  1713. // Step 3. Create Admin Values
  1714. if (!createAdminValues()) {
  1715. System.out.println(
  1716. "Configuring Cert Instance: error configuring admin values ");
  1717. return false;
  1718. }
  1719. // Step 4. SubSystems
  1720. if (!selectSubSystem()) {
  1721. System.out.println(
  1722. "Configuring Cert Instance: error selecting subsystems");
  1723. return false;
  1724. }
  1725. // SetSerial Number
  1726. if (!setSerial("1", "1000000")) {
  1727. System.out.println(
  1728. "Configuring Cert Instance: error setting serial number");
  1729. return false;
  1730. }
  1731. if (!setOCSP()) {
  1732. System.out.println(
  1733. "Configuring Cert Instance: error selecting subsystems");
  1734. return false;
  1735. }
  1736. // Step 5. Network Configuration
  1737. if (!networkConfig()) {
  1738. System.out.println(
  1739. "Configuring Cert Instance: error configuring network ports ");
  1740. return false;
  1741. }
  1742. // Step 6. setting up Server Migration
  1743. // if (!serverMigration())
  1744. // { System.out.println("Configuring Cert Instance: error configuring server migration"); return false;}
  1745. // Step 7: Initialize Token
  1746. if (!initializeToken()) {
  1747. System.out.println(
  1748. "Configuring Cert Instance: error initializing token");
  1749. return false;
  1750. }
  1751. // Step 8 : keyLenth
  1752. if (!keyLength()) {
  1753. System.out.println(
  1754. "Configuring Cert Instance: error configuring KeyLength");
  1755. return false;
  1756. }
  1757. // Step 9 : CheckDN
  1758. if (!checkDN()) {
  1759. System.out.println(
  1760. "Configuring Cert Instance: error checking deamon");
  1761. return false;
  1762. }
  1763. // Step 10 :
  1764. if (!createCert()) {
  1765. System.out.println("Configuring Cert Instance: error creating cert");
  1766. return false;
  1767. }
  1768. // Create a SSL signing cert
  1769. Date tmpdate = new Date();
  1770. certType = "serverCert";
  1771. subjectName = "CN=" + host + "." + adminDomain + ",OU=ssltest"
  1772. + tmpdate.getTime() + ",O=SSL,C=US";
  1773. keyType = "RSA";
  1774. keyLength = "512";
  1775. String mtokenPWD = tokenPWD;
  1776. tokenPWD = "";
  1777. if (!initializeToken()) {
  1778. System.out.println(
  1779. "Configuring Cert Instance: error initializing token");
  1780. return false;
  1781. }
  1782. // Step 8 : keyLenth
  1783. if (!keyLength()) {
  1784. System.out.println(
  1785. "Configuring Cert Instance: error configuring KeyLength");
  1786. return false;
  1787. }
  1788. // Step 9 : CheckDN
  1789. if (!checkDN()) {
  1790. System.out.println(
  1791. "Configuring Cert Instance: error checking deamon");
  1792. return false;
  1793. }
  1794. // Step 10 :
  1795. if (!createCert()) {
  1796. System.out.println("Configuring Cert Instance: error creating cert");
  1797. return false;
  1798. }
  1799. // After creating ssl cert
  1800. tokenPWD = mtokenPWD;
  1801. // Step 11
  1802. if (!singleSignON()) {
  1803. System.out.println(
  1804. "Configuring Cert Instance: error setting up singlesignon");
  1805. return false;
  1806. }
  1807. // Step 11
  1808. if (!doMisc()) {
  1809. System.out.println(
  1810. "Configuring Cert Instance: error setting up miscell");
  1811. return false;
  1812. }
  1813. // Step 12
  1814. if (!exitDeamon()) {
  1815. System.out.println(
  1816. "Configuring Cert Instance: Unable to exit deamon");
  1817. return false;
  1818. }
  1819. return true;
  1820. }
  1821. // Configure Clone
  1822. private boolean ConfClone() {
  1823. // Start Configuring
  1824. // Step 1. Start Deamon
  1825. if (!startDeamon()) {
  1826. System.out.println(
  1827. "Configuring Cert Instance: Unable to start deamon");
  1828. return false;
  1829. }
  1830. // Sometimes it takes time to start deamon so wait for few seconds
  1831. try {
  1832. System.out.println("going to sleep for 10 seconds");
  1833. Thread.sleep(10000);
  1834. } catch (InterruptedException ie) {
  1835. System.out.println("sleep exection");
  1836. }
  1837. // Step 1a: Initialize Token ( Changed in 6.0)jjj
  1838. if (!initializePWD()) {
  1839. System.out.println(
  1840. "Configuring Cert Instance: error initializing pwd token");
  1841. return false;
  1842. }
  1843. // Step 2. Configure Internal DB
  1844. if (!configInternalDB()) {
  1845. System.out.println(
  1846. "Configuring Cert Instance: error configuring internal db");
  1847. return false;
  1848. }
  1849. // Step 3. Create Admin Values
  1850. if (!createAdminValues()) {
  1851. System.out.println(
  1852. "Configuring Cert Instance: error configuring admin values ");
  1853. return false;
  1854. }
  1855. // Step 4. SubSystems
  1856. if (!selectSubSystem()) {
  1857. System.out.println(
  1858. "Configuring Cert Instance: error selecting subsystems");
  1859. return false;
  1860. }
  1861. // Step 5. SetCASerial
  1862. if (!setSerial("1000000", "2000000")) {
  1863. System.out.println("Configuring Cert Instance: error setSerial");
  1864. return false;
  1865. }
  1866. if (!setOCSP()) {
  1867. System.out.println("Configuring Cert Instance: error setOCSP");
  1868. return false;
  1869. }
  1870. // Step 5. Network Configuration
  1871. if (!networkConfig()) {
  1872. System.out.println(
  1873. "Configuring Cert Instance: error configuring network ports ");
  1874. return false;
  1875. }
  1876. if (!taskCloning()) {
  1877. System.out.println("Configuring Cert Instance: error Task Cloning ");
  1878. return false;
  1879. }
  1880. if (!taskCloneMaster()) {
  1881. System.out.println(
  1882. "Configuring Cert Instance: error configuring network ports ");
  1883. return false;
  1884. }
  1885. // Create a SSL signing cert
  1886. certType = "serverCert";
  1887. if (!taskCloning()) {
  1888. System.out.println("Configuring Cert Instance: error Task Cloning ");
  1889. return false;
  1890. }
  1891. // Step 11
  1892. if (!singleSignON()) {
  1893. System.out.println(
  1894. "Configuring Cert Instance: error setting up singlesignon");
  1895. return false;
  1896. }
  1897. // Step 11
  1898. if (!doMisc()) {
  1899. System.out.println(
  1900. "Configuring Cert Instance: error setting up miscell");
  1901. return false;
  1902. }
  1903. // Step 12
  1904. if (!exitDeamon()) {
  1905. System.out.println(
  1906. "Configuring Cert Instance: Unable to exit deamon");
  1907. return false;
  1908. }
  1909. return true;
  1910. }
  1911. public boolean readProperties() {
  1912. // Read the properties file and assign values to variables .
  1913. try {
  1914. getProperties(propFileName);
  1915. } catch (Exception e) {
  1916. System.out.println(
  1917. "exception reading Properties File " + e.getMessage());
  1918. }
  1919. // read all properties
  1920. adminDomain = props.getProperty("inst.admin.domain");
  1921. adminID = props.getProperty("inst.admin.uid");
  1922. adminPWD = props.getProperty("inst.admin.pwd");
  1923. adminPort = props.getProperty("inst.admin.port");
  1924. machineName = props.getProperty("inst.machineName");
  1925. host = props.getProperty("inst.host");
  1926. serverID = props.getProperty("inst.serverIdentifier");
  1927. instanceID = "cert-" + serverID;
  1928. serverRoot = props.getProperty("inst.serverRoot");
  1929. // Just for debugging"
  1930. sieURL = props.getProperty("inst.sie.url");
  1931. dbConnPort = props.getProperty("inst.dbConnPort");
  1932. dbConnHost = props.getProperty("inst.dbConnHost");
  1933. dbInstanceName = props.getProperty("inst.dbInstanceName");
  1934. dbPassword = props.getProperty("inst.dbPassword");
  1935. dbLDAPauthDN = props.getProperty("inst.ldap.auth.dn");
  1936. dbmode = props.getProperty("inst.dbmode");
  1937. ldapServerDB = props.getProperty("inst.ldapServerDB");
  1938. certAdminName = props.getProperty("inst.cert.admin.name");
  1939. certAdminUid = props.getProperty("inst.cert.admin.uid");
  1940. certAdminPWD = props.getProperty("inst.cert.admin.pwd");
  1941. kra = props.getProperty("inst.subsystem.kra");
  1942. subsystems = props.getProperty("inst.subsystem");
  1943. ca = props.getProperty("inst.subsystem.ca");
  1944. ra = props.getProperty("inst.subsystem.ra");
  1945. ocsp = props.getProperty("inst.subsystem.ocsp");
  1946. remoteKRA = props.getProperty("inst.subsystem.remoteKRA");
  1947. wirelessSupport = props.getProperty("inst.subsystem.wireless");
  1948. eeHttpPort = props.getProperty("inst.ee.http.port");
  1949. eeHttpsPort = props.getProperty("inst.ee.https.port");
  1950. agentHttpsPort = props.getProperty("inst.agent.https.port");
  1951. radminHttpsPort = props.getProperty("inst.admin.https.port");
  1952. tokenName = props.getProperty("inst.tokenName");
  1953. tokenPWD = props.getProperty("inst.token.pwd");
  1954. signingCert = props.getProperty("inst.cert.Type");
  1955. certType = signingCert;
  1956. keyType = props.getProperty("inst.key.type");
  1957. keyLength = props.getProperty("inst.key.length");
  1958. SingleSignOnPWD = props.getProperty("inst.singlesignon.pwd");
  1959. subjectName = props.getProperty("inst.ca.dn");
  1960. isCA = props.getProperty("inst.isca");
  1961. aki = props.getProperty("inst.aki");
  1962. ski = props.getProperty("inst.ski");
  1963. sslCABit = props.getProperty("inst.sslCABit");
  1964. objectSigningCABit = props.getProperty("inst.objectSigningCABit");
  1965. mailCABit = props.getProperty("inst.mailCABit");
  1966. hashType = props.getProperty("inst.hash.Type");
  1967. caOComponent = props.getProperty("inst.ca.component");
  1968. certValidityDays = props.getProperty("inst.cert.validity");
  1969. caHostname = props.getProperty("inst.cahostname");
  1970. caPortnum = props.getProperty("inst.caportnum");
  1971. caAgentPortnum = props.getProperty("inst.caASport");
  1972. caTimeout = props.getProperty("inst.catimeout");
  1973. caEEPort = props.getProperty("inst.caEEport");
  1974. cloneInstanceId = props.getProperty("inst.cloneid");
  1975. CAadminId = props.getProperty("inst.caAdminId");
  1976. CAadminPwd = props.getProperty("inst.caAdminPwd");
  1977. CAcertnickname = props.getProperty("inst.caCertnickname");
  1978. enpropfile = props.getProperty("inst.propfile");
  1979. cdir = props.getProperty("inst.certdir");
  1980. tokenpwd = props.getProperty("inst.certtokenpwd");
  1981. if (subsystems.equals("ca")) {
  1982. return ConfCA();
  1983. }
  1984. if (subsystems.equals("ra")) {
  1985. return ConfRA();
  1986. }
  1987. if (subsystems.equals("ocsp")) {
  1988. return ConfOCSP();
  1989. }
  1990. if (subsystems.equals("kra")) {
  1991. return ConfKRA();
  1992. }
  1993. if (subsystems.equals("subca")) {
  1994. subca = true;
  1995. subsystems = "ca";
  1996. return ConfSubCA();
  1997. }
  1998. return true;
  1999. } // end of r
  2000. public static void main(String args[]) {
  2001. // Exit Status - (-1) for error
  2002. // - 1 Configured and server Alive
  2003. // - 0 Configured bur could not sart server
  2004. AutoInstaller t = new AutoInstaller();
  2005. System.out.println(args.length);
  2006. t.setPropFile(args[0]);
  2007. if (args.length < 1) {
  2008. System.out.println("Usage : PropertiesFilePath");
  2009. System.exit(-1);
  2010. }
  2011. System.out.println("configuring Cert Instance : Start");
  2012. boolean st = t.readProperties();
  2013. if (st) {
  2014. System.out.println("Configuring Cert Instance : Successful");
  2015. System.exit(1);
  2016. } else {
  2017. System.out.println("Configuring Cert Instance : Error ");
  2018. System.exit(0);
  2019. }
  2020. }
  2021. } // end of class