1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
|
package com.netscape.pkisilent;
// --- BEGIN COPYRIGHT BLOCK ---
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; version 2 of the License.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// (C) 2007 Red Hat, Inc.
// All rights reserved.
// --- END COPYRIGHT BLOCK ---
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.net.URLEncoder;
import java.util.ArrayList;
import org.mozilla.jss.asn1.SEQUENCE;
import org.mozilla.jss.pkcs12.AuthenticatedSafes;
import org.mozilla.jss.pkcs12.PFX;
import com.netscape.osutil.OSUtil;
import com.netscape.pkisilent.argparser.ArgParser;
import com.netscape.pkisilent.argparser.StringHolder;
import com.netscape.pkisilent.common.ComCrypto;
import com.netscape.pkisilent.common.ParseXML;
import com.netscape.pkisilent.http.HTTPClient;
import com.netscape.pkisilent.http.HTTPResponse;
public class ConfigureOCSP {
public static final String DEFAULT_KEY_TYPE = "RSA";
public static final String DEFAULT_KEY_SIZE = "2048";
public static final String DEFAULT_KEY_CURVENAME = "nistp256";
public static final String DEFAULT_KEY_ALGORITHM_RSA = "SHA256withRSA";
public static final String DEFAULT_KEY_ALGORITHM_ECC = "SHA256withEC";
// define global variables
public static HTTPClient hc = null;
public static String login_uri = "/ocsp/admin/console/config/login";
public static String wizard_uri = "/ocsp/admin/console/config/wizard";
public static String admin_uri = "/ca/admin/ca/getBySerial";
public static String sd_login_uri = "/ca/admin/ca/securityDomainLogin";
public static String sd_get_cookie_uri = "/ca/admin/ca/getCookie";
public static String pkcs12_uri = "/ocsp/admin/console/config/savepkcs12";
public static String cs_hostname = null;
public static String cs_port = null;
public static String sd_hostname = null;
public static String sd_ssl_port = null;
public static String sd_agent_port = null;
public static String sd_admin_port = null;
public static String sd_admin_name = null;
public static String sd_admin_password = null;
public static String ca_hostname = null;
public static String ca_port = null;
public static String ca_ssl_port = null;
public static String client_certdb_dir = null;
public static String client_certdb_pwd = null;
// Login Panel
public static String pin = null;
public static String domain_name = null;
public static String admin_user = null;
public static String admin_email = null;
public static String admin_password = null;
public static String admin_serial_number = null;
public static String agent_name = null;
public static String ldap_host = null;
public static String ldap_port = null;
public static String bind_dn = null;
public static String bind_password = null;
public static String base_dn = null;
public static String db_name = null;
public static String secure_conn = null;
public static String clone_start_tls = null;
public static String remove_data = null;
public static String key_type = null;
public static String key_size = null;
public static String key_curvename = null;
public static String signing_algorithm = null;
public static String signing_key_type = null;
public static String signing_key_size = null;
public static String signing_key_curvename = null;
public static String signing_signingalgorithm = null;
public static String subsystem_key_type = null;
public static String subsystem_key_size = null;
public static String subsystem_key_curvename = null;
public static String audit_signing_key_type = null;
public static String audit_signing_key_size = null;
public static String audit_signing_key_curvename = null;
public static String sslserver_key_type = null;
public static String sslserver_key_size = null;
public static String sslserver_key_curvename = null;
public static String token_name = null;
public static String token_pwd = null;
public static String agent_key_size = null;
public static String agent_key_type = null;
public static String agent_cert_subject = null;
public static String ocsp_signing_cert_name = null;
public static String ocsp_signing_cert_req = null;
public static String ocsp_signing_cert_pp = null;
public static String ocsp_signing_cert_cert = null;
public static String server_cert_name = null;
public static String server_cert_req = null;
public static String server_cert_pp = null;
public static String server_cert_cert = null;
public static String ocsp_subsystem_cert_name = null;
public static String ocsp_subsystem_cert_req = null;
public static String ocsp_subsystem_cert_pp = null;
public static String ocsp_subsystem_cert_cert = null;
public static String ocsp_audit_signing_cert_name = null;
public static String ocsp_audit_signing_cert_req = null;
public static String ocsp_audit_signing_cert_pp = null;
public static String ocsp_audit_signing_cert_cert = null;
public static String backup_pwd = null;
public static String backup_fname = null;
// cert subject names
public static String ocsp_sign_cert_subject_name = null;
public static String ocsp_subsystem_cert_subject_name = null;
public static String ocsp_server_cert_subject_name = null;
public static String ocsp_audit_signing_cert_subject_name = null;
public static String subsystem_name = null;
public ConfigureOCSP() {
// do nothing :)
}
public void sleep_time() {
try {
System.out.println("Sleeping for 5 secs..");
Thread.sleep(5000);
} catch (Exception e) {
System.out.println("ERROR: sleep problem");
}
}
public boolean LoginPanel() {
boolean st = false;
HTTPResponse hr = null;
ByteArrayInputStream bais = null;
ParseXML px = new ParseXML();
String query_string = "pin=" + pin + "&xml=true";
hr = hc.sslConnect(cs_hostname, cs_port, login_uri, query_string);
System.out.println("xml returned: " + hr.getHTML());
// parse xml here - nothing to parse
// get cookie
String temp = hr.getCookieValue("JSESSIONID");
if (temp != null) {
int index = temp.indexOf(";");
HTTPClient.j_session_id = temp.substring(0, index);
st = true;
}
hr = null;
hr = hc.sslConnect(cs_hostname, cs_port, wizard_uri,
"p=0&op=next&xml=true");
// parse xml here
bais = new ByteArrayInputStream(hr.getHTML().getBytes());
px.parse(bais);
px.prettyprintxml();
return st;
}
public boolean TokenChoicePanel() {
boolean st = false;
HTTPResponse hr = null;
ByteArrayInputStream bais = null;
ParseXML px = new ParseXML();
String query_string = null;
// Software Token
if (token_name.equalsIgnoreCase("internal")) {
query_string = "p=1" + "&op=next" + "&xml=true" + "&choice="
+ URLEncoder.encode("Internal Key Storage Token") + "";
hr = hc.sslConnect(cs_hostname, cs_port, wizard_uri, query_string);
// parse xml
bais = new ByteArrayInputStream(hr.getHTML().getBytes());
px.parse(bais);
px.prettyprintxml();
}
// HSM
else {
// login to hsm first
query_string = "p=2" + "&op=next" + "&xml=true" + "&uTokName="
+ URLEncoder.encode(token_name) + "&__uPasswd="
+ URLEncoder.encode(token_pwd) + "";
hr = hc.sslConnect(cs_hostname, cs_port, wizard_uri, query_string);
// parse xml
bais = new ByteArrayInputStream(hr.getHTML().getBytes());
px.parse(bais);
px.prettyprintxml();
// choice with token name now
query_string = "p=1" + "&op=next" + "&xml=true" + "&choice="
+ URLEncoder.encode(token_name) + "";
hr = hc.sslConnect(cs_hostname, cs_port, wizard_uri, query_string);
// parse xml
bais = new ByteArrayInputStream(hr.getHTML().getBytes());
px.parse(bais);
px.prettyprintxml();
}
return true;
}
public boolean DomainPanel() {
boolean st = false;
HTTPResponse hr = null;
ByteArrayInputStream bais = null;
ParseXML px = new ParseXML();
String domain_url = "https://" + sd_hostname + ":" + sd_admin_port;
String query_string = "sdomainURL=" + URLEncoder.encode(domain_url)
+ "&choice=existingdomain" + "&p=3" + "&op=next" + "&xml=true";
hr = hc.sslConnect(cs_hostname, cs_port, wizard_uri, query_string);
// parse xml
bais = new ByteArrayInputStream(hr.getHTML().getBytes());
px.parse(bais);
px.prettyprintxml();
return true;
}
public boolean DisplayChainPanel() {
boolean st = false;
HTTPResponse hr = null;
ByteArrayInputStream bais = null;
ParseXML px = new ParseXML();
String query_string = null;
query_string = "p=4" + "&op=next" + "&xml=true";
hr = hc.sslConnect(cs_hostname, cs_port, wizard_uri, query_string);
// parse xml
// bais = new ByteArrayInputStream(hr.getHTML().getBytes());
// px.parse(bais);
// px.prettyprintxml();
return true;
}
public boolean SecurityDomainLoginPanel() {
boolean st = false;
HTTPResponse hr = null;
ByteArrayInputStream bais = null;
ParseXML px = new ParseXML();
String ocsp_url = "https://" + cs_hostname + ":" + cs_port
+ "/ocsp/admin/console/config/wizard" + "?p=5&subsystem=OCSP";
String query_string = "url=" + URLEncoder.encode(ocsp_url);
hr = hc.sslConnect(sd_hostname, sd_admin_port, sd_login_uri,
query_string);
String query_string_1 = "uid=" + sd_admin_name + "&pwd="
+ URLEncoder.encode(sd_admin_password) + "&url="
+ URLEncoder.encode(ocsp_url);
hr = hc.sslConnect(sd_hostname, sd_admin_port, sd_get_cookie_uri,
query_string_1);
// get session id from security domain
String ocsp_session_id = hr.getContentValue("header.session_id");
String ocsp_url_1 = hr.getContentValue("header.url");
System.out.println("OCSP_SESSION_ID=" + ocsp_session_id);
System.out.println("OCSP_URL=" + ocsp_url_1);
// use session id to connect back to OCSP
String query_string_2 = "p=5" + "&subsystem=OCSP" + "&session_id="
+ ocsp_session_id + "&xml=true";
hr = hc.sslConnect(cs_hostname, cs_port, wizard_uri, query_string_2);
// parse xml
// bais = new ByteArrayInputStream(hr.getHTML().getBytes());
// px.parse(bais);
// px.prettyprintxml();
return true;
}
public boolean SubsystemPanel() {
boolean st = false;
HTTPResponse hr = null;
ByteArrayInputStream bais = null;
ParseXML px = new ParseXML();
String query_string = "p=5" + "&op=next" + "&xml=true"
+ "&subsystemName=" + URLEncoder.encode(subsystem_name)
+ "&choice=newsubsystem";
hr = hc.sslConnect(cs_hostname, cs_port, wizard_uri, query_string);
// parse xml
bais = new ByteArrayInputStream(hr.getHTML().getBytes());
px.parse(bais);
px.prettyprintxml();
return true;
}
public boolean LdapConnectionPanel() {
boolean st = false;
HTTPResponse hr = null;
ByteArrayInputStream bais = null;
ParseXML px = new ParseXML();
String query_string = "p=7" + "&op=next" + "&xml=true" + "&host="
+ URLEncoder.encode(ldap_host) + "&port="
+ URLEncoder.encode(ldap_port) + "&binddn="
+ URLEncoder.encode(bind_dn) + "&__bindpwd="
+ URLEncoder.encode(bind_password) + "&basedn="
+ URLEncoder.encode(base_dn) + "&database="
+ URLEncoder.encode(db_name) + "&display="
+ URLEncoder.encode("$displayStr")
+ (secure_conn.equals("true") ? "&secureConn=on" : "")
+ (clone_start_tls.equals("true") ? "&cloneStartTLS=on" : "")
+ (remove_data.equals("true") ? "&removeData=true" : "");
hr = hc.sslConnect(cs_hostname, cs_port, wizard_uri, query_string);
// parse xml
bais = new ByteArrayInputStream(hr.getHTML().getBytes());
px.parse(bais);
px.prettyprintxml();
return true;
}
public boolean KeyPanel() {
boolean st = false;
HTTPResponse hr = null;
ByteArrayInputStream bais = null;
ParseXML px = new ParseXML();
ArrayList<String> al = null;
String query_string = "p=8" + "&op=next" + "&xml=true"
+ "&signing_custom_size="
+ signing_key_size
+ "&subsystem_custom_size="
+ subsystem_key_size
+ "&sslserver_custom_size="
+ sslserver_key_size
+ "&audit_signing_custom_size="
+ audit_signing_key_size
+ "&custom_size="
+ key_size
+ "&signing_custom_curvename="
+ signing_key_curvename
+ "&subsystem_custom_curvename="
+ subsystem_key_curvename
+ "&sslserver_custom_curvename="
+ sslserver_key_curvename
+ "&audit_signing_custom_curvename="
+ audit_signing_key_curvename
+ "&custom_curvename="
+ key_curvename
+ "&signing_keytype="
+ signing_key_type
+ "&subsystem_keytype="
+ subsystem_key_type
+ "&sslserver_keytype="
+ sslserver_key_type
+ "&audit_signing_keytype="
+ audit_signing_key_type
+ "&keytype="
+ key_type
+ "&signing_choice=custom"
+ "&subsystem_choice=custom"
+ "&sslserver_choice=custom"
+ "&audit_signing_choice=custom"
+ "&signingalgorithm="
+ signing_algorithm
+ "&signing_signingalgorithm="
+ signing_signingalgorithm + "&choice=custom";
hr = hc.sslConnect(cs_hostname, cs_port, wizard_uri, query_string);
// parse xml
bais = new ByteArrayInputStream(hr.getHTML().getBytes());
px.parse(bais);
px.prettyprintxml();
al = px.constructValueList("CertReqPair", "DN");
// get ca cert subject name
if (al != null) {
for (int i = 0; i < al.size(); i++) {
String temp = al.get(i);
if (temp.indexOf("OCSP Signing") > 0) {
ocsp_signing_cert_name = temp;
} else if (temp.indexOf("OCSP Subsystem") > 0) {
ocsp_subsystem_cert_name = temp;
} else if (temp.indexOf("Audit Signing Certificate") > 0) {
ocsp_audit_signing_cert_name = temp;
} else {
server_cert_name = temp;
}
}
}
System.out.println("default: ocsp_signing_cert_name="
+ ocsp_signing_cert_name);
System.out.println("default: ocsp_subsystem_cert_name="
+ ocsp_subsystem_cert_name);
System.out.println("default: server_cert_name=" + server_cert_name);
System.out.println("default: oscp_audit_signing_cert_name="
+ ocsp_audit_signing_cert_name);
return true;
}
public boolean CertSubjectPanel() {
boolean st = false;
HTTPResponse hr = null;
ByteArrayInputStream bais = null;
ParseXML px = new ParseXML();
ArrayList<String> req_list = null;
ArrayList<String> cert_list = null;
ArrayList<String> dn_list = null;
String domain_url = "https://" + ca_hostname + ":" + ca_ssl_port;
String query_string = "p=9" + "&op=next" + "&xml=true" + "&subsystem="
+ URLEncoder.encode(ocsp_subsystem_cert_subject_name)
+ "&signing=" + URLEncoder.encode(ocsp_sign_cert_subject_name)
+ "&sslserver="
+ URLEncoder.encode(ocsp_server_cert_subject_name)
+ "&audit_signing="
+ URLEncoder.encode(ocsp_audit_signing_cert_subject_name)
+ "&urls=" + URLEncoder.encode(domain_url) + "";
hr = hc.sslConnect(cs_hostname, cs_port, wizard_uri, query_string);
// parse xml
bais = new ByteArrayInputStream(hr.getHTML().getBytes());
px.parse(bais);
px.prettyprintxml();
req_list = px.constructValueList("CertReqPair", "Request");
cert_list = px.constructValueList("CertReqPair", "Certificate");
dn_list = px.constructValueList("CertReqPair", "Nickname");
if (req_list != null && cert_list != null && dn_list != null) {
for (int i = 0; i < dn_list.size(); i++) {
String temp = dn_list.get(i);
if (temp.indexOf("ocspSigningCert") >= 0) {
ocsp_signing_cert_req = req_list.get(i);
ocsp_signing_cert_cert = cert_list.get(i);
} else if (temp.indexOf("subsystemCert") >= 0) {
ocsp_subsystem_cert_req = req_list.get(i);
ocsp_subsystem_cert_cert = cert_list.get(i);
} else if (temp.indexOf("auditSigningCert") >= 0) {
ocsp_audit_signing_cert_req = req_list.get(i);
ocsp_audit_signing_cert_cert = cert_list.get(i);
} else {
server_cert_req = req_list.get(i);
server_cert_cert = cert_list.get(i);
}
}
}
return true;
}
public boolean CertificatePanel() {
boolean st = false;
HTTPResponse hr = null;
ByteArrayInputStream bais = null;
ParseXML px = new ParseXML();
ArrayList<String> req_list = null;
ArrayList<String> cert_list = null;
ArrayList<String> dn_list = null;
ArrayList<String> pp_list = null;
String query_string = "p=10" + "&op=next" + "&xml=true" + "&subsystem="
+ URLEncoder.encode(ocsp_subsystem_cert_cert)
+ "&subsystem_cc=" + "&signing="
+ URLEncoder.encode(ocsp_signing_cert_cert) + "&signing_cc="
+ "&sslserver=" + URLEncoder.encode(server_cert_cert)
+ "&sslserver_cc=" + "&audit_signing="
+ URLEncoder.encode(ocsp_audit_signing_cert_cert)
+ "&audit_signing_cc=" + "";
hr = hc.sslConnect(cs_hostname, cs_port, wizard_uri, query_string);
// parse xml
bais = new ByteArrayInputStream(hr.getHTML().getBytes());
System.out.println("html returned=" + hr.getHTML());
px.parse(bais);
px.prettyprintxml();
return true;
}
public boolean BackupPanel() {
boolean st = false;
HTTPResponse hr = null;
ByteArrayInputStream bais = null;
ParseXML px = new ParseXML();
String query_string = "p=11" + "&op=next" + "&xml=true"
+ "&choice=backupkey" + "&__pwd="
+ URLEncoder.encode(backup_pwd) + "&__pwdagain="
+ URLEncoder.encode(backup_pwd);
hr = hc.sslConnect(cs_hostname, cs_port, wizard_uri, query_string);
// parse xml
bais = new ByteArrayInputStream(hr.getHTML().getBytes());
px.parse(bais);
px.prettyprintxml();
return true;
}
public boolean SavePKCS12Panel() {
boolean st = false;
HTTPResponse hr = null;
ByteArrayInputStream bais = null;
ParseXML px = new ParseXML();
String query_string = "";
hr = hc.sslConnect(cs_hostname, cs_port, pkcs12_uri, query_string);
// dump hr.getResponseData() to file
try {
FileOutputStream fos = new FileOutputStream(backup_fname);
fos.write(hr.getResponseData());
fos.close();
// set file to permissions 600
String rtParams[] = { "chmod", "600", backup_fname };
Process proc = Runtime.getRuntime().exec(rtParams);
BufferedReader br = new BufferedReader(new InputStreamReader(
proc.getErrorStream()));
String line = null;
while ((line = br.readLine()) != null)
System.out.println("Error: " + line);
int exitVal = proc.waitFor();
// verify p12 file
// Decode the P12 file
FileInputStream fis = new FileInputStream(backup_fname);
PFX.Template pfxt = new PFX.Template();
PFX pfx = (PFX) pfxt.decode(new BufferedInputStream(fis, 2048));
System.out.println("Decoded PFX");
// now peruse it for interesting info
System.out.println("Version: " + pfx.getVersion());
AuthenticatedSafes authSafes = pfx.getAuthSafes();
SEQUENCE asSeq = authSafes.getSequence();
System.out.println("AuthSafes has " + asSeq.size()
+ " SafeContents");
fis.close();
} catch (Exception e) {
System.out.println("ERROR: Exception=" + e.getMessage());
return false;
}
return true;
}
public boolean AdminCertReqPanel() {
boolean st = false;
HTTPResponse hr = null;
ByteArrayInputStream bais = null;
ParseXML px = new ParseXML();
String admin_cert_request = null;
String cert_subject = "CN=ocsp-" + admin_user;
ComCrypto cCrypt = new ComCrypto(client_certdb_dir, client_certdb_pwd,
agent_cert_subject, agent_key_size, agent_key_type);
cCrypt.setDebug(true);
cCrypt.setGenerateRequest(true);
cCrypt.setTransportCert(null);
cCrypt.setDualKey(false);
cCrypt.loginDB();
String crmf_request = cCrypt.generateCRMFrequest();
if (crmf_request == null) {
System.out
.println("ERROR: AdminCertReqPanel() cert req gen failed");
return false;
}
admin_cert_request = crmf_request;
String query_string = "p=13" + "&op=next" + "&xml=true"
+ "&cert_request_type=" + "crmf" + "&uid=" + admin_user
+ "&name=" + admin_user + "&__pwd="
+ URLEncoder.encode(admin_password)
+ "&__admin_password_again="
+ URLEncoder.encode(admin_password) + "&profileId="
+ "caAdminCert" + "&email=" + URLEncoder.encode(admin_email)
+ "&cert_request=" + URLEncoder.encode(admin_cert_request)
+ "&subject=" + URLEncoder.encode(agent_cert_subject)
+ "&clone=new" + "&import=true" + "&securitydomain="
+ URLEncoder.encode(domain_name) + "";
hr = hc.sslConnect(cs_hostname, cs_port, wizard_uri, query_string);
// parse xml
bais = new ByteArrayInputStream(hr.getHTML().getBytes());
px.parse(bais);
px.prettyprintxml();
admin_serial_number = px.getvalue("serialNumber");
return true;
}
public boolean AdminCertImportPanel() {
boolean st = false;
HTTPResponse hr = null;
ByteArrayInputStream bais = null;
ParseXML px = new ParseXML();
String query_string = "serialNumber=" + admin_serial_number
+ "&importCert=" + "true" + "";
hr = hc.sslConnect(sd_hostname, sd_admin_port, admin_uri, query_string);
// get response data
// String cert_to_import =
// new sun.misc.BASE64Encoder().encode(hr.getResponseData());
String cert_to_import = OSUtil.BtoA(hr.getResponseData());
System.out.println("Imported Cert=" + cert_to_import);
ComCrypto cCrypt = new ComCrypto(client_certdb_dir, client_certdb_pwd,
null, null, null);
cCrypt.setDebug(true);
cCrypt.setGenerateRequest(true);
cCrypt.loginDB();
String start = "-----BEGIN CERTIFICATE-----\r\n";
String end = "\r\n-----END CERTIFICATE-----";
st = cCrypt.importCert(start + cert_to_import + end, agent_name);
if (!st) {
System.out
.println("ERROR: AdminCertImportPanel() during cert import");
return false;
}
System.out.println("SUCCESS: imported admin user cert");
return true;
}
public boolean UpdateDomainPanel() {
boolean st = false;
HTTPResponse hr = null;
ByteArrayInputStream bais = null;
ParseXML px = new ParseXML();
String query_string = "p=14" + "&op=next" + "&xml=true" + "&caHost="
+ URLEncoder.encode(sd_hostname) + "&caPort="
+ URLEncoder.encode(sd_agent_port) + "";
hr = hc.sslConnect(cs_hostname, cs_port, wizard_uri, query_string);
// parse xml
bais = new ByteArrayInputStream(hr.getHTML().getBytes());
px.parse(bais);
px.prettyprintxml();
return true;
}
public boolean ConfigureOCSPInstance() {
// 0. login to cert db
ComCrypto cCrypt = new ComCrypto(client_certdb_dir, client_certdb_pwd,
null, null, null);
cCrypt.setDebug(true);
cCrypt.setGenerateRequest(true);
cCrypt.loginDB();
// instantiate http client
hc = new HTTPClient();
// 1. Login panel
boolean log_st = LoginPanel();
if (!log_st) {
System.out.println("ERROR: ConfigureOCSP: LoginPanel() failure");
return false;
}
sleep_time();
// 2. Token Choice Panel
boolean disp_token = TokenChoicePanel();
if (!disp_token) {
System.out
.println("ERROR: ConfigureOCSP: TokenChoicePanel() failure");
return false;
}
sleep_time();
// 3. domain panel
boolean dom_st = DomainPanel();
if (!dom_st) {
System.out.println("ERROR: ConfigureOCSP: DomainPanel() failure");
return false;
}
sleep_time();
// 4. display cert chain panel
boolean disp_st = DisplayChainPanel();
if (!disp_st) {
System.out
.println("ERROR: ConfigureOCSP: DisplayChainPanel() failure");
return false;
}
sleep_time();
// security domain login panel
boolean disp_sd = SecurityDomainLoginPanel();
if (!disp_sd) {
System.out
.println("ERROR: ConfigureOCSP: SecurityDomainLoginPanel() failure");
return false;
}
sleep_time();
// subsystem panel
boolean disp_ss = SubsystemPanel();
if (!disp_ss) {
System.out
.println("ERROR: ConfigureOCSP: SubsystemPanel() failure");
return false;
}
sleep_time();
// 7. ldap connection panel
boolean disp_ldap = LdapConnectionPanel();
if (!disp_ldap) {
System.out
.println("ERROR: ConfigureOCSP: LdapConnectionPanel() failure");
return false;
}
sleep_time();
sleep_time();
// 9. Key Panel
boolean disp_key = KeyPanel();
if (!disp_key) {
System.out.println("ERROR: ConfigureOCSP: KeyPanel() failure");
return false;
}
sleep_time();
// 10. Cert Subject Panel
boolean disp_csubj = CertSubjectPanel();
if (!disp_csubj) {
System.out
.println("ERROR: ConfigureOCSP: CertSubjectPanel() failure");
return false;
}
sleep_time();
// 11. Certificate Panel
boolean disp_cp = CertificatePanel();
if (!disp_cp) {
System.out
.println("ERROR: ConfigureOCSP: CertificatePanel() failure");
return false;
}
sleep_time();
// backup panel
boolean disp_back = BackupPanel();
if (!disp_back) {
System.out.println("ERROR: ConfigureOCSP: BackupPanel() failure");
return false;
}
sleep_time();
// save panel
boolean disp_save = SavePKCS12Panel();
if (!disp_save) {
System.out
.println("ERROR: ConfigureOCSP: SavePKCS12Panel() failure");
return false;
}
sleep_time();
// 13. Admin Cert Req Panel
boolean disp_adm = AdminCertReqPanel();
if (!disp_adm) {
System.out
.println("ERROR: ConfigureOCSP: AdminCertReqPanel() failure");
return false;
}
sleep_time();
// 14. Admin Cert import Panel
boolean disp_im = AdminCertImportPanel();
if (!disp_im) {
System.out
.println("ERROR: ConfigureOCSP: AdminCertImportPanel() failure");
return false;
}
sleep_time();
// 15. Update Domain Panel
boolean disp_ud = UpdateDomainPanel();
if (!disp_ud) {
System.out
.println("ERROR: ConfigureOCSP: UpdateDomainPanel() failure");
return false;
}
sleep_time();
return true;
}
private static String set_default(String val, String def) {
if ((val == null) || (val.equals(""))) {
return def;
} else {
return val;
}
}
public static void main(String args[]) {
ConfigureOCSP ca = new ConfigureOCSP();
// set variables
StringHolder x_cs_hostname = new StringHolder();
StringHolder x_cs_port = new StringHolder();
StringHolder x_sd_hostname = new StringHolder();
StringHolder x_sd_ssl_port = new StringHolder();
StringHolder x_sd_agent_port = new StringHolder();
StringHolder x_sd_admin_port = new StringHolder();
StringHolder x_sd_admin_name = new StringHolder();
StringHolder x_sd_admin_password = new StringHolder();
StringHolder x_ca_hostname = new StringHolder();
StringHolder x_ca_port = new StringHolder();
StringHolder x_ca_ssl_port = new StringHolder();
StringHolder x_client_certdb_dir = new StringHolder();
StringHolder x_client_certdb_pwd = new StringHolder();
StringHolder x_preop_pin = new StringHolder();
StringHolder x_domain_name = new StringHolder();
StringHolder x_admin_user = new StringHolder();
StringHolder x_admin_email = new StringHolder();
StringHolder x_admin_password = new StringHolder();
// ldap
StringHolder x_ldap_host = new StringHolder();
StringHolder x_ldap_port = new StringHolder();
StringHolder x_bind_dn = new StringHolder();
StringHolder x_bind_password = new StringHolder();
StringHolder x_base_dn = new StringHolder();
StringHolder x_db_name = new StringHolder();
StringHolder x_secure_conn = new StringHolder();
StringHolder x_clone_start_tls = new StringHolder();
StringHolder x_remove_data = new StringHolder();
// key properties (defaults)
StringHolder x_key_size = new StringHolder();
StringHolder x_key_type = new StringHolder();
StringHolder x_key_curvename = new StringHolder();
StringHolder x_signing_algorithm = new StringHolder();
// key properties (custom - signing)
StringHolder x_signing_key_size = new StringHolder();
StringHolder x_signing_key_type = new StringHolder();
StringHolder x_signing_key_curvename = new StringHolder();
StringHolder x_signing_signingalgorithm = new StringHolder();
// key properties (custom - audit_signing)
StringHolder x_audit_signing_key_size = new StringHolder();
StringHolder x_audit_signing_key_type = new StringHolder();
StringHolder x_audit_signing_key_curvename = new StringHolder();
// key properties (custom - subsystem)
StringHolder x_subsystem_key_size = new StringHolder();
StringHolder x_subsystem_key_type = new StringHolder();
StringHolder x_subsystem_key_curvename = new StringHolder();
// key properties (custom - sslserver)
StringHolder x_sslserver_key_size = new StringHolder();
StringHolder x_sslserver_key_type = new StringHolder();
StringHolder x_sslserver_key_curvename = new StringHolder();
StringHolder x_token_name = new StringHolder();
StringHolder x_token_pwd = new StringHolder();
StringHolder x_agent_key_size = new StringHolder();
StringHolder x_agent_key_type = new StringHolder();
StringHolder x_agent_cert_subject = new StringHolder();
StringHolder x_agent_name = new StringHolder();
StringHolder x_backup_pwd = new StringHolder();
StringHolder x_backup_fname = new StringHolder();
// ca cert subject name params
StringHolder x_ocsp_sign_cert_subject_name = new StringHolder();
StringHolder x_ocsp_subsystem_cert_subject_name = new StringHolder();
StringHolder x_ocsp_server_cert_subject_name = new StringHolder();
StringHolder x_ocsp_audit_signing_cert_subject_name = new StringHolder();
// subsystemName
StringHolder x_subsystem_name = new StringHolder();
// parse the args
ArgParser parser = new ArgParser("ConfigureOCSP");
parser.addOption("-cs_hostname %s #CS Hostname", x_cs_hostname);
parser.addOption("-cs_port %s #CS SSL Admin port", x_cs_port);
parser.addOption("-sd_hostname %s #Security Domain Hostname",
x_sd_hostname);
parser.addOption("-sd_ssl_port %s #Security Domain SSL EE port",
x_sd_ssl_port);
parser.addOption("-sd_agent_port %s #Security Domain SSL Agent port",
x_sd_agent_port);
parser.addOption("-sd_admin_port %s #Security Domain SSL Admin port",
x_sd_admin_port);
parser.addOption("-sd_admin_name %s #Security Domain Admin Name",
x_sd_admin_name);
parser.addOption(
"-sd_admin_password %s #Security Domain Admin password",
x_sd_admin_password);
parser.addOption("-ca_hostname %s #CA Hostname", x_ca_hostname);
parser.addOption("-ca_port %s #CA non-SSL EE port", x_ca_port);
parser.addOption("-ca_ssl_port %s #CA SSL EE port", x_ca_ssl_port);
parser.addOption("-client_certdb_dir %s #Client CertDB dir",
x_client_certdb_dir);
parser.addOption("-client_certdb_pwd %s #client certdb password",
x_client_certdb_pwd);
parser.addOption("-preop_pin %s #pre op pin", x_preop_pin);
parser.addOption("-domain_name %s #domain name", x_domain_name);
parser.addOption("-admin_user %s #Admin User Name", x_admin_user);
parser.addOption("-admin_email %s #Admin email", x_admin_email);
parser.addOption("-admin_password %s #Admin password", x_admin_password);
parser.addOption("-agent_name %s #Agent Cert Nickname", x_agent_name);
parser.addOption("-ldap_host %s #ldap host", x_ldap_host);
parser.addOption("-ldap_port %s #ldap port", x_ldap_port);
parser.addOption("-bind_dn %s #ldap bind dn", x_bind_dn);
parser.addOption("-bind_password %s #ldap bind password",
x_bind_password);
parser.addOption("-base_dn %s #base dn", x_base_dn);
parser.addOption("-db_name %s #db name", x_db_name);
parser.addOption(
"-secure_conn %s #use ldaps port (optional, default is false)",
x_secure_conn);
parser.addOption(
"-remove_data %s #remove existing data under base_dn (optional, default is false) ",
x_remove_data);
parser.addOption(
"-clone_start_tls %s #use startTLS for cloning replication agreement (optional, default is false)",
x_clone_start_tls);
// key and algorithm options (default)
parser.addOption(
"-key_type %s #Key type [RSA,ECC] (optional, default is RSA)",
x_key_type);
parser.addOption(
"-key_size %s #Key Size (optional, for RSA default is 2048)",
x_key_size);
parser.addOption(
"-key_curvename %s #Key Curve Name (optional, for ECC default is nistp256)",
x_key_curvename);
parser.addOption(
"-signing_algorithm %s #Signing algorithm (optional, default is SHA256withRSA for RSA and SHA256withEC for ECC)",
x_signing_algorithm);
// key and algorithm options for signing certificate (overrides default)
parser.addOption(
"-signing_key_type %s #Key type [RSA,ECC] (optional, default is key_type)",
x_signing_key_type);
parser.addOption(
"-signing_key_size %s #Key Size (optional, for RSA default is key_size)",
x_signing_key_size);
parser.addOption(
"-signing_key_curvename %s #Key Curve Name (optional, for ECC default is key_curvename)",
x_signing_key_curvename);
parser.addOption(
"-signing_signingalgorithm %s #Algorithm used be ocsp signing cert to sign objects (optional, default is signing_algorithm)",
x_signing_signingalgorithm);
// key and algorithm options for audit_signing certificate (overrides
// default)
parser.addOption(
"-audit_signing_key_type %s #Key type [RSA,ECC] (optional, default is key_type)",
x_audit_signing_key_type);
parser.addOption(
"-audit_signing_key_size %s #Key Size (optional, for RSA default is key_size)",
x_audit_signing_key_size);
parser.addOption(
"-audit_signing_key_curvename %s #Key Curve Name (optional, for ECC default is key_curvename)",
x_audit_signing_key_curvename);
// key and algorithm options for subsystem certificate (overrides
// default)
parser.addOption(
"-subsystem_key_type %s #Key type [RSA,ECC] (optional, default is key_type)",
x_subsystem_key_type);
parser.addOption(
"-subsystem_key_size %s #Key Size (optional, for RSA default is key_size)",
x_subsystem_key_size);
parser.addOption(
"-subsystem_key_curvename %s #Key Curve Name (optional, for ECC default is key_curvename)",
x_subsystem_key_curvename);
// key and algorithm options for sslserver certificate (overrides
// default)
parser.addOption(
"-sslserver_key_type %s #Key type [RSA,ECC] (optional, default is key_type)",
x_sslserver_key_type);
parser.addOption(
"-sslserver_key_size %s #Key Size (optional, for RSA default is key_size)",
x_sslserver_key_size);
parser.addOption(
"-sslserver_key_curvename %s #Key Curve Name (optional, for ECC default is key_curvename)",
x_sslserver_key_curvename);
parser.addOption("-token_name %s #HSM/Software Token name",
x_token_name);
parser.addOption(
"-token_pwd %s #HSM/Software Token password (optional, required for HSM)",
x_token_pwd);
parser.addOption("-agent_key_size %s #Agent Cert Key Size",
x_agent_key_size);
parser.addOption("-agent_key_type %s #Agent Cert Key type [rsa]",
x_agent_key_type);
parser.addOption("-agent_cert_subject %s #Agent Cert Subject",
x_agent_cert_subject);
parser.addOption("-backup_pwd %s #PKCS12 password", x_backup_pwd);
parser.addOption(
"-ocsp_sign_cert_subject_name %s #OCSP cert subject name",
x_ocsp_sign_cert_subject_name);
parser.addOption(
"-ocsp_subsystem_cert_subject_name %s #OCSP subsystem cert subject name",
x_ocsp_subsystem_cert_subject_name);
parser.addOption(
"-ocsp_server_cert_subject_name %s #OCSP server cert subject name",
x_ocsp_server_cert_subject_name);
parser.addOption(
"-backup_fname %s #Backup File for p12, (optional, default /root/tmp-ocsp.p12",
x_backup_fname);
parser.addOption("-subsystem_name %s #OCSP subsystem name",
x_subsystem_name);
parser.addOption(
"-ocsp_audit_signing_cert_subject_name %s #OCSP audit signing cert subject name",
x_ocsp_audit_signing_cert_subject_name);
// and then match the arguments
String[] unmatched = null;
unmatched = parser.matchAllArgs(args, 0, ArgParser.EXIT_ON_UNMATCHED);
if (unmatched != null) {
System.out.println("ERROR: Argument Mismatch");
System.exit(-1);
}
parser.checkRequiredArgs();
// set variables
cs_hostname = x_cs_hostname.value;
cs_port = x_cs_port.value;
sd_hostname = x_sd_hostname.value;
sd_ssl_port = x_sd_ssl_port.value;
sd_agent_port = x_sd_agent_port.value;
sd_admin_port = x_sd_admin_port.value;
sd_admin_name = x_sd_admin_name.value;
sd_admin_password = x_sd_admin_password.value;
ca_hostname = x_ca_hostname.value;
ca_port = x_ca_port.value;
ca_ssl_port = x_ca_ssl_port.value;
client_certdb_dir = x_client_certdb_dir.value;
client_certdb_pwd = x_client_certdb_pwd.value;
pin = x_preop_pin.value;
domain_name = x_domain_name.value;
admin_user = x_admin_user.value;
admin_email = x_admin_email.value;
admin_password = x_admin_password.value;
agent_name = x_agent_name.value;
ldap_host = x_ldap_host.value;
ldap_port = x_ldap_port.value;
bind_dn = x_bind_dn.value;
bind_password = x_bind_password.value;
base_dn = x_base_dn.value;
db_name = x_db_name.value;
secure_conn = set_default(x_secure_conn.value, "false");
remove_data = set_default(x_remove_data.value, "false");
clone_start_tls = set_default(x_clone_start_tls.value, "false");
key_type = set_default(x_key_type.value, DEFAULT_KEY_TYPE);
signing_key_type = set_default(x_signing_key_type.value, key_type);
audit_signing_key_type = set_default(x_audit_signing_key_type.value,
key_type);
subsystem_key_type = set_default(x_subsystem_key_type.value, key_type);
sslserver_key_type = set_default(x_sslserver_key_type.value, key_type);
key_size = set_default(x_key_size.value, DEFAULT_KEY_SIZE);
signing_key_size = set_default(x_signing_key_size.value, key_size);
audit_signing_key_size = set_default(x_audit_signing_key_size.value,
key_size);
subsystem_key_size = set_default(x_subsystem_key_size.value, key_size);
sslserver_key_size = set_default(x_sslserver_key_size.value, key_size);
key_curvename = set_default(x_key_curvename.value,
DEFAULT_KEY_CURVENAME);
signing_key_curvename = set_default(x_signing_key_curvename.value,
key_curvename);
audit_signing_key_curvename = set_default(
x_audit_signing_key_curvename.value, key_curvename);
subsystem_key_curvename = set_default(x_subsystem_key_curvename.value,
key_curvename);
sslserver_key_curvename = set_default(x_sslserver_key_curvename.value,
key_curvename);
if (signing_key_type.equalsIgnoreCase("RSA")) {
signing_algorithm = set_default(x_signing_algorithm.value,
DEFAULT_KEY_ALGORITHM_RSA);
} else {
signing_algorithm = set_default(x_signing_algorithm.value,
DEFAULT_KEY_ALGORITHM_ECC);
}
signing_signingalgorithm = set_default(
x_signing_signingalgorithm.value, signing_algorithm);
token_name = x_token_name.value;
token_pwd = x_token_pwd.value;
agent_key_size = x_agent_key_size.value;
agent_key_type = x_agent_key_type.value;
agent_cert_subject = x_agent_cert_subject.value;
backup_pwd = x_backup_pwd.value;
backup_fname = set_default(x_backup_fname.value, "/root/tmp-ocsp.p12");
ocsp_sign_cert_subject_name = x_ocsp_sign_cert_subject_name.value;
ocsp_subsystem_cert_subject_name = x_ocsp_subsystem_cert_subject_name.value;
ocsp_server_cert_subject_name = x_ocsp_server_cert_subject_name.value;
ocsp_audit_signing_cert_subject_name = x_ocsp_audit_signing_cert_subject_name.value;
subsystem_name = x_subsystem_name.value;
boolean st = ca.ConfigureOCSPInstance();
if (!st) {
System.out.println("ERROR: unable to create OCSP");
System.exit(-1);
}
System.out.println("Certificate System - OCSP Instance Configured");
System.exit(0);
}
};
|