This project has retired. For details please refer to its Attic page.
XmlSigApplet2 xref
View Javadoc
1   /*
2    * Copyright 2013 The Apache Software Foundation.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.apache.juddi.gui.dsig;
17  
18  import java.io.File;
19  import java.io.StringReader;
20  import java.io.StringWriter;
21  import java.security.Key;
22  import java.security.KeyStore;
23  import java.security.KeyStoreException;
24  import java.security.PrivateKey;
25  import java.security.cert.Certificate;
26  import java.security.cert.X509Certificate;
27  import java.util.Enumeration;
28  import java.util.Vector;
29  import java.util.logging.Level;
30  import java.util.logging.Logger;
31  import javax.swing.JOptionPane;
32  import javax.xml.bind.JAXB;
33  import netscape.javascript.JSObject;
34  import org.apache.juddi.v3.client.cryptor.DigSigUtil;
35  import org.apache.juddi.v3.client.cryptor.XmlUtils;
36  import org.uddi.api_v3.BindingTemplate;
37  import org.uddi.api_v3.BusinessEntity;
38  import org.uddi.api_v3.BusinessService;
39  import org.uddi.api_v3.TModel;
40  import org.w3c.dom.ls.DOMImplementationLS;
41  import org.w3c.dom.ls.LSSerializer;
42  
43  /**
44   * This is the current Digital Signature Applet used by juddi-gui. It can easily
45   * be adapted to sign any xml document
46   *
47   * @author <a href="mailto:alexoree@apache.org>Alex O'Ree</a>
48   */
49  public class XmlSigApplet2 extends java.applet.Applet {
50  
51     private static final long serialVersionUID = 1L;
52  
53     /**
54      * Initializes the applet XmlSigApplet2
55      */
56     @Override
57     public void init() {
58        try {
59           java.awt.EventQueue.invokeAndWait(new Runnable() {
60              public void run() {
61                 initComponents();
62              }
63           });
64        } catch (Exception ex) {
65           ex.printStackTrace();
66        }
67        setupCertificates();
68  
69     }
70  
71     /**
72      * this converts a xml document to a string for writing back to the browser
73      *
74      * @param doc
75      * @return string
76      */
77     public String getStringFromDoc(org.w3c.dom.Document doc) {
78        DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation();
79        LSSerializer lsSerializer = domImplementation.createLSSerializer();
80        lsSerializer.getDomConfig().setParameter("xml-declaration", false);
81        //lsSerializer.getDomConfig().setParameter("xml-declaration", false);
82  
83        return lsSerializer.writeToString(doc);
84     }
85     KeyStore keyStore = null;
86     KeyStore firefox = null;
87  
88     private void setupCertificates() {
89  
90        this.jList1.clearSelection();
91        this.jList1.removeAll();
92        Vector<String> certs = new Vector<String>();
93  
94        String keyStoreError = "";
95        //covers all modern browsers in windows
96        if (System.getProperty("os.name").startsWith("Windows")) {
97           try {
98              keyStore = KeyStore.getInstance("Windows-MY");
99              keyStore.load(null, null);
100          } catch (Exception ex) {
101             keyStoreError += "Error loading Windows cert store " + ex.getMessage() + "\n";
102 	            //ex.printStackTrace();
103             //JOptionPane.showMessageDialog(this, ex.getMessage());
104          }
105       }
106       //firefox keystore
107       if (keyStore == null) {
108 
109          try {
110 
111             String strCfg = System.getProperty("user.home") + File.separator
112                     + "jdk6-nss-mozilla.cfg";
113                 //   Provider p1 = new sun.security.pkcs11.SunPKCS11(strCfg);
114             //   Security.addProvider(p1);
115             keyStore = KeyStore.getInstance("PKCS11");
116             keyStore.load(null, "password".toCharArray());
117          } catch (Exception ex) {
118             //JOptionPane.showMessageDialog(this, ex.getMessage());
119             keyStoreError += "Error loading Firefox cert store " + ex.getMessage() + "\n";
120             //ex.printStackTrace();
121          }
122       }
123       //MacOS with Safari possibly others
124       if (keyStore == null) {
125          try {
126             keyStore = KeyStore.getInstance("KeychainStore");
127             keyStore.load(null, null);
128 
129          } catch (Exception ex) {
130                 //JOptionPane.showMessageDialog(this, ex.getMessage());
131             //ex.printStackTrace();
132             keyStoreError += "Error loading MACOS Key chain cert store " + ex.getMessage() + "\n";
133          }
134       }
135 
136       if (keyStore == null) {
137          System.err.println(keyStoreError);
138           jTextArea1.setText(keyStoreError);
139           jTabbedPane1.setSelectedIndex(2);
140          
141       } else {
142          try {
143             Enumeration<String> aliases = keyStore.aliases();
144 
145             while (aliases.hasMoreElements()) {
146                String a = aliases.nextElement();
147                X509Certificate certificate = (X509Certificate) keyStore.getCertificate(a);
148                //this is needed to test for access
149 
150                try {
151                   char[] cp = jPasswordField1.getPassword();
152                   if (cp != null && cp.length <= 0) {
153                      cp = null;
154                   }
155                   if (cp != null) {
156                      String s = new String(cp);
157                      s = s.trim();
158                      if ("".equalsIgnoreCase(s)) {
159                         cp = null;
160                      }
161                   }
162                   Key key = keyStore.getKey(a, cp);
163                   certs.add(a);
164 
165                } catch (Exception x) {
166                   System.out.println("error loading certificate " + a + " " + x.getMessage());
167                }
168             }
169 
170          } catch (Exception e) {
171             e.printStackTrace();
172             JOptionPane.showMessageDialog(this, e.getMessage());
173          }
174       }
175       jList1.setListData(certs);
176       if (!certs.isEmpty()) {
177          jList1.setSelectedIndex(0);
178       }
179    }
180 
181    /**
182     * This method is called from within the init() method to initialize the
183     * form. WARNING: Do NOT modify this code. The content of this method is
184     * always regenerated by the Form Editor.
185     */
186    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
187    private void initComponents() {
188 
189       buttonGroup1 = new javax.swing.ButtonGroup();
190       jPanel3 = new javax.swing.JPanel();
191       jButton3 = new javax.swing.JButton();
192       jTabbedPane1 = new javax.swing.JTabbedPane();
193       jPanel1 = new javax.swing.JPanel();
194       jButton1 = new javax.swing.JButton();
195       jScrollPane1 = new javax.swing.JScrollPane();
196       jList1 = new javax.swing.JList();
197       jButton2 = new javax.swing.JButton();
198       jLabel5 = new javax.swing.JLabel();
199       jPanel2 = new javax.swing.JPanel();
200       jLabel1 = new javax.swing.JLabel();
201       isIncludeSubjectName = new javax.swing.JCheckBox();
202       isIncludePublicKey = new javax.swing.JCheckBox();
203       isIncludeIssuer = new javax.swing.JCheckBox();
204       jLabel2 = new javax.swing.JLabel();
205       jTextFieldSigMethod = new javax.swing.JTextField();
206       jLabel3 = new javax.swing.JLabel();
207       jTextFieldDigestMethod = new javax.swing.JTextField();
208       jLabel4 = new javax.swing.JLabel();
209       jTextFieldc14n = new javax.swing.JTextField();
210       jPanel4 = new javax.swing.JPanel();
211       jScrollPane2 = new javax.swing.JScrollPane();
212       jTextArea1 = new javax.swing.JTextArea();
213       jPanel5 = new javax.swing.JPanel();
214       jToggleButton1 = new javax.swing.JToggleButton();
215       jPasswordField1 = new javax.swing.JPasswordField();
216       jLabel6 = new javax.swing.JLabel();
217       jLabel7 = new javax.swing.JLabel();
218 
219       jButton3.setText("jButton3");
220 
221       setLayout(new java.awt.BorderLayout());
222 
223       jButton1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
224       jButton1.setText("Digitally Sign");
225       jButton1.addActionListener(new java.awt.event.ActionListener() {
226          public void actionPerformed(java.awt.event.ActionEvent evt) {
227             jButton1ActionPerformed(evt);
228          }
229       });
230 
231       jScrollPane1.setViewportView(jList1);
232 
233       jButton2.setText("Show Certificate Details");
234       jButton2.addActionListener(new java.awt.event.ActionListener() {
235          public void actionPerformed(java.awt.event.ActionEvent evt) {
236             jButton2ActionPerformed(evt);
237          }
238       });
239 
240       jLabel5.setText("Available Certificates");
241 
242       javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
243       jPanel1.setLayout(jPanel1Layout);
244       jPanel1Layout.setHorizontalGroup(
245          jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
246          .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
247             .addContainerGap(70, Short.MAX_VALUE)
248             .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
249                .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE)
250                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE))
251             .addGap(82, 82, 82))
252          .addGroup(jPanel1Layout.createSequentialGroup()
253             .addContainerGap()
254             .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
255                .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING)
256                .addGroup(jPanel1Layout.createSequentialGroup()
257                   .addComponent(jLabel5)
258                   .addGap(0, 0, Short.MAX_VALUE)))
259             .addContainerGap())
260       );
261       jPanel1Layout.setVerticalGroup(
262          jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
263          .addGroup(jPanel1Layout.createSequentialGroup()
264             .addContainerGap()
265             .addComponent(jLabel5)
266             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
267             .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 222, javax.swing.GroupLayout.PREFERRED_SIZE)
268             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 46, Short.MAX_VALUE)
269             .addComponent(jButton2)
270             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
271             .addComponent(jButton1)
272             .addContainerGap())
273       );
274 
275       jTabbedPane1.addTab("Sign", jPanel1);
276 
277       jLabel1.setText("Advanced Settings");
278 
279       isIncludeSubjectName.setSelected(true);
280       isIncludeSubjectName.setText("Include your certificate's subject name");
281 
282       isIncludePublicKey.setSelected(true);
283       isIncludePublicKey.setText("Include your public key in the signature (recommended)");
284 
285       isIncludeIssuer.setText("Include your certificate's issuer and your certificate's serial");
286 
287       jLabel2.setText("Signature Method");
288 
289       jTextFieldSigMethod.setText("http://www.w3.org/2000/09/xmldsig#rsa-sha1");
290 
291       jLabel3.setText("Digest Method");
292 
293       jTextFieldDigestMethod.setText("http://www.w3.org/2000/09/xmldsig#sha1");
294       jTextFieldDigestMethod.addActionListener(new java.awt.event.ActionListener() {
295          public void actionPerformed(java.awt.event.ActionEvent evt) {
296             jTextFieldDigestMethodActionPerformed(evt);
297          }
298       });
299 
300       jLabel4.setText("Canonicalization Method");
301 
302       jTextFieldc14n.setText("http://www.w3.org/2001/10/xml-exc-c14n#");
303       jTextFieldc14n.addActionListener(new java.awt.event.ActionListener() {
304          public void actionPerformed(java.awt.event.ActionEvent evt) {
305             jTextFieldc14nActionPerformed(evt);
306          }
307       });
308 
309       javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
310       jPanel2.setLayout(jPanel2Layout);
311       jPanel2Layout.setHorizontalGroup(
312          jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
313          .addGroup(jPanel2Layout.createSequentialGroup()
314             .addContainerGap()
315             .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
316                .addComponent(jTextFieldDigestMethod)
317                .addComponent(jTextFieldSigMethod)
318                .addGroup(jPanel2Layout.createSequentialGroup()
319                   .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
320                      .addComponent(jLabel1)
321                      .addComponent(jLabel2)
322                      .addComponent(isIncludeIssuer)
323                      .addComponent(isIncludePublicKey)
324                      .addComponent(isIncludeSubjectName)
325                      .addComponent(jLabel3)
326                      .addComponent(jLabel4))
327                   .addGap(0, 0, Short.MAX_VALUE))
328                .addComponent(jTextFieldc14n, javax.swing.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE))
329             .addContainerGap())
330       );
331       jPanel2Layout.setVerticalGroup(
332          jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
333          .addGroup(jPanel2Layout.createSequentialGroup()
334             .addContainerGap()
335             .addComponent(jLabel1)
336             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
337             .addComponent(isIncludePublicKey)
338             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
339             .addComponent(isIncludeSubjectName)
340             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
341             .addComponent(isIncludeIssuer)
342             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
343             .addComponent(jLabel2)
344             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
345             .addComponent(jTextFieldSigMethod, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
346             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
347             .addComponent(jLabel3)
348             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
349             .addComponent(jTextFieldDigestMethod, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
350             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
351             .addComponent(jLabel4)
352             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
353             .addComponent(jTextFieldc14n, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
354             .addContainerGap(127, Short.MAX_VALUE))
355       );
356 
357       jTabbedPane1.addTab("Settings", jPanel2);
358 
359       jTextArea1.setColumns(20);
360       jTextArea1.setRows(5);
361       jScrollPane2.setViewportView(jTextArea1);
362 
363       javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
364       jPanel4.setLayout(jPanel4Layout);
365       jPanel4Layout.setHorizontalGroup(
366          jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
367          .addGroup(jPanel4Layout.createSequentialGroup()
368             .addContainerGap()
369             .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE)
370             .addContainerGap())
371       );
372       jPanel4Layout.setVerticalGroup(
373          jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
374          .addGroup(jPanel4Layout.createSequentialGroup()
375             .addContainerGap()
376             .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 340, Short.MAX_VALUE)
377             .addContainerGap())
378       );
379 
380       jTabbedPane1.addTab("Info", jPanel4);
381 
382       jToggleButton1.setText("OK");
383       jToggleButton1.addMouseListener(new java.awt.event.MouseAdapter() {
384          public void mouseClicked(java.awt.event.MouseEvent evt) {
385             jToggleButton1MouseClicked(evt);
386          }
387       });
388       jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
389          public void actionPerformed(java.awt.event.ActionEvent evt) {
390             jToggleButton1ActionPerformed(evt);
391          }
392       });
393 
394       jLabel6.setText("Password");
395 
396       jLabel7.setText("<html>For Firefox and certain browser and OS combinations, you may need to specify a password in order to get access to certificates. This is typically used for non-Windows users.</html>");
397 
398       javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
399       jPanel5.setLayout(jPanel5Layout);
400       jPanel5Layout.setHorizontalGroup(
401          jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
402          .addGroup(jPanel5Layout.createSequentialGroup()
403             .addContainerGap()
404             .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
405          .addGroup(jPanel5Layout.createSequentialGroup()
406             .addGap(34, 34, 34)
407             .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
408                .addComponent(jToggleButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
409                .addGroup(jPanel5Layout.createSequentialGroup()
410                   .addComponent(jLabel6)
411                   .addGap(18, 18, 18)
412                   .addComponent(jPasswordField1, javax.swing.GroupLayout.DEFAULT_SIZE, 182, Short.MAX_VALUE)))
413             .addGap(100, 100, 100))
414       );
415       jPanel5Layout.setVerticalGroup(
416          jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
417          .addGroup(jPanel5Layout.createSequentialGroup()
418             .addContainerGap()
419             .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
420             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
421             .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
422                .addComponent(jPasswordField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
423                .addComponent(jLabel6))
424             .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
425             .addComponent(jToggleButton1)
426             .addContainerGap(248, Short.MAX_VALUE))
427       );
428 
429       jTabbedPane1.addTab("Key Store", null, jPanel5, "");
430 
431       add(jTabbedPane1, java.awt.BorderLayout.CENTER);
432       jTabbedPane1.getAccessibleContext().setAccessibleName("Key Store");
433    }// </editor-fold>//GEN-END:initComponents
434 
435     private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
436 
437        //JPopupMenu jp = new JPopupMenu("Certificate Info");
438        String data = "No certificate selected";
439        try {
440           Certificate publickey = keyStore.getCertificate((String) jList1.getSelectedValue());
441           data = "Issuer: " + ((X509Certificate) publickey).getIssuerDN().getName() + System.getProperty("line.separator");
442           data += "Subject: " + ((X509Certificate) publickey).getSubjectDN().getName() + System.getProperty("line.separator");
443           data += "Valid From: " + ((X509Certificate) publickey).getNotBefore().toString() + System.getProperty("line.separator");
444           data += "Valid Until: " + ((X509Certificate) publickey).getNotAfter().toString() + System.getProperty("line.separator");
445           data += "Serial Number: " + ((X509Certificate) publickey).getSerialNumber() + System.getProperty("line.separator");
446        } catch (KeyStoreException ex) {
447           Logger.getLogger(XmlSigApplet2.class.getName()).log(Level.SEVERE, null, ex);
448        }
449        jTextArea1.setText(data);
450        jPanel4.setVisible(true);
451        jTabbedPane1.setSelectedIndex(2);
452     }//GEN-LAST:event_jButton2ActionPerformed
453 
454     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
455 
456        boolean error = false;
457        String signedXml = "error!";
458        JSObject window = JSObject.getWindow(this);
459        try {
460           if (keyStore == null || keyStore.size() == 0) {
461              error = true;
462              signedXml = "Unforunately, it looks as if you don't have any certificates to choose from.";
463              jTextArea1.setText(signedXml);
464              jTabbedPane1.setSelectedIndex(2);
465              return;
466           }
467        } catch (Exception ex) {
468           error = true;
469           signedXml = "Unforunately, it looks as if you don't have any certificates to choose from.";
470           jTextArea1.setText(signedXml);
471           jTabbedPane1.setSelectedIndex(2);
472        }
473        if (jList1.getSelectedValue() == null) {
474           error = true;
475           signedXml = "You must pick a certificate first";
476           jTextArea1.setText(signedXml);
477           jTabbedPane1.setSelectedIndex(2);
478        }
479 
480         //Object object2 = window.call("getBrowserName", null);
481        //Object object1 = window.call("getOsName", null);
482        Object object3 = window.call("getObjectType", null);
483         //String browserName = (String) object2;
484        //tring osName = (String) object2;
485        String objecttype = (String) object3;
486 
487        //get the xml
488        String xml = (String) window.call("getXml", new Object[]{});
489        Object j = null;
490 
491        if (objecttype.equalsIgnoreCase("business")) {
492           try {
493              StringReader sr = new StringReader(xml.trim());
494              j = (BusinessEntity) XmlUtils.unmarshal(sr, BusinessEntity.class);
495           } catch (Exception ex) {
496           }
497        }
498        if (objecttype.equalsIgnoreCase("service")) {
499           try {
500              StringReader sr = new StringReader(xml.trim());
501              j = (BusinessService) XmlUtils.unmarshal(sr, BusinessService.class);
502           } catch (Exception ex) {
503           }
504        }
505        if (objecttype.equalsIgnoreCase("bindingTemplate")) {
506           try {
507              StringReader sr = new StringReader(xml.trim());
508              j = (BindingTemplate) XmlUtils.unmarshal(sr, BindingTemplate.class);
509           } catch (Exception ex) {
510           }
511        }
512        if (objecttype.equalsIgnoreCase("tmodel")) {
513           try {
514              StringReader sr = new StringReader(xml.trim());
515              j = (TModel) XmlUtils.unmarshal(sr, TModel.class);
516           } catch (Exception ex) {
517           }
518        }
519 
520        if (j != null) {
521           try {
522              //sign it
523              org.apache.juddi.v3.client.cryptor.DigSigUtil ds = new DigSigUtil();
524              if (isIncludePublicKey.isSelected()) {
525                 ds.put(DigSigUtil.SIGNATURE_OPTION_CERT_INCLUSION_BASE64, "true");
526              }
527              if (isIncludeSubjectName.isSelected()) {
528                 ds.put(DigSigUtil.SIGNATURE_OPTION_CERT_INCLUSION_SUBJECTDN, "true");
529              }
530              if (isIncludeIssuer.isSelected()) {
531                 ds.put(DigSigUtil.SIGNATURE_OPTION_CERT_INCLUSION_SERIAL, "true");
532              }
533              ds.put(DigSigUtil.SIGNATURE_METHOD, jTextFieldSigMethod.getText());
534              ds.put(DigSigUtil.SIGNATURE_OPTION_DIGEST_METHOD, jTextFieldDigestMethod.getText());
535              ds.put(DigSigUtil.CANONICALIZATIONMETHOD, jTextFieldc14n.getText());
536 
537              char[] cp = jPasswordField1.getPassword();
538              if (cp != null && cp.length <= 0) {
539                 cp = null;
540              }
541              if (cp != null) {
542                 String s = new String(cp);
543                 s = s.trim();
544                 if ("".equalsIgnoreCase(s)) {
545                    cp = null;
546                 }
547              }
548              PrivateKey key = (PrivateKey) keyStore.getKey((String) jList1.getSelectedValue(), cp);
549              Certificate publickey = keyStore.getCertificate((String) jList1.getSelectedValue());
550 
551              j = ds.signUddiEntity(j, publickey, key);
552              ds.clear();
553              StringWriter sw = new StringWriter();
554              JAXB.marshal(j, sw);
555              signedXml = sw.toString();
556           } catch (Exception ex) {
557              error = true;
558              Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
559              signedXml = "Sorry I couldn't sign the data. " + ex.getMessage();
560           }
561        } else {
562           error=true;
563           signedXml = "Unable to determine which type of object that we're signing";
564        }
565 
566 
567        /*
568         try {
569         signedXml = this.sign(xml);
570         } catch (Exception ex) {
571         signedXml = ex.getMessage();
572         Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
573         }*/
574        if (error) {
575           jTextArea1.setText(signedXml);
576           jTabbedPane1.setSelectedIndex(2);
577        } else {
578           //write it back to the web page
579           window.call("writeXml", new Object[]{signedXml});
580 
581        }
582     }//GEN-LAST:event_jButton1ActionPerformed
583 
584     private void jTextFieldDigestMethodActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldDigestMethodActionPerformed
585        // TODO add your handling code here:
586     }//GEN-LAST:event_jTextFieldDigestMethodActionPerformed
587 
588     private void jTextFieldc14nActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextFieldc14nActionPerformed
589        // TODO add your handling code here:
590     }//GEN-LAST:event_jTextFieldc14nActionPerformed
591 
592    private void jToggleButton1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jToggleButton1MouseClicked
593       // TODO add your handling code here:
594    }//GEN-LAST:event_jToggleButton1MouseClicked
595 
596    private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton1ActionPerformed
597       setupCertificates();
598 
599 
600    }//GEN-LAST:event_jToggleButton1ActionPerformed
601    /**
602     * XML digital signature namespace
603     */
604    public final static String XML_DIGSIG_NS = "http://www.w3.org/2000/09/xmldsig#";
605 
606 
607    // Variables declaration - do not modify//GEN-BEGIN:variables
608    private javax.swing.ButtonGroup buttonGroup1;
609    private javax.swing.JCheckBox isIncludeIssuer;
610    private javax.swing.JCheckBox isIncludePublicKey;
611    private javax.swing.JCheckBox isIncludeSubjectName;
612    private javax.swing.JButton jButton1;
613    private javax.swing.JButton jButton2;
614    private javax.swing.JButton jButton3;
615    private javax.swing.JLabel jLabel1;
616    private javax.swing.JLabel jLabel2;
617    private javax.swing.JLabel jLabel3;
618    private javax.swing.JLabel jLabel4;
619    private javax.swing.JLabel jLabel5;
620    private javax.swing.JLabel jLabel6;
621    private javax.swing.JLabel jLabel7;
622    private javax.swing.JList jList1;
623    private javax.swing.JPanel jPanel1;
624    private javax.swing.JPanel jPanel2;
625    private javax.swing.JPanel jPanel3;
626    private javax.swing.JPanel jPanel4;
627    private javax.swing.JPanel jPanel5;
628    private javax.swing.JPasswordField jPasswordField1;
629    private javax.swing.JScrollPane jScrollPane1;
630    private javax.swing.JScrollPane jScrollPane2;
631    private javax.swing.JTabbedPane jTabbedPane1;
632    private javax.swing.JTextArea jTextArea1;
633    private javax.swing.JTextField jTextFieldDigestMethod;
634    private javax.swing.JTextField jTextFieldSigMethod;
635    private javax.swing.JTextField jTextFieldc14n;
636    private javax.swing.JToggleButton jToggleButton1;
637    // End of variables declaration//GEN-END:variables
638 }