|
33 | 33 | import it.hackerinside.etk.GUI.DTOs.CertificateTableRow; |
34 | 34 | import it.hackerinside.etk.GUI.DTOs.CertificateWrapper; |
35 | 35 | import it.hackerinside.etk.Utils.X509CertificateLoader; |
| 36 | +import it.hackerinside.etk.Utils.X509KeyUsageValidator; |
36 | 37 | import it.hackerinside.etk.Utils.X509Utils; |
37 | 38 | import it.hackerinside.etk.core.Models.DefaultExtensions; |
38 | 39 | import it.hackerinside.etk.core.Models.EncodingOption; |
| 40 | +import it.hackerinside.etk.core.Models.KeyUsageProfile; |
39 | 41 | import it.hackerinside.etk.core.Models.SymmetricAlgorithms; |
40 | 42 | import it.hackerinside.etk.core.Services.EncryptionService; |
41 | 43 | import it.hackerinside.etk.core.keystore.AbstractKeystore; |
@@ -330,7 +332,7 @@ public void actionPerformed(ActionEvent e) { |
330 | 332 |
|
331 | 333 | btnAddRecipient.addActionListener(new ActionListener() { |
332 | 334 | public void actionPerformed(ActionEvent e) { |
333 | | - if(recipient != null && Utils.acceptX509Certificate(recipient)) { |
| 335 | + if(recipient != null && Utils.acceptX509Certificate(recipient) && (ctx.validateKeyUsages() ? Utils.validateCertFlags(recipient, KeyUsageProfile.ENCRYPTION) : true)) { |
334 | 336 | recipients.add(recipient); |
335 | 337 | Object selectedCert = cmbRecipientCert.getSelectedItem(); |
336 | 338 | if(selectedCert != null) { |
@@ -402,7 +404,8 @@ private void populateKnowCerts(JComboBox<CertificateWrapper> combo) { |
402 | 404 | cert -> { |
403 | 405 | String alg = cert.getPublicKey().getAlgorithm(); |
404 | 406 | boolean validCert = ctx.hideInvalidCerts() ? X509Utils.checkTimeValidity(cert) : true; |
405 | | - return alg != null && validCert && !alg.toUpperCase().contains("DSA"); |
| 407 | + boolean validKeyUsages = ctx.validateKeyUsages() ? X509KeyUsageValidator.hasKeyUsage(cert, X509KeyUsageValidator.Mode.ANY, KeyUsageProfile.ENCRYPTION) : true; |
| 408 | + return alg != null && validCert && !alg.toUpperCase().contains("DSA") && validKeyUsages; |
406 | 409 | } |
407 | 410 | ); |
408 | 411 | } |
|
0 commit comments