Search in sources :

Example 6 with InvalidKeyException

use of java.security.InvalidKeyException in project kafka by apache.

the class ScramSaslClient method handleServerFinalMessage.

private void handleServerFinalMessage(byte[] signature) throws SaslException {
    try {
        byte[] serverKey = formatter.serverKey(saltedPassword);
        byte[] serverSignature = formatter.serverSignature(serverKey, clientFirstMessage, serverFirstMessage, clientFinalMessage);
        if (!Arrays.equals(signature, serverSignature))
            throw new SaslException("Invalid server signature in server final message");
    } catch (InvalidKeyException e) {
        throw new SaslException("Sasl server signature verification failed", e);
    }
}
Also used : SaslException(javax.security.sasl.SaslException) InvalidKeyException(java.security.InvalidKeyException)

Example 7 with InvalidKeyException

use of java.security.InvalidKeyException in project kafka by apache.

the class ScramSaslServer method verifyClientProof.

private void verifyClientProof(ClientFinalMessage clientFinalMessage) throws SaslException {
    try {
        byte[] expectedStoredKey = scramCredential.storedKey();
        byte[] clientSignature = formatter.clientSignature(expectedStoredKey, clientFirstMessage, serverFirstMessage, clientFinalMessage);
        byte[] computedStoredKey = formatter.storedKey(clientSignature, clientFinalMessage.proof());
        if (!Arrays.equals(computedStoredKey, expectedStoredKey))
            throw new SaslException("Invalid client credentials");
    } catch (InvalidKeyException e) {
        throw new SaslException("Sasl client verification failed", e);
    }
}
Also used : SaslException(javax.security.sasl.SaslException) InvalidKeyException(java.security.InvalidKeyException)

Example 8 with InvalidKeyException

use of java.security.InvalidKeyException in project LolliPin by OrangeGangsters.

the class FingerprintUiHelper method initCipher.

/**
     * Initialize the {@link Cipher} instance with the created key in the {@link #createKey()}
     * method.
     *
     * @return {@code true} if initialization is successful, {@code false} if the lock screen has
     * been disabled or reset after the key was generated, or if a fingerprint got enrolled after
     * the key was generated.
     */
private boolean initCipher() {
    try {
        if (mKeyStore == null) {
            mKeyStore = KeyStore.getInstance("AndroidKeyStore");
        }
        createKey();
        mKeyStore.load(null);
        SecretKey key = (SecretKey) mKeyStore.getKey(KEY_NAME, null);
        mCipher = Cipher.getInstance("AES/CBC/PKCS7Padding");
        mCipher.init(Cipher.ENCRYPT_MODE, key);
        return true;
    } catch (NoSuchPaddingException | KeyStoreException | CertificateException | UnrecoverableKeyException | IOException | NoSuchAlgorithmException | InvalidKeyException e) {
        return false;
    }
}
Also used : SecretKey(javax.crypto.SecretKey) UnrecoverableKeyException(java.security.UnrecoverableKeyException) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) CertificateException(java.security.cert.CertificateException) KeyStoreException(java.security.KeyStoreException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException)

Example 9 with InvalidKeyException

use of java.security.InvalidKeyException in project android_frameworks_base by ParanoidAndroid.

the class KeyChain method getPrivateKey.

/**
     * Returns the {@code PrivateKey} for the requested alias, or null
     * if no there is no result.
     *
     * @param alias The alias of the desired private key, typically
     * returned via {@link KeyChainAliasCallback#alias}.
     * @throws KeyChainException if the alias was valid but there was some problem accessing it.
     */
public static PrivateKey getPrivateKey(Context context, String alias) throws KeyChainException, InterruptedException {
    if (alias == null) {
        throw new NullPointerException("alias == null");
    }
    KeyChainConnection keyChainConnection = bind(context);
    try {
        final IKeyChainService keyChainService = keyChainConnection.getService();
        final String keyId = keyChainService.requestPrivateKey(alias);
        if (keyId == null) {
            throw new KeyChainException("keystore had a problem");
        }
        final OpenSSLEngine engine = OpenSSLEngine.getInstance("keystore");
        return engine.getPrivateKeyById(keyId);
    } catch (RemoteException e) {
        throw new KeyChainException(e);
    } catch (RuntimeException e) {
        // only certain RuntimeExceptions can be propagated across the IKeyChainService call
        throw new KeyChainException(e);
    } catch (InvalidKeyException e) {
        throw new KeyChainException(e);
    } finally {
        keyChainConnection.close();
    }
}
Also used : OpenSSLEngine(org.apache.harmony.xnet.provider.jsse.OpenSSLEngine) RemoteException(android.os.RemoteException) InvalidKeyException(java.security.InvalidKeyException)

Example 10 with InvalidKeyException

use of java.security.InvalidKeyException in project SeriesGuide by UweTrottmann.

the class Security method verify.

/**
     * Verifies that the signature from the server matches the computed
     * signature on the data.  Returns true if the data is correctly signed.
     *
     * @param publicKey public key associated with the developer account
     * @param signedData signed data from server
     * @param signature server signature
     * @return true if the data and signature match
     */
public static boolean verify(PublicKey publicKey, String signedData, String signature) {
    Signature sig;
    try {
        sig = Signature.getInstance(SIGNATURE_ALGORITHM);
        sig.initVerify(publicKey);
        sig.update(signedData.getBytes());
        if (!sig.verify(Base64.decode(signature))) {
            Timber.e("Signature verification failed.");
            return false;
        }
        return true;
    } catch (NoSuchAlgorithmException | InvalidKeyException | SignatureException | Base64DecoderException e) {
        Timber.e(e, "Signature verification aborted.");
    }
    return false;
}
Also used : Signature(java.security.Signature) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SignatureException(java.security.SignatureException) InvalidKeyException(java.security.InvalidKeyException)

Aggregations

InvalidKeyException (java.security.InvalidKeyException)478 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)246 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)123 SignatureException (java.security.SignatureException)92 IOException (java.io.IOException)90 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)87 BadPaddingException (javax.crypto.BadPaddingException)83 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)80 Cipher (javax.crypto.Cipher)71 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)61 Signature (java.security.Signature)58 SecretKeySpec (javax.crypto.spec.SecretKeySpec)52 PublicKey (java.security.PublicKey)49 SecretKey (javax.crypto.SecretKey)49 PrivateKey (java.security.PrivateKey)47 CertificateException (java.security.cert.CertificateException)44 IvParameterSpec (javax.crypto.spec.IvParameterSpec)40 NoSuchProviderException (java.security.NoSuchProviderException)38 Mac (javax.crypto.Mac)38 SecureRandom (java.security.SecureRandom)32