use of java.lang.Throwable 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();
}
}
use of java.lang.Throwable 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);
}
}
}
use of java.lang.Throwable in project grpc-java by grpc.
the class TesterInstrumentation method onCreate.
@Override
public void onCreate(Bundle args) {
super.onCreate(args);
testCase = args.getString("test_case") != null ? args.getString("test_case") : "empty_unary";
host = args.getString("server_host");
port = Integer.parseInt(args.getString("server_port"));
serverHostOverride = args.getString("server_host_override");
useTls = args.getString("use_tls") != null ? Boolean.parseBoolean(args.getString("use_tls")) : true;
useTestCa = args.getString("use_test_ca") != null ? Boolean.parseBoolean(args.getString("use_test_ca")) : false;
androidSocketFactoryTls = args.getString("android_socket_factory_tls");
InputStream testCa = null;
if (useTestCa) {
testCa = getContext().getResources().openRawResource(R.raw.ca);
}
if (useTls) {
try {
ProviderInstaller.installIfNeeded(getContext());
} catch (GooglePlayServicesRepairableException e) {
// The provider is helpful, but it is possible to succeed without it.
// Hope that the system-provided libraries are new enough.
Log.w(InteropTester.LOG_TAG, "Failed installing security provider", e);
} catch (GooglePlayServicesNotAvailableException e) {
// The provider is helpful, but it is possible to succeed without it.
// Hope that the system-provided libraries are new enough.
Log.w(InteropTester.LOG_TAG, "Failed installing security provider", e);
}
}
try {
new InteropTester(testCase, TesterOkHttpChannelBuilder.build(host, port, serverHostOverride, useTls, testCa, androidSocketFactoryTls), new InteropTester.TestListener() {
@Override
public void onPreTest() {
}
@Override
public void onPostTest(String result) {
Bundle bundle = new Bundle();
bundle.putString("grpc test result", result);
if (InteropTester.SUCCESS_MESSAGE.equals(result)) {
finish(0, bundle);
} else {
finish(1, bundle);
}
}
}).execute();
} catch (Throwable t) {
Bundle bundle = new Bundle();
bundle.putString("Exception encountered", t.toString());
finish(1, bundle);
}
}
use of java.lang.Throwable in project jdk8u_jdk by JetBrains.
the class CipherInputStreamExceptions method cbc_readAllIllegalBlockSize.
/* Check that exception is thrown when message is fully read
* This test:
* 1) Encrypts a 96 byte message with AES/CBC/PKCS5Padding
* 2) Create a stream that sends 95 bytes.
* 3) Read stream to the end
* 4) Expect IllegalBlockSizeException thrown
*/
static void cbc_readAllIllegalBlockSize() throws Exception {
byte[] read = new byte[200];
System.out.println("Running cbc_readAllIllegalBlockSize test");
// Encrypt 96 byte with AES/CBC/PKCS5Padding
byte[] ct = encryptedText("CBC", 96);
// Create a stream with only 95 bytes of encrypted data
CipherInputStream in = getStream("CBC", ct, 95);
try {
int s, size = 0;
while ((s = in.read(read)) != -1) {
size += s;
}
throw new RuntimeException("Fail: No IllegalBlockSizeException. " + "CipherInputStream.read() returned " + size);
} catch (IOException e) {
Throwable ec = e.getCause();
if (ec instanceof IllegalBlockSizeException) {
System.out.println(" Pass.");
} else {
System.out.println(" Fail: " + ec.getMessage());
throw new RuntimeException(ec);
}
}
}
Aggregations