mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2026-11-27 04:16:42 -08:00
Switch from Bouncycastle to Spongycastle
This commit is contained in:
1 parent
a278ad9c03
commit
9fa5eececf
180 files changed
+37
-21863
No files matched your search
@@ -1,36 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010 Brian Pellin.
|
||||
*
|
||||
* This file is part of KeePassDroid.
|
||||
*
|
||||
* KeePassDroid is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* KeePassDroid is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with KeePassDroid. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
package com.keepassdroid.crypto;
|
||||
|
||||
import java.security.Provider;
|
||||
|
||||
public class BouncyCastleProvider extends Provider {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -6705090615178002994L;
|
||||
|
||||
public BouncyCastleProvider() {
|
||||
super("BouncyCastleProvider", 1.0, "");
|
||||
|
||||
put("Cipher.TWOFISH", org.bouncycastle.jce.provider.JCEBlockCipher.Twofish.class.getName());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -22,6 +22,7 @@ package com.keepassdroid.crypto;
|
||||
import java.security.InvalidAlgorithmParameterException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.Security;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
@@ -33,9 +34,15 @@ import android.os.Build;
|
||||
|
||||
import com.keepassdroid.utils.Types;
|
||||
|
||||
import org.spongycastle.jce.provider.BouncyCastleProvider;
|
||||
|
||||
public class CipherFactory {
|
||||
private static boolean blacklistInit = false;
|
||||
private static boolean blacklisted;
|
||||
|
||||
static {
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
}
|
||||
|
||||
public static Cipher getInstance(String transformation) throws NoSuchAlgorithmException, NoSuchPaddingException {
|
||||
return getInstance(transformation, false);
|
||||
@@ -46,14 +53,7 @@ public class CipherFactory {
|
||||
if ( (!deviceBlacklisted()) && (!androidOverride) && hasNativeImplementation(transformation) && NativeLib.loaded() ) {
|
||||
return Cipher.getInstance(transformation, new AESProvider());
|
||||
} else {
|
||||
try {
|
||||
return Cipher.getInstance(transformation, new BouncyCastleProvider());
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
// Do nothing, fall through
|
||||
} catch (NoSuchPaddingException e) {
|
||||
// Do nothing, fall through
|
||||
}
|
||||
return Cipher.getInstance(transformation);
|
||||
return Cipher.getInstance(transformation);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,9 +103,9 @@ public class CipherFactory {
|
||||
} else if ( uuid.equals(TWOFISH_CIPHER) ) {
|
||||
Cipher cipher;
|
||||
if (opmode == Cipher.ENCRYPT_MODE) {
|
||||
cipher = CipherFactory.getInstance("TWOFISH/CBC/ZeroBytePadding", androidOverride);
|
||||
cipher = CipherFactory.getInstance("Twofish/CBC/ZeroBytePadding", androidOverride);
|
||||
} else {
|
||||
cipher = CipherFactory.getInstance("TWOFISH/CBC/NoPadding", androidOverride);
|
||||
cipher = CipherFactory.getInstance("Twofish/CBC/NoPadding", androidOverride);
|
||||
}
|
||||
|
||||
cipher.init(opmode, new SecretKeySpec(key, "AES"), new IvParameterSpec(IV));
|
||||
|
||||
@@ -22,10 +22,10 @@ package com.keepassdroid.crypto;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import org.bouncycastle.crypto.StreamCipher;
|
||||
import org.bouncycastle.crypto.engines.Salsa20Engine;
|
||||
import org.bouncycastle.crypto.params.KeyParameter;
|
||||
import org.bouncycastle.crypto.params.ParametersWithIV;
|
||||
import org.spongycastle.crypto.StreamCipher;
|
||||
import org.spongycastle.crypto.engines.Salsa20Engine;
|
||||
import org.spongycastle.crypto.params.KeyParameter;
|
||||
import org.spongycastle.crypto.params.ParametersWithIV;
|
||||
|
||||
import com.keepassdroid.database.CrsAlgorithm;
|
||||
|
||||
|
||||
@@ -184,7 +184,7 @@ public class ImporterV3 extends Importer {
|
||||
if ( newManager.algorithm == PwEncryptionAlgorithm.Rjindal ) {
|
||||
cipher = CipherFactory.getInstance("AES/CBC/PKCS5Padding");
|
||||
} else if ( newManager.algorithm == PwEncryptionAlgorithm.Twofish ) {
|
||||
cipher = CipherFactory.getInstance("TWOFISH/CBC/PKCS7PADDING");
|
||||
cipher = CipherFactory.getInstance("Twofish/CBC/PKCS7PADDING");
|
||||
} else {
|
||||
throw new IOException( "Encryption algorithm is not supported" );
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ import java.util.zip.GZIPInputStream;
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
|
||||
import org.bouncycastle.crypto.StreamCipher;
|
||||
import org.spongycastle.crypto.StreamCipher;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
|
||||
@@ -82,7 +82,7 @@ public class PwDbV3Output extends PwDbOutput {
|
||||
if (mPM.algorithm == PwEncryptionAlgorithm.Rjindal) {
|
||||
cipher = CipherFactory.getInstance("AES/CBC/PKCS5Padding");
|
||||
} else if (mPM.algorithm == PwEncryptionAlgorithm.Twofish){
|
||||
cipher = CipherFactory.getInstance("TWOFISH/CBC/PKCS7PADDING");
|
||||
cipher = CipherFactory.getInstance("Twofish/CBC/PKCS7PADDING");
|
||||
} else {
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ import java.util.zip.GZIPOutputStream;
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.CipherOutputStream;
|
||||
|
||||
import org.bouncycastle.crypto.StreamCipher;
|
||||
import org.spongycastle.crypto.StreamCipher;
|
||||
import org.xmlpull.v1.XmlSerializer;
|
||||
|
||||
import android.util.Xml;
|
||||
|
||||
Reference in new issue
Block a user