Search in sources :

Example 91 with NoSuchProviderException

use of java.security.NoSuchProviderException in project jackrabbit-oak by apache.

the class LoginContextProviderImpl method getConfiguration.

@Nonnull
private Configuration getConfiguration() {
    if (configuration == null) {
        Configuration loginConfig = null;
        String configSpiName = params.getConfigValue(PARAM_CONFIG_SPI_NAME, null, String.class);
        if (configSpiName != null) {
            try {
                /*
                     Create a configuration instance with the following characteristics
                     - Algorithm name : "JavaLoginConfig"
                     - Extra parameters : 'null' for this impl
                     - Name of the config provider : 'configSpiName' as retrieved from the PARAM_CONFIG_SPI_NAME configuration (default: null)
                     */
                loginConfig = Configuration.getInstance("JavaLoginConfig", null, configSpiName);
                if (loginConfig.getAppConfigurationEntry(appName) == null) {
                    log.warn("No configuration found for application {} though fetching JAAS " + "configuration from SPI {} is enabled.", appName, configSpiName);
                }
            } catch (NoSuchAlgorithmException e) {
                log.warn("Error fetching JAAS config from SPI {}", configSpiName, e);
            } catch (NoSuchProviderException e) {
                log.warn("Error fetching JAAS config from SPI {}", configSpiName, e);
            }
        }
        if (loginConfig == null) {
            try {
                loginConfig = Configuration.getConfiguration();
                // NOTE: workaround for Java7 behavior (see OAK-497)
                if (loginConfig.getAppConfigurationEntry(appName) == null) {
                    loginConfig = null;
                }
            } catch (SecurityException e) {
                log.info("Failed to retrieve login configuration: using default. " + e);
            }
        }
        if (loginConfig == null) {
            log.debug("No login configuration available for {}; using default", appName);
            loginConfig = ConfigurationUtil.getDefaultConfiguration(params);
        }
        configuration = loginConfig;
    }
    return configuration;
}
Also used : Configuration(javax.security.auth.login.Configuration) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NoSuchProviderException(java.security.NoSuchProviderException) Nonnull(javax.annotation.Nonnull)

Example 92 with NoSuchProviderException

use of java.security.NoSuchProviderException in project sic by belluccifranco.

the class AfipWebServiceSOAPClient method crearCMS.

public byte[] crearCMS(byte[] p12file, String p12pass, String signer, String service, long ticketTime) {
    PrivateKey pKey = null;
    X509Certificate pCertificate = null;
    byte[] asn1_cms = null;
    CertStore cstore = null;
    try {
        KeyStore ks = KeyStore.getInstance("pkcs12");
        InputStream is;
        is = Utilidades.convertirByteArrayToInputStream(p12file);
        ks.load(is, p12pass.toCharArray());
        is.close();
        pKey = (PrivateKey) ks.getKey(signer, p12pass.toCharArray());
        pCertificate = (X509Certificate) ks.getCertificate(signer);
        ArrayList<X509Certificate> certList = new ArrayList<>();
        certList.add(pCertificate);
        if (Security.getProvider("BC") == null) {
            Security.addProvider(new BouncyCastleProvider());
        }
        cstore = CertStore.getInstance("Collection", new CollectionCertStoreParameters(certList), "BC");
    } catch (KeyStoreException | IOException | NoSuchAlgorithmException | CertificateException | UnrecoverableKeyException | InvalidAlgorithmParameterException | NoSuchProviderException ex) {
        LOGGER.error(ex.getMessage());
        throw new BusinessServiceException(ResourceBundle.getBundle("Mensajes").getString("mensaje_certificado_error"));
    }
    String loginTicketRequest_xml = this.crearTicketRequerimientoAcceso(service, ticketTime);
    try {
        CMSSignedDataGenerator generator = new CMSSignedDataGenerator();
        generator.addSigner(pKey, pCertificate, CMSSignedDataGenerator.DIGEST_SHA1);
        generator.addCertificatesAndCRLs(cstore);
        CMSProcessable data = new CMSProcessableByteArray(loginTicketRequest_xml.getBytes());
        CMSSignedData signed = generator.generate(data, true, "BC");
        asn1_cms = signed.getEncoded();
    } catch (IllegalArgumentException | CertStoreException | CMSException | NoSuchAlgorithmException | NoSuchProviderException | IOException ex) {
        LOGGER.error(ex.getMessage());
        throw new BusinessServiceException(ResourceBundle.getBundle("Mensajes").getString("mensaje_firmando_certificado_error"));
    }
    return asn1_cms;
}
Also used : CMSSignedDataGenerator(org.bouncycastle.cms.CMSSignedDataGenerator) PrivateKey(java.security.PrivateKey) ArrayList(java.util.ArrayList) CertificateException(java.security.cert.CertificateException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) CollectionCertStoreParameters(java.security.cert.CollectionCertStoreParameters) BusinessServiceException(sic.service.BusinessServiceException) UnrecoverableKeyException(java.security.UnrecoverableKeyException) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider) CMSProcessableByteArray(org.bouncycastle.cms.CMSProcessableByteArray) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) InputStream(java.io.InputStream) CertStoreException(java.security.cert.CertStoreException) KeyStoreException(java.security.KeyStoreException) IOException(java.io.IOException) KeyStore(java.security.KeyStore) CMSSignedData(org.bouncycastle.cms.CMSSignedData) X509Certificate(java.security.cert.X509Certificate) CMSProcessable(org.bouncycastle.cms.CMSProcessable) NoSuchProviderException(java.security.NoSuchProviderException) CertStore(java.security.cert.CertStore) CMSException(org.bouncycastle.cms.CMSException)

Example 93 with NoSuchProviderException

use of java.security.NoSuchProviderException in project ddf by codice.

the class KeystoreEditor method importASN1CertificatesToStore.

private boolean importASN1CertificatesToStore(KeyStore store, boolean setEntry, ASN1Set certificates) throws KeystoreEditorException {
    Enumeration certificateEnumeration = certificates.getObjects();
    try {
        while (certificateEnumeration.hasMoreElements()) {
            ASN1Primitive asn1Primitive = ((ASN1Encodable) certificateEnumeration.nextElement()).toASN1Primitive();
            org.bouncycastle.asn1.x509.Certificate instance = org.bouncycastle.asn1.x509.Certificate.getInstance(asn1Primitive);
            CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509", "BC");
            Certificate certificate = certificateFactory.generateCertificate(new ByteArrayInputStream(instance.getEncoded()));
            X500Name x500name = new JcaX509CertificateHolder((X509Certificate) certificate).getSubject();
            RDN cn = x500name.getRDNs(BCStyle.CN)[0];
            store.setCertificateEntry(IETFUtils.valueToString(cn.getFirst().getValue()), certificate);
            setEntry = true;
        }
    } catch (CertificateException | NoSuchProviderException | KeyStoreException | IOException e) {
        throw new KeystoreEditorException("Unable to import ASN1 certificates to store", e);
    }
    return setEntry;
}
Also used : Enumeration(java.util.Enumeration) CertificateException(java.security.cert.CertificateException) X500Name(org.bouncycastle.asn1.x500.X500Name) KeyStoreException(java.security.KeyStoreException) IOException(java.io.IOException) CertificateFactory(java.security.cert.CertificateFactory) JcaX509CertificateHolder(org.bouncycastle.cert.jcajce.JcaX509CertificateHolder) X509Certificate(java.security.cert.X509Certificate) ByteArrayInputStream(java.io.ByteArrayInputStream) ASN1Encodable(org.bouncycastle.asn1.ASN1Encodable) NoSuchProviderException(java.security.NoSuchProviderException) ASN1Primitive(org.bouncycastle.asn1.ASN1Primitive) RDN(org.bouncycastle.asn1.x500.RDN) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Aggregations

NoSuchProviderException (java.security.NoSuchProviderException)93 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)67 InvalidKeyException (java.security.InvalidKeyException)30 IOException (java.io.IOException)28 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)18 CertificateException (java.security.cert.CertificateException)18 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)14 Cipher (javax.crypto.Cipher)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 BadPaddingException (javax.crypto.BadPaddingException)12 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)12 KeyStoreException (java.security.KeyStoreException)11 SignatureException (java.security.SignatureException)10 X509Certificate (java.security.cert.X509Certificate)10 SecretKey (javax.crypto.SecretKey)10 CertificateFactory (java.security.cert.CertificateFactory)9 CertificateEncodingException (java.security.cert.CertificateEncodingException)8 IvParameterSpec (javax.crypto.spec.IvParameterSpec)8 KeyStore (java.security.KeyStore)7 Provider (java.security.Provider)7