// Copyright 2000-2005 the Contributors, as shown in the revision logs. // Licensed under the Apache Public Source License 2.0 ("the License"). // You may not use this file except in compliance with the License. package org.ibex.net.ssl; import javax.swing.*; import java.awt.*; import org.ibex.net.SSL; import org.ibex.crypto.*; public class SwingVerifyCallback /*extends JDialog*/ implements SSL.VerifyCallback { //private Component owner; public SwingVerifyCallback(/*Component*/Object owner) { //this.owner = owner; } /* super(owner,"Certificate Verification",true); setModal(true); JTextPane tp = new JTextPane(); doc = tp.getStyledDocument(); JScrollPane sp = new JScrollPane(); sp.setPreferredSize(new Dimension(400,300)); sp.setViewportView(tp); sp.setAutoscrolls(false); this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); JComponent bottom = new JPanel(new FlowLayout(FlowLayout.RIGHT)); JButton accept = new JButton("Accept"); JButton reject = new JButton("Reject"); accept.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { accepted = true; hide(); }}); reject.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { accepted = false; hide(); }}); bottom.add(accept); bottom.add(reject); getContentPane().add(BorderLayout.CENTER,sp); getContentPane().add(BorderLayout.SOUTH,bottom); pack(); }*/ public static String prettyFingerprint(byte[] fp) { StringBuffer sb = new StringBuffer(fp.length*3); for(int i=0;i0) sb.append(":"); sb.append("0123456789abcdef".charAt((fp[i] & 0xf0) >>> 4)); sb.append("0123456789abcdef".charAt((fp[i] & 0x0f) >>> 0)); } return sb.toString(); } public synchronized boolean checkCerts(X509.Certificate[] certs, String hostname, SSL.Exn exn) { /* final boolean[] ret = new boolean[1]; JTextArea ta = new JTextArea(); ta.append("Subject: " + certs[0].subject + "\n"); ta.append("Issuer: " + certs[0].issuer + "\n"); ta.append("Start Date: " + certs[0].startDate + "\n"); ta.append("End Date: " + certs[0].endDate + "\n"); ta.append("MD5: " + prettyFingerprint(certs[0].getMD5Fingerprint()) + "\n"); ta.append("SHA1: " + prettyFingerprint(certs[0].getSHA1Fingerprint()) + "\n"); ta.setEditable(false); ta.setOpaque(false); JScrollPane sp = new JScrollPane(ta); sp.setPreferredSize(new Dimension(300,150)); final Object[] messages = new Object[] { "The SSL Certificate the server presented could not be verified.", exn.getMessage(), sp, }; Runnable r = new Runnable() { public void run() { int n = JOptionPane.showOptionDialog( owner, messages, "Confirm Server Certificate", 0, JOptionPane.WARNING_MESSAGE, null, new Object[] { "Accept", "Reject" }, "Accept"); ret[0] = n == 0; } }; if(SwingUtilities.isEventDispatchThread()) { r.run(); } else { try { SwingUtilities.invokeAndWait(r); } catch(Exception e) { e.printStackTrace(); } } return ret[0]; */ return false; } }