Wrap and propagate unexpected exceptions

This commit is contained in:
Cameron Gutman
2020-07-07 00:52:11 -05:00
parent a99e070c26
commit 484be9bfe6
3 changed files with 22 additions and 29 deletions

View File

@@ -102,9 +102,7 @@ public class AndroidCryptoProvider implements LimelightCryptoProvider {
LimeLog.warning("Corrupted certificate"); LimeLog.warning("Corrupted certificate");
return false; return false;
} catch (NoSuchAlgorithmException e) { } catch (NoSuchAlgorithmException e) {
// Should never happen throw new RuntimeException(e);
e.printStackTrace();
return false;
} catch (InvalidKeySpecException e) { } catch (InvalidKeySpecException e) {
// May happen if the key is corrupt // May happen if the key is corrupt
LimeLog.warning("Corrupted key"); LimeLog.warning("Corrupted key");
@@ -124,10 +122,8 @@ public class AndroidCryptoProvider implements LimelightCryptoProvider {
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA", bcProvider); KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA", bcProvider);
keyPairGenerator.initialize(2048); keyPairGenerator.initialize(2048);
keyPair = keyPairGenerator.generateKeyPair(); keyPair = keyPairGenerator.generateKeyPair();
} catch (NoSuchAlgorithmException e1) { } catch (NoSuchAlgorithmException e) {
// Should never happen throw new RuntimeException(e);
e1.printStackTrace();
return false;
} }
Date now = new Date(); Date now = new Date();
@@ -152,8 +148,6 @@ public class AndroidCryptoProvider implements LimelightCryptoProvider {
cert = new JcaX509CertificateConverter().setProvider(bcProvider).getCertificate(certBuilder.build(sigGen)); cert = new JcaX509CertificateConverter().setProvider(bcProvider).getCertificate(certBuilder.build(sigGen));
key = (RSAPrivateKey) keyPair.getPrivate(); key = (RSAPrivateKey) keyPair.getPrivate();
} catch (Exception e) { } catch (Exception e) {
// Nothing should go wrong here
e.printStackTrace();
throw new RuntimeException(e); throw new RuntimeException(e);
} }

View File

@@ -43,25 +43,26 @@ public class NvConnection {
this.context = new ConnectionContext(); this.context = new ConnectionContext();
this.context.streamConfig = config; this.context.streamConfig = config;
this.context.serverCert = serverCert; this.context.serverCert = serverCert;
try {
// This is unique per connection // This is unique per connection
this.context.riKey = generateRiAesKey(); this.context.riKey = generateRiAesKey();
} catch (NoSuchAlgorithmException e) { context.riKeyId = generateRiKeyId();
// Should never happen
e.printStackTrace();
}
this.context.riKeyId = generateRiKeyId();
this.isMonkey = ActivityManager.isUserAMonkey(); this.isMonkey = ActivityManager.isUserAMonkey();
} }
private static SecretKey generateRiAesKey() throws NoSuchAlgorithmException { private static SecretKey generateRiAesKey() {
KeyGenerator keyGen = KeyGenerator.getInstance("AES"); try {
KeyGenerator keyGen = KeyGenerator.getInstance("AES");
// RI keys are 128 bits
keyGen.init(128); // RI keys are 128 bits
keyGen.init(128);
return keyGen.generateKey();
return keyGen.generateKey();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
} }
private static int generateRiKeyId() { private static int generateRiKeyId() {

View File

@@ -314,9 +314,8 @@ public class PairingManager {
return md.digest(data); return md.digest(data);
} }
catch (NoSuchAlgorithmException e) { catch (NoSuchAlgorithmException e) {
// Shouldn't ever happen
e.printStackTrace(); e.printStackTrace();
return null; throw new RuntimeException(e);
} }
} }
} }
@@ -332,9 +331,8 @@ public class PairingManager {
return md.digest(data); return md.digest(data);
} }
catch (NoSuchAlgorithmException e) { catch (NoSuchAlgorithmException e) {
// Shouldn't ever happen
e.printStackTrace(); e.printStackTrace();
return null; throw new RuntimeException(e);
} }
} }
} }