Index: branches/2.3/security/ExpressoCert/src/br/gov/serpro/i18n/ExpressoCertMessages_pt_BR.properties
===================================================================
--- branches/2.3/security/ExpressoCert/src/br/gov/serpro/i18n/ExpressoCertMessages_pt_BR.properties	(revision 5152)
+++ branches/2.3/security/ExpressoCert/src/br/gov/serpro/i18n/ExpressoCertMessages_pt_BR.properties	(revision 5152)
@@ -0,0 +1,14 @@
+# To change this template, choose Tools | Templates
+# and open the template in the editor.
+
+DigitalCertificate001 = Nenhum token/smartcard foi detectado.\nOpera\u00E7\u00E3o n\u00E3o p\u00F4de ser realizada!
+DigitalCertificate002 = N\u00E3o \u00E9 poss\u00EDvel ler este e-mail com o Certificado Digital apresentado!\nMotivo: Este e-mail n\u00E3o foi cifrado com a chave p\u00FAblica deste Certificado Digital.
+
+DialogBuilder001 = Entre com o seu PIN:
+DialogBuilder002 = Selecione o certificado:
+
+cancel = Cancelar
+pin = PIN
+ok = Ok
+certificate = Certificado
+select = Selecionar
Index: branches/2.3/security/ExpressoCert/src/br/gov/serpro/setup/Setup.java
===================================================================
--- branches/2.3/security/ExpressoCert/src/br/gov/serpro/setup/Setup.java	(revision 3394)
+++ branches/2.3/security/ExpressoCert/src/br/gov/serpro/setup/Setup.java	(revision 5152)
@@ -45,7 +45,9 @@
         for (String[] parameter : getParameterInfo()) {
             String parameterName = parameter[0];
-            String parameterValue;
+            String parameterValue = null;
 
-            parameterValue = this.currentApplet.getParameter(parameterName);
+            if (this.currentApplet != null){
+                parameterValue = this.currentApplet.getParameter(parameterName);
+            }
 
             System.out.println("parameter: "+parameterName+" value: "+parameterValue);
@@ -76,6 +78,19 @@
         currentLocale = this.buildLocale(parameters.getProperty("locale"));
         langResources = new HashMap<String, ResourceBundle>(2);
-        langResources.put("ExpressoCertMessages", ResourceBundle.getBundle("ExpressoCertMessages", currentLocale));
+        langResources.put("ExpressoCertMessages", ResourceBundle.getBundle("br.gov.serpro.i18n.ExpressoCertMessages", currentLocale));
 
+    }
+
+    public boolean setParameter(String parameter, String value){
+
+        if (parameter != null && value != null){
+
+            if (parameter.equals("debug") || parameter.equals("token") || parameter.equals("locale")){
+                this.parameters.setProperty(parameter, value);
+                return true;
+            }
+        }
+
+        return false;
     }
 
Index: branches/2.3/security/ExpressoCert/src/br/gov/serpro/cert/DigitalCertificate.java
===================================================================
--- branches/2.3/security/ExpressoCert/src/br/gov/serpro/cert/DigitalCertificate.java	(revision 5024)
+++ branches/2.3/security/ExpressoCert/src/br/gov/serpro/cert/DigitalCertificate.java	(revision 5152)
@@ -31,4 +31,6 @@
 import java.util.Properties;
 
+import java.util.logging.Level;
+import java.util.logging.Logger;
 import javax.crypto.Cipher;
 import javax.mail.Message;
@@ -55,6 +57,10 @@
 import br.gov.serpro.ui.DialogBuilder;
 import br.gov.serpro.util.Base64Utils;
+import java.io.BufferedInputStream;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
 import java.io.OutputStream;
 import java.io.OutputStreamWriter;
+import java.io.StringReader;
 import java.security.AlgorithmParameters;
 import java.security.cert.CertificateEncodingException;
@@ -65,4 +71,5 @@
 import javax.activation.MailcapCommandMap;
 import javax.mail.internet.ContentType;
+import javax.mail.internet.HeaderTokenizer;
 import javax.mail.internet.MimeUtility;
 import javax.mail.internet.PreencodedMimeBodyPart;
@@ -337,4 +344,108 @@
     }
 
+    static public String verifyP7S(MimeMessage body){
+        try {
+
+            MimeMultipart mm = (MimeMultipart) body.getContent();
+            externalLoop:for (int i = mm.getCount() - 1; i >= 0 ; i--){
+                MimeBodyPart mbp = (MimeBodyPart) mm.getBodyPart(i);
+                if (mbp.getContentType().contains("application/pkcs7-signature")){
+                    String[] contentTypeArray = body.getHeader("Content-Type");
+                    HeaderTokenizer hTokenizer = new HeaderTokenizer(contentTypeArray[0]);
+
+                    String boundary = "";
+                    HeaderTokenizer.Token t = hTokenizer.next();
+                    for (; t.getType() != HeaderTokenizer.Token.EOF; t = hTokenizer.next()){
+                        if (t.getType() == HeaderTokenizer.Token.ATOM && t.getValue().equalsIgnoreCase("boundary=")){
+                            break;
+                        }
+                    }
+                    t = hTokenizer.next();
+                    if (t.getType() == HeaderTokenizer.Token.QUOTEDSTRING){
+                        boundary = t.getValue();
+                    }
+
+                    InputStreamReader rawStreamReader = new InputStreamReader(mbp.getRawInputStream(), "iso-8859-1");
+
+                    StringBuilder signature = new StringBuilder(256);
+                    while (rawStreamReader.ready()){
+                        char[] buffer = new char[256];
+                        rawStreamReader.read(buffer);
+                        signature.append(buffer);
+                    }
+                    
+                    String[] array = signature.toString().split("\\r\\n|(?<!\\r)\\n");
+
+                    boolean badFormat = false;
+                    for (int j = 0; j < array.length; j++){
+                        if (array[j].length() > array[0].length()){
+                            badFormat = true;
+                            break;
+                        }
+                    }
+
+                    signature = null;
+                    array = null;
+
+                    if (badFormat){
+                        BufferedInputStream parsedIS = new BufferedInputStream(mbp.getInputStream());
+                        ByteArrayOutputStream baos = new ByteArrayOutputStream(parsedIS.available());
+                        
+                        while (parsedIS.available() > 0){
+                            byte[] buffer = new byte[parsedIS.available()];
+                            parsedIS.read(buffer);
+                            baos.write(buffer);
+                        }
+
+                        Enumeration headers = headers = mbp.getAllHeaderLines();
+                        String headersString = "";
+                        while (headers.hasMoreElements()){
+                            String header = (String) headers.nextElement();
+                            System.out.println("header: "+header);
+                            headersString += header+"\r\n";
+                        }
+
+                        String base64Encoded = Base64Utils.der2pem(baos.toByteArray(), false);
+
+                        mm.removeBodyPart(i);
+                        body.saveChanges();
+        
+                        ByteArrayOutputStream oStream = new ByteArrayOutputStream();
+
+                        oStream = new ByteArrayOutputStream();
+                        body.writeTo(oStream);
+
+                        BufferedReader reader = new BufferedReader(new StringReader(oStream.toString()));
+                        OutputStream os = new ByteArrayOutputStream();
+
+                        String line = "";
+                        while ((line = reader.readLine()) != null ){
+                            if (!line.equals("--"+boundary+"--")){
+                                os.write((line+"\r\n").getBytes("iso-8859-1"));
+                            }
+                        }
+
+                        return os.toString()
+                                +"--"+boundary+"\r\n"+headersString
+                                +"\r\n"+base64Encoded
+                                +"--"+boundary+"--\r\n";
+
+                    }
+
+                    break externalLoop;
+                }
+            }
+
+        } catch (IOException ex) {
+            Logger.getLogger(DigitalCertificate.class.getName()).log(Level.SEVERE, null, ex);
+        } catch (MessagingException ex) {
+            Logger.getLogger(DigitalCertificate.class.getName()).log(Level.SEVERE, null, ex);
+        } catch (ClassCastException ex) {
+            Logger.getLogger(DigitalCertificate.class.getName()).log(Level.SEVERE, null, ex);
+        }
+
+        return null;
+    }
+
     /**
      * Usado para assinar digitalmente um e-mail.
@@ -506,12 +617,17 @@
 	body.saveChanges();
 
-	ByteArrayOutputStream oStream = new ByteArrayOutputStream();
+        ByteArrayOutputStream oStream = new ByteArrayOutputStream();
 
 	oStream = new ByteArrayOutputStream();
-	body.writeTo(oStream);
-
-	body = null;
-	return oStream.toString("iso-8859-1");
-
+        body.writeTo(oStream);
+
+        String verified = DigitalCertificate.verifyP7S(body);
+        body = null;
+
+        if (verified != null){
+            return verified;
+        } else {
+            return oStream.toString("iso-8859-1");
+        }
     }
 
Index: branches/2.3/security/ExpressoCert/src/br/gov/serpro/util/Base64Utils.java
===================================================================
--- branches/2.3/security/ExpressoCert/src/br/gov/serpro/util/Base64Utils.java	(revision 1174)
+++ branches/2.3/security/ExpressoCert/src/br/gov/serpro/util/Base64Utils.java	(revision 5152)
@@ -131,21 +131,22 @@
     }
 
-    public static String der2pem(byte[] der){
 
-    	int begin = 0;
-    	int lineSize = 64;
-    	int end = lineSize;
+    public static String der2pem(byte[] der, boolean isCert){
+
+        int begin = 0;
+    	int lineSize = isCert ? 64 : 76;
+        int end = lineSize;
     	int bytesWriten = 0;
 
+        String CRLF = "\r\n";
+        String base64encoded = Base64Utils.base64Encode(der);
+        StringBuilder sb = new StringBuilder();
 
-    	String LF = "\n";
-    	String beginCertificate = "-----BEGIN CERTIFICATE-----" +LF;
-    	String endCertificate = "-----END CERTIFICATE-----";
+        String beginCertificate = "-----BEGIN CERTIFICATE-----" +CRLF;
+        String endCertificate = "-----END CERTIFICATE-----";
 
-    	String base64encoded = Base64Utils.base64Encode(der);
-
-    	StringBuilder sb = new StringBuilder();
-    	sb.append(beginCertificate);
-
+        if (isCert){
+            sb.append(beginCertificate);
+        }
 
     	do {
@@ -156,5 +157,5 @@
 
     		String subs = base64encoded.substring(begin, end);
-    		sb.append(subs + LF);
+    		sb.append(subs + CRLF);
     		bytesWriten += end - begin;
     		begin = end;
@@ -163,9 +164,14 @@
     	} while (bytesWriten != base64encoded.length());
 
-    	sb.append(endCertificate);
+        if (isCert){
+            sb.append(endCertificate);
+        }
 
     	return sb.toString();
 
+    }
 
+    public static String der2pem(byte[] der){
+        return Base64Utils.der2pem(der, false);
     }
 
