Search in sources :

Example 86 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 87 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 88 with InvalidKeyException

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

the class LocalSASKeyGeneratorImpl method getSASKeyBasedStorageAccountInstance.

/**
   * Helper method that creates a CloudStorageAccount instance based on
   *  SAS key for accountName
   *
   * @param accountName Storage Account Name
   * @return CloudStorageAccount instance created using SAS key for
   *   the Storage Account.
   * @throws SASKeyGenerationException
   */
private CloudStorageAccount getSASKeyBasedStorageAccountInstance(String accountName) throws SASKeyGenerationException {
    try {
        String accountNameWithoutDomain = getAccountNameWithoutDomain(accountName);
        CloudStorageAccount account = getStorageAccountInstance(accountNameWithoutDomain, AzureNativeFileSystemStore.getAccountKeyFromConfiguration(accountName, getConf()));
        return new CloudStorageAccount(new StorageCredentialsSharedAccessSignature(account.generateSharedAccessSignature(getDefaultAccountAccessPolicy())), false, account.getEndpointSuffix(), accountNameWithoutDomain);
    } catch (KeyProviderException keyProviderEx) {
        throw new SASKeyGenerationException("Encountered KeyProviderException" + " while retrieving Storage key from configuration for account " + accountName, keyProviderEx);
    } catch (InvalidKeyException invalidKeyEx) {
        throw new SASKeyGenerationException("Encoutered InvalidKeyException " + "while generating Account level SAS key for account" + accountName, invalidKeyEx);
    } catch (StorageException storeEx) {
        throw new SASKeyGenerationException("Encoutered StorageException while " + "generating Account level SAS key for account" + accountName, storeEx);
    } catch (URISyntaxException uriSyntaxEx) {
        throw new SASKeyGenerationException("Encountered URISyntaxException for" + " account " + accountName, uriSyntaxEx);
    }
}
Also used : StorageCredentialsSharedAccessSignature(com.microsoft.azure.storage.StorageCredentialsSharedAccessSignature) CloudStorageAccount(com.microsoft.azure.storage.CloudStorageAccount) URISyntaxException(java.net.URISyntaxException) InvalidKeyException(java.security.InvalidKeyException) StorageException(com.microsoft.azure.storage.StorageException)

Example 89 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)

Example 90 with InvalidKeyException

use of java.security.InvalidKeyException in project walle by Meituan-Dianping.

the class V2SchemeSigner method generateApkSignatureSchemeV2Block.

private static byte[] generateApkSignatureSchemeV2Block(List<SignerConfig> signerConfigs, Map<ContentDigestAlgorithm, byte[]> contentDigests) throws InvalidKeyException, SignatureException {
    // FORMAT:
    // * length-prefixed sequence of length-prefixed signer blocks.
    List<byte[]> signerBlocks = new ArrayList<>(signerConfigs.size());
    int signerNumber = 0;
    for (SignerConfig signerConfig : signerConfigs) {
        signerNumber++;
        byte[] signerBlock;
        try {
            signerBlock = generateSignerBlock(signerConfig, contentDigests);
        } catch (InvalidKeyException e) {
            throw new InvalidKeyException("Signer #" + signerNumber + " failed", e);
        } catch (SignatureException e) {
            throw new SignatureException("Signer #" + signerNumber + " failed", e);
        }
        signerBlocks.add(signerBlock);
    }
    return encodeAsSequenceOfLengthPrefixedElements(new byte[][] { encodeAsSequenceOfLengthPrefixedElements(signerBlocks) });
}
Also used : ArrayList(java.util.ArrayList) SignatureException(java.security.SignatureException) InvalidKeyException(java.security.InvalidKeyException)

Aggregations

InvalidKeyException (java.security.InvalidKeyException)499 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)263 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)124 SignatureException (java.security.SignatureException)95 IOException (java.io.IOException)94 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)93 BadPaddingException (javax.crypto.BadPaddingException)89 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)87 Cipher (javax.crypto.Cipher)77 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)63 SecretKeySpec (javax.crypto.spec.SecretKeySpec)63 Signature (java.security.Signature)58 SecretKey (javax.crypto.SecretKey)50 PublicKey (java.security.PublicKey)49 PrivateKey (java.security.PrivateKey)47 CertificateException (java.security.cert.CertificateException)46 Mac (javax.crypto.Mac)44 IvParameterSpec (javax.crypto.spec.IvParameterSpec)41 NoSuchProviderException (java.security.NoSuchProviderException)39 KeyStoreException (java.security.KeyStoreException)33