Search in sources :

Example 81 with GeneralSecurityException

use of java.security.GeneralSecurityException in project ignite by apache.

the class SslContextFactory method loadKeyStore.

/**
 * Loads key store with configured parameters.
 *
 * @param keyStoreType Type of key store.
 * @param storeFilePath Path to key store file.
 * @param keyStorePwd Store password.
 * @return Initialized key store.
 * @throws SSLException If key store could not be initialized.
 */
private KeyStore loadKeyStore(String keyStoreType, String storeFilePath, char[] keyStorePwd) throws SSLException {
    InputStream input = null;
    try {
        KeyStore keyStore = KeyStore.getInstance(keyStoreType);
        input = openFileInputStream(storeFilePath);
        keyStore.load(input, keyStorePwd);
        return keyStore;
    } catch (GeneralSecurityException e) {
        throw new SSLException("Failed to initialize key store (security exception occurred) [type=" + keyStoreType + ", keyStorePath=" + storeFilePath + ']', e);
    } catch (FileNotFoundException e) {
        throw new SSLException("Failed to initialize key store (key store file was not found): [path=" + storeFilePath + ", msg=" + e.getMessage() + ']');
    } catch (IOException e) {
        throw new SSLException("Failed to initialize key store (I/O error occurred): " + storeFilePath, e);
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException ignored) {
            }
        }
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) GeneralSecurityException(java.security.GeneralSecurityException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) KeyStore(java.security.KeyStore) SSLException(javax.net.ssl.SSLException)

Example 82 with GeneralSecurityException

use of java.security.GeneralSecurityException in project AndLang by wugemu.

the class EncryptUtil method encryptSHA.

public static String encryptSHA(String data) throws IOException {
    byte[] bytes = null;
    try {
        MessageDigest md = MessageDigest.getInstance("SHA-1");
        bytes = md.digest(data.getBytes(CHARSET_UTF8));
    } catch (GeneralSecurityException gse) {
        String msg = getStringFromException(gse);
        throw new IOException(msg, gse);
    }
    return byte2hex(bytes);
}
Also used : GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) MessageDigest(java.security.MessageDigest)

Example 83 with GeneralSecurityException

use of java.security.GeneralSecurityException in project AndLang by wugemu.

the class EncryptUtil method encryptMD5.

public static String encryptMD5(String data) throws IOException {
    byte[] bytes = null;
    try {
        MessageDigest md = MessageDigest.getInstance("MD5");
        bytes = md.digest(data.getBytes(CHARSET_UTF8));
    } catch (GeneralSecurityException gse) {
        String msg = getStringFromException(gse);
        throw new IOException(msg, gse);
    }
    return byte2hex(bytes);
}
Also used : GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) MessageDigest(java.security.MessageDigest)

Example 84 with GeneralSecurityException

use of java.security.GeneralSecurityException in project cas by apereo.

the class DuoAuthenticationHandler method authenticateDuoCredential.

private AuthenticationHandlerExecutionResult authenticateDuoCredential(final Credential credential) throws FailedLoginException {
    try {
        final DuoCredential duoCredential = (DuoCredential) credential;
        if (!duoCredential.isValid()) {
            throw new GeneralSecurityException("Duo credential validation failed. Ensure a username " + " and the signed Duo response is configured and passed. Credential received: " + duoCredential);
        }
        final DuoSecurityAuthenticationService duoAuthenticationService = getDuoAuthenticationService();
        final String duoVerifyResponse = duoAuthenticationService.authenticate(duoCredential).getValue();
        LOGGER.debug("Response from Duo verify: [{}]", duoVerifyResponse);
        final String primaryCredentialsUsername = duoCredential.getUsername();
        final boolean isGoodAuthentication = duoVerifyResponse.equals(primaryCredentialsUsername);
        if (isGoodAuthentication) {
            LOGGER.info("Successful Duo authentication for [{}]", primaryCredentialsUsername);
            final Principal principal = this.principalFactory.createPrincipal(duoVerifyResponse);
            return createHandlerResult(credential, principal, new ArrayList<>());
        }
        throw new FailedLoginException("Duo authentication username " + primaryCredentialsUsername + " does not match Duo response: " + duoVerifyResponse);
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
        throw new FailedLoginException(e.getMessage());
    }
}
Also used : FailedLoginException(javax.security.auth.login.FailedLoginException) GeneralSecurityException(java.security.GeneralSecurityException) Principal(org.apereo.cas.authentication.principal.Principal) GeneralSecurityException(java.security.GeneralSecurityException) FailedLoginException(javax.security.auth.login.FailedLoginException)

Example 85 with GeneralSecurityException

use of java.security.GeneralSecurityException in project cas by apereo.

the class CouchbaseClientFactory method query.

/**
 * Query and get a result by username.
 *
 * @param usernameAttribute the username attribute
 * @param usernameValue     the username value
 * @return the n1ql query result
 * @throws GeneralSecurityException the general security exception
 */
public N1qlQueryResult query(final String usernameAttribute, final String usernameValue) throws GeneralSecurityException {
    final Statement statement = Select.select("*").from(Expression.i(getBucket().name())).where(Expression.x(usernameAttribute).eq('\'' + usernameValue + '\''));
    LOGGER.debug("Running query [{}] on bucket [{}]", statement.toString(), getBucket().name());
    final SimpleN1qlQuery query = N1qlQuery.simple(statement);
    final N1qlQueryResult result = getBucket().query(query, timeout, TimeUnit.MILLISECONDS);
    if (!result.finalSuccess()) {
        LOGGER.error("Couchbase query failed with [{}]", result.errors().stream().map(JsonObject::toString).collect(Collectors.joining(",")));
        throw new GeneralSecurityException("Could not locate account for user " + usernameValue);
    }
    return result;
}
Also used : SimpleN1qlQuery(com.couchbase.client.java.query.SimpleN1qlQuery) Statement(com.couchbase.client.java.query.Statement) GeneralSecurityException(java.security.GeneralSecurityException) JsonObject(com.couchbase.client.java.document.json.JsonObject) N1qlQueryResult(com.couchbase.client.java.query.N1qlQueryResult)

Aggregations

GeneralSecurityException (java.security.GeneralSecurityException)1171 IOException (java.io.IOException)435 Cipher (javax.crypto.Cipher)144 Test (org.junit.Test)136 X509Certificate (java.security.cert.X509Certificate)124 KeyStore (java.security.KeyStore)89 SSLContext (javax.net.ssl.SSLContext)84 SecretKeySpec (javax.crypto.spec.SecretKeySpec)80 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)72 ArrayList (java.util.ArrayList)72 File (java.io.File)61 InputStream (java.io.InputStream)57 Certificate (java.security.cert.Certificate)57 PublicKey (java.security.PublicKey)53 PrivateKey (java.security.PrivateKey)50 FileInputStream (java.io.FileInputStream)49 BigInteger (java.math.BigInteger)49 SecretKey (javax.crypto.SecretKey)48 IvParameterSpec (javax.crypto.spec.IvParameterSpec)43 SecureRandom (java.security.SecureRandom)42