summaryrefslogtreecommitdiffstats
path: root/pki/base/silent/src/com/netscape/pkisilent/common/CMSLDAP.java
blob: d0222897d79fc0edfed2179a028e57410d53c269 (plain)
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
package com.netscape.pkisilent.common;

// --- 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.ByteArrayInputStream;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;

import netscape.ldap.LDAPAttribute;
import netscape.ldap.LDAPAttributeSet;
import netscape.ldap.LDAPConnection;
import netscape.ldap.LDAPEntry;
import netscape.ldap.LDAPException;
import netscape.ldap.LDAPModification;
import netscape.ldap.LDAPModificationSet;
import netscape.ldap.LDAPSearchResults;
import netscape.ldap.LDAPv2;

/**
 * CMS Test framework .
 * Using this class you can add a user and user certificate to LDAP server.
 * You can also check if a certificate / CRL is published in LDAP server
 * USe this class to turn of SSL and turn on SSL in a LDAP server.
 */

public class CMSLDAP {

    private String HOST, DN, BASEDN, PASSWORD;
    private int PORT;

    private LDAPConnection conn = new LDAPConnection();

    public CMSLDAP() {
    }

    /**
     * Constructor. Takes parametes ldaphost, ldapport
     */
    public CMSLDAP(String h, String p) {
        HOST = h;
        PORT = Integer.parseInt(p);
    }

    /**
     * Cosntructor. Takes parameters ldaphost,ldapport,ldapbinddn, ldapbindnpassword.
     */
    public CMSLDAP(String h, String p, String dn, String pwd) {
        HOST = h;
        PORT = Integer.parseInt(p);
        DN = dn;
        PASSWORD = pwd;
    }

    /**
     * Connect to ldap server
     */

    public boolean connect() {
        try {
            conn.connect(HOST, PORT, DN, PASSWORD);
            return true;
        } catch (Exception e) {
            System.out.println("ERROR: " + e.toString());
            return false;
        }
    }

    /**
     * Disconnect form ldap server
     */

    public void disconnect() {

        if ((conn != null) && conn.isConnected()) {
            try {
                conn.disconnect();
            } catch (Exception e) {
                System.out.println("ERROR: " + e.toString());
            }

        }

    }

    /**
     * Search for certificaterevocationList attribute. Takes basedn and filter as parameters
     */

    public boolean searchCRL(String basedn, String filter) throws LDAPException {
        int searchScope = LDAPv2.SCOPE_SUB;
        String getAttrs[] = { "certificateRevocationList;binary" };
        LDAPSearchResults results = conn.search(basedn, searchScope, filter,
                getAttrs, false);

        if (results == null) {
            System.out.println("Could not search");
            return false;
        }
        while (results.hasMoreElements()) {
            LDAPEntry entry = (LDAPEntry) results.nextElement();

            System.out.println(entry.getDN());
            LDAPAttribute anAttr = entry.getAttribute(
                    "certificateRevocationList;binary");

            if (anAttr == null) {
                System.out.println("Attribute not found ");
                return false;
            } else {
                System.out.println(anAttr.getName());
                System.out.println(anAttr.getByteValueArray());
                return true;
            }
        }
        return true;
    }

    /**
     * Search for attriburte usercertificate. Takes parameters basedn and filter
     */

    public boolean searchUserCert(String basedn, String filter) throws LDAPException {
        int searchScope = LDAPv2.SCOPE_SUB;
        String getAttrs[] = { "usercertificate;binary" };
        LDAPSearchResults results = conn.search(basedn, searchScope, filter,
                getAttrs, false);

        if (results == null) {
            System.out.println("Could not search");
            return false;
        }
        while (results.hasMoreElements()) {
            LDAPEntry entry = (LDAPEntry) results.nextElement();

            System.out.println(entry.getDN());
            LDAPAttribute anAttr = entry.getAttribute("usercertificate;binary");

            if (anAttr == null) {
                System.out.println("Attribute not found ");
                return false;
            } else {
                System.out.println(anAttr.getName());
                System.out.println(anAttr.getByteValueArray());
                return true;
            }
        }
        return true;
    }

    /**
     * Adds a user to direcrtory server . Takes parameters basedn, cn,sn,uid and passwd
     */

    public boolean userAdd(String basedn, String cn, String sn, String uid, String pwd) {
        try {
            LDAPAttributeSet attrSet = new LDAPAttributeSet();

            attrSet.add(
                    new LDAPAttribute("objectclass",
                            new String[] {
                                    "top", "person", "organizationalPerson",
                                    "inetorgperson" }));
            attrSet.add(new LDAPAttribute("cn", cn));
            attrSet.add(new LDAPAttribute("mail", uid + "@netscape.com"));
            attrSet.add(new LDAPAttribute("userpassword", pwd));
            attrSet.add(new LDAPAttribute("sn", sn));
            attrSet.add(new LDAPAttribute("givenName", cn + sn));
            String name = "uid=" + uid + "," + basedn;

            System.out.println("Basedn " + name);
            LDAPEntry entry = new LDAPEntry(name, attrSet);

            conn.add(entry);
            System.out.println("ADDED: " + name);
            return true;
        } catch (Exception e) {
            System.out.println("ERROR: " + e.toString());
            return false;
        }

    }

    private X509Certificate getXCertificate(byte[] cpack) {

        try {
            CertificateFactory cf = CertificateFactory.getInstance("X.509");
            ByteArrayInputStream s = new ByteArrayInputStream(cpack);

            System.out.println("Building certificate :" + cpack);
            java.security.cert.X509Certificate the_cert = (
                    java.security.cert.X509Certificate) cf.generateCertificate(s);

            return the_cert;
        } catch (Exception e) {
            System.out.println("ERROR: getXCertificate " + e.toString());
            return null;
        }

    }

    private String buildDNString(String s) {

        String val = "";

        for (int i = 0; i < s.length(); i++) {
            if ((s.charAt(i) == ',') && (s.charAt(i + 1) == ' ')) {
                val += ',';
                i++;
                continue;
            } else {
                val += s.charAt(i);
            }
        }
        return val;
    }

    /**
     * Returns the SerialNumber;issuerDN;SubjectDN string.
     * Takes certificate as parameter
     */

    public String getCertificateString(X509Certificate cert) {
        if (cert == null) {
            return null;
        }
        String idn = ((cert.getIssuerDN()).toString()).trim();

        idn = buildDNString(idn);
        String sdn = ((cert.getSubjectDN()).toString()).trim();

        sdn = buildDNString(sdn);

        System.out.println("GetCertificateString : " + idn + ";" + sdn);

        // note that it did not represent a certificate fully
        // return cert.getVersion() + ";" + cert.getSerialNumber().toString() +
        // ";" + cert.getIssuerDN() + ";" + cert.getSubjectDN();
        return "2;" + cert.getSerialNumber().toString() + ";" + idn + ";" + sdn;

    }

    /**
     * Adds a user of objectclass cmsuser . Takes cn,sn,uid,password,certificate as parameters.
     */
    public boolean CMSuserAdd(String cn, String sn, String uid, String pwd, byte[] certpack) {
        try {
            X509Certificate cert = getXCertificate(certpack);

            LDAPAttributeSet attrSet = new LDAPAttributeSet();

            attrSet.add(
                    new LDAPAttribute("objectclass",
                            new String[] {
                                    "top", "person", "organizationalPerson",
                                    "inetorgperson", "cmsuser" }));
            attrSet.add(new LDAPAttribute("cn", cn));
            attrSet.add(new LDAPAttribute("mail", uid + "@netscape.com"));
            attrSet.add(new LDAPAttribute("userpassword", pwd));
            attrSet.add(new LDAPAttribute("sn", sn));
            attrSet.add(new LDAPAttribute("givenName", cn + sn));
            attrSet.add(new LDAPAttribute("usertype", "sub"));
            attrSet.add(new LDAPAttribute("userstate", "1"));

            attrSet.add(
                    new LDAPAttribute("description", getCertificateString(cert)));
            LDAPAttribute attrCertBin = new LDAPAttribute("usercertificate");

            attrCertBin.addValue(cert.getEncoded());
            attrSet.add(attrCertBin);

            String name = "uid=" + uid + ","
                    + "ou=People,o=netscapecertificateServer";
            LDAPEntry entry = new LDAPEntry(name, attrSet);

            conn.add(entry);
            System.out.println("ADDED: " + name);
            return true;
        } catch (Exception e) {
            System.out.println("ERROR: " + e.toString());
            return false;
        }

    }

    /**
     * Adds a user of objectclass cmsuser . Takes cn,sn,uid,password,certificate as parameters.
     */

    public boolean CMSuserAdd(String cn, String sn, String uid, String pwd, X509Certificate cert) {

        try {
            LDAPAttributeSet attrSet = new LDAPAttributeSet();

            attrSet.add(
                    new LDAPAttribute("objectclass",
                            new String[] {
                                    "top", "person", "organizationalPerson",
                                    "inetorgperson", "cmsuser" }));
            attrSet.add(new LDAPAttribute("cn", cn));
            attrSet.add(new LDAPAttribute("mail", uid + "@netscape.com"));
            attrSet.add(new LDAPAttribute("userpassword", pwd));
            attrSet.add(new LDAPAttribute("sn", sn));
            attrSet.add(new LDAPAttribute("givenName", cn + sn));
            attrSet.add(new LDAPAttribute("usertype", "sub"));
            attrSet.add(new LDAPAttribute("userstate", "1"));

            attrSet.add(
                    new LDAPAttribute("description", getCertificateString(cert)));

            LDAPAttribute attrCertBin = new LDAPAttribute("usercertificate");

            attrCertBin.addValue(cert.getEncoded());
            attrSet.add(attrCertBin);

            String name = "uid=" + uid + ","
                    + "ou=People,o=netscapecertificateServer";
            LDAPEntry entry = new LDAPEntry(name, attrSet);

            conn.add(entry);
            System.out.println("ADDED: " + name);
        } catch (Exception e) {
            System.out.println("ERROR: " + e.toString());
            return false;
        }

        return true;
    }

    /**
     * adds a cms user to Trusted Manager Group. Takes uid as parameter.
     */

    public boolean addCMSUserToTMGroup(String uid) {
        try {
            LDAPAttributeSet attrSet = new LDAPAttributeSet();
            LDAPAttribute um = new LDAPAttribute("uniquemember",
                    "uid=" + uid + ",ou=People,o=NetscapeCertificateServer");

            attrSet.add(um);
            LDAPModification gr = new LDAPModification(LDAPModification.ADD, um);

            String dn = "cn=Trusted Managers,ou=groups,o=netscapeCertificateServer";

            conn.modify(dn, gr);
            return true;

        } catch (Exception e) {
            System.out.println("ERROR: " + e.toString());
            return false;
        }

    }

    /**
     * adds a cms user to Agent Group. Takes subsytem (ca/ra/ocsp/kra) and uid as parameters .
     */

    public boolean addCMSUserToAgentGroup(String subsystem, String uid) {
        try {
            String dn = null;

            if (subsystem.equals("ocsp")) {
                dn = "cn=Online Certificate Status Manager Agents,ou=groups,o=netscapeCertificateServer";
            }
            if (subsystem.equals("kra")) {
                dn = "cn=Data Recovery Manager Agents,ou=groups,o=netscapeCertificateServer";
            }
            if (subsystem.equals("ra")) {
                dn = "cn=Registration Manager Agents,ou=groups,o=netscapeCertificateServer";
            }
            if (subsystem.equals("ca")) {
                dn = "cn=Certificate Manager Agents,ou=groups,o=netscapeCertificateServer";
            }
            if (subsystem.equals("tks")) {
                dn = "cn=Token Key Service Manager Agents,ou=groups,o=netscapeCertificateServer";
            }

            LDAPAttributeSet attrSet = new LDAPAttributeSet();
            LDAPAttribute um = new LDAPAttribute("uniquemember",
                    "uid=" + uid + ",ou=People,o=NetscapeCertificateServer");

            System.out.println(
                    "uid=" + uid + ",ou=People,o=NetscapeCertificateServer");

            attrSet.add(um);
            LDAPModification gr = new LDAPModification(LDAPModification.ADD, um);

            conn.modify(dn, gr);

            return true;

        } catch (Exception e) {
            System.out.println("ERROR: " + e.toString());
            return false;
        }

    }

    /**
     * Will trun of SSL in LDAP server
     **/

    public boolean TurnOffSSL() {
        try {

            LDAPModificationSet mods = new LDAPModificationSet();
            LDAPAttribute ssl3 = new LDAPAttribute("nsssl3", "off");
            LDAPAttribute ssl3ciphers = new LDAPAttribute("nsssl3ciphers", "");
            LDAPAttribute kfile = new LDAPAttribute("nskeyfile", "alias/");
            LDAPAttribute cfile = new LDAPAttribute("nscertfile", "alias/");
            LDAPAttribute cauth = new LDAPAttribute("nssslclientauth", "allowed");

            // conn.delete("cn=RSA,cn=encryption,cn=config"); 		

            mods.add(LDAPModification.REPLACE, ssl3);
            mods.add(LDAPModification.DELETE, ssl3ciphers);
            mods.add(LDAPModification.DELETE, kfile);
            mods.add(LDAPModification.DELETE, cfile);
            mods.add(LDAPModification.DELETE, cauth);
            System.out.println("going to mod");
            // conn.modify("cn=encryption,cn=config",mods);
            System.out.println("mod en=encryption");
            int i = 4;

            while (i >= 0) {
                mods.removeElementAt(i);
                i--;
            }

            LDAPAttribute sec = new LDAPAttribute("nsslapd-security", "off");

            mods.add(LDAPModification.REPLACE, sec);
            conn.modify("cn=config", mods);
            System.out.println("mod cn=config");

            return true;

        } catch (Exception e) {
            System.out.println("ERROR: " + e.toString());
            return false;
        }

    }

    /**
     * Will Turn ON SSL in LDAP server . Takes certPrefix, certificatenickanme and sslport as parameters.
     **/

    public boolean TurnOnSSL(String certPrefix, String certName, String sslport) {
        String dn;
        String CIPHERS =
                "-rsa_null_md5,+rsa_fips_3des_sha,+rsa_fips_des_sha,+rsa_3des_sha,+rsa_rc4_128_md5,+rsa_des_sha,+rsa_rc2_40_md5,+rsa_rc4_40_md5";

        try {
            boolean found = false;
            int searchScope = LDAPv2.SCOPE_SUB;
            String getAttrs[] = { "nssslactivation" };

            LDAPModificationSet mods = new LDAPModificationSet();
            LDAPAttribute sec = new LDAPAttribute("nsslapd-security", "on");
            LDAPAttribute sp = new LDAPAttribute("nsslapd-securePort", sslport);

            mods.add(LDAPModification.REPLACE, sec);
            mods.add(LDAPModification.REPLACE, sp);
            conn.modify("cn=config", mods);
            mods.removeElementAt(1);
            mods.removeElementAt(0);

            LDAPAttribute ssl3 = new LDAPAttribute("nsssl3", "on");
            LDAPAttribute ssl3ciphers = new LDAPAttribute("nsssl3ciphers",
                    CIPHERS);
            LDAPAttribute kfile = new LDAPAttribute("nskeyfile",
                    "alias/" + certPrefix + "-key3.db");
            LDAPAttribute cfile = new LDAPAttribute("nscertfile",
                    "alias/" + certPrefix + "-cert7.db");
            LDAPAttribute cauth = new LDAPAttribute("nssslclientauth", "allowed");

            mods.add(LDAPModification.REPLACE, ssl3);
            mods.add(LDAPModification.REPLACE, ssl3ciphers);
            mods.add(LDAPModification.REPLACE, kfile);
            mods.add(LDAPModification.REPLACE, cfile);
            mods.add(LDAPModification.REPLACE, cauth);

            conn.modify("cn=encryption,cn=config", mods);
            int i = 4;

            while (i >= 0) {
                mods.removeElementAt(i);
                i--;
            }

            // conn.delete("cn=RSA,cn=encryption,cn=config"); 		
            try {
                LDAPSearchResults results = conn.search(
                        "cn=RSA,cn=encryption,cn=config", searchScope, null,
                        getAttrs, false);
                LDAPAttribute cn = new LDAPAttribute("cn", "RSA");
                LDAPAttribute ssltoken = new LDAPAttribute("nsssltoken",
                        "internal (software)");
                LDAPAttribute activation = new LDAPAttribute("nssslactivation",
                        "on");
                LDAPAttribute cname = new LDAPAttribute("nssslpersonalityssl",
                        certName);

                mods.add(LDAPModification.REPLACE, cn);
                mods.add(LDAPModification.REPLACE, ssltoken);
                mods.add(LDAPModification.REPLACE, activation);
                mods.add(LDAPModification.REPLACE, cname);

                conn.modify("cn=RSA,cn=encryption,cn=config", mods);

            } catch (Exception e1) {
                LDAPAttributeSet attrSet = new LDAPAttributeSet();

                attrSet.add(
                        new LDAPAttribute("objectclass",
                                new String[] { "top", "nsEncryptionModule" }));
                attrSet.add(new LDAPAttribute("cn", "RSA"));
                attrSet.add(
                        new LDAPAttribute("nsssltoken", "internal (software)"));
                attrSet.add(new LDAPAttribute("nssslactivation", "on"));
                attrSet.add(new LDAPAttribute("nssslpersonalityssl", certName));
                LDAPEntry entry = new LDAPEntry("cn=RSA,cn=encryption,cn=config",
                        attrSet);

                conn.add(entry);
            }

            return true;

        } catch (Exception e) {
            System.out.println("ERROR: " + e.toString());
            return false;
        }

    }

    public static void main(String args[]) {
        String HOST = args[0];
        // int PORT = Integer.parseInt(args[1]);
        String PORT = args[1];
        String DN = args[2];
        String PASSWORD = args[3];
        String BASEDN = args[4];

        String s =
                "MIICFzCCAYCgAwIBAgIBBjANBgkqhkiG9w0BAQQFADBDMRswGQYDVQQKExJhY2NlcHRhY25ldGVz\ndDEwMjQxFzAVBgNVBAsTDmFjY2VwdGFuY2V0ZXN0MQswCQYDVQQDEwJjYTAeFw0wMzA0MTEyMTUx\nMzZaFw0wNDA0MTAwOTQ2NTVaMFwxCzAJBgNVBAYTAlVTMQwwCgYDVQQKEwNTU0wxHTAbBgNVBAsT\nFHNzbHRlc3QxMDUwMDk3ODkzNzQ1MSAwHgYDVQQDExdqdXBpdGVyMi5uc2NwLmFvbHR3Lm5ldDBc\nMA0GCSqGSIb3DQEBAQUAA0sAMEgCQQDCsCTIIQ+bJMfPHi6kwa7HF+/xSTVHcpZ5zsodXsNWjPlD\noRu/5KAO8NotfwGnYmALWdYnqXCF0q0gkaJQalQTAgMBAAGjRjBEMA4GA1UdDwEB/wQEAwIFoDAR\nBglghkgBhvhCAQEEBAMCBkAwHwYDVR0jBBgwFoAUzxZkSySZT/Y3SxGMEiNyHnLUOPAwDQYJKoZI\nhvcNAQEEBQADgYEALtpqMOtZt6j5KlghDFgdg/dvf36nWiZwC1ap6+ka22shLkA/RjmOix97btzT\nQ+8LcmdkAW5iap4YbtrCu0wdN6IbIEXoQI1QGZBoKO2o02utssXANmTnRCyH/GX2KefQlp1NSRj9\nZNZ+GRT2Qk/8G5Ds9vVjm1I5+/AkzI9jS14=";

        s = "-----BEGIN CERTIFICATE-----" + "\n" + s + "\n"
                + "-----END CERTIFICATE-----\n";

        try {

            System.out.println(HOST + PORT + DN + PASSWORD + BASEDN);
            CMSLDAP caIdb = new CMSLDAP(HOST, PORT, DN, PASSWORD);

            /* FileInputStream fis = new FileInputStream("t1");
             DataInputStream dis = new DataInputStream(fis);

             byte[] bytes = new byte[dis.available()];
             dis.readFully(bytes);		

             //		bytes=s.getBytes();
             */

            if (!caIdb.connect()) {
                System.out.println("Could not connect to CA internal DB port");
            }

            if (!caIdb.searchCRL("o=mcom.com", "uid=CManager")) {
                System.out.println("CRL is not published");
            }

            // if(!caIdb.searchUserCert("o=mcom.com","uid=test"))
            // System.out.println("USer cert is not published");

            // if (!caIdb.CMSuserAdd("ra-trust" ,"ra-trust","ra-trust","netscape",bytes))
            // {System.out.println("Trusted MAnager user Could not be add ");}

            // if(!caIdb.addCMSUserToTMGroup("ra-trust"))
            // {System.out.println("CMS user Could not be added to Trusted manager group ");  }

            // if(!caIdb.addCMSUserToAgentGroup("ra","ra-agent"))
            // {System.out.println("CMS user Could not be added to Trusted manager group ");  }
            /* if(!caIdb.userAdd(BASEDN,"raeetest1","raeetest1","raeetest1","netscape"))
             {System.out.println("CMS user Could not be added to Trusted manager group ");  }
             */

        } catch (Exception e) {
            System.out.println("ERROR: " + e.toString());
        }

    }
}