aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/plugin/certconfig/CertConfigPanel.java
blob: 6f7bf675373f3da46c0172bd27a4d9d467340e84 (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
/*
 * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Copyright @ 2015 Atlassian Pty Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.java.sip.communicator.plugin.certconfig;

import java.awt.*;
import java.awt.event.*;
import java.security.*;

import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;

import net.java.sip.communicator.plugin.desktoputil.*;
import net.java.sip.communicator.service.certificate.*;
import net.java.sip.communicator.service.gui.*;

import org.jitsi.service.resources.*;
import org.jitsi.util.*;

/**
 * Advanced configuration form to define client TLS certificate templates.
 *
 * @author Ingo Bauersachs
 */
public class CertConfigPanel
    extends TransparentPanel
    implements ConfigurationForm, ActionListener, ListSelectionListener
{
    // ------------------------------------------------------------------------
    // Fields
    // ------------------------------------------------------------------------
    private static final long serialVersionUID = 2324122652952574574L;
    private ResourceManagementService R;
    private CertConfigTableModel model;

    // ------------------------------------------------------------------------
    // GUI members
    // ------------------------------------------------------------------------
    private JButton cmdAdd;
    private JButton cmdRemove;
    private JButton cmdEdit;
    private JTable tblCertList;
    private JRadioButton rdoUseWindows;
    private JRadioButton rdoUseJava;
    private SIPCommCheckBox chkEnableRevocationCheck;
    private SIPCommCheckBox chkEnableOcsp;

    // ------------------------------------------------------------------------
    // initialization
    // ------------------------------------------------------------------------
    /**
     * Creates a new instance of this class.
     */
    public CertConfigPanel()
    {
        R = CertConfigActivator.R;
        model = new CertConfigTableModel();
        initComponents();
        valueChanged(null);
    }

    private void initComponents()
    {
        this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

        // trusted root CA source selection
        if (OSUtils.IS_WINDOWS)
        {
            JPanel pnlCertConfig = new TransparentPanel(new GridLayout(2, 1));
            pnlCertConfig.setBorder(BorderFactory.createTitledBorder(
                R.getI18NString("plugin.certconfig.TRUSTSTORE_CONFIG")));
            add(pnlCertConfig);

            ButtonGroup grpTrustStore = new ButtonGroup();

            rdoUseJava = new SIPCommRadioButton();
            rdoUseJava.setText(
                R.getI18NString("plugin.certconfig.JAVA_TRUSTSTORE"));
            rdoUseJava.addActionListener(this);
            grpTrustStore.add(rdoUseJava);
            pnlCertConfig.add(rdoUseJava);

            rdoUseWindows = new SIPCommRadioButton();
            rdoUseWindows.setText(
                R.getI18NString("plugin.certconfig.WINDOWS_TRUSTSTORE"));
            rdoUseWindows.addActionListener(this);
            grpTrustStore.add(rdoUseWindows);
            pnlCertConfig.add(rdoUseWindows);

            if ("Windows-ROOT".equals(CertConfigActivator.getConfigService()
                .getProperty(CertificateService.PNAME_TRUSTSTORE_TYPE)))
            {
                rdoUseWindows.setSelected(true);
            }
            else
            {
                rdoUseJava.setSelected(true);
            }
        }

        // revocation options
        JPanel pnlRevocation = new TransparentPanel(new GridLayout(2, 1));
        pnlRevocation.setBorder(BorderFactory.createTitledBorder(
            R.getI18NString("plugin.certconfig.REVOCATION_TITLE")));
        add(pnlRevocation);

        chkEnableRevocationCheck = new SIPCommCheckBox(
            R.getI18NString("plugin.certconfig.REVOCATION_CHECK_ENABLED"));
        chkEnableRevocationCheck.addActionListener(this);
        chkEnableRevocationCheck.setSelected(
            "true".equals(
                System.getProperty("com.sun.net.ssl.checkRevocation")));
        pnlRevocation.add(chkEnableRevocationCheck);

        chkEnableOcsp = new SIPCommCheckBox(
            R.getI18NString("plugin.certconfig.REVOCATION_OCSP_ENABLED"));
        chkEnableOcsp.addActionListener(this);
        chkEnableOcsp.setSelected(
            "true".equals(Security.getProperty("ocsp.enable")));
        chkEnableOcsp.setEnabled(chkEnableRevocationCheck.isSelected());
        pnlRevocation.add(chkEnableOcsp);

        // Client certificate authentication list
        JPanel pnlCertList = new TransparentPanel(new BorderLayout());
        pnlCertList.setBorder(BorderFactory.createTitledBorder(
            R.getI18NString("plugin.certconfig.CERT_LIST_TITLE")));
        add(pnlCertList);

        JLabel lblNote = new JLabel();
        lblNote.setText(
            R.getI18NString("plugin.certconfig.CERT_LIST_DESCRIPTION"));
        lblNote.setBorder(new EmptyBorder(7, 7, 7, 7));
        pnlCertList.add(lblNote, BorderLayout.NORTH);

        tblCertList = new JTable();
        tblCertList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        tblCertList.getSelectionModel().addListSelectionListener(this);
        tblCertList.setModel(model);
        pnlCertList.add(new JScrollPane(tblCertList), BorderLayout.CENTER);

        TransparentPanel buttons = new TransparentPanel();
        buttons.setLayout(new FlowLayout(FlowLayout.RIGHT));
        pnlCertList.add(buttons, BorderLayout.SOUTH);

        cmdAdd = new JButton();
        cmdAdd.setText(R.getI18NString("service.gui.ADD"));
        cmdAdd.addActionListener(this);
        buttons.add(cmdAdd);

        cmdRemove = new JButton();
        cmdRemove.setText(R.getI18NString("service.gui.REMOVE"));
        cmdRemove.addActionListener(this);
        buttons.add(cmdRemove);

        cmdEdit = new JButton();
        cmdEdit.setText(R.getI18NString("service.gui.EDIT"));
        cmdEdit.addActionListener(this);
        buttons.add(cmdEdit);
    }

    // ------------------------------------------------------------------------
    // event handling
    // ------------------------------------------------------------------------
    public void valueChanged(ListSelectionEvent e)
    {
        int row = tblCertList.getSelectedRow();
        cmdRemove.setEnabled(row > -1);
        cmdEdit.setEnabled(row > -1);
    }

    public void actionPerformed(ActionEvent e)
    {
        if (e.getSource() == cmdAdd)
        {
            CertificateConfigEntry newEntry = new CertificateConfigEntry();
            CertConfigEntryDialog dlg = new CertConfigEntryDialog(newEntry);
            if (dlg.showDialog())
                CertConfigActivator.getCertService()
                    .setClientAuthCertificateConfig(newEntry);
        }
        if (e.getSource() == cmdRemove)
        {
            CertConfigActivator.getCertService()
                .removeClientAuthCertificateConfig(
                    model.getItem(tblCertList.getSelectedRow()).getId());
        }
        if (e.getSource() == cmdEdit)
        {
            CertificateConfigEntry entry =
                model.getItem(tblCertList.getSelectedRow());
            CertConfigEntryDialog dlg = new CertConfigEntryDialog(entry);
            if (dlg.showDialog())
                CertConfigActivator.getCertService()
                    .setClientAuthCertificateConfig(entry);
        }
        if (e.getSource() == rdoUseJava)
        {
            CertConfigActivator.getConfigService().setProperty(
                CertificateService.PNAME_TRUSTSTORE_TYPE,
                "meta:default");
            CertConfigActivator.getConfigService().removeProperty(
                CertificateService.PNAME_TRUSTSTORE_FILE);
            CertConfigActivator.getCredService().removePassword(
                CertificateService.PNAME_TRUSTSTORE_PASSWORD);
        }
        if (e.getSource() == rdoUseWindows)
        {
            CertConfigActivator.getConfigService().setProperty(
                CertificateService.PNAME_TRUSTSTORE_TYPE, "Windows-ROOT");
            CertConfigActivator.getConfigService().removeProperty(
                CertificateService.PNAME_TRUSTSTORE_FILE);
            CertConfigActivator.getCredService().removePassword(
                CertificateService.PNAME_TRUSTSTORE_PASSWORD);
        }
        if (e.getSource() == chkEnableRevocationCheck)
        {
            CertConfigActivator.getConfigService().setProperty(
                CertificateService.PNAME_REVOCATION_CHECK_ENABLED,
                chkEnableRevocationCheck.isSelected());

            String enabled = new Boolean(
                chkEnableRevocationCheck.isSelected()).toString();
            System.setProperty("com.sun.security.enableCRLDP", enabled);
            System.setProperty("com.sun.net.ssl.checkRevocation", enabled);
            chkEnableOcsp.setEnabled(chkEnableRevocationCheck.isSelected());
        }
        if (e.getSource() == chkEnableOcsp)
        {
            CertConfigActivator.getConfigService().setProperty(
                CertificateService.PNAME_OCSP_ENABLED,
                chkEnableOcsp.isSelected());

            Security.setProperty("ocsp.enable",
                new Boolean(chkEnableOcsp.isSelected()).toString());
        }
    }

    // ------------------------------------------------------------------------
    // Configuration form members
    // ------------------------------------------------------------------------
    public String getTitle()
    {
        return CertConfigActivator.R.getI18NString("plugin.certconfig.TITLE");
    }

    public byte[] getIcon()
    {
        return null;
    }

    public Object getForm()
    {
        return this;
    }

    public int getIndex()
    {
        return -1;
    }

    public boolean isAdvanced()
    {
        return true;
    }

}