Changeset 1574 for trunk/security/ExpressoCertMail/src/br/gov
- Timestamp:
- 11/03/09 16:23:16 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/security/ExpressoCertMail/src/br/gov/serpro/js/ParamReaderThread.java
r1174 r1574 17 17 import netscape.javascript.JSObject; 18 18 import org.bouncycastle.cms.CMSException; 19 20 19 21 20 public class ParamReaderThread extends Thread { … … 40 39 super.run(); 41 40 42 while (true){ 43 if (setup.getParameter("debug").equalsIgnoreCase("true")){ 44 System.out.println("Classe ParamReaderThread: pegando resultado."); 45 } 46 47 // processa o smime. Método sign implementado na classe DigitalCertificate 48 String smime = null; 49 DigitalCertificate dc = null; 50 51 try { 52 53 //Map<String, String> parsedData = parseData(resultado); 54 Map<String, String> parsedData = data.getMap(); 55 56 dc = new DigitalCertificate(this.parentFrame, this.setup); 57 dc.init(); 58 59 // Testa a operação e se for 60 if (parsedData.get("operation").equals("sign")){ 61 62 smime = dc.signMail(parsedData); 63 if (setup.getParameter("debug").equalsIgnoreCase("true")) { 64 System.out.println("\nMensagem assinada: " + smime); 65 } 66 67 } 68 else if (parsedData.get("operation").equals("decript")){ 69 String decryptedMsg = dc.cipherMail(parsedData); 70 if (setup.getParameter("debug").equalsIgnoreCase("true")) { 71 System.out.println("Mensagem decifrada: " + decryptedMsg); 72 } 73 if (decryptedMsg == null){ 74 smime = null; 75 } else { 76 smime = Base64Utils.base64Encode(decryptedMsg.getBytes()); 77 } 78 79 } 80 else { 81 throw new UnsupportedOperationException("Operation not supported: " + parsedData.get("operation")); 82 // Lança 83 } 84 85 // Retorna para a página 86 // se smime = null, a assinatura não funcionou 87 if (smime != null){ 88 page.call("appletReturn", new String[] {smime, parsedData.get("ID"), parsedData.get("operation"), parsedData.get("folder")}); 89 } 90 91 } catch (IOException e) { 92 //DialogBuilder.showMessageDialog(this.parentFrame, "Não foi possível carregar Token/SmartCard: senha incorreta", this.setup); 93 DialogBuilder.showMessageDialog(this.parentFrame, setup.getLang("ExpressoCertMailMessages", "ParamReaderThread001"), this.setup); 94 //JOptionPane.showMessageDialog(this.parentFrame, "Não foi possível carregar Token/SmartCard: senha incorreta", 95 // "Aviso", JOptionPane.INFORMATION_MESSAGE); 96 if (setup.getParameter("debug").equalsIgnoreCase("true")) { 41 while (true){ 42 if (setup.getParameter("debug").equalsIgnoreCase("true")){ 43 System.out.println("Classe ParamReaderThread: pegando resultado."); 44 } 45 46 // processa o smime. Método sign implementado na classe DigitalCertificate 47 String smime = null; 48 DigitalCertificate dc = null; 49 Map<String, String> parsedData = null; 50 51 try { 52 53 //Map<String, String> parsedData = parseData(resultado); 54 parsedData = data.getMap(); 55 56 dc = new DigitalCertificate(this.parentFrame, this.setup); 57 dc.init(); 58 59 // Testa a operação e se for 60 if (parsedData.get("operation").equals("sign")){ 61 62 smime = dc.signMail(parsedData); 63 if (setup.getParameter("debug").equalsIgnoreCase("true")) { 64 System.out.println("\nMensagem assinada: " + smime); 65 } 66 67 } 68 else if (parsedData.get("operation").equals("decript")){ 69 String decryptedMsg = dc.cipherMail(parsedData); 70 if (setup.getParameter("debug").equalsIgnoreCase("true")) { 71 System.out.println("Mensagem decifrada: " + decryptedMsg); 72 } 73 if (decryptedMsg == null){ 74 smime = null; 75 } else { 76 smime = Base64Utils.base64Encode(decryptedMsg.getBytes()); 77 } 78 79 } 80 else { 81 throw new UnsupportedOperationException("Operation not supported: " + parsedData.get("operation")); 82 // Lança 83 } 84 85 // Retorna para a página 86 // se smime = null, a assinatura não funcionou 87 88 } catch (IOException e) { 89 //DialogBuilder.showMessageDialog(this.parentFrame, "Não foi possível carregar Token/SmartCard: senha incorreta", this.setup); 90 DialogBuilder.showMessageDialog(this.parentFrame, setup.getLang("ExpressoCertMailMessages", "ParamReaderThread001"), this.setup); 91 //JOptionPane.showMessageDialog(this.parentFrame, "Não foi possível carregar Token/SmartCard: senha incorreta", 92 // "Aviso", JOptionPane.INFORMATION_MESSAGE); 93 if (setup.getParameter("debug").equalsIgnoreCase("true")) { 94 e.printStackTrace(); 95 } 96 } catch (GeneralSecurityException e) { 97 if (e.getCause() != null){ 98 DialogBuilder.showMessageDialog(this.parentFrame, "GeneralSecurityException: " + e.getCause().getMessage(), this.setup); 99 //JOptionPane.showMessageDialog(this.parentFrame, "GeneralSecurityException: " + e.getCause().getMessage(), 100 // "Aviso", JOptionPane.INFORMATION_MESSAGE); 101 } 102 else { 103 DialogBuilder.showMessageDialog(this.parentFrame, "GeneralSecurityException: " + e.getMessage(), this.setup); 104 //JOptionPane.showMessageDialog(this.parentFrame, "GeneralSecurityException: " + e.getMessage(), 105 // "Aviso", JOptionPane.INFORMATION_MESSAGE); 106 } 107 if (setup.getParameter("debug").equalsIgnoreCase("true")) { 108 e.printStackTrace(); 109 } 110 } catch (SMIMEException e) { 111 //DialogBuilder.showMessageDialog(this.parentFrame, "Erro no processamento da assinatura: " + e.getMessage(), this.setup); 112 DialogBuilder.showMessageDialog(this.parentFrame, setup.getLang("ExpressoCertMailMessages", "ParamReaderThread002"), this.setup); 113 //JOptionPane.showMessageDialog(this.parentFrame, "Erro no processamento da assinatura: " + e.getMessage(), 114 // "Aviso", JOptionPane.INFORMATION_MESSAGE); 115 if (setup.getParameter("debug").equalsIgnoreCase("true")) { 116 e.printStackTrace(); 117 } 118 } catch (MessagingException e) { 119 //DialogBuilder.showMessageDialog(this.parentFrame, "Erro no processamento da mensagem: " + e.getMessage(), this.setup); 120 DialogBuilder.showMessageDialog(this.parentFrame, setup.getLang("ExpressoCertMailMessages", "ParamReaderThread003"), this.setup); 121 //JOptionPane.showMessageDialog(this.parentFrame, "Erro no processamento da mensagem: " + e.getMessage(), 122 // "Aviso", JOptionPane.INFORMATION_MESSAGE); 123 if (setup.getParameter("debug").equalsIgnoreCase("true")) { 124 e.printStackTrace(); 125 } 126 } 127 catch (CMSException e){ 128 //DialogBuilder.showMessageDialog(this.parentFrame, "Erro ao decifrar mensagem: Detectado problema na integridade da mensagem cifrada!", this.setup); 129 DialogBuilder.showMessageDialog(this.parentFrame, setup.getLang("ExpressoCertMailMessages", "ParamReaderThread004"), this.setup); 130 //if (setup.getParameter("debug").equalsIgnoreCase("true")) { 131 Throwable cause = e.getCause(); 132 System.out.println(e.getClass().getCanonicalName() + ": " + e.getMessage()); 133 if (cause != null){ 134 System.out.println(cause.getClass().getCanonicalName() + ": " + cause.getMessage()); 135 } 97 136 e.printStackTrace(); 98 } 99 } catch (GeneralSecurityException e) { 100 if (e.getCause() != null){ 101 DialogBuilder.showMessageDialog(this.parentFrame, "GeneralSecurityException: " + e.getCause().getMessage(), this.setup); 102 //JOptionPane.showMessageDialog(this.parentFrame, "GeneralSecurityException: " + e.getCause().getMessage(), 103 // "Aviso", JOptionPane.INFORMATION_MESSAGE); 104 } 105 else { 106 DialogBuilder.showMessageDialog(this.parentFrame, "GeneralSecurityException: " + e.getMessage(), this.setup); 107 //JOptionPane.showMessageDialog(this.parentFrame, "GeneralSecurityException: " + e.getMessage(), 108 // "Aviso", JOptionPane.INFORMATION_MESSAGE); 109 } 110 if (setup.getParameter("debug").equalsIgnoreCase("true")) { 111 e.printStackTrace(); 112 } 113 } catch (SMIMEException e) { 114 //DialogBuilder.showMessageDialog(this.parentFrame, "Erro no processamento da assinatura: " + e.getMessage(), this.setup); 115 DialogBuilder.showMessageDialog(this.parentFrame, setup.getLang("ExpressoCertMailMessages", "ParamReaderThread002"), this.setup); 116 //JOptionPane.showMessageDialog(this.parentFrame, "Erro no processamento da assinatura: " + e.getMessage(), 117 // "Aviso", JOptionPane.INFORMATION_MESSAGE); 118 if (setup.getParameter("debug").equalsIgnoreCase("true")) { 119 e.printStackTrace(); 120 } 121 } catch (MessagingException e) { 122 //DialogBuilder.showMessageDialog(this.parentFrame, "Erro no processamento da mensagem: " + e.getMessage(), this.setup); 123 DialogBuilder.showMessageDialog(this.parentFrame, setup.getLang("ExpressoCertMailMessages", "ParamReaderThread003"), this.setup); 124 //JOptionPane.showMessageDialog(this.parentFrame, "Erro no processamento da mensagem: " + e.getMessage(), 125 // "Aviso", JOptionPane.INFORMATION_MESSAGE); 126 if (setup.getParameter("debug").equalsIgnoreCase("true")) { 127 e.printStackTrace(); 128 } 137 //} 138 } 139 catch (ProviderException e){ 140 //DialogBuilder.showMessageDialog(this.parentFrame, "Problema no acesso às informações do Token: " + e.getMessage(), this.setup); 141 DialogBuilder.showMessageDialog(this.parentFrame, setup.getLang("ExpressoCertMailMessages", "ParamReaderThread005"), this.setup); 142 //JOptionPane.showMessageDialog(this.parentFrame, "Problema no acesso às informações do Token: " + e.getMessage(), 143 // "Aviso", JOptionPane.INFORMATION_MESSAGE); 144 if (setup.getParameter("debug").equalsIgnoreCase("true")) { 145 e.printStackTrace(); 146 } 147 } 148 catch (UnsupportedOperationException e){ 149 // DialogBuilder.showMessageDialog(this.parentFrame, e.getMessage()); 150 if (setup.getParameter("debug").equalsIgnoreCase("true")) { 151 e.printStackTrace(); 152 } 153 } 154 catch (IllegalArgumentException e){ 155 //DialogBuilder.showMessageDialog(this.parentFrame, e.getMessage()); 156 if (setup.getParameter("debug").equalsIgnoreCase("true")) { 157 e.printStackTrace(); 158 } 159 } 160 catch (InterruptedException e){ 161 if (setup.getParameter("debug").equalsIgnoreCase("true")){ 162 System.out.println("Classe ParamReaderThread: Thread has been interrupted! Break."); 163 e.printStackTrace(); 164 } 165 break; 166 } 167 finally { 168 169 page.call("appletReturn", new String[]{smime, parsedData.get("ID"), parsedData.get("operation"), parsedData.get("folder")}); 170 171 } 172 173 dc.destroy(); 174 dc = null; 175 System.gc(); 176 Thread.yield(); 177 129 178 } 130 catch (CMSException e){ 131 //DialogBuilder.showMessageDialog(this.parentFrame, "Erro ao decifrar mensagem: Detectado problema na integridade da mensagem cifrada!", this.setup); 132 DialogBuilder.showMessageDialog(this.parentFrame, setup.getLang("ExpressoCertMailMessages", "ParamReaderThread004"), this.setup); 133 //if (setup.getParameter("debug").equalsIgnoreCase("true")) { 134 Throwable cause = e.getCause(); 135 System.out.println(e.getClass().getCanonicalName() + ": " + e.getMessage()); 136 if (cause != null){ 137 System.out.println(cause.getClass().getCanonicalName() + ": " + cause.getMessage()); 138 } 139 e.printStackTrace(); 140 //} 141 } 142 catch (ProviderException e){ 143 //DialogBuilder.showMessageDialog(this.parentFrame, "Problema no acesso às informações do Token: " + e.getMessage(), this.setup); 144 DialogBuilder.showMessageDialog(this.parentFrame, setup.getLang("ExpressoCertMailMessages", "ParamReaderThread005"), this.setup); 145 //JOptionPane.showMessageDialog(this.parentFrame, "Problema no acesso às informações do Token: " + e.getMessage(), 146 // "Aviso", JOptionPane.INFORMATION_MESSAGE); 147 if (setup.getParameter("debug").equalsIgnoreCase("true")) { 148 e.printStackTrace(); 149 } 150 } 151 catch (UnsupportedOperationException e){ 152 // DialogBuilder.showMessageDialog(this.parentFrame, e.getMessage()); 153 if (setup.getParameter("debug").equalsIgnoreCase("true")) { 154 e.printStackTrace(); 155 } 156 } 157 catch (IllegalArgumentException e){ 158 //DialogBuilder.showMessageDialog(this.parentFrame, e.getMessage()); 159 if (setup.getParameter("debug").equalsIgnoreCase("true")) { 160 e.printStackTrace(); 161 } 162 } 163 catch (InterruptedException e){ 164 if (setup.getParameter("debug").equalsIgnoreCase("true")){ 165 System.out.println("Classe ParamReaderThread: Thread has been interrupted! Break."); 166 e.printStackTrace(); 167 } 168 break; 169 } 170 171 dc.destroy(); 172 dc = null; 173 System.gc(); 174 Thread.yield(); 175 176 } 177 } 178 179 } 179 180 //TODO: Documentar o que recebe!!! 180 181 /*private Map<String, String> parseData(String expressoMailData){
Note: See TracChangeset
for help on using the changeset viewer.