1 package org.ibex.net.ssl;
7 import org.ibex.net.SSL;
8 import org.ibex.crypto.*;
10 public class SwingVerifyCallback extends JDialog implements SSL.VerifyCallback {
11 private Component owner;
13 public SwingVerifyCallback(Component owner) {
17 super(owner,"Certificate Verification",true);
20 JTextPane tp = new JTextPane();
21 doc = tp.getStyledDocument();
22 JScrollPane sp = new JScrollPane();
23 sp.setPreferredSize(new Dimension(400,300));
24 sp.setViewportView(tp);
25 sp.setAutoscrolls(false);
27 this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
28 JComponent bottom = new JPanel(new FlowLayout(FlowLayout.RIGHT));
29 JButton accept = new JButton("Accept");
30 JButton reject = new JButton("Reject");
31 accept.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {
35 reject.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) {
41 getContentPane().add(BorderLayout.CENTER,sp);
42 getContentPane().add(BorderLayout.SOUTH,bottom);
46 public static String prettyFingerprint(byte[] fp) {
47 StringBuffer sb = new StringBuffer(fp.length*3);
48 for(int i=0;i<fp.length;i++) {
49 if(i>0) sb.append(":");
50 sb.append("0123456789abcdef".charAt((fp[i] & 0xf0) >>> 4));
51 sb.append("0123456789abcdef".charAt((fp[i] & 0x0f) >>> 0));
56 public synchronized boolean checkCerts(X509.Certificate[] certs, String hostname, SSL.Exn exn) {
57 final boolean[] ret = new boolean[1];
58 JTextArea ta = new JTextArea();
59 ta.append("Subject: " + certs[0].subject + "\n");
60 ta.append("Issuer: " + certs[0].issuer + "\n");
61 ta.append("Start Date: " + certs[0].startDate + "\n");
62 ta.append("End Date: " + certs[0].endDate + "\n");
63 ta.append("MD5: " + prettyFingerprint(certs[0].getMD5Fingerprint()) + "\n");
64 ta.append("SHA1: " + prettyFingerprint(certs[0].getSHA1Fingerprint()) + "\n");
65 ta.setEditable(false);
67 JScrollPane sp = new JScrollPane(ta);
68 sp.setPreferredSize(new Dimension(300,150));
69 final Object[] messages = new Object[] {
70 "The SSL Certificate the server presented could not be verified.",
74 Runnable r = new Runnable() { public void run() {
75 int n = JOptionPane.showOptionDialog(
78 "Confirm Server Certificate",
80 JOptionPane.WARNING_MESSAGE,
82 new Object[] { "Accept", "Reject" },
87 if(SwingUtilities.isEventDispatchThread()) {
91 SwingUtilities.invokeAndWait(r);
92 } catch(Exception e) {