mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 23:28:42 +03:00
Use RSAPublicKey interface instead of OpenSSLRsaPublicKey to avoid conscrypt version conflicts
OpenSSLRsaPublicKey has a different package when using the open-source conscrypt vs. the one inserted by Play Services. Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
This commit is contained in:
parent
7abef86169
commit
66e19849cb
3 changed files with 9 additions and 9 deletions
|
@ -53,7 +53,6 @@ import com.owncloud.android.utils.EncryptionUtils;
|
|||
import com.owncloud.android.utils.FileStorageUtils;
|
||||
|
||||
import org.bouncycastle.operator.OperatorCreationException;
|
||||
import org.conscrypt.OpenSSLRSAPublicKey;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
|
@ -67,6 +66,7 @@ import java.security.KeyPair;
|
|||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.interfaces.RSAPrivateCrtKey;
|
||||
import java.security.interfaces.RSAPublicKey;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
@ -502,7 +502,7 @@ public class EndToEndRandomIT extends AbstractOnServerIT {
|
|||
|
||||
// check key
|
||||
RSAPrivateCrtKey privateKey = (RSAPrivateCrtKey) keyPair.getPrivate();
|
||||
OpenSSLRSAPublicKey publicKey = EncryptionUtils.convertPublicKeyFromString(publicKeyString);
|
||||
RSAPublicKey publicKey = EncryptionUtils.convertPublicKeyFromString(publicKeyString);
|
||||
|
||||
BigInteger modulusPublic = publicKey.getModulus();
|
||||
BigInteger modulusPrivate = privateKey.getModulus();
|
||||
|
@ -615,7 +615,7 @@ public class EndToEndRandomIT extends AbstractOnServerIT {
|
|||
|
||||
// check key
|
||||
RSAPrivateCrtKey privateKey = (RSAPrivateCrtKey) keyPair.getPrivate();
|
||||
OpenSSLRSAPublicKey publicKey = EncryptionUtils.convertPublicKeyFromString(publicKeyString);
|
||||
RSAPublicKey publicKey = EncryptionUtils.convertPublicKeyFromString(publicKeyString);
|
||||
|
||||
BigInteger modulusPublic = publicKey.getModulus();
|
||||
BigInteger modulusPrivate = privateKey.getModulus();
|
||||
|
|
|
@ -36,7 +36,6 @@ import com.owncloud.android.utils.EncryptionUtils;
|
|||
|
||||
import org.apache.commons.codec.binary.Hex;
|
||||
import org.apache.commons.io.FileUtils;
|
||||
import org.conscrypt.OpenSSLRSAPublicKey;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
@ -53,6 +52,7 @@ import java.security.MessageDigest;
|
|||
import java.security.PrivateKey;
|
||||
import java.security.SecureRandom;
|
||||
import java.security.interfaces.RSAPrivateCrtKey;
|
||||
import java.security.interfaces.RSAPublicKey;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
|
@ -184,7 +184,7 @@ public class EncryptionTestIT {
|
|||
@Test
|
||||
public void testModulus() throws Exception {
|
||||
KeyPair keyPair = EncryptionUtils.generateKeyPair();
|
||||
OpenSSLRSAPublicKey publicKey = (OpenSSLRSAPublicKey) keyPair.getPublic();
|
||||
RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
|
||||
RSAPrivateCrtKey privateKey = (RSAPrivateCrtKey) keyPair.getPrivate();
|
||||
|
||||
BigInteger modulusPublic = publicKey.getModulus();
|
||||
|
|
|
@ -46,7 +46,6 @@ import com.owncloud.android.lib.resources.e2ee.UpdateMetadataRemoteOperation;
|
|||
import com.owncloud.android.operations.UploadException;
|
||||
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.conscrypt.OpenSSLRSAPublicKey;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
|
@ -72,6 +71,7 @@ import java.security.cert.CertificateException;
|
|||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.security.interfaces.RSAPrivateCrtKey;
|
||||
import java.security.interfaces.RSAPublicKey;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import java.security.spec.KeySpec;
|
||||
import java.security.spec.PKCS8EncodedKeySpec;
|
||||
|
@ -855,7 +855,7 @@ public final class EncryptionUtils {
|
|||
}
|
||||
}
|
||||
|
||||
public static OpenSSLRSAPublicKey convertPublicKeyFromString(String string) throws CertificateException {
|
||||
public static RSAPublicKey convertPublicKeyFromString(String string) throws CertificateException {
|
||||
String trimmedCert = string.replace("-----BEGIN CERTIFICATE-----\n", "")
|
||||
.replace("-----END CERTIFICATE-----\n", "");
|
||||
byte[] encodedCert = trimmedCert.getBytes(StandardCharsets.UTF_8);
|
||||
|
@ -864,7 +864,7 @@ public final class EncryptionUtils {
|
|||
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
|
||||
InputStream in = new ByteArrayInputStream(decodedCert);
|
||||
X509Certificate certificate = (X509Certificate) certFactory.generateCertificate(in);
|
||||
return (OpenSSLRSAPublicKey) certificate.getPublicKey();
|
||||
return (RSAPublicKey) certificate.getPublicKey();
|
||||
}
|
||||
|
||||
public static void removeE2E(ArbitraryDataProvider arbitraryDataProvider, User user) {
|
||||
|
@ -877,7 +877,7 @@ public final class EncryptionUtils {
|
|||
public static boolean isMatchingKeys(KeyPair keyPair, String publicKeyString) throws CertificateException {
|
||||
// check key
|
||||
RSAPrivateCrtKey privateKey = (RSAPrivateCrtKey) keyPair.getPrivate();
|
||||
OpenSSLRSAPublicKey publicKey = EncryptionUtils.convertPublicKeyFromString(publicKeyString);
|
||||
RSAPublicKey publicKey = EncryptionUtils.convertPublicKeyFromString(publicKeyString);
|
||||
|
||||
BigInteger modulusPublic = publicKey.getModulus();
|
||||
BigInteger modulusPrivate = privateKey.getModulus();
|
||||
|
|
Loading…
Reference in a new issue