Skip to content

Commit 8fc3d2c

Browse files
committed
Removed setting port for STARTTLS, fixed enabled on start checkboxes.
Added setUp method to SPARKSSLContext, removed acceptAll from Security tab as there is already Accept All checkbox in certificates tab.
1 parent 6c4c731 commit 8fc3d2c

File tree

5 files changed

+24
-34
lines changed

5 files changed

+24
-34
lines changed

core/src/main/java/org/jivesoftware/AccountCreationWizard.java

+1-9
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import org.jivesoftware.spark.util.SwingWorker;
3535
import org.jivesoftware.spark.util.log.Log;
3636
import org.jivesoftware.sparkimpl.certificates.SparkSSLContext;
37-
import org.jivesoftware.sparkimpl.certificates.SparkTrustManager;
3837
import org.jivesoftware.sparkimpl.settings.local.LocalPreferences;
3938
import org.jivesoftware.sparkimpl.settings.local.SettingsManager;
4039
import org.jxmpp.util.XmppStringUtils;
@@ -45,9 +44,6 @@
4544
import java.io.IOException;
4645
import java.security.KeyManagementException;
4746
import java.security.NoSuchAlgorithmException;
48-
import java.security.Provider;
49-
import java.security.SecureRandom;
50-
import java.security.Security;
5147

5248
/**
5349
* Allows the creation of accounts on an XMPP server.
@@ -362,14 +358,10 @@ private XMPPConnection getConnection() throws SmackException, IOException, XMPPE
362358
}
363359

364360
if (securityMode != ConnectionConfiguration.SecurityMode.disabled && !useOldSSL) {
365-
builder.setPort(5222);
366361
// This use STARTTLS which starts initially plain connection to upgrade it to TLS, it use the same port as
367362
// plain connections which is 5222.
368363
try {
369-
Provider bcProvider = new BouncyCastleJsseProvider();
370-
Security.addProvider(bcProvider);
371-
SSLContext context = SparkSSLContext.getInstance("TLS");
372-
context.init(null, SparkTrustManager.getTrustManagerList(), new SecureRandom());
364+
SSLContext context = SparkSSLContext.setUpContext();
373365
builder.setCustomSSLContext(context);
374366
builder.setSecurityMode( securityMode );
375367
} catch (NoSuchAlgorithmException | KeyManagementException e) {

core/src/main/java/org/jivesoftware/LoginDialog.java

+1-10
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.jivesoftware;
1818

19-
import org.bouncycastle.jsse.provider.BouncyCastleJsseProvider;
2019
import org.dom4j.Document;
2120
import org.dom4j.DocumentException;
2221
import org.dom4j.Element;
@@ -47,7 +46,6 @@
4746
import org.jivesoftware.spark.util.log.Log;
4847
import org.jivesoftware.sparkimpl.plugin.manager.Enterprise;
4948
import org.jivesoftware.sparkimpl.certificates.SparkSSLContext;
50-
import org.jivesoftware.sparkimpl.certificates.SparkTrustManager;
5149
import org.jivesoftware.sparkimpl.plugin.layout.LayoutSettings;
5250
import org.jivesoftware.sparkimpl.plugin.layout.LayoutSettingsManager;
5351
import org.jivesoftware.sparkimpl.settings.JiveInfo;
@@ -81,9 +79,6 @@
8179
import java.security.KeyManagementException;
8280
import java.security.NoSuchAlgorithmException;
8381
import java.security.Principal;
84-
import java.security.Provider;
85-
import java.security.SecureRandom;
86-
import java.security.Security;
8782
import java.util.*;
8883
import java.util.List;
8984

@@ -285,14 +280,10 @@ protected XMPPTCPConnectionConfiguration retrieveConnectionConfiguration() {
285280
}
286281

287282
if (securityMode != ConnectionConfiguration.SecurityMode.disabled && !useOldSSL) {
288-
builder.setPort(5222);
289283
// This use STARTTLS which starts initially plain connection to upgrade it to TLS, it use the same port as
290284
// plain connections which is 5222.
291285
try {
292-
Provider bcProvider = new BouncyCastleJsseProvider();
293-
Security.addProvider(bcProvider);
294-
SSLContext context = SparkSSLContext.getInstance("TLS");
295-
context.init(null, SparkTrustManager.getTrustManagerList(), new SecureRandom());
286+
SSLContext context = SparkSSLContext.setUpContext();
296287
builder.setCustomSSLContext(context);
297288
builder.setSecurityMode( securityMode );
298289
} catch (NoSuchAlgorithmException | KeyManagementException e) {

core/src/main/java/org/jivesoftware/spark/ui/login/CertificatesManagerSettingsPanel.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ public Component prepareRenderer(TableCellRenderer renderer, int rowIndex,
144144
checkCRL.addActionListener(this);
145145
checkOCSP.addActionListener(this);
146146
acceptRevoked.addActionListener(this);
147+
acceptExpired.setEnabled(!acceptAll.isSelected());
148+
acceptNotValidYet.setEnabled(!acceptAll.isSelected());
149+
acceptRevoked.setEnabled(!acceptAll.isSelected());
150+
acceptSelfSigned.setEnabled(!acceptAll.isSelected());
147151
checkCRL.setEnabled(!acceptRevoked.isSelected());
148152
checkOCSP.setEnabled(checkCRL.isSelected());
149153
allowSoftFail.setEnabled(checkOCSP.isSelected());
@@ -197,9 +201,6 @@ public void actionPerformed(ActionEvent e) {
197201
acceptExpired.setEnabled(true);
198202
acceptNotValidYet.setEnabled(true);
199203
acceptRevoked.setEnabled(true);
200-
checkCRL.setEnabled(true);
201-
checkOCSP.setEnabled(true);
202-
allowSoftFail.setEnabled(true);
203204

204205
}
205206
} else if (e.getSource() == showCert) {
@@ -213,7 +214,6 @@ public void actionPerformed(ActionEvent e) {
213214
if (checkCRL.isSelected()) {
214215

215216
checkOCSP.setEnabled(true);
216-
allowSoftFail.setEnabled(true);
217217
} else if (!checkCRL.isSelected()) {
218218

219219
checkOCSP.setSelected(false);

core/src/main/java/org/jivesoftware/spark/ui/login/SecurityLoginSettingsPanel.java

+1-11
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424

2525
import javax.swing.*;
2626
import java.awt.*;
27-
import java.awt.event.ActionEvent;
28-
import java.awt.event.ActionListener;
29-
3027
import static java.awt.GridBagConstraints.*;
3128

3229
/**
@@ -49,7 +46,6 @@ public class SecurityLoginSettingsPanel extends JPanel
4946
// Checkbox that toggles between 'old' style SSL (socket encryption, typically on port 5223), or STARTTLS. A check indicates 'old' behavior.
5047
private JCheckBox useSSLBox;
5148

52-
private JCheckBox acceptAllCertificatesBox;
5349
private JCheckBox disableHostnameVerificationBox;
5450

5551
public SecurityLoginSettingsPanel( LocalPreferences localPreferences, JDialog optionsDialog )
@@ -73,15 +69,13 @@ public SecurityLoginSettingsPanel( LocalPreferences localPreferences, JDialog op
7369
modeDisabledRadio.setToolTipText( Res.getString( "tooltip.encryptionmode.disabled" ) );
7470

7571
useSSLBox = new JCheckBox();
76-
acceptAllCertificatesBox = new JCheckBox();
7772
disableHostnameVerificationBox = new JCheckBox();
7873

7974
// .. Set labels/text for all the components.
8075
ResourceUtils.resButton( modeRequiredRadio, Res.getString( "radio.encryptionmode.required" ) );
8176
ResourceUtils.resButton( modeIfPossibleRadio, Res.getString( "radio.encryptionmode.ifpossible" ) );
8277
ResourceUtils.resButton( modeDisabledRadio, Res.getString( "radio.encryptionmode.disabled" ) );
8378
ResourceUtils.resButton( useSSLBox, Res.getString( "label.old.ssl" ) );
84-
ResourceUtils.resButton( acceptAllCertificatesBox, Res.getString( "checkbox.accept.all.certificates" ) );
8579
ResourceUtils.resButton( disableHostnameVerificationBox, Res.getString( "checkbox.disable.hostname.verification" ) );
8680

8781
// ... add the radio buttons to a group to make them interdependent.
@@ -94,7 +88,6 @@ public SecurityLoginSettingsPanel( LocalPreferences localPreferences, JDialog op
9488
modeDisabledRadio.addChangeListener( e -> {
9589
final boolean encryptionPossible = !modeDisabledRadio.isSelected();
9690
useSSLBox.setEnabled( encryptionPossible );
97-
acceptAllCertificatesBox.setEnabled( encryptionPossible );
9891
disableHostnameVerificationBox.setEnabled( encryptionPossible );
9992
} );
10093

@@ -103,7 +96,6 @@ public SecurityLoginSettingsPanel( LocalPreferences localPreferences, JDialog op
10396
modeIfPossibleRadio.setSelected( localPreferences.getSecurityMode() == ConnectionConfiguration.SecurityMode.ifpossible );
10497
modeDisabledRadio.setSelected( localPreferences.getSecurityMode() == ConnectionConfiguration.SecurityMode.disabled );
10598
useSSLBox.setSelected( localPreferences.isSSL() );
106-
acceptAllCertificatesBox.setSelected( localPreferences.isAcceptAllCertificates() );
10799
disableHostnameVerificationBox.setSelected( localPreferences.isDisableHostnameVerification() );
108100

109101
// ... place the components on the titled-border panel.
@@ -116,8 +108,7 @@ public SecurityLoginSettingsPanel( LocalPreferences localPreferences, JDialog op
116108
add( encryptionModePanel, new GridBagConstraints( 0, 0, 1, 1, 1.0, 0.0, NORTHWEST, HORIZONTAL, DEFAULT_INSETS, 0, 0 ) );
117109

118110
// ... place the other components under the titled-border panel.
119-
add( acceptAllCertificatesBox, new GridBagConstraints( 0, 1, 1, 1, 0.0, 0.0, NORTHWEST, HORIZONTAL, DEFAULT_INSETS, 0, 0 ) );
120-
add( disableHostnameVerificationBox, new GridBagConstraints( 0, 2, 1, 1, 0.0, 1.0, NORTHWEST, HORIZONTAL, DEFAULT_INSETS, 0, 0 ) );
111+
add( disableHostnameVerificationBox, new GridBagConstraints( 0, 1, 1, 1, 0.0, 1.0, NORTHWEST, HORIZONTAL, DEFAULT_INSETS, 0, 0 ) );
121112
}
122113

123114
public boolean validate_settings()
@@ -140,7 +131,6 @@ public void saveSettings()
140131
localPreferences.setSecurityMode( ConnectionConfiguration.SecurityMode.disabled );
141132
}
142133
localPreferences.setSSL( useSSLBox.isSelected() );
143-
localPreferences.setAcceptAllCertificates( acceptAllCertificatesBox.isSelected() );
144134
localPreferences.setDisableHostnameVerification( disableHostnameVerificationBox.isSelected() );
145135
SettingsManager.saveSettings();
146136
}

core/src/main/java/org/jivesoftware/sparkimpl/certificates/SparkSSLContext.java

+17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package org.jivesoftware.sparkimpl.certificates;
22

3+
import java.security.KeyManagementException;
4+
import java.security.NoSuchAlgorithmException;
5+
import java.security.NoSuchProviderException;
36
import java.security.Provider;
7+
import java.security.SecureRandom;
48

59
import javax.net.ssl.SSLContext;
610
import javax.net.ssl.SSLContextSpi;
@@ -12,4 +16,17 @@ protected SparkSSLContext(SSLContextSpi contextSpi, Provider provider, String pr
1216
// TODO Auto-generated constructor stub
1317
}
1418

19+
/**
20+
* Create SSLContext and initialize it
21+
*
22+
* @return initialized SSL context with BouncyCastleProvider
23+
* @throws KeyManagementException
24+
* @throws NoSuchAlgorithmException
25+
* @throws NoSuchProviderException
26+
*/
27+
public static SSLContext setUpContext() throws KeyManagementException, NoSuchAlgorithmException {
28+
SSLContext context = SparkSSLContext.getInstance("TLS");
29+
context.init(null, SparkTrustManager.getTrustManagerList(), new SecureRandom());
30+
return context;
31+
}
1532
}

0 commit comments

Comments
 (0)