Ignore:
Timestamp:
12/27/10 12:27:43 (14 years ago)
Author:
rafaelraymundo
Message:

Ticket #1430 - Mais de um certificados gravados no mesmo token.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.2/security/ExpressoCert/src/br/gov/serpro/cert/DigitalCertificate.java

    r3413 r3633  
    8181 
    8282    private TokenCollection tokens; 
     83    private String selectedCertificateAlias; 
    8384    private Certificate cert; // Certificado extraído da KeyStore. Pode ser nulo. 
    8485    private KeyStore keyStore; // KeyStore que guarda o certificado do usuário. Pode ser nulo. 
     
    233234 
    234235        this.cert = null; 
     236        this.selectedCertificateAlias = null; 
    235237        this.keyStore = null; 
    236238        this.hostAddress = null; 
     
    343345            if (pin != null) { 
    344346                openKeyStore(pin.toCharArray()); 
    345                 privateKey = this.keyStore.getKey(keyStore.aliases().nextElement(), pin.toCharArray()); 
     347                if (this.selectedCertificateAlias == null){ 
     348                    return null; 
     349                } 
     350                privateKey = this.keyStore.getKey(this.selectedCertificateAlias, pin.toCharArray()); 
    346351            } else { 
    347352                return null; 
     
    521526            if (pin != null) { 
    522527                openKeyStore(pin.toCharArray()); 
    523                 privateKey = this.keyStore.getKey(keyStore.aliases().nextElement(), pin.toCharArray()); 
     528                if (this.selectedCertificateAlias == null){ 
     529                    return null; 
     530                } 
     531                privateKey = this.keyStore.getKey(this.selectedCertificateAlias, pin.toCharArray()); 
    524532            } else { 
    525533                return null; 
     
    601609                ByteArrayOutputStream oStream = new ByteArrayOutputStream(); 
    602610                decriptedBodyPart.writeTo(oStream); 
    603                 decriptedBodyPart = null; 
     611 
     612                decriptedBodyPart = null; 
    604613                encriptedMsg = null; 
    605614 
     
    609618 
    610619            } else { 
     620                 
    611621                encriptedMsg.setContent(decriptedBodyPart.getContent(), decriptedBodyPart.getContentType()); 
    612622                encriptedMsg.saveChanges(); 
     
    650660        String[] resposta = null; 
    651661 
     662        if (this.selectedCertificateAlias == null){ 
     663            return resposta; 
     664        } 
     665 
    652666        if (this.setup.getParameter("debug").equalsIgnoreCase("true")) { 
    653667            System.out.println("Proxy Configurado no browser: " + System.getProperty("http.proxyHost") + ":" + System.getProperty("http.proxyPort")); 
     
    710724 
    711725        // Pega a chave privada do primeiro certificado armazenado na KeyStore 
    712         Enumeration<String> en = this.keyStore.aliases(); 
    713         String certAlias = en.nextElement(); 
    714         Key privateKey = this.keyStore.getKey(certAlias, pin.toCharArray()); 
     726        Key privateKey = this.keyStore.getKey(selectedCertificateAlias, pin.toCharArray()); 
    715727 
    716728        // Inicializa os cipher com os parâmetros corretos para realizar a decriptação 
     
    745757     */ 
    746758    public void openKeyStore(char[] pin) throws IOException { 
    747  
     759        // TODO:  Verify if object DigitalCertificate was initiated 
    748760        try { 
    749761 
     
    754766            } 
    755767 
    756             this.cert = this.keyStore.getCertificate(this.keyStore.aliases().nextElement()); 
    757  
    758             System.out.println("Aliases (" + this.keyStore.size() + "): "); 
    759             if (this.setup.getParameter("debug").equalsIgnoreCase("true")) { 
    760                 for (Enumeration alias = this.keyStore.aliases(); alias.hasMoreElements();) { 
    761                     System.out.println(alias.nextElement()); 
    762                 } 
    763             } 
     768            List<String> aliases = new ArrayList<String>(); 
     769            for (Enumeration<String> certificateList = keyStore.aliases(); certificateList.hasMoreElements();){ 
     770                aliases.add(certificateList.nextElement()); 
     771            } 
     772 
     773            // selecionador de certificado 
     774            this.selectedCertificateAlias = DialogBuilder.showCertificateSelector(this.parentFrame, this.setup, aliases); 
     775            if (this.selectedCertificateAlias != null){ 
     776                this.cert = this.keyStore.getCertificate(this.selectedCertificateAlias); 
     777             
     778                System.out.println("Aliases (" + this.keyStore.size() + "): "); 
     779                if (this.setup.getParameter("debug").equalsIgnoreCase("true")) { 
     780                    for (Enumeration alias = this.keyStore.aliases(); alias.hasMoreElements();) { 
     781                        System.out.println(alias.nextElement()); 
     782                    } 
     783                } 
     784            } 
    764785 
    765786        } catch (GeneralSecurityException e) { 
Note: See TracChangeset for help on using the changeset viewer.