Search in sources :

Example 1 with RuntimeException

use of java.lang.RuntimeException in project jdk8u_jdk by JetBrains.

the class CipherInputStreamExceptions method gcm_oneReadByte.

/*
     * Verify noexception thrown when 1 byte is read from a GCM stream
     * and then closed
     * This test:
     *   1) Encrypt 100 bytes with AES/GCM/PKCS5Padding
     *   2) Read one byte from the stream, expect no exception thrown.
     *   4) Close stream,expect no exception thrown.
     */
static void gcm_oneReadByte() throws Exception {
    System.out.println("Running gcm_oneReadByte test");
    // Encrypt 100 bytes with AES/GCM/PKCS5Padding
    byte[] ct = encryptedText("GCM", 100);
    // Create stream for decryption
    CipherInputStream in = getStream("GCM", ct);
    try {
        in.read();
        System.out.println("  Pass.");
    } catch (Exception e) {
        System.out.println("  Fail: " + e.getMessage());
        throw new RuntimeException(e.getCause());
    }
}
Also used : RuntimeException(java.lang.RuntimeException) CipherInputStream(javax.crypto.CipherInputStream) IllegalBlockSizeException(javax.crypto.IllegalBlockSizeException) IOException(java.io.IOException) RuntimeException(java.lang.RuntimeException) AEADBadTagException(javax.crypto.AEADBadTagException) Exception(java.lang.Exception)

Example 2 with RuntimeException

use of java.lang.RuntimeException in project jdk8u_jdk by JetBrains.

the class CipherInputStreamExceptions method gcm_AEADBadTag.

/* Full read stream, check that getMoreData() is throwing an exception
     * This test
     *   1) Encrypt 100 bytes with AES/GCM/PKCS5Padding
     *   2) Changes the last byte to invalidate the authetication tag.
     *   3) Fully reads CipherInputStream to decrypt the message and closes
     */
static void gcm_AEADBadTag() throws Exception {
    Cipher c;
    byte[] read = new byte[200];
    System.out.println("Running gcm_AEADBadTag");
    // Encrypt 100 bytes with AES/GCM/PKCS5Padding
    byte[] ct = encryptedText("GCM", 100);
    // Corrupt the encrypted message
    ct = corruptGCM(ct);
    // Create stream for decryption
    CipherInputStream in = getStream("GCM", ct);
    try {
        int size = in.read(read);
        throw new RuntimeException("Fail: CipherInputStream.read() " + "returned " + size + " and didn't throw an exception.");
    } catch (IOException e) {
        Throwable ec = e.getCause();
        if (ec instanceof AEADBadTagException) {
            System.out.println("  Pass.");
        } else {
            System.out.println("  Fail: " + ec.getMessage());
            throw new RuntimeException(ec);
        }
    } finally {
        in.close();
    }
}
Also used : RuntimeException(java.lang.RuntimeException) CipherInputStream(javax.crypto.CipherInputStream) Throwable(java.lang.Throwable) Cipher(javax.crypto.Cipher) IOException(java.io.IOException) AEADBadTagException(javax.crypto.AEADBadTagException)

Example 3 with RuntimeException

use of java.lang.RuntimeException in project jdk8u_jdk by JetBrains.

the class CipherInputStreamExceptions method gcm_oneReadByteCorrupt.

/*
     * Verify exception thrown when 1 byte is read from a corrupted GCM stream
     * and then closed
     * This test:
     *   1) Encrypt 100 bytes with AES/GCM/PKCS5Padding
     *   2) Changes the last byte to invalidate the authetication tag.
     *   3) Read one byte from the stream, expect exception thrown.
     *   4) Close stream,expect no exception thrown.
     */
static void gcm_oneReadByteCorrupt() throws Exception {
    System.out.println("Running gcm_oneReadByteCorrupt test");
    // Encrypt 100 bytes with AES/GCM/PKCS5Padding
    byte[] ct = encryptedText("GCM", 100);
    // Corrupt the encrypted message
    ct = corruptGCM(ct);
    // Create stream for decryption
    CipherInputStream in = getStream("GCM", ct);
    try {
        in.read();
        System.out.println("  Fail. No exception thrown.");
    } catch (IOException e) {
        Throwable ec = e.getCause();
        if (ec instanceof AEADBadTagException) {
            System.out.println("  Pass.");
        } else {
            System.out.println("  Fail: " + ec.getMessage());
            throw new RuntimeException(ec);
        }
    }
}
Also used : RuntimeException(java.lang.RuntimeException) CipherInputStream(javax.crypto.CipherInputStream) Throwable(java.lang.Throwable) IOException(java.io.IOException) AEADBadTagException(javax.crypto.AEADBadTagException)

Example 4 with RuntimeException

use of java.lang.RuntimeException in project jdk8u_jdk by JetBrains.

the class CipherInputStreamExceptions method gcm_shortReadAEAD.

/* Short read stream,
     * This test
     *   1) Encrypt 100 bytes with AES/GCM/PKCS5Padding
     *   2) Reads 100 bytes from stream to decrypt the message and closes
     *   3) Make sure no value is returned by read()
     *   4) Make sure no exception is thrown
     */
static void gcm_shortReadAEAD() throws Exception {
    Cipher c;
    byte[] read = new byte[100];
    System.out.println("Running gcm_shortReadAEAD");
    byte[] pt = new byte[600];
    pt[0] = 1;
    // Encrypt provided 600 bytes with AES/GCM/PKCS5Padding
    byte[] ct = encryptedText("GCM", pt);
    // Create stream for decryption
    CipherInputStream in = getStream("GCM", ct);
    int size = 0;
    try {
        size = in.read(read);
        in.close();
        if (read.length != 100) {
            throw new RuntimeException("Fail: read size = " + read.length + "should be 100.");
        }
        if (read[0] != 1) {
            throw new RuntimeException("Fail: The decrypted text does " + "not match the plaintext: '" + read[0] + "'");
        }
    } catch (IOException e) {
        System.out.println("  Fail: " + e.getMessage());
        throw new RuntimeException(e.getCause());
    }
    System.out.println("  Pass.");
}
Also used : RuntimeException(java.lang.RuntimeException) CipherInputStream(javax.crypto.CipherInputStream) Cipher(javax.crypto.Cipher) IOException(java.io.IOException)

Example 5 with RuntimeException

use of java.lang.RuntimeException in project h2o-3 by h2oai.

the class H2OBuildVersion method calcBuildNumber.

private String calcBuildNumber(File rootDir, String versionFromGradle) {
    try {
        String buildNumberFileName = rootDir.toString() + File.separator + "gradle" + File.separator + "buildnumber.properties";
        File f = new File(buildNumberFileName);
        if (!f.exists()) {
            return "99999";
        }
        BufferedReader br = new BufferedReader(new FileReader(buildNumberFileName));
        String line = br.readLine();
        while (line != null) {
            Pattern p = Pattern.compile("BUILD_NUMBER\\s*=\\s*(\\S+)");
            Matcher m = p.matcher(line);
            boolean b = m.matches();
            if (b) {
                br.close();
                String buildNumber = m.group(1);
                return buildNumber;
            }
            line = br.readLine();
        }
        throw new RuntimeException("BUILD_NUMBER property not found in " + buildNumberFileName);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Pattern(java.util.regex.Pattern) RuntimeException(java.lang.RuntimeException) Matcher(java.util.regex.Matcher) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File) RuntimeException(java.lang.RuntimeException)

Aggregations

RuntimeException (java.lang.RuntimeException)23 IOException (java.io.IOException)11 CipherInputStream (javax.crypto.CipherInputStream)9 WebElement (org.openqa.selenium.WebElement)7 Hashtable (java.util.Hashtable)4 Cipher (javax.crypto.Cipher)4 File (java.io.File)3 Exception (java.lang.Exception)3 Throwable (java.lang.Throwable)3 AEADBadTagException (javax.crypto.AEADBadTagException)3 Test (org.junit.Test)3 FileNotFoundException (java.io.FileNotFoundException)2 Boolean (java.lang.Boolean)2 IllegalBlockSizeException (javax.crypto.IllegalBlockSizeException)2 SearchContext (org.openqa.selenium.SearchContext)2 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)2 SuppressLint (android.annotation.SuppressLint)1 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)1 TransactionTooLargeException (android.os.TransactionTooLargeException)1 BufferedReader (java.io.BufferedReader)1