public boolean isServerTrusted(X509Certificate[] certificates) { if ((certificates != null) && logger.isDebugEnabled()) { logger.debug("Server certificate chain:"); for (int i = 0; i < certificates.length; i++) { if (logger.isDebugEnabled()) { logger.debug("X509Certificate[" + i + "]=" + certificates[i]); } } } if ((certificates != null) && (certificates.length == 1)) { X509Certificate certificate = certificates[0]; try { certificate.checkValidity(); } catch (CertificateException e) { logger.error(e.toString()); return false; } return true; } else { return true; // return this.standardTrustManager.isServerTrusted(certificates); } }
public boolean isServerTrusted(X509Certificate[] certificates) { if ((certificates != null) && LOG.isDebugEnabled()) { LOG.debug("Server certificate chain:"); for (int i = 0; i < certificates.length; i++) { if (LOG.isDebugEnabled()) { LOG.debug("X509Certificate[" + i + "]=" + certificates[i]); } } } if ((certificates != null) && (certificates.length == 1)) { X509Certificate certificate = certificates[0]; try { certificate.checkValidity(); } catch (CertificateException e) { LOG.error(e.toString()); return false; } return true; } else { return true; // return this.standardTrustManager.isServerTrusted(certificates); } }
public boolean isServerTrusted(X509Certificate[] certificates) { if ((certificates != null) && LOG.isDebugEnabled()) { LOG.debug("Server certificate chain:"); for (int i = 0; i < certificates.length; i++) { if (LOG.isDebugEnabled()) { LOG.debug("X509Certificate[" + i + "]=" + certificates[i]); } } } if ((certificates != null) && (certificates.length == 1)) { X509Certificate certificate = certificates[0]; try { certificate.checkValidity(); } catch (CertificateException e) { LOG.error(e.toString()); return false; } return true; } else { return true; // return this.standardTrustManager.isServerTrusted(certificates); } }
public boolean isServerTrusted(X509Certificate[] certificates) { if ((certificates != null) && LOG.isDebugEnabled()) { LOG.debug("Server certificate chain:"); for (int i = 0; i < certificates.length; i++) { if (LOG.isDebugEnabled()) { LOG.debug("X509Certificate[" + i + "]=" + certificates[i]); } } } if ((certificates != null) && (certificates.length == 1)) { X509Certificate certificate = certificates[0]; try { certificate.checkValidity(); } catch (CertificateException e) { LOG.error(e.toString()); return false; } return true; } else { return true; // return this.standardTrustManager.isServerTrusted(certificates); } }
public boolean isServerTrusted(X509Certificate[] certificates) { if ((certificates != null) && logger.isDebugEnabled()) { logger.debug("Server certificate chain:"); for (int i = 0; i < certificates.length; i++) { if (logger.isDebugEnabled()) { logger.debug("X509Certificate[" + i + "]=" + certificates[i]); } } } if ((certificates != null) && (certificates.length == 1)) { X509Certificate certificate = certificates[0]; try { certificate.checkValidity(); } catch (CertificateException e) { logger.error(e.toString()); return false; } return true; } else { return true; // return this.standardTrustManager.isServerTrusted(certificates); } }
public boolean isServerTrusted(X509Certificate[] certificates) { if ((certificates != null) && LOG.isDebugEnabled()) { LOG.debug("Server certificate chain:"); for (int i = 0; i < certificates.length; i++) { LOG.debug("X509Certificate[" + i + "]=" + certificates[i]); } } if ((certificates != null) && (certificates.length == 1)) { X509Certificate certificate = certificates[0]; try { certificate.checkValidity(); } catch (CertificateException e) { LOG.error(e.toString()); return false; } return true; } else { try { this.standardTrustManager.checkServerTrusted(certificates, null); return true; } catch (CertificateException e) { return false; } } }
private Certificate decodeCertificate( DataInputStream dIn) throws IOException { String type = dIn.readUTF(); byte[] cEnc = new byte[dIn.readInt()]; dIn.readFully(cEnc); try { CertificateFactory cFact = CertificateFactory.getInstance(type, BouncyCastleProvider.PROVIDER_NAME); ByteArrayInputStream bIn = new ByteArrayInputStream(cEnc); return cFact.generateCertificate(bIn); } catch (NoSuchProviderException ex) { throw new IOException(ex.toString()); } catch (CertificateException ex) { throw new IOException(ex.toString()); } }
private Certificate decodeCertificate( DataInputStream dIn) throws IOException { String type = dIn.readUTF(); byte[] cEnc = new byte[dIn.readInt()]; dIn.readFully(cEnc); try { CertificateFactory cFact = CertificateFactory.getInstance(type, BouncyCastleProvider.PROVIDER_NAME); ByteArrayInputStream bIn = new ByteArrayInputStream(cEnc); return cFact.generateCertificate(bIn); } catch (NoSuchProviderException ex) { throw new IOException(ex.toString()); } catch (CertificateException ex) { throw new IOException(ex.toString()); } }
private Certificate decodeCertificate( DataInputStream dIn) throws IOException { String type = dIn.readUTF(); byte[] cEnc = new byte[dIn.readInt()]; dIn.readFully(cEnc); try { CertificateFactory cFact = CertificateFactory.getInstance(type, BouncyCastleProvider.PROVIDER_NAME); ByteArrayInputStream bIn = new ByteArrayInputStream(cEnc); return cFact.generateCertificate(bIn); } catch (NoSuchProviderException ex) { throw new IOException(ex.toString()); } catch (CertificateException ex) { throw new IOException(ex.toString()); } }
private void addCertificate(byte[] derData) { try { if (mCertificateFactory == null) { mCertificateFactory = CertificateFactory.getInstance(X_509); } Certificate cert = mCertificateFactory.generateCertificate( new ByteArrayInputStream(derData)); addCertificateDetails(cert, getDigest(derData, "SHA-256"), getDigest(derData, "SHA-1")); } catch (CertificateException e) { Log.e("CertViewer", "Error parsing certificate" + e.toString()); } }
private Certificate decodeCertificate( DataInputStream dIn) throws IOException { String type = dIn.readUTF(); byte[] cEnc = new byte[dIn.readInt()]; dIn.readFully(cEnc); try { CertificateFactory cFact = helper.createCertificateFactory(type); ByteArrayInputStream bIn = new ByteArrayInputStream(cEnc); return cFact.generateCertificate(bIn); } catch (NoSuchProviderException ex) { throw new IOException(ex.toString()); } catch (CertificateException ex) { throw new IOException(ex.toString()); } }
private Certificate decodeCertificate( DataInputStream dIn) throws IOException { String type = dIn.readUTF(); byte[] cEnc = new byte[dIn.readInt()]; dIn.readFully(cEnc); try { CertificateFactory cFact = helper.createCertificateFactory(type); ByteArrayInputStream bIn = new ByteArrayInputStream(cEnc); return cFact.generateCertificate(bIn); } catch (NoSuchProviderException ex) { throw new IOException(ex.toString()); } catch (CertificateException ex) { throw new IOException(ex.toString()); } }
private Certificate decodeCertificate( DataInputStream dIn) throws IOException { String type = dIn.readUTF(); byte[] cEnc = new byte[dIn.readInt()]; dIn.readFully(cEnc); try { CertificateFactory cFact = helper.createCertificateFactory(type); ByteArrayInputStream bIn = new ByteArrayInputStream(cEnc); return cFact.generateCertificate(bIn); } catch (NoSuchProviderException ex) { throw new IOException(ex.toString()); } catch (CertificateException ex) { throw new IOException(ex.toString()); } }
private Certificate[] readCertArray(InputStream in) throws IOException { int length = readInt(in); if (length == -1) { return null; } try { CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509"); Certificate[] result = new Certificate[length]; for (int i = 0; i < result.length; i++) { String line = Streams.readAsciiLine(in); byte[] bytes = Base64.decode(Strings.getBytes(line,Charsets.US_ASCII)); result[i] = certificateFactory.generateCertificate( new ByteArrayInputStream(bytes)); } return result; } catch (CertificateException e) { throw new IOException(e.toString()); } }
public static CertPathEntry decode(DataInputStream in) throws IOException { CertPathEntry entry = new CertPathEntry(); entry.properties = new Properties(); entry.properties.decode(in); entry.makeCreationDate(); int len = in.readInt(); MeteredInputStream in2 = new MeteredInputStream(in, len); try { CertificateFactory fact = CertificateFactory.getInstance("X.509"); entry.path = (Certificate[]) fact.generateCertificates(in2).toArray(new Certificate[0]); } catch (CertificateException ce) { throw new MalformedKeyringException(ce.toString()); } return entry; }
public void engineSetKeyEntry(String alias, Key key, char[] password, Certificate[] chain) throws KeyStoreException { if (!loaded) { throw NOT_LOADED; } if (keyring == null) { keyring = new GnuPrivateKeyring("HMAC-SHA-1", 20, "AES", "OFB", 16); } if (!(keyring instanceof IPrivateKeyring)) { throw new IllegalStateException("not a private keyring"); } if (key instanceof PublicKey) { ((IPrivateKeyring) keyring).putPublicKey(alias, (PublicKey) key); return; } if (!(key instanceof PrivateKey) && !(key instanceof SecretKey)) { throw new KeyStoreException("cannot store keys of type " + key.getClass().getName()); } try { CertificateFactory fact = CertificateFactory.getInstance("X.509"); ((IPrivateKeyring) keyring).putCertPath(alias, chain); } catch (CertificateException ce) { throw new KeyStoreException(ce.toString()); } ((IPrivateKeyring) keyring).putPrivateKey(alias, key, password); }
@Override public void addCertificate(X509Certificate certificate) throws KeyManagementException { keystore.addTrustedSslCertificate(certificate, certificate.getSubjectX500Principal().getName()); try { keystore.save(); } catch(KeyStoreException e) { throw new KeyManagementException("Cannot add certificate to keystore: "+e.toString(), e); } catch(IOException e) { throw new KeyManagementException("Cannot add certificate to keystore: "+e.toString(), e); } catch(NoSuchAlgorithmException e) { throw new KeyManagementException("Cannot add certificate to keystore: "+e.toString(), e); } catch(CertificateException e) { throw new KeyManagementException("Cannot add certificate to keystore: "+e.toString(), e); } hashCode = null; // signal to recalculate the hashcode due to changed contents } /*
public static CertificateEntry decode(DataInputStream in) throws IOException { CertificateEntry entry = new CertificateEntry(); entry.properties = new Properties(); entry.properties.decode(in); entry.makeCreationDate(); String type = entry.properties.get("type"); if (type == null) { throw new MalformedKeyringException("no certificate type"); } int len = in.readInt(); MeteredInputStream in2 = new MeteredInputStream(in, len); try { CertificateFactory fact = CertificateFactory.getInstance(type); entry.certificate = fact.generateCertificate(in2); } catch (CertificateException ce) { throw new MalformedKeyringException(ce.toString()); } if (!in2.limitReached()) { throw new MalformedKeyringException("extra data at end of payload"); } return entry; }
protected ValidationResult validate(X509Certificate[] certChain, Set<TrustAnchor> anchors) { if (isDisposed()) throw new IllegalStateException("The validator instance was disposed"); ValidationResult result; try { result = validator.validate(certChain, getProxySupport() == ProxySupport.ALLOW, anchors, new SimpleCRLStore(crlStore), revocationMode, observers); } catch (CertificateException e) { e.printStackTrace(); ValidationError error = new ValidationError(certChain, -1, ValidationErrorCode.inputError, e.toString()); result = new ValidationResult(false, Collections.singletonList(error)); } if (!result.isValid()) { List<ValidationError> errors = result.getErrors(); processErrorList(errors); result.setErrors(errors); if (result.getErrors().size() == 0 && result.getUnresolvedCriticalExtensions().size() == 0) return new ValidationResult(true); } return result; }