@Override public String getDigest(final DigestAlgorithm digestAlgorithm) { String base64EncodeDigest = base64EncodeDigestMap.get(digestAlgorithm); if (base64EncodeDigest == null) { throw new DSSException("Unknown digest value for algorithm : " + digestAlgorithm); } return base64EncodeDigest; }
private URL getURL(String urlString) { try { return new URL(urlString); } catch (MalformedURLException e) { throw new DSSException("Unable to create URL instance", e); } }
/** * Creates the new empty Document. * * @return a new empty Document */ public static Document buildDOM() { try { return dbFactory.newDocumentBuilder().newDocument(); } catch (ParserConfigurationException e) { throw new DSSException(e); } }
private Provider getProviderJavaGreaterOrEquals9(String configString) { try { Provider provider = Security.getProvider(SUN_PKCS11_PROVIDERNAME); Method configureMethod = provider.getClass().getMethod("configure", String.class); // "--" is permitted in the constructor sun.security.pkcs11.Config return (Provider) configureMethod.invoke(provider, "--" + configString); } catch (Exception e) { throw new DSSException("Unable to instantiate PKCS11 (JDK >= 9)", e); } }
private File getCacheFile(final String fileName) { final String trimmedFileName = fileName.trim(); if ((toIgnored != null) && toIgnored.contains(trimmedFileName)) { throw new DSSException("Part of urls to ignore."); } LOG.debug("Cached file: {}/{}", fileCacheDirectory, trimmedFileName); final File file = new File(fileCacheDirectory, trimmedFileName); return file; }
private Provider getProviderJavaLowerThan9(String configString) { try (ByteArrayInputStream bais = new ByteArrayInputStream(configString.getBytes())) { Class<?> sunPkcs11ProviderClass = Class.forName(SUN_PKCS11_CLASSNAME); Constructor<?> constructor = sunPkcs11ProviderClass.getConstructor(InputStream.class); return (Provider) constructor.newInstance(bais); } catch (Exception e) { throw new DSSException("Unable to instantiate PKCS11 (JDK < 9) ", e); } }
public static byte[] getEncoded(OCSPResp ocspResp) { try { return ocspResp.getEncoded(); } catch (IOException e) { throw new DSSException(e); } }
public static Date toDate(final ASN1GeneralizedTime asn1Date) { try { return asn1Date.getDate(); } catch (ParseException e) { throw new DSSException(e); } }
private void initKeystore(final InputStream ksStream, final String ksType, final String ksPassword) { try { keyStore = KeyStore.getInstance(ksType); final char[] password = (ksPassword == null) ? null : ksPassword.toCharArray(); keyStore.load(ksStream, password); passwordProtection = new PasswordProtection(password); } catch (GeneralSecurityException | IOException e) { throw new DSSException("Unable to initialize the keystore", e); } finally { Utils.closeQuietly(ksStream); } }
private MessageDigest getMessageDigest(DigestAlgorithm digestAlgorithm) { try { return MessageDigest.getInstance(digestAlgorithm.getOid(), BouncyCastleProvider.PROVIDER_NAME); } catch (GeneralSecurityException e) { throw new DSSException("Cannot generate a MessageDigest", e); } }
@Override KeyStore getKeyStore() throws DSSException { KeyStore keyStore = null; try { keyStore = KeyStore.getInstance("Windows-MY"); keyStore.load(null, null); _fixAliases(keyStore); } catch (IOException | GeneralSecurityException e) { throw new DSSException("Unable to load MS CAPI keystore", e); } return keyStore; }
private static ASN1Sequence getASN1Sequence(byte[] bytes) { try (ASN1InputStream input = new ASN1InputStream(bytes)) { return (ASN1Sequence) input.readObject(); } catch (IOException e) { throw new DSSException("Unable to retrieve the ASN1Sequence", e); } }
public static byte[] digest(DigestAlgorithm digestAlgorithm, DSSDocument document) { try (InputStream is = document.openStream()) { return digest(digestAlgorithm, is); } catch (IOException e) { throw new DSSException(e); } }
@Override protected MessageTag getMessageTag() { if (TimestampedObjectType.CERTIFICATE.equals(referenceCategory)) { return MessageTag.PSV_ITPOCOBCT; } else if (TimestampedObjectType.REVOCATION.equals(referenceCategory)) { return MessageTag.PSV_ITPORDAOBCT; } throw new DSSException("Problem VTS"); }
private static String convertToPEM(Object obj) { try (StringWriter out = new StringWriter(); PemWriter pemWriter = new PemWriter(out)) { pemWriter.writeObject(new JcaMiscPEMGenerator(obj)); pemWriter.flush(); return out.toString(); } catch (Exception e) { throw new DSSException("Unable to convert DER to PEM", e); } }
private void checkSignatureValue(final X509CRL x509CRL, final CertificateToken issuerToken, final CRLValidity crlValidity) { try { x509CRL.verify(issuerToken.getPublicKey()); crlValidity.setSignatureIntact(true); crlValidity.setIssuerToken(issuerToken); } catch (KeyException | CRLException | NoSuchAlgorithmException | SignatureException e) { crlValidity.setSignatureInvalidityReason(e.getClass().getSimpleName() + " - " + e.getMessage()); } catch (NoSuchProviderException e) { throw new DSSException(e); } }
public static byte[] getEncoded(BasicOCSPResp basicOCSPResp) { try { BasicOCSPResponse basicOCSPResponse = BasicOCSPResponse.getInstance(basicOCSPResp.getEncoded()); return getDEREncoded(basicOCSPResponse); } catch (IOException e) { throw new DSSException(e); } }
private static byte[] getDEROctetStringContent(byte[] bytes) { try (ASN1InputStream input = new ASN1InputStream(bytes)) { final DEROctetString s = (DEROctetString) input.readObject(); return s.getOctets(); } catch (IOException e) { throw new DSSException("Unable to retrieve the DEROctetString content", e); } }
public static byte[] computeSkiFromCert(final CertificateToken certificateToken) { try { DLSequence seq = (DLSequence) DERSequence.fromByteArray(certificateToken.getPublicKey().getEncoded()); DERBitString item = (DERBitString) seq.getObjectAt(1); return DSSUtils.digest(DigestAlgorithm.SHA1, item.getOctets()); } catch (IOException e) { throw new DSSException(e); } }
public static CertificateToken getCertificate(final X509CertificateHolder x509CertificateHolder) { try { JcaX509CertificateConverter converter = new JcaX509CertificateConverter().setProvider(BouncyCastleProvider.PROVIDER_NAME); X509Certificate x509Certificate = converter.getCertificate(x509CertificateHolder); return new CertificateToken(x509Certificate); } catch (CertificateException e) { throw new DSSException(e); } }