Index: /branches/2.3/phpgwapi/templates/default/login_default.php
===================================================================
--- /branches/2.3/phpgwapi/templates/default/login_default.php	(revision 5371)
+++ /branches/2.3/phpgwapi/templates/default/login_default.php	(revision 5898)
@@ -505,6 +505,6 @@
 		$cod_applet =
 
-/*    // com debug ativado
-            '<script type="text/javascript">
+    // com debug ativado
+/*            '<script type="text/javascript">
 					if (navigator.userAgent.match(\'MSIE\')){
 						document.write(\'<object style="display:yes;width:0;height:0;vertical-align:bottom;" id="login_applet" \' +
@@ -513,5 +513,5 @@
                                                 \'<param name="codebase" value="/security/">\' +
 						\'<param name="code" value="LoginApplet.class"> \' +
-						\'<param name="locale" value="' . $lang . '"> \' +
+						\'<param name="locale" value="' . $GLOBALS['phpgw']->translation->userlang . '"> \' +
 						\'<param name="mayscript" value="true"> \' + '
 						. $param1
@@ -521,5 +521,5 @@
 					}
 					else {
-						document.write(\'<embed style="display:yes;width:0;height:0;vertical-align:bottom;" id="login_applet" codebase="/security/" code="LoginApplet.class" locale="' . $lang . '"\' +
+						document.write(\'<embed style="display:yes;width:0;height:0;vertical-align:bottom;" id="login_applet" codebase="/security/" code="LoginApplet.class" locale="' . $GLOBALS['phpgw']->translation->userlang . '"\' +
 						\'archive="ExpressoCertLogin.jar,ExpressoCert.jar,commons-httpclient-3.1.jar,commons-logging-1.1.1.jar,commons-codec-1.3.jar,bcmail-jdk15-142.jar,mail.jar,activation.jar,bcprov-jdk15-142.jar" \' + '
 						. $param2
Index: /branches/2.3/preferences/handlecertificate.php
===================================================================
--- /branches/2.3/preferences/handlecertificate.php	(revision 5010)
+++ /branches/2.3/preferences/handlecertificate.php	(revision 5898)
@@ -156,55 +156,58 @@
                                                                                        ";
                     $cod_applet =
-        /*    // com debug ativado
-                '<script type="text/javascript">
-                                            if (navigator.userAgent.match(\'MSIE\')){
-                                                    document.write(\'<object style="display:yes;width:0;height:0;vertical-align:bottom;" id="login_applet" \' +
-                                                    \'classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"> \' +
-                                                    \'<param name="type" value="application/x-java-applet;version=1.5"> \' +
-                                                    \'<param name="code" value="LoginApplet.class"> \' +
-                                                    \'<param name="locale" value="' . $lang . '"> \' +
-                                                    \'<param name="mayscript" value="true"> \' + '
-                                                    . $param1
-                                                    . ' \'<param name="archive" value="ExpressoCertLogin.jar,ExpressoCert.jar,commons-httpclient-3.1.jar,commons-logging-1.1.1.jar,commons-codec-1.3.jar,bcmail-jdk15-142.jar,mail.jar,activation.jar,bcprov-jdk15-142.jar"> \' +
-                            \'<param name="debug" value="true"> \' +
-                                                    \'</object>\');
-                                            }
-                                            else {
-                                                    document.write(\'<embed style="display:yes;width:0;height:0;vertical-align:bottom;" id="login_applet" code="LoginApplet.class" locale="' . $lang . '"\' +
-                                                    \'archive="ExpressoCertLogin.jar,ExpressoCert.jar,commons-httpclient-3.1.jar,commons-logging-1.1.1.jar,commons-codec-1.3.jar,bcmail-jdk15-142.jar,mail.jar,activation.jar,bcprov-jdk15-142.jar" \' + '
-                                                    . $param2
-                                                    . ' \'type="application/x-java-applet;version=1.5" debug= "true" mayscript > \' +
-                                                    \'<noembed> \' +
-                                                    \'No Java Support. \' +
-                                                    \'</noembed> \' +
-                                                    \'</embed> \');
-                                            }
-                                    </script>';
-        */
-                // sem debug ativado
-                '<script type="text/javascript">
-                                            if (navigator.userAgent.match(\'MSIE\')){
-                                                    document.write(\'<object style="display:yes;width:0;height:0;vertical-align:bottom;" id="login_applet" \' +
-                                                    \'classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"> \' +
-                                                    \'<param name="type" value="application/x-java-applet;version=1.5"> \' +
-                                                    \'<param name="codebase" value="/security/">\' +
-                                                    \'<param name="code" value="LoginApplet.class"> \' +
-                                                    \'<param name="locale" value="' . $lang . '"> \' +
-                                                    \'<param name="mayscript" value="true"> \' + '
-                                                    . $param1
-                                                    . ' \'<param name="archive" value="ExpressoCertLogin.jar,ExpressoCert.jar,commons-httpclient-3.1.jar,commons-logging-1.1.1.jar,commons-codec-1.3.jar,bcmail-jdk15-142.jar,mail.jar,activation.jar,bcprov-jdk15-142.jar"> \' +
-                                                    \'</object>\');
-                                            }
-                                            else {
-                                                    document.write(\'<embed style="display:yes;width:0;height:0;vertical-align:bottom;" id="login_applet" codebase="/security/" code="LoginApplet.class" locale="' . $lang . '"\' +
-                                                    \'archive="ExpressoCertLogin.jar,ExpressoCert.jar,commons-httpclient-3.1.jar,commons-logging-1.1.1.jar,commons-codec-1.3.jar,bcmail-jdk15-142.jar,mail.jar,activation.jar,bcprov-jdk15-142.jar" \' + '
-                                                    . $param2
-                                                    . ' \'type="application/x-java-applet;version=1.5" mayscript > \' +
-                                                    \'<noembed> \' +
-                                                    \'No Java Support. \' +
-                                                    \'</noembed> \' +
-                                                    \'</embed> \');
-                                            }
-                                    </script>';
+/*
+// com debug ativado
+            '<script type="text/javascript">
+					if (navigator.userAgent.match(\'MSIE\')){
+						document.write(\'<object style="display:yes;width:0;height:0;vertical-align:bottom;" id="login_applet" \' +
+						\'classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"> \' +
+						\'<param name="type" value="application/x-java-applet;version=1.5"> \' +
+                                                \'<param name="codebase" value="/security/">\' +
+						\'<param name="code" value="LoginApplet.class"> \' +
+						\'<param name="locale" value="' . $GLOBALS['phpgw']->translation->userlang . '"> \' +
+						\'<param name="mayscript" value="true"> \' + '
+						. $param1
+						. ' \'<param name="archive" value="ExpressoCertLogin.jar,ExpressoCert.jar,commons-httpclient-3.1.jar,commons-logging-1.1.1.jar,commons-codec-1.3.jar,bcmail-jdk15-142.jar,mail.jar,activation.jar,bcprov-jdk15-142.jar"> \' +
+                        \'<param name="debug" value="true"> \' +
+						\'</object>\');
+					}
+					else {
+						document.write(\'<embed style="display:yes;width:0;height:0;vertical-align:bottom;" id="login_applet" codebase="/security/" code="LoginApplet.class" locale="' . $GLOBALS['phpgw']->translation->userlang . '"\' +
+						\'archive="ExpressoCertLogin.jar,ExpressoCert.jar,commons-httpclient-3.1.jar,commons-logging-1.1.1.jar,commons-codec-1.3.jar,bcmail-jdk15-142.jar,mail.jar,activation.jar,bcprov-jdk15-142.jar" \' + '
+						. $param2
+						. ' \'type="application/x-java-applet;version=1.5" debug= "true" mayscript > \' +
+						\'<noembed> \' +
+						\'No Java Support. \' +
+						\'</noembed> \' +
+						\'</embed> \');
+					}
+				</script>';
+*/
+            // sem debug ativado
+            '<script type="text/javascript">
+					if (navigator.userAgent.match(\'MSIE\')){
+						document.write(\'<object style="display:yes;width:0;height:0;vertical-align:bottom;" id="login_applet" \' +
+						\'classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"> \' +
+						\'<param name="type" value="application/x-java-applet;version=1.5"> \' +
+                                                \'<param name="codebase" value="/security/">\' +
+						\'<param name="code" value="LoginApplet.class"> \' +
+						\'<param name="locale" value="' . $GLOBALS['phpgw']->translation->userlang . '"> \' +
+						\'<param name="mayscript" value="true"> \' + '
+						. $param1
+						. ' \'<param name="archive" value="ExpressoCertLogin.jar,ExpressoCert.jar,commons-httpclient-3.1.jar,commons-logging-1.1.1.jar,commons-codec-1.3.jar,bcmail-jdk15-142.jar,mail.jar,activation.jar,bcprov-jdk15-142.jar"> \' +
+						\'</object>\');
+					}
+					else {
+						document.write(\'<embed style="display:yes;width:0;height:0;vertical-align:bottom;" id="login_applet" codebase="/security/" code="LoginApplet.class" locale="' . $GLOBALS['phpgw']->translation->userlang . '"\' +
+						\'archive="ExpressoCertLogin.jar,ExpressoCert.jar,commons-httpclient-3.1.jar,commons-logging-1.1.1.jar,commons-codec-1.3.jar,bcmail-jdk15-142.jar,mail.jar,activation.jar,bcprov-jdk15-142.jar" \' + '
+						. $param2
+						. ' \'type="application/x-java-applet;version=1.5" mayscript > \' +
+						\'<noembed> \' +
+						\'No Java Support. \' +
+						\'</noembed> \' +
+						\'</embed> \');
+					}
+				</script>';
+
                   echo $cod_applet;
                   echo '<form id="certificateForm" name="certificateForm" method="POST" action="handlecertificate.php" >';
Index: /branches/2.3/security/ExpressoCertLogin/src/LoginApplet.java
===================================================================
--- /branches/2.3/security/ExpressoCertLogin/src/LoginApplet.java	(revision 4124)
+++ /branches/2.3/security/ExpressoCertLogin/src/LoginApplet.java	(revision 5898)
@@ -176,10 +176,19 @@
                     case DigitalCertificate.KEYSTORE_DETECTED:
                         // Mostra PinNeedeDialog.
-                        String pin = DialogBuilder.showPinDialog((Frame) SwingUtilities.getAncestorOfClass(Frame.class, this), this.setup);
-                        
-                        if (pin != null) {
-                            dc.openKeyStore(pin.toCharArray());
+                        char[] pin = null;
+                        if (!DigitalCertificate.isUseMSCapi()){
+                            String sPin = DialogBuilder.showPinDialog((Frame) SwingUtilities.getAncestorOfClass(Frame.class, this), this.setup);
+                            if (sPin != null) {
+                                pin = sPin.toCharArray();
+                            }
+                        }
+                        if (DigitalCertificate.isUseMSCapi() || pin != null) {
+                            dc.openKeyStore(pin);
                             if (documentURL.getPath().matches(".*login.php$")){
-                                tryAgain = parseVercert(dc.getCredentials(pin, new URL(this.getCodeBase().getProtocol()+"://" +
+
+                                tryAgain = pin == null ? parseVercert(dc.getCredentials(null, new URL(this.getCodeBase().getProtocol()+"://" +
+                                    this.getCodeBase().getHost() + ":" + this.getCodeBase().getPort() +
+                                    "/security/vercert.php")), dc.getPEMCertificate()) :
+                                    parseVercert(dc.getCredentials(new String(pin), new URL(this.getCodeBase().getProtocol()+"://" +
                                     this.getCodeBase().getHost() + ":" + this.getCodeBase().getPort() +
                                     "/security/vercert.php")), dc.getPEMCertificate());
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 5386)
+++ /branches/2.3/security/ExpressoCert/src/br/gov/serpro/cert/DigitalCertificate.java	(revision 5898)
@@ -65,5 +65,7 @@
 import java.security.AlgorithmParameters;
 import java.security.cert.CertificateEncodingException;
+import java.text.DateFormat;
 import java.util.HashMap;
+import java.util.Locale;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -109,4 +111,5 @@
     // caso seja necessário.
     private int keystoreStatus;
+    private static boolean useMSCapi = false;
     public static final int KEYSTORE_DETECTED = 0;
     public static final int KEYSTORE_NOT_DETECTED = 1;
@@ -133,5 +136,5 @@
 	    HOME_SUBDIR = "\\dados de aplicativos\\sun\\java\\deployment\\security";
 	    EPASS_2000 = System.getenv("SystemRoot") + "\\system32\\ngp11v211.dll";
-	    //EPASS_2000 = System.getenv("ProgramFiles")+"\\Gemplus\\GemSafe Libraries\\BIN\\gclib.dll";
+            DigitalCertificate.useMSCapi = true;
 	}
 
@@ -201,4 +204,8 @@
     }
 
+    public static boolean isUseMSCapi() {
+        return useMSCapi;
+    }
+
     public KeyStore getKeyStore() {
 	return keyStore;
@@ -219,33 +226,31 @@
     public void destroy() {
 
-	AuthProvider ap = null;
-
-	if (this.setup.getParameter("debug").equalsIgnoreCase("true")) {
-	    System.out.println("logout no provider");
-	}
-	if (keyStore != null) {
-	    ap = (AuthProvider) this.keyStore.getProvider();
-	}
-
-	if (ap != null) {
-	    try {
-		ap.logout();
-	    } catch (LoginException e) {
-		if (this.setup.getParameter("debug").equalsIgnoreCase("true")) {
-		    e.printStackTrace();
-		}
-	    }
-	}
-
-	if (providerName != null) {
-	    Security.removeProvider(providerName);
-	}
-
-	this.cert = null;
+        AuthProvider ap = null;
+
+        if (this.setup.getParameter("debug").equalsIgnoreCase("true")) {
+            System.out.println("logout no provider");
+        }
+        
+        if (this.keyStore != null && this.keyStore.getProvider() instanceof AuthProvider) {
+            ap = (AuthProvider) this.keyStore.getProvider();
+        
+            try {
+                ap.logout();
+            } catch (LoginException e) {
+                if (this.setup.getParameter("debug").equalsIgnoreCase("true")) {
+                    e.printStackTrace();
+                }
+            }
+
+            if (this.providerName != null) {
+                Security.removeProvider(providerName);
+            }
+        }
+        
+        this.cert = null;
         this.selectedCertificateAlias = null;
-	this.keyStore = null;
-	this.pkcs12Input = null;
-	this.providerName = null;
-
+        this.keyStore = null;
+        this.pkcs12Input = null;
+        this.providerName = null;
     }
 
@@ -262,6 +267,7 @@
     public int init() {
 
-	// TODO: Usar dentro de um "loop" para testar outros modelos de tokens.
-	this.tokens = new TokenCollection(setup);
+        if (!DigitalCertificate.useMSCapi){
+            this.tokens = new TokenCollection(setup);
+        }
 
         Provider[] providers = Security.getProviders();
@@ -272,5 +278,5 @@
         }
 
-        int interfaceType = DigitalCertificate.KEYSTORE_DETECTED;
+        int interfaceType = DigitalCertificate.KEYSTORE_NOT_DETECTED;
 
 	try {
@@ -312,5 +318,6 @@
 	    try {
 		// Testa se uma keystore já foi carregada previamente
-		if (keyStore.getType().equalsIgnoreCase("pkcs11")) {
+		if (keyStore.getType().equalsIgnoreCase("pkcs11") 
+                        || keyStore.getType().equalsIgnoreCase("windows-my")) {
 		    keyStore.load(null, null);
 		} else {
@@ -319,5 +326,5 @@
 
 		// Se chegou aqui KeyStore está liberada, mostrar tela de login sem pedir o pin.
-		this.keystoreStatus = DigitalCertificate.KEYSTORE_ALREADY_LOADED;
+		this.keystoreStatus = DigitalCertificate.useMSCapi ? DigitalCertificate.KEYSTORE_DETECTED : DigitalCertificate.KEYSTORE_ALREADY_LOADED ;
 
 	    } catch (ProviderException e) {
@@ -402,5 +409,4 @@
                         while (headers.hasMoreElements()){
                             String header = (String) headers.nextElement();
-                            System.out.println("header: "+header);
                             headersString += header+"\r\n";
                         }
@@ -455,16 +461,35 @@
     public String signMail(Map<String, String> data) throws IOException, GeneralSecurityException, SMIMEException, MessagingException {
 
-	Key privateKey = null;
+        Key privateKey = null;
 	if (this.keystoreStatus == DigitalCertificate.KEYSTORE_DETECTED) {
-	    String pin = DialogBuilder.showPinDialog(this.parentFrame, this.setup);
-	    if (pin != null) {
-		openKeyStore(pin.toCharArray());
-                if (this.selectedCertificateAlias == null){
+            char[] pin = null;
+            if (!DigitalCertificate.useMSCapi) {
+                String sPin = DialogBuilder.showPinDialog(this.parentFrame, this.setup);
+                if (sPin != null) {
+                    pin = sPin.toCharArray();
+                }
+                else {
                     return null;
                 }
-                privateKey = this.keyStore.getKey(this.selectedCertificateAlias, pin.toCharArray());
-	    } else {
-		return null;
-	    }
+            }
+
+            try {
+                openKeyStore(pin);
+            }
+            catch (Exception e)
+            {
+                if (e instanceof IOException){
+                    throw new IOException(e);
+                }
+                else if (e instanceof GeneralSecurityException){
+                    throw new GeneralSecurityException(e);
+                }
+            }
+            
+            if (this.selectedCertificateAlias == null){
+                return null;
+            }
+            privateKey = this.keyStore.getKey(this.selectedCertificateAlias, pin);
+	    
 	} /*
 	else if (this.keystoreStatus == DigitalCertificate.KEYSTORE_ALREADY_LOADED){
@@ -671,14 +696,21 @@
 	Key privateKey = null;
 	if (this.keystoreStatus == DigitalCertificate.KEYSTORE_DETECTED) {
-	    String pin = DialogBuilder.showPinDialog(this.parentFrame, this.setup);
-	    if (pin != null) {
-		openKeyStore(pin.toCharArray());
-                if (this.selectedCertificateAlias == null){
-                    return null;
-                }
-                privateKey = this.keyStore.getKey(this.selectedCertificateAlias, pin.toCharArray());
-	    } else {
-		return null;
-	    }
+            char[] pin = null;
+	    if (!DigitalCertificate.useMSCapi) {
+               String sPin = DialogBuilder.showPinDialog(this.parentFrame, this.setup);
+               if (sPin != null) {
+                   pin = sPin.toCharArray();
+               }
+               else {
+                   return null;
+               }
+            }
+
+            openKeyStore(pin);
+            if (this.selectedCertificateAlias == null){
+                return null;
+            }
+            privateKey = this.keyStore.getKey(this.selectedCertificateAlias, pin);
+	    
 	} /*
 	else if (this.keystoreStatus == DigitalCertificate.KEYSTORE_ALREADY_LOADED){
@@ -847,5 +879,5 @@
 		if (Integer.parseInt(resposta[0].trim()) == 0) {
 		    // Se código da resposta for zero, decripta a senha criptografada do usuário
-		    resposta[2] = decriptPassword(resposta[2].trim(), pin);
+		    resposta[2] = decryptPassword(resposta[2].trim(), pin);
 		}
 	    }
@@ -875,18 +907,24 @@
      * @throws GeneralSecurityException se algum problema ocorrer na decriptação da senha.
      */
-    public String decriptPassword(String encodedPassword, String pin) throws GeneralSecurityException {
-
-	String decodedPassword = new String();
-
-	// Pega a chave privada do primeiro certificado armazenado na KeyStore
-	Key privateKey = this.keyStore.getKey(selectedCertificateAlias, pin.toCharArray());
+    public String decryptPassword(String encodedPassword, String pin) throws GeneralSecurityException, IOException {
+
+        String decodedPassword = new String();
+
+        // Pega a chave privada do primeiro certificado armazenado na KeyStore
+	Key privateKey = pin == null ? this.keyStore.getKey(selectedCertificateAlias, null) :
+            this.keyStore.getKey(selectedCertificateAlias, pin.toCharArray());
+
+        Cipher dcipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
+        dcipher.init(Cipher.DECRYPT_MODE, privateKey);
 
 	// Inicializa os cipher com os parâmetros corretos para realizar a decriptação
-	Cipher dcipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
-	dcipher.init(Cipher.DECRYPT_MODE, privateKey);
+//	Cipher dcipher = DigitalCertificate.useMSCapi ?
+//            Cipher.getInstance("RSA/ECB/PKCS1Padding", Security.getProvider(this.providerName))
+//            : Cipher.getInstance("RSA/ECB/PKCS1Padding");
+//	dcipher.init(Cipher.DECRYPT_MODE, privateKey);
 
 	// Decodifica a senha em base64 e a decripta
-	decodedPassword = new String(dcipher.doFinal(Base64Utils.base64Decode(encodedPassword)));
-
+        decodedPassword = new String(dcipher.doFinal(Base64Utils.base64Decode(encodedPassword)));
+       
 	return decodedPassword.trim();
 
@@ -902,9 +940,22 @@
 
         try{
-            if (this.setup.getParameter("debug").equalsIgnoreCase("true")) {
-                System.out.println("Carregando provider: PKCS11");
-            }
-            this.keyStore = KeyStore.getInstance("PKCS11");
-            this.providerName = keyStore.getProvider().getName();
+            if (!DigitalCertificate.useMSCapi) {
+                if (this.setup.getParameter("debug").equalsIgnoreCase("true")) {
+                    System.out.println("Carregando provider: PKCS11");
+                }
+                this.keyStore = KeyStore.getInstance("PKCS11");
+                this.providerName = keyStore.getProvider().getName();
+            }
+            else {
+                if (this.setup.getParameter("debug").equalsIgnoreCase("true")) {
+                    System.out.println("Carregando provider: SunMSCAPI");
+                }
+                this.keyStore = KeyStore.getInstance("Windows-MY", "SunMSCAPI");
+                this.providerName = this.keyStore.getProvider().getName();
+
+                if (this.setup.getParameter("debug").equalsIgnoreCase("true")) {
+                    System.out.println(keyStore.getProvider().getName() +" carregado!");
+                }
+            }
         }
         catch (GeneralSecurityException kex){
@@ -921,8 +972,62 @@
     }
 
+    Map<String, String> getAliasesList() throws IOException, KeyStoreException{
+
+        if (setup.getParameter("debug").equalsIgnoreCase("true")) {
+            System.out.println("Getting Aliases");
+        }
+
+        Map<String, String> aliases = new HashMap<String, String>();
+      
+        for (Enumeration<String> al = this.keyStore.aliases(); al.hasMoreElements();){
+            String alias = al.nextElement();
+            X509Certificate certObj = (X509Certificate) this.keyStore.getCertificate(alias);
+            
+            StringBuilder selector = new StringBuilder();
+            // get more info to generate the value
+            // Subject's CN / Issuer's CN / Expiration Data
+            String subject = certObj.getSubjectX500Principal().getName();
+            int pInicial = subject.indexOf('=')+1;
+            int pFinal = subject.indexOf(',', pInicial);
+            selector.append(subject.substring(pInicial, pFinal)+" | ");
+
+            String issuer = certObj.getIssuerX500Principal().getName();
+            pInicial = issuer.indexOf('=')+1;
+            pFinal = issuer.indexOf(',', pInicial);
+            selector.append(issuer.substring(pInicial, pFinal)+" | ");
+
+            // TODO: get the system locale
+            Locale locale = new Locale("pt", "BR");
+            DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
+            selector.append(df.format(certObj.getNotAfter())+" | ");
+
+            selector.append("("+certObj.getSerialNumber()+")");
+
+            aliases.put(alias, selector.toString());
+            
+        }
+
+        return aliases;
+    }
+
+//    public void removeCertificate() throws IOException {
+//        Token token = tokens.getRegisteredTokens().iterator().next();
+//        token.removeCertificate();
+//    }
+//
+//    public void writeCerts(char[] pin, LinkedHashMap<char[], Certificate> certs) throws IOException{
+//        Token token = tokens.getRegisteredTokens().iterator().next();
+//        token.getAliases();
+//
+//        for (Map.Entry<char[], Certificate> entry : certs.entrySet()) {
+//            token.writeCert(pin, entry.getKey(), entry.getValue());
+//        }
+//    }
+
     /**
      *  Abre a keystore passando o pin
      *  @param pin pin para acessar o Token
      */
+    @SuppressWarnings("empty-statement")
     public void openKeyStore(char[] pin) throws IOException {
         // TODO:  Verify if object DigitalCertificate was initiated
@@ -931,15 +1036,13 @@
 	    if (this.keyStore.getType().equals("PKCS11")) {
 		this.keyStore.load(null, pin);
-	    } else {
+	    } else if (this.keyStore.getType().equals("Windows-MY")) {
+                this.keyStore.load(null, null);
+            } else {
 		this.keyStore.load(this.pkcs12Input, pin);
 	    }
 
-            Map<String, String> aliases = new HashMap<String, String>();
-            for (Token token : tokens.getRegisteredTokens()){
-                aliases.putAll(token.getAliases());
-            }
-
             // selecionador de certificado
-            this.selectedCertificateAlias = DialogBuilder.showCertificateSelector(this.parentFrame, this.setup, aliases);
+            this.selectedCertificateAlias = DialogBuilder.showCertificateSelector(this.parentFrame,
+                    this.setup, this.getAliasesList());
 	    if (this.selectedCertificateAlias != null){
                 this.cert = this.keyStore.getCertificate(this.selectedCertificateAlias);
Index: /branches/2.3/security/ExpressoCert/src/br/gov/serpro/cert/Token.java
===================================================================
--- /branches/2.3/security/ExpressoCert/src/br/gov/serpro/cert/Token.java	(revision 5179)
+++ /branches/2.3/security/ExpressoCert/src/br/gov/serpro/cert/Token.java	(revision 5898)
@@ -13,18 +13,4 @@
 import java.security.ProviderException;
 import java.security.Security;
-import java.security.cert.CertificateFactory;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import java.security.cert.X509Certificate;
-import java.text.DateFormat;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-import sun.security.pkcs11.wrapper.CK_ATTRIBUTE;
-import sun.security.pkcs11.wrapper.CK_C_INITIALIZE_ARGS;
-import sun.security.pkcs11.wrapper.Functions;
-import sun.security.pkcs11.wrapper.PKCS11;
-import sun.security.pkcs11.wrapper.PKCS11Exception;
-import static sun.security.pkcs11.wrapper.PKCS11Constants.*;
 
 //TODO: Deal with wildcards for environments variables.
@@ -111,154 +97,4 @@
     }
 
-    Map<String, String> getAliases() throws IOException{
-
-        if (setup.getParameter("debug").equalsIgnoreCase("true")) {
-            System.out.println("Getting Aliases");
-        }
-
-        Map<String, String> aliases = new HashMap<String, String>();
-
-        CK_C_INITIALIZE_ARGS initArgs = new CK_C_INITIALIZE_ARGS();
-        String functionList = "C_GetFunctionList";
-
-        initArgs.flags = CKF_OS_LOCKING_OK;
-
-        PKCS11 tmpPKCS11 = null;
-        try {
-            try {
-                tmpPKCS11 = PKCS11.getInstance(libraryPath, functionList, initArgs, false);
-            } catch (IOException ex) {
-                if (setup.getParameter("debug").equalsIgnoreCase("true")) {
-                    Logger.getLogger(TokenCollection.class.getName()).log(Level.SEVERE, null, ex);
-                }
-                throw ex;
-            }
-        } catch (PKCS11Exception e) {
-            try {
-                initArgs = null;
-                tmpPKCS11 = PKCS11.getInstance(libraryPath, functionList, initArgs, true);
-            } catch (IOException ex) {
-                if (setup.getParameter("debug").equalsIgnoreCase("true")) {
-                    Logger.getLogger(TokenCollection.class.getName()).log(Level.SEVERE, null, ex);
-                }
-            } catch (PKCS11Exception ex) {
-                if (setup.getParameter("debug").equalsIgnoreCase("true")) {
-                    Logger.getLogger(TokenCollection.class.getName()).log(Level.SEVERE, null, ex);
-                }
-            }
-        }
-
-        try {
-            // cria sessão pública rw. com flag CKF_SERIAL_SESSION
-            long session = tmpPKCS11.C_OpenSession(this.slot, CKF_SERIAL_SESSION, null, null);
-
-            if (setup.getParameter("debug").equalsIgnoreCase("true")) {
-                System.out.println("session number:  "+session);
-            }
-
-            // TODO: Verifica se está logado, senão loga usuário. Pede pin? ou recebe pin?
-
-            CK_ATTRIBUTE[] TEMPLATE_CERTIFICATE = {new CK_ATTRIBUTE(CKA_CLASS, CKO_CERTIFICATE)};
-            CK_ATTRIBUTE[] TEMPLATE_PKEY = {new CK_ATTRIBUTE(CKA_CLASS, CKO_PRIVATE_KEY)};
-            CK_ATTRIBUTE[] TEMPLATE_KEY_LABEL_ID = {new CK_ATTRIBUTE(CKA_LABEL), new CK_ATTRIBUTE(CKA_ID)};
-            CK_ATTRIBUTE[] TEMPLATE_CERT_LABEL_ID = {
-                new CK_ATTRIBUTE(CKA_LABEL),
-                new CK_ATTRIBUTE(CKA_ID),
-                new CK_ATTRIBUTE(CKA_VALUE)
-            };
-
-            tmpPKCS11.C_FindObjectsInit(session, TEMPLATE_CERTIFICATE);
-            long[] certs = tmpPKCS11.C_FindObjects(session, 20);
-
-            tmpPKCS11.C_FindObjectsFinal(session);
-
-            tmpPKCS11.C_FindObjectsInit(session, TEMPLATE_PKEY);
-            long[] keys = tmpPKCS11.C_FindObjects(session, 20);
-
-            if (setup.getParameter("debug").equalsIgnoreCase("true")) {
-                System.out.println("Private Keys: "+keys.length);
-            }
-
-            for (long key : keys){
-                tmpPKCS11.C_GetAttributeValue(session, key, TEMPLATE_KEY_LABEL_ID);
-
-                if (setup.getParameter("debug").equalsIgnoreCase("true")) {
-                    System.out.print("Private key ID: ");
-                    for (byte b : (byte [])TEMPLATE_KEY_LABEL_ID[1].pValue){
-                        System.out.print(b);
-                    }
-                    System.out.println();
-                    if (TEMPLATE_KEY_LABEL_ID[0].pValue != null)
-                    {
-                        System.out.println("Private key LABEL: "+new String((char [])TEMPLATE_KEY_LABEL_ID[0].pValue));
-                    }
-                }
-
-                if (setup.getParameter("debug").equalsIgnoreCase("true")) {
-                    System.out.println("Certs:");
-                }
-                
-                for (long cert : certs){
-                    tmpPKCS11.C_GetAttributeValue(session, cert, TEMPLATE_CERT_LABEL_ID);
-
-                    if (Functions.equals((byte [])TEMPLATE_KEY_LABEL_ID[1].pValue, 
-                            (byte [])TEMPLATE_CERT_LABEL_ID[1].pValue)){
-                        if (TEMPLATE_CERT_LABEL_ID[0].pValue != null)
-                        {
-                            if (setup.getParameter("debug").equalsIgnoreCase("true")) {
-                                System.out.println("Certificate LABEL: "+new String((char [])TEMPLATE_CERT_LABEL_ID[0].pValue));
-                            }
-                            ByteArrayInputStream in = new ByteArrayInputStream((byte [])TEMPLATE_CERT_LABEL_ID[2].pValue);
-                            CertificateFactory cf = CertificateFactory.getInstance("X.509");
-                            X509Certificate certObj = (X509Certificate)cf.generateCertificate(in);
-                            if (certObj.getBasicConstraints() == -1 ){
-
-                                StringBuilder selector = new StringBuilder();
-                                // get more info to generate the value
-                                // Subject's CN / Issuer's CN / Expiration Data
-                                String subject = certObj.getSubjectX500Principal().getName();
-                                int pInicial = subject.indexOf('=')+1;
-                                int pFinal = subject.indexOf(',', pInicial);
-                                selector.append(subject.substring(pInicial, pFinal)+" | ");
-
-                                String issuer = certObj.getIssuerX500Principal().getName();
-                                pInicial = issuer.indexOf('=')+1;
-                                pFinal = issuer.indexOf(',', pInicial);
-                                selector.append(issuer.substring(pInicial, pFinal)+" | ");
-
-                                Locale locale = new Locale("pt", "BR");
-                                DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM, locale);
-                                selector.append(df.format(certObj.getNotAfter())+" | ");
-                                
-                                selector.append("("+certObj.getSerialNumber()+")");
-                                
-                                aliases.put(new String((char [])TEMPLATE_CERT_LABEL_ID[0].pValue),
-                                        selector.toString());
-                            }
-                        }
-                    }
-
-                }
-                if (setup.getParameter("debug").equalsIgnoreCase("true")) {
-                    System.out.println();
-                }
-            }
-
-            tmpPKCS11.C_CloseSession(session);
-
-        } catch (PKCS11Exception ex) {
-            if (setup.getParameter("debug").equalsIgnoreCase("true")) {
-                Logger.getLogger(TokenCollection.class.getName()).log(Level.SEVERE, null, ex);
-            }
-        } catch (Throwable t) {
-            if (setup.getParameter("debug").equalsIgnoreCase("true")) {
-                Logger.getLogger(TokenCollection.class.getName()).log(Level.SEVERE, null, t);
-            }
-        }
-
-        return aliases;
-
-    }
-
     public boolean libraryExists(){
 
Index: /branches/2.3/expressoMail1_2/index.php
===================================================================
--- /branches/2.3/expressoMail1_2/index.php	(revision 5319)
+++ /branches/2.3/expressoMail1_2/index.php	(revision 5898)
@@ -182,8 +182,9 @@
     var sentfolder = "'.$_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSentFolder'].'";
     var spamfolder = "'.$_SESSION['phpgw_info']['expressomail']['email_server']['imapDefaultSpamFolder'].'";
+    var locale = "'.$GLOBALS['phpgw']->translation->userlang.'";
     var token_param = "'.$var_tokens.'";
-    var locale = "'.$GLOBALS['phpgw']->common->getPreferredLanguage().'";
+
     </script>';
-
+    
     // End Set Imap Folder names options
 	//User info
@@ -221,8 +222,4 @@
 	echo '<script type="text/javascript">init();</script>';
 
-        // Maybe it's better to put locale in another place.
-        $locale = $GLOBALS['phpgw']->translation->userlang;
-        echo '<input type="hidden" id="locale" name="locale" value="'.$locale.'" />';
-
 	if ($GLOBALS['phpgw_info']['user']['preferences']['expressoMail']['use_shortcuts'])
 	{
Index: /branches/2.3/expressoMail1_2/js/main.js
===================================================================
--- /branches/2.3/expressoMail1_2/js/main.js	(revision 5319)
+++ /branches/2.3/expressoMail1_2/js/main.js	(revision 5898)
@@ -137,5 +137,4 @@
 	var search_div = Element('search_div');
 	var applet = null;
-        var locale = Element('locale').value;
 	if (navigator.userAgent.match('MSIE')){
 		applet = document.createElement('<object style="display:yes;width:0;height:0;vertical-align:bottom;" id="cert_applet" ' +
@@ -158,5 +157,5 @@
 				'commons-httpclient-3.1.jar,' +
 				'commons-logging-1.1.1.jar'
-			//debug:'true'
+			//debug:'false'
 		}
 
