use of org.kse.crypto.CryptoException in project keystore-explorer by kaikramer.
the class DProperties method getAliasesInAlphaOrder.
private TreeSet<String> getAliasesInAlphaOrder() throws CryptoException {
try {
KeyStore keyStore = currentState.getKeyStore();
TreeSet<String> aliases = new TreeSet<String>();
Enumeration<String> enumAliases = keyStore.aliases();
while (enumAliases.hasMoreElements()) {
String alias = enumAliases.nextElement();
if (KeyStoreUtil.isSupportedEntryType(alias, keyStore)) {
aliases.add(alias);
}
}
return aliases;
} catch (KeyStoreException ex) {
throw new CryptoException(res.getString("DProperties.NoGetProperties.exception.message"), ex);
}
}
use of org.kse.crypto.CryptoException in project keystore-explorer by kaikramer.
the class DProperties method createKeyPairNodes.
private void createKeyPairNodes(DefaultMutableTreeNode parentNode, String alias) throws CryptoException {
try {
KeyStore keyStore = currentState.getKeyStore();
DefaultMutableTreeNode keyPairNode = new DefaultMutableTreeNode(alias);
parentNode.add(keyPairNode);
createLastModifiedNode(keyPairNode, alias);
createPrivateKeyNodes(keyPairNode, alias);
X509Certificate[] certificates = X509CertUtil.convertCertificates(keyStore.getCertificateChain(alias));
DefaultMutableTreeNode certificatesNode = new DefaultMutableTreeNode(res.getString("DProperties.properties.Certificates"));
keyPairNode.add(certificatesNode);
for (int i = 0; i < certificates.length; i++) {
X509Certificate certificate = certificates[i];
DefaultMutableTreeNode certificateNode = new DefaultMutableTreeNode(X509CertUtil.getShortName(certificate));
certificatesNode.add(certificateNode);
populateCertificateNode(certificateNode, certificate);
}
} catch (KeyStoreException ex) {
throw new CryptoException(res.getString("DProperties.NoGetProperties.exception.message"), ex);
}
}
use of org.kse.crypto.CryptoException in project keystore-explorer by kaikramer.
the class DProperties method populateCertificateNode.
private void populateCertificateNode(DefaultMutableTreeNode certificateNode, X509Certificate certificate) throws CryptoException {
try {
String version = MessageFormat.format(res.getString("DProperties.properties.Version"), "" + certificate.getVersion());
certificateNode.add(new DefaultMutableTreeNode(version));
String subject = MessageFormat.format(res.getString("DProperties.properties.Subject"), X500NameUtils.x500PrincipalToX500Name(certificate.getSubjectX500Principal()));
certificateNode.add(new DefaultMutableTreeNode(subject));
String issuer = MessageFormat.format(res.getString("DProperties.properties.Issuer"), X500NameUtils.x500PrincipalToX500Name(certificate.getIssuerX500Principal()));
certificateNode.add(new DefaultMutableTreeNode(issuer));
String serialNumber = MessageFormat.format(res.getString("DProperties.properties.SerialNumber"), new BigInteger(certificate.getSerialNumber().toByteArray()).toString(16).toUpperCase());
certificateNode.add(new DefaultMutableTreeNode(serialNumber));
Date validFromDate = certificate.getNotBefore();
String validFrom = MessageFormat.format(res.getString("DProperties.properties.ValidFrom"), StringUtils.formatDate(validFromDate));
certificateNode.add(new DefaultMutableTreeNode(validFrom));
Date validUntilDate = certificate.getNotAfter();
String validUntil = MessageFormat.format(res.getString("DProperties.properties.ValidUntil"), StringUtils.formatDate(validUntilDate));
certificateNode.add(new DefaultMutableTreeNode(validUntil));
createPublicKeyNodes(certificateNode, certificate);
String signatureAlgorithm = MessageFormat.format(res.getString("DProperties.properties.SignatureAlgorithm"), X509CertUtil.getCertificateSignatureAlgorithm(certificate));
certificateNode.add(new DefaultMutableTreeNode(signatureAlgorithm));
byte[] cert = certificate.getEncoded();
String md5 = MessageFormat.format(res.getString("DProperties.properties.Md5Fingerprint"), DigestUtil.getFriendlyMessageDigest(cert, DigestType.MD5));
certificateNode.add(new DefaultMutableTreeNode(md5));
String sha1 = MessageFormat.format(res.getString("DProperties.properties.Sha1Fingerprint"), DigestUtil.getFriendlyMessageDigest(cert, DigestType.SHA1));
certificateNode.add(new DefaultMutableTreeNode(sha1));
} catch (CertificateEncodingException ex) {
throw new CryptoException(res.getString("DProperties.NoGetProperties.exception.message"), ex);
}
}
use of org.kse.crypto.CryptoException in project keystore-explorer by kaikramer.
the class DViewCertificate method populateDetails.
private void populateDetails() {
X509Certificate cert = getSelectedCertificate();
if (cert == null) {
jdnSubject.setEnabled(false);
jdnIssuer.setEnabled(false);
jbViewPublicKeyDetails.setEnabled(false);
jcfFingerprint.setEnabled(false);
jbExtensions.setEnabled(false);
jbPem.setEnabled(false);
jbAsn1.setEnabled(false);
jtfVersion.setText("");
jdnSubject.setDistinguishedName(null);
jdnIssuer.setDistinguishedName(null);
jtfSerialNumber.setText("");
jtfValidFrom.setText("");
jtfValidUntil.setText("");
jtfPublicKey.setText("");
jtfSignatureAlgorithm.setText("");
jcfFingerprint.setEncodedCertificate(null);
} else {
jdnSubject.setEnabled(true);
jdnIssuer.setEnabled(true);
jbViewPublicKeyDetails.setEnabled(true);
jbExtensions.setEnabled(true);
jbPem.setEnabled(true);
jbAsn1.setEnabled(true);
try {
Date currentDate = new Date();
Date startDate = cert.getNotBefore();
Date endDate = cert.getNotAfter();
boolean notYetValid = currentDate.before(startDate);
boolean noLongerValid = currentDate.after(endDate);
jtfVersion.setText(Integer.toString(cert.getVersion()));
jtfVersion.setCaretPosition(0);
jdnSubject.setDistinguishedName(X500NameUtils.x500PrincipalToX500Name(cert.getSubjectX500Principal()));
jdnIssuer.setDistinguishedName(X500NameUtils.x500PrincipalToX500Name(cert.getIssuerX500Principal()));
jtfSerialNumber.setText("0x" + new BigInteger(1, cert.getSerialNumber().toByteArray()).toString(16).toUpperCase());
jtfSerialNumber.setCaretPosition(0);
jtfValidFrom.setText(StringUtils.formatDate(startDate));
if (notYetValid) {
jtfValidFrom.setText(MessageFormat.format(res.getString("DViewCertificate.jtfValidFrom.notyetvalid.text"), jtfValidFrom.getText()));
jtfValidFrom.setForeground(Color.red);
} else {
jtfValidFrom.setForeground(jtfVersion.getForeground());
}
jtfValidFrom.setCaretPosition(0);
jtfValidUntil.setText(StringUtils.formatDate(endDate));
if (noLongerValid) {
jtfValidUntil.setText(MessageFormat.format(res.getString("DViewCertificate.jtfValidUntil.expired.text"), jtfValidUntil.getText()));
jtfValidUntil.setForeground(Color.red);
} else {
jtfValidUntil.setForeground(jtfVersion.getForeground());
}
jtfValidUntil.setCaretPosition(0);
KeyInfo keyInfo = KeyPairUtil.getKeyInfo(cert.getPublicKey());
jtfPublicKey.setText(keyInfo.getAlgorithm());
Integer keySize = keyInfo.getSize();
if (keySize != null) {
jtfPublicKey.setText(MessageFormat.format(res.getString("DViewCertificate.jtfPublicKey.text"), jtfPublicKey.getText(), "" + keySize));
} else {
jtfPublicKey.setText(MessageFormat.format(res.getString("DViewCertificate.jtfPublicKey.text"), jtfPublicKey.getText(), "?"));
}
jtfPublicKey.setCaretPosition(0);
jtfSignatureAlgorithm.setText(X509CertUtil.getCertificateSignatureAlgorithm(cert));
jtfSignatureAlgorithm.setCaretPosition(0);
byte[] encodedCertificate;
try {
encodedCertificate = cert.getEncoded();
} catch (CertificateEncodingException ex) {
throw new CryptoException(res.getString("DViewCertificate.NoGetEncodedCert.exception.message"), ex);
}
jcfFingerprint.setEncodedCertificate(encodedCertificate);
jcfFingerprint.setFingerprintAlg(ApplicationSettings.getInstance().getCertificateFingerprintType());
Set<?> critExts = cert.getCriticalExtensionOIDs();
Set<?> nonCritExts = cert.getNonCriticalExtensionOIDs();
if (critExts != null && critExts.size() != 0 || nonCritExts != null && nonCritExts.size() != 0) {
jbExtensions.setEnabled(true);
} else {
jbExtensions.setEnabled(false);
}
} catch (CryptoException ex) {
DError dError = new DError(this, ex);
dError.setLocationRelativeTo(this);
dError.setVisible(true);
dispose();
}
}
}
use of org.kse.crypto.CryptoException in project keystore-explorer by kaikramer.
the class DViewCsr method pubKeyDetailsPressed.
private void pubKeyDetailsPressed() {
try {
PublicKey publicKey = null;
if (pkcs10Csr != null) {
publicKey = getPkcs10PublicKey();
} else {
publicKey = spkacCsr.getPublicKey();
}
DViewPublicKey dViewPublicKey = new DViewPublicKey(this, res.getString("DViewCsr.PubKeyDetails.Title"), publicKey);
dViewPublicKey.setLocationRelativeTo(this);
dViewPublicKey.setVisible(true);
} catch (CryptoException ex) {
DError dError = new DError(this, ex);
dError.setLocationRelativeTo(this);
dError.setVisible(true);
}
}
Aggregations