📄 certificateinfopanel.java
字号:
/*** $Id: CertificateInfoPanel.java,v 1.4 2001/05/07 12:37:22 kunugi Exp $**** Copyright (c) 2000-2001 Jeff Gay** on behalf of ICEMail.org <http://www.icemail.org>** Copyright (c) 1998-2000 by Timothy Gerard Endres** ** This program is free software.** ** You may 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 should be included with this distribution in** the file LICENSE, as well as License.html. If the license is not** included with this distribution, you may find a copy at the FSF web** site at 'www.gnu.org' or 'www.fsf.org', or you may write to the** Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139 USA.**** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR** REDISTRIBUTION OF THIS SOFTWARE. */package org.icemail.mail.smime;import java.awt.Color;import java.awt.BorderLayout;import java.awt.GridBagLayout;import java.awt.GridBagConstraints;import java.awt.Insets;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.IOException;import java.math.BigInteger;import java.security.cert.CertificateException;import java.text.SimpleDateFormat;import java.util.Date;import java.util.Vector;import java.util.Enumeration;import javax.swing.*;import javax.swing.border.EmptyBorder;import javax.swing.tree.TreePath;import javax.swing.event.TreeSelectionEvent;import javax.swing.event.TreeSelectionListener;import iaik.asn1.ObjectID;import iaik.asn1.structures.AVA;import iaik.asn1.structures.AlgorithmID;import iaik.asn1.structures.Name;import iaik.asn1.structures.RDN;import iaik.pkcs.PKCSException;import iaik.x509.X509Certificate;import org.icemail.mail.Configuration;import org.icemail.smime.MissingCertificateException;import org.icemail.smime.PasswordCancelException;import org.icemail.util.AWTUtilities;public class CertificateInfoPanel extends JPanel implements ActionListener, TreeSelectionListener{ private CertDetailsPanel detailsPanel; private CertImportPanel importPanel; private CertRDNPanel rdnPanel; private CertDescriptionPanel descriptionPanel; private JTabbedPane tabbedPane; private X509Certificate currCert; private X509Certificate[] certChain; public CertificateInfoPanel( X509Certificate[] chain, boolean showImportPanel ) { super(); this.certChain = chain; this.setLayout( new BorderLayout() ); this.tabbedPane = new JTabbedPane(); this.detailsPanel = new CertDetailsPanel(); this.rdnPanel = new CertRDNPanel(); this.importPanel = showImportPanel ? new CertImportPanel() : null; this.descriptionPanel = new CertDescriptionPanel(); this.tabbedPane.add( "Certificate", this.detailsPanel ); if ( showImportPanel ) { this.tabbedPane.add( "Import", this.importPanel ); } this.tabbedPane.add( "RDN", this.rdnPanel ); this.tabbedPane.add( "Details", this.descriptionPanel ); this.add( BorderLayout.CENTER, this.tabbedPane ); } public void valueChanged( TreeSelectionEvent evt ) { X509Certificate cert = null; TreePath selPath = evt.getNewLeadSelectionPath(); if ( selPath != null ) { CertificateNode node = (CertificateNode) selPath.getLastPathComponent(); if ( node != null ) { cert = node.getCertificate(); } } this.setCurrentCertificate( cert ); } public void actionPerformed( ActionEvent evt ) { String command = evt.getActionCommand(); if ( command.equals( "IMPORTCERT" ) ) { this.importCurrentCertificate(); } } public void setCurrentCertificate( X509Certificate cert ) { this.currCert = cert; this.detailsPanel.setCurrentCertificate( cert ); this.rdnPanel.setCurrentCertificate( cert ); if ( this.importPanel != null ) { this.importPanel.setCurrentCertificate( cert ); } this.descriptionPanel.setCurrentCertificate( cert ); } public void importCurrentCertificate() { try { Name nm = (Name) this.currCert.getSubjectDN(); String emailAddr = nm.getRDN( ObjectID.emailAddress ); SecurityConfig cfgSec = SecurityConfig.getInstance(); X509Certificate cert = null; try { cert = cfgSec.getRecipientCertificate( emailAddr ); } catch ( MissingCertificateException ex ) { cert = null; } boolean doit = true; if ( cert != null ) { Object[] options = { "OK", "CANCEL" }; String msg = "There is already a certificate for '" + emailAddr + "'.\nDo you wish to replace it with this certificate?"; int op = JOptionPane.showOptionDialog( null, msg, "Replace?", JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null, options, options[1] ); if ( op == JOptionPane.NO_OPTION ) { doit = false; } } cfgSec.saveCertificate( emailAddr, this.currCert ); Configuration.getInstance().saveProperties(); } catch ( IOException ex ) { ex.printStackTrace(); } catch ( PKCSException ex ) { ex.printStackTrace(); } } private class CertDetailsPanel extends JPanel { private JLabel friendlyName; private JLabel before; private JLabel after; private JLabel algorithm; private JLabel serial; private JLabel finger; public CertDetailsPanel() { super(); this.setLayout( new GridBagLayout() ); this.setBorder( new EmptyBorder( 4, 4, 4, 4 ) ); int row = 0; JLabel lbl; EmptyBorder commonBorder = new EmptyBorder( 3, 4, 1, 4 ); lbl = new JLabel( "Friendly Name:" ); lbl.setForeground( Color.black ); lbl.setBorder( commonBorder ); AWTUtilities.constrain( this, lbl, GridBagConstraints.NONE, GridBagConstraints.EAST, 0, row, 1, 1, 0.0, 0.0 ); this.friendlyName = new JLabel( " " ); this.friendlyName.setHorizontalAlignment( JLabel.LEFT ); this.friendlyName.setForeground( Color.black ); this.friendlyName.setBorder( commonBorder ); // this.friendlyName.setBorder // ( new CompoundBorder // ( new EmptyBorder( 2, 0, 6, 0 ), // new CompoundBorder // ( new BevelBorder( BevelBorder.LOWERED ), // new EmptyBorder( 1, 2, 1, 2 ) ) ) ); AWTUtilities.constrain( this, this.friendlyName, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST, 1, row++, 1, 1, 1.0, 0.0 ); lbl = new JLabel( "Valid Between:" ); lbl.setForeground( Color.black ); lbl.setBorder( commonBorder ); AWTUtilities.constrain( this, lbl, GridBagConstraints.NONE, GridBagConstraints.EAST, 0, row, 1, 1, 0.0, 0.0, new Insets( 23, 0, 0, 0 ) ); this.before = new JLabel( " " ); this.before.setHorizontalAlignment( JLabel.LEFT ); this.before.setForeground( Color.black ); this.before.setBorder( commonBorder ); AWTUtilities.constrain( this, this.before, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST, 1, row++, 1, 1, 1.0, 0.0, new Insets( 23, 0, 0, 0 ) ); lbl = new JLabel( "And:" ); lbl.setForeground( Color.black ); lbl.setBorder( commonBorder ); AWTUtilities.constrain( this, lbl, GridBagConstraints.NONE,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -