use of org.spongycastle.jce.provider.BouncyCastleProvider in project conceal by facebook.
the class CipherReadBenchmark method setUp.
@Override
public void setUp() throws Exception {
// Initialize the buffers
Random random = new Random();
mData = new byte[size];
random.nextBytes(mData);
mReadBuffer = new byte[1024];
// Initialize the ciphers and Macs.
mHMAC = HMAC.getInstance();
mNativeGCMCipherHelper = NativeGCMCipherHelper.getInstance();
mAESCipher = AESCipher.getInstance();
Security.addProvider(new BouncyCastleProvider());
mBCGCMCipher = BouncyCastleGCMCipher.getInstance();
// Initialize the ciphered outputs.
mNativeGCMCipheredData = generateCipherText(mNativeGCMCipherHelper);
mBCGCMCipheredData = generateCipherText(mBCGCMCipher);
mAESCipherText = generateCipherText(mAESCipher);
}
use of org.spongycastle.jce.provider.BouncyCastleProvider in project kdeconnect-android by KDE.
the class DeviceTest method testPairingDoneWithCertificate.
public void testPairingDoneWithCertificate() throws Exception {
KeyPair keyPair = null;
try {
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
keyGen.initialize(2048);
keyPair = keyGen.genKeyPair();
} catch (Exception e) {
e.printStackTrace();
Log.e("KDE/initializeRsaKeys", "Exception");
}
X509Certificate certificate = null;
try {
BouncyCastleProvider BC = new BouncyCastleProvider();
X500NameBuilder nameBuilder = new X500NameBuilder(BCStyle.INSTANCE);
nameBuilder.addRDN(BCStyle.CN, "testDevice");
nameBuilder.addRDN(BCStyle.OU, "KDE Connect");
nameBuilder.addRDN(BCStyle.O, "KDE");
Date notBefore = new Date(System.currentTimeMillis());
Date notAfter = new Date(System.currentTimeMillis() + System.currentTimeMillis());
X509v3CertificateBuilder certificateBuilder = new JcaX509v3CertificateBuilder(nameBuilder.build(), BigInteger.ONE, notBefore, notAfter, nameBuilder.build(), keyPair.getPublic());
ContentSigner contentSigner = new JcaContentSignerBuilder("SHA256WithRSAEncryption").setProvider(BC).build(keyPair.getPrivate());
certificate = new JcaX509CertificateConverter().setProvider(BC).getCertificate(certificateBuilder.build(contentSigner));
} catch (Exception e) {
e.printStackTrace();
Log.e("KDE/initialiseCert", "Exception");
}
NetworkPackage fakeNetworkPackage = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_IDENTITY);
fakeNetworkPackage.set("deviceId", "unpairedTestDevice");
fakeNetworkPackage.set("deviceName", "Unpaired Test Device");
fakeNetworkPackage.set("protocolVersion", NetworkPackage.ProtocolVersion);
fakeNetworkPackage.set("deviceType", Device.DeviceType.Phone.toString());
fakeNetworkPackage.set("certificate", Base64.encodeToString(certificate.getEncoded(), 0));
LanLinkProvider linkProvider = Mockito.mock(LanLinkProvider.class);
Mockito.when(linkProvider.getName()).thenReturn("LanLinkProvider");
LanLink link = Mockito.mock(LanLink.class);
Mockito.when(link.getPairingHandler(Mockito.any(Device.class), Mockito.any(BasePairingHandler.PairingHandlerCallback.class))).thenReturn(Mockito.mock(LanPairingHandler.class));
Mockito.when(link.getLinkProvider()).thenReturn(linkProvider);
Device device = new Device(getContext(), fakeNetworkPackage, link);
device.publicKey = keyPair.getPublic();
assertNotNull(device);
assertEquals(device.getDeviceId(), "unpairedTestDevice");
assertEquals(device.getName(), "Unpaired Test Device");
assertEquals(device.getDeviceType(), Device.DeviceType.Phone);
assertNotNull(device.publicKey);
assertNotNull(device.certificate);
Method method;
try {
method = Device.class.getDeclaredMethod("pairingDone");
method.setAccessible(true);
method.invoke(device);
} catch (Exception e) {
e.printStackTrace();
}
assertEquals(device.isPaired(), true);
SharedPreferences preferences = getContext().getSharedPreferences("trusted_devices", Context.MODE_PRIVATE);
assertEquals(preferences.getBoolean(device.getDeviceId(), false), true);
SharedPreferences settings = getContext().getSharedPreferences(device.getDeviceId(), Context.MODE_PRIVATE);
assertEquals(settings.getString("deviceName", "Unknown device"), "Unpaired Test Device");
assertEquals(settings.getString("deviceType", "tablet"), "phone");
// Cleanup for unpaired test device
preferences.edit().remove(device.getDeviceId()).apply();
settings.edit().clear().apply();
}
use of org.spongycastle.jce.provider.BouncyCastleProvider in project conceal by facebook.
the class CipherWriteBenchmark method setUp.
@Override
public void setUp() throws Exception {
Random random = new Random();
mData = new byte[size];
random.nextBytes(mData);
mNullOutputStream = new NullOutputStream();
mHMAC = HMAC.getInstance();
mNativeGCMCipherHelper = NativeGCMCipherHelper.getInstance();
mAESCipher = AESCipher.getInstance();
Security.addProvider(new BouncyCastleProvider());
mBCGCMCipher = BouncyCastleGCMCipher.getInstance();
}
Aggregations