1
2
3
4
5
6
7
8
9
10
11
12
13 package com.eviware.soapui.impl.wsdl.panels.request.components.editor.inspectors.ssl;
14
15 import java.awt.BorderLayout;
16 import java.beans.PropertyChangeEvent;
17 import java.beans.PropertyChangeListener;
18 import java.security.cert.Certificate;
19
20 import javax.swing.JComponent;
21 import javax.swing.JEditorPane;
22 import javax.swing.JPanel;
23 import javax.swing.JScrollPane;
24 import javax.swing.text.html.HTMLEditorKit;
25
26 import com.eviware.soapui.impl.wsdl.WsdlRequest;
27 import com.eviware.soapui.impl.wsdl.panels.request.components.editor.XmlLocation;
28 import com.eviware.soapui.impl.wsdl.panels.request.components.editor.inspectors.AbstractXmlInspector;
29 import com.eviware.soapui.impl.wsdl.submit.transports.http.SSLInfo;
30 import com.eviware.soapui.impl.wsdl.submit.transports.http.WsdlResponse;
31
32 public class ResponseSSLInspector extends AbstractXmlInspector implements PropertyChangeListener
33 {
34 private JEditorPane sslInfoPane;
35 private JPanel panel;
36 private WsdlRequest request;
37
38 protected ResponseSSLInspector( WsdlRequest request )
39 {
40 super( "SSL Info", "SSL Certificate Informaation for this response", true, SSLInspectorFactory.INSPECTOR_ID );
41 this.request = request;
42 request.addPropertyChangeListener( WsdlRequest.RESPONSE_PROPERTY, this );
43 }
44
45 public JComponent getComponent()
46 {
47 if( panel != null )
48 return panel;
49
50 panel = new JPanel( new BorderLayout());
51 sslInfoPane = new JEditorPane();
52 sslInfoPane.setEditorKit( new HTMLEditorKit() );
53 panel.add( new JScrollPane( sslInfoPane ));
54
55 return panel;
56 }
57
58 @Override
59 public void release()
60 {
61 super.release();
62
63 request.removePropertyChangeListener( WsdlRequest.RESPONSE_PROPERTY, this );
64 }
65
66 public void locationChanged( XmlLocation location )
67 {
68 }
69
70 private void updateSSLInfo( SSLInfo sslInfo )
71 {
72 String sslInfoTabTitle = "SSL Info";
73
74 if( sslInfo != null )
75 {
76 StringBuffer buf = new StringBuffer( "<html><body><table cellpadding=1 cellspacing=1 border=0>" );
77
78 buf.append( "<tr><td><b>CipherSuite:</b></td><td align=left valign=top>" ).
79 append( sslInfo.getCipherSuite().toString() ).append( "</td></tr>");
80
81 if( sslInfo.getLocalPrincipal() != null )
82 buf.append( "<tr><td><b>LocalPrincipal:</b></td><td align=left valign=top>" ).
83 append( sslInfo.getLocalPrincipal().getName() ).append( "</td></tr>");
84
85 Certificate[] localCertificates = sslInfo.getLocalCertificates();
86
87 if( localCertificates != null)
88 {
89 buf.append( "</table><table cellpadding=0 cellspacing=0 border=0>" );
90
91 int cnt = 1;
92 for( Certificate cert : localCertificates )
93 {
94 buf.append( "<tr><td><b>Local Certificate " ).append( cnt++ ).
95 append( ":</b><pre><font size=-1>" ).
96 append( cert.toString() ).append( "</font></pre></td></tr>");
97
98 }
99
100 buf.append( "</table><table cellpadding=1 cellspacing=1 border=0>" );
101 }
102
103 if( sslInfo.getPeerPrincipal() != null )
104 buf.append( "<tr><td><b>PeerPrincipal:</b></td><td align=left valign=top>" ).
105 append( sslInfo.getPeerPrincipal().toString() ).append( "</td></tr>");
106
107 Certificate[] peerCertificates = sslInfo.getPeerCertificates();
108 if( peerCertificates != null)
109 {
110 buf.append( "</table><table cellpadding=0 cellspacing=0 border=0>" );
111
112 int cnt = 1;
113 for( Certificate cert : peerCertificates )
114 {
115 buf.append( "<tr><td colspan=2><b>Peer Certificate " ).append( cnt++ ).
116 append( ":</b><pre><font size=-1>" ).
117 append( cert.toString() ).append( "</font></pre></td></tr>");
118 }
119
120 buf.append( "</table><table cellpadding=0 cellspacing=0 border=0>" );
121 }
122
123 buf.append( "</table></body></html>" );
124 sslInfoPane.setText( buf.toString() );
125
126 sslInfoTabTitle += " (" + sslInfo.getPeerCertificates().length + " certs)";
127 }
128
129 setTitle( sslInfoTabTitle );
130 }
131
132 public void propertyChange( PropertyChangeEvent evt )
133 {
134 WsdlResponse response = request.getResponse();
135 updateSSLInfo( response == null ? null : response.getSSLInfo() );
136 setEnabled( response != null && response.getSSLInfo() != null );
137 }
138 }