- Timestamp:
- 12/27/10 12:27:43 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2.2/security/ExpressoCert/src/br/gov/serpro/cert/DigitalCertificate.java
r3413 r3633 81 81 82 82 private TokenCollection tokens; 83 private String selectedCertificateAlias; 83 84 private Certificate cert; // Certificado extraído da KeyStore. Pode ser nulo. 84 85 private KeyStore keyStore; // KeyStore que guarda o certificado do usuário. Pode ser nulo. … … 233 234 234 235 this.cert = null; 236 this.selectedCertificateAlias = null; 235 237 this.keyStore = null; 236 238 this.hostAddress = null; … … 343 345 if (pin != null) { 344 346 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()); 346 351 } else { 347 352 return null; … … 521 526 if (pin != null) { 522 527 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()); 524 532 } else { 525 533 return null; … … 601 609 ByteArrayOutputStream oStream = new ByteArrayOutputStream(); 602 610 decriptedBodyPart.writeTo(oStream); 603 decriptedBodyPart = null; 611 612 decriptedBodyPart = null; 604 613 encriptedMsg = null; 605 614 … … 609 618 610 619 } else { 620 611 621 encriptedMsg.setContent(decriptedBodyPart.getContent(), decriptedBodyPart.getContentType()); 612 622 encriptedMsg.saveChanges(); … … 650 660 String[] resposta = null; 651 661 662 if (this.selectedCertificateAlias == null){ 663 return resposta; 664 } 665 652 666 if (this.setup.getParameter("debug").equalsIgnoreCase("true")) { 653 667 System.out.println("Proxy Configurado no browser: " + System.getProperty("http.proxyHost") + ":" + System.getProperty("http.proxyPort")); … … 710 724 711 725 // 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()); 715 727 716 728 // Inicializa os cipher com os parâmetros corretos para realizar a decriptação … … 745 757 */ 746 758 public void openKeyStore(char[] pin) throws IOException { 747 759 // TODO: Verify if object DigitalCertificate was initiated 748 760 try { 749 761 … … 754 766 } 755 767 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 } 764 785 765 786 } catch (GeneralSecurityException e) {
Note: See TracChangeset
for help on using the changeset viewer.