aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl/certificate
diff options
context:
space:
mode:
authorDamian Minkov <damencho@jitsi.org>2013-05-16 10:35:06 +0300
committerDamian Minkov <damencho@jitsi.org>2013-05-16 10:40:38 +0300
commit311d7512c909466e9c662481a5af7198717d8a8c (patch)
tree5a21a9a2b03fdf33ba4eb5f287e489dee2720d4a /src/net/java/sip/communicator/impl/certificate
parentf222bd9bb54a9edfa5a00b2152e62d92479d3f73 (diff)
downloadjitsi-311d7512c909466e9c662481a5af7198717d8a8c.zip
jitsi-311d7512c909466e9c662481a5af7198717d8a8c.tar.gz
jitsi-311d7512c909466e9c662481a5af7198717d8a8c.tar.bz2
Moves verify certificate dialog in separate service in order to use the certificate service in android.
Diffstat (limited to 'src/net/java/sip/communicator/impl/certificate')
-rw-r--r--src/net/java/sip/communicator/impl/certificate/CertificateServiceImpl.java41
-rw-r--r--src/net/java/sip/communicator/impl/certificate/CertificateVerificationActivator.java24
-rw-r--r--src/net/java/sip/communicator/impl/certificate/VerifyCertificateDialog.java285
3 files changed, 41 insertions, 309 deletions
diff --git a/src/net/java/sip/communicator/impl/certificate/CertificateServiceImpl.java b/src/net/java/sip/communicator/impl/certificate/CertificateServiceImpl.java
index fc059fe..1a1557c 100644
--- a/src/net/java/sip/communicator/impl/certificate/CertificateServiceImpl.java
+++ b/src/net/java/sip/communicator/impl/certificate/CertificateServiceImpl.java
@@ -18,7 +18,6 @@ import java.util.*;
import javax.net.ssl.*;
import javax.security.auth.callback.*;
-import javax.swing.*;
import net.java.sip.communicator.plugin.desktoputil.*;
import net.java.sip.communicator.service.certificate.*;
@@ -29,7 +28,7 @@ import net.java.sip.communicator.util.Logger;
import org.bouncycastle.asn1.*;
import org.bouncycastle.asn1.x509.*;
import org.bouncycastle.asn1.x509.X509Extension;
-import org.bouncycastle.x509.extension.*;
+import org.bouncycastle.x509.extension.*;
import org.jitsi.service.configuration.*;
import org.jitsi.service.resources.*;
import org.jitsi.util.*;
@@ -39,6 +38,7 @@ import org.jitsi.util.*;
* certificate when the automatic verification fails.
*
* @author Ingo Bauersachs
+ * @author Damian Minkov
*/
public class CertificateServiceImpl
implements CertificateService, PropertyChangeListener
@@ -182,7 +182,7 @@ public class CertificateServiceImpl
{
config.setProperty(PNAME_TRUSTSTORE_TYPE, "Windows-ROOT");
}
-
+
if(tsType != null && !"meta:default".equals(tsType))
System.setProperty("javax.net.ssl.trustStoreType", tsType);
else
@@ -827,9 +827,9 @@ public class CertificateServiceImpl
if (aiaBytes == null)
break;
- AuthorityInformationAccess aia
- = AuthorityInformationAccess.getInstance(
- X509ExtensionUtil.fromExtensionValue(aiaBytes));
+ AuthorityInformationAccess aia
+ = AuthorityInformationAccess.getInstance(
+ X509ExtensionUtil.fromExtensionValue(aiaBytes));
// the AIA may contain different URLs and types, try all
// of them
@@ -990,29 +990,22 @@ public class CertificateServiceImpl
if(config.getBoolean(PNAME_NO_USER_INTERACTION, false))
return DO_NOT_TRUST;
- final VerifyCertificateDialog dialog =
- new VerifyCertificateDialog(chain, null, message);
- try
+ if(CertificateVerificationActivator
+ .getCertificateDialogService() == null)
{
- // show the dialog in the swing thread and wait for the user
- // choice
- SwingUtilities.invokeAndWait(new Runnable()
- {
- public void run()
- {
- dialog.setVisible(true);
- }
- });
- }
- catch (Exception e)
- {
- logger.error("Cannot show certificate verification dialog", e);
+ logger.error("Missing CertificateDialogService by default " +
+ "will not trust!");
return DO_NOT_TRUST;
}
- if(!dialog.isTrusted)
+ VerifyCertificateDialogService.VerifyCertificateDialog dialog =
+ CertificateVerificationActivator.getCertificateDialogService()
+ .createDialog(chain, null, message);
+ dialog.setVisible(true);
+
+ if(!dialog.isTrusted())
return DO_NOT_TRUST;
- else if(dialog.alwaysTrustCheckBox.isSelected())
+ else if(dialog.isAlwaysTrustSelected())
return TRUST_ALWAYS;
else
return TRUST_THIS_SESSION_ONLY;
diff --git a/src/net/java/sip/communicator/impl/certificate/CertificateVerificationActivator.java b/src/net/java/sip/communicator/impl/certificate/CertificateVerificationActivator.java
index fbe5f6f..eeee7e3 100644
--- a/src/net/java/sip/communicator/impl/certificate/CertificateVerificationActivator.java
+++ b/src/net/java/sip/communicator/impl/certificate/CertificateVerificationActivator.java
@@ -43,6 +43,11 @@ public class CertificateVerificationActivator
private static CredentialsStorageService credService;
/**
+ * The service to create and show dialogs for user interaction.
+ */
+ private static VerifyCertificateDialogService certificateDialogService;
+
+ /**
* Called when this bundle is started.
*
* @param bc The execution context of the bundle being started.
@@ -130,4 +135,23 @@ public class CertificateVerificationActivator
}
return credService;
}
+
+ /**
+ * Returns the <tt>VerifyCertificateDialogService</tt>, through which we
+ * will use to create dialogs.
+ *
+ * @return the <tt>VerifyCertificateDialogService</tt>, through which we
+ * will use to create dialogs.
+ */
+ public static VerifyCertificateDialogService getCertificateDialogService()
+ {
+ if (certificateDialogService == null)
+ {
+ certificateDialogService
+ = ServiceUtils.getService(
+ bundleContext,
+ VerifyCertificateDialogService.class);
+ }
+ return certificateDialogService;
+ }
}
diff --git a/src/net/java/sip/communicator/impl/certificate/VerifyCertificateDialog.java b/src/net/java/sip/communicator/impl/certificate/VerifyCertificateDialog.java
deleted file mode 100644
index bf68514..0000000
--- a/src/net/java/sip/communicator/impl/certificate/VerifyCertificateDialog.java
+++ /dev/null
@@ -1,285 +0,0 @@
-/*
- * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package net.java.sip.communicator.impl.certificate;
-
-import java.awt.*;
-import java.awt.event.*;
-import java.security.cert.*;
-
-import javax.swing.*;
-
-import net.java.sip.communicator.plugin.desktoputil.*;
-
-import org.jitsi.service.resources.*;
-
-/**
- * Dialog that is shown to the user when a certificate verification failed.
- */
-class VerifyCertificateDialog
- extends SIPCommDialog
-{
- /**
- * Serial version UID.
- */
- private static final long serialVersionUID = 0L;
-
- private ResourceManagementService R = CertificateVerificationActivator
- .getResources();
-
- /**
- * The maximum width that we allow message dialogs to have.
- */
- private static final int MAX_MSG_PANE_WIDTH = 600;
-
- /**
- * The maximum height that we allow message dialogs to have.
- */
- private static final int MAX_MSG_PANE_HEIGHT = 800;
-
- /**
- * The certificate to show.
- */
- Certificate cert;
-
- /**
- * A text that describes why the verification failed.
- */
- String message;
-
- /**
- * The certificate panel.
- */
- TransparentPanel certPanel;
-
- /**
- * This dialog content pane.
- */
- TransparentPanel contentPane;
-
- /**
- * Whether certificate description is shown.
- */
- boolean certOpened = false;
-
- /**
- * The button to show certificate description.
- */
- JButton certButton;
-
- /**
- * The check box if checked permanently stored the certificate
- * which will be always trusted.
- */
- SIPCommCheckBox alwaysTrustCheckBox = new SIPCommCheckBox(
- R.getI18NString("service.gui.ALWAYS_TRUST"),
- false);
-
- /**
- * Whether the user trusts this certificate.
- */
- boolean isTrusted = false;
-
- /**
- * Creates the dialog.
- *
- * @param certs the certificates list
- * @param title The title of the dialog; when null the resource
- * <tt>service.gui.CERT_DIALOG_TITLE</tt> is loaded.
- * @param message A text that describes why the verification failed.
- */
- public VerifyCertificateDialog( Certificate[] certs,
- String title, String message)
- {
- super(false);
-
- setTitle(title != null ? title :
- R.getI18NString("service.gui.CERT_DIALOG_TITLE"));
- setModal(true);
-
- // for now shows only the first certificate from the chain
- this.cert = certs[0];
- this.message = message;
-
- setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
-
- init();
-
- setLocationRelativeTo(getParent());
- }
-
- /**
- * Inits the dialog initial display.
- */
- private void init()
- {
- this.getContentPane().setLayout(new BorderLayout());
-
- contentPane =
- new TransparentPanel(new BorderLayout(5, 5));
-
- TransparentPanel northPanel =
- new TransparentPanel(new BorderLayout(5, 5));
- northPanel.setBorder(BorderFactory.createEmptyBorder(10, 5, 5, 5));
-
- JLabel imgLabel = new JLabel(
- R.getImage("service.gui.icons.CERTIFICATE_WARNING"));
- imgLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
- northPanel.add(imgLabel, BorderLayout.WEST);
-
- StyledHTMLEditorPane descriptionPane = new StyledHTMLEditorPane();
- descriptionPane.setOpaque(false);
- descriptionPane.setEditable(false);
- descriptionPane.setContentType("text/html");
- descriptionPane.setText(message);
- descriptionPane.setSize(
- new Dimension(MAX_MSG_PANE_WIDTH, MAX_MSG_PANE_HEIGHT));
- int height = descriptionPane.getPreferredSize().height;
- descriptionPane.setPreferredSize(
- new Dimension(MAX_MSG_PANE_WIDTH, height));
-
- northPanel.add(descriptionPane, BorderLayout.CENTER);
- contentPane.add(northPanel, BorderLayout.NORTH);
-
- certPanel = new TransparentPanel();
- contentPane.add(certPanel, BorderLayout.CENTER);
-
- TransparentPanel southPanel =
- new TransparentPanel(new BorderLayout());
- contentPane.add(southPanel, BorderLayout.SOUTH);
-
- certButton = new JButton();
- certButton.setText(R.getI18NString("service.gui.SHOW_CERT"));
- certButton.addActionListener(new ActionListener() {
-
- public void actionPerformed(ActionEvent e)
- {
- actionShowCertificate();
- }
- });
- TransparentPanel firstButonPanel =
- new TransparentPanel(new FlowLayout(FlowLayout.LEFT));
- firstButonPanel.add(certButton);
- southPanel.add(firstButonPanel, BorderLayout.WEST);
-
- TransparentPanel secondButonPanel =
- new TransparentPanel(new FlowLayout(FlowLayout.RIGHT));
- JButton cancelButton = new JButton(
- R.getI18NString("service.gui.CANCEL"));
-
- cancelButton.addActionListener(new ActionListener() {
-
- public void actionPerformed(ActionEvent e)
- {
- actionCancel();
- }
- });
- JButton continueButton = new JButton(
- R.getI18NString("service.gui.CONTINUE_ANYWAY"));
-
- continueButton.addActionListener(new ActionListener() {
-
- public void actionPerformed(ActionEvent e)
- {
- actionContinue();
- }
- });
- secondButonPanel.add(continueButton);
- secondButonPanel.add(cancelButton);
- southPanel.add(secondButonPanel, BorderLayout.EAST);
-
- this.getContentPane().add(contentPane, BorderLayout.CENTER);
-
- pack();
- }
-
- /**
- * Action when shoe certificate button is clicked.
- */
- private void actionShowCertificate()
- {
- if(certOpened)
- {
- certPanel.removeAll();
- certButton.setText(R.getI18NString("service.gui.SHOW_CERT"));
-
- certPanel.revalidate();
- certPanel.repaint();
- pack();
- certOpened = false;
- setLocationRelativeTo(getParent());
- return;
- }
-
- certPanel.setLayout(new BorderLayout());
- certPanel.add(alwaysTrustCheckBox, BorderLayout.NORTH);
-
- Component certInfoPane = null;
- if(cert instanceof X509Certificate)
- {
- certInfoPane = new X509CertificatePanel((X509Certificate)cert);
- }
- else
- {
- JTextArea textArea = new JTextArea();
- textArea.setOpaque(false);
- textArea.setEditable(false);
- textArea.setText(cert.toString());
- certInfoPane = textArea;
- }
-
- final JScrollPane certScroll = new JScrollPane(certInfoPane);
- certScroll.setPreferredSize(new Dimension(300, 300));
- certPanel.add(certScroll, BorderLayout.CENTER);
-
- SwingUtilities.invokeLater(new Runnable()
- {
- public void run()
- {
- certScroll.getVerticalScrollBar().setValue(0);
- }
- });
-
- certButton.setText(R.getI18NString("service.gui.HIDE_CERT"));
-
- certPanel.revalidate();
- certPanel.repaint();
- // restore default values for prefered size,
- // as we have resized its components let it calculate
- // that size
- setPreferredSize(null);
- pack();
- certOpened = true;
- setLocationRelativeTo(getParent());
- }
-
- /**
- * Action when cancel button is clicked.
- */
- private void actionCancel()
- {
- isTrusted = false;
- dispose();
- }
-
- /**
- * Action when continue is clicked.
- */
- private void actionContinue()
- {
- isTrusted = true;
- dispose();
- }
-
- /**
- * Called when dialog closed or escape pressed.
- * @param isEscaped is escape button pressed.
- */
- protected void close(boolean isEscaped)
- {
- actionCancel();
- }
-}