summaryrefslogtreecommitdiffstats
path: root/base/console/src/com/netscape/admin/certsrv/keycert/WManualCertRequestPage.java
blob: ebbbd6be2132693340fc621cfdfb1f21deae38bf (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
// --- 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 ---
package com.netscape.admin.certsrv.keycert;

import java.util.*;
import java.awt.*;
import java.io.*;
import javax.swing.*;
import com.netscape.admin.certsrv.*;
import com.netscape.admin.certsrv.connection.*;
import com.netscape.admin.certsrv.wizard.*;
import com.netscape.certsrv.common.*;
import com.netscape.admin.certsrv.config.*;
import com.netscape.admin.certsrv.task.*;

/**
 * Generate cert request page for cert setup wizard.
 *
 * @author Christine Ho
 * @version $Revision$, $Date$
 * @see com.netscape.admin.certsrv.keycert
 */
class WManualCertRequestPage extends WBaseManualCertRequestPage implements IWizardPanel {

    public static final String SERVER_CERT = "server";
    public static final String CLIENT_CERT = "client";
    public static final String CA_CERT = "ca";
    public static final String RA_CERT = "ra";
    public static final String OCSP_CERT = "ocsp";
    public static final String OBJECT_SIGNING_CERT = "objSignClient";
    public static final String OTHER_CERT = "other";
    public static final String ROUTER_CERT = "router"; // deprecated
    public static final String CEP_CERT = "CEP-Request";

    private static final String PANELNAME = "MANUALCERTREQUESTWIZARD";
    private static final String HELPINDEX =
      "configuration-keycert-wizard-displaycertrequest-help";

    WManualCertRequestPage(JDialog parent) {
        super(PANELNAME);
        mParent = parent;
        init();
    }

    WManualCertRequestPage(JDialog parent, JFrame frame) {
        super(PANELNAME);
        mParent = parent;
        mAdminFrame = frame;
        init();
    }

    public boolean isLastPage() {
        return false;
    }

    public boolean initializePanel(WizardInfo info) {
        CertSetupWizardInfo wizardInfo = (CertSetupWizardInfo)info;

        if (wizardInfo.getOperationType().equals(wizardInfo.INSTALLTYPE) ||
          wizardInfo.getCAType().equals(wizardInfo.SELF_SIGNED))
            return false;

        String str = wizardInfo.getCSR();
//        mText.setText(CMSAdminUtil.certRequestWrapText(str, 40));
        mText.setText(str);
        mText.selectAll();
        setBorder(makeTitledBorder(PANELNAME));

        CMSServerInfo serverInfo = wizardInfo.getServerInfo();
        String certType = wizardInfo.getCertType();
        if (certType.equals(Constants.PR_CA_SIGNING_CERT)) {
            mDesc.setText(mResource.getString(mPanelName+"_TEXT_CADESC_LABEL"));
            str = mResource.getString(mPanelName+"_TEXT_CAFILELOC_LABEL");
        } else if (certType.equals(Constants.PR_OCSP_SIGNING_CERT)) {
            str = mResource.getString(mPanelName+"_TEXT_OCSPFILELOC_LABEL");
            mDesc.setText(mResource.getString(mPanelName+"_TEXT_RADESC_LABEL"));
        } else if (certType.equals(Constants.PR_RA_SIGNING_CERT)) {
            str = mResource.getString(mPanelName+"_TEXT_RAFILELOC_LABEL");
            mDesc.setText(mResource.getString(mPanelName+"_TEXT_RADESC_LABEL"));
        } else if (certType.equals(Constants.PR_KRA_TRANSPORT_CERT)) {
            str = mResource.getString(mPanelName+"_TEXT_KRAFILELOC_LABEL");
            mDesc.setText(mResource.getString(mPanelName+"_TEXT_KRADESC_LABEL"));
        } else if (certType.equals(Constants.PR_SERVER_CERT)) {
            str = mResource.getString(mPanelName+"_TEXT_SSLFILELOC_LABEL");
            mDesc.setText(mResource.getString(mPanelName+"_TEXT_SSLDESC_LABEL"));
        } else if (certType.equals(Constants.PR_SERVER_CERT_RADM)) {
            str = mResource.getString(mPanelName+"_TEXT_SSLRADMFILELOC_LABEL");
            mDesc.setText(mResource.getString(mPanelName+"_TEXT_SSLDESC_LABEL"));
        } else if (certType.equals(Constants.PR_OTHER_CERT)) {
            str = mResource.getString(mPanelName+"_TEXT_OTHERFILELOC_LABEL");
            mDesc.setText(mResource.getString(mPanelName+"_TEXT_OTHERDESC_LABEL"));
        }

        String dir = wizardInfo.getCertRequestDir();
        mFileName.setText(str+dir+".");

        if (mSendNowBox.isSelected())
            enableFields(true, mActiveColor);
        else
            enableFields(false, getBackground());
		String host = wizardInfo.getCMHost();
		if (host != null && !host.equals(""))
			mHostText.setText(host);
		String port = wizardInfo.getCMEEPort();
		if (port != null && !port.equals(""))
			mPortText.setText(port);

        return true;
    }

    public boolean validatePanel() {
        return super.validatePanel();
    }

    public boolean concludePanel(WizardInfo info) {
		if (!mSendNowBox.isSelected())
			return true;

        CertSetupWizardInfo wizardInfo = (CertSetupWizardInfo)info;
		if (mHost != null && !mHost.equals(""))
			wizardInfo.setCMHost(mHost);
		if (mPort != null && !mPort.equals(""))
			wizardInfo.setCMEEPort(mPort);
		if (mSSL.isSelected())
			wizardInfo.setCMEEType("https");
		else
			wizardInfo.setCMEEType("http");

        CMSCertRequest requestCertCgi = new CMSCertRequest();
        requestCertCgi.initialize(wizardInfo);
        Hashtable data = new Hashtable();

        String certType = null;

        String mReqType = wizardInfo.getCertType();
        String mReq = null;

        mReq = wizardInfo.getCSR();

        if (mReqType.equals(Constants.PR_CA_SIGNING_CERT)){
                        data.put("profileId", "caCACert");
        }else if (mReqType.equals(Constants.PR_SERVER_CERT) ||
                  mReqType.equals(Constants.PR_KRA_TRANSPORT_CERT)){
                        data.put("profileId", "caServerCert");
        }else if (mReqType.equals(Constants.PR_OCSP_SIGNING_CERT)){
                        data.put("profileId", "caOCSPCert");
        }else if (mReqType.equals(Constants.PR_RA_SIGNING_CERT)){
                        data.put("profileId", "caRACert");
        }else if (mReqType.equals(Constants.PR_OTHER_CERT)) {
            data.put("profileId", "caOtherCert");
        } else {
                        data.put("profileId", mReqType);
        }

            data.put("cert_request_type", "pkcs10");
            data.put("cert_request", mReq);

        startProgressStatus();
        boolean ready = requestCertCgi.requestCert(data);
        endProgressStatus();

        if (!ready) {
            String str = requestCertCgi.getErrorMessage();
            if (str.equals(""))
                setErrorMessage("Server Error");
            else
                setErrorMessage(str);
        }

		wizardInfo.setRequestSent(ready);
        return ready;
    }

    public void callHelp() {
        CMSAdminUtil.help(HELPINDEX);
    }

    protected void init() {
        super.init();
    }

    public void getUpdateInfo(WizardInfo info) {
    }
}