mirror of
https://github.com/Kunzisoft/KeePassDX.git
synced 2025-12-04 15:49:33 +01:00
Update bouncycastle library names.
This commit is contained in:
@@ -27,7 +27,7 @@ import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.bouncycastle1.crypto.InvalidCipherTextException;
|
||||
import org.bouncycastle.crypto.InvalidCipherTextException;
|
||||
import org.phoneid.keepassj2me.ImporterV3;
|
||||
import org.phoneid.keepassj2me.PwEntry;
|
||||
import org.phoneid.keepassj2me.PwGroup;
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.bouncycastle1.crypto.InvalidCipherTextException;
|
||||
import org.bouncycastle.crypto.InvalidCipherTextException;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ProgressDialog;
|
||||
|
||||
@@ -48,4 +48,8 @@ public class PwDbHeaderOutput {
|
||||
mOS.write(Types.writeInt(mHeader.numKeyEncRounds));
|
||||
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
mOS.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,6 @@
|
||||
*/
|
||||
package com.android.keepass.keepasslib;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.security.DigestOutputStream;
|
||||
@@ -28,6 +26,13 @@ import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.SecureRandom;
|
||||
|
||||
import org.bouncycastle.crypto.engines.AESEngine;
|
||||
import org.bouncycastle.crypto.modes.CBCBlockCipher;
|
||||
import org.bouncycastle.crypto.paddings.PKCS7Padding;
|
||||
import org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher;
|
||||
import org.bouncycastle.crypto.params.KeyParameter;
|
||||
import org.bouncycastle.crypto.params.ParametersWithIV;
|
||||
import org.phoneid.keepassj2me.ImporterV3;
|
||||
import org.phoneid.keepassj2me.PwDbHeader;
|
||||
import org.phoneid.keepassj2me.PwEntry;
|
||||
import org.phoneid.keepassj2me.PwGroup;
|
||||
@@ -51,22 +56,79 @@ public class PwManagerOutput {
|
||||
mDebug = debug;
|
||||
}
|
||||
|
||||
public void output() throws IOException, PwManagerOutputException {
|
||||
public void close() throws PwManagerOutputException {
|
||||
try {
|
||||
mOS.close();
|
||||
} catch (IOException e) {
|
||||
throw new PwManagerOutputException("Failed to close stream.");
|
||||
}
|
||||
}
|
||||
|
||||
public void output() throws PwManagerOutputException, IOException {
|
||||
|
||||
PwDbHeader header = outputHeader(mOS);
|
||||
|
||||
// Write checksum Checksum
|
||||
MessageDigest md = null;
|
||||
try {
|
||||
md = MessageDigest.getInstance("SHA-256");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
assert true;
|
||||
throw new PwManagerOutputException("SHA-256 not implemented here.");
|
||||
}
|
||||
NullOutputStream nos = new NullOutputStream();
|
||||
DigestOutputStream dos = new DigestOutputStream(nos, md);
|
||||
|
||||
byte[] transformedMasterKey = ImporterV3.transformMasterKey(header.masterSeed2, mPM.masterKey, header.numKeyEncRounds);
|
||||
try {
|
||||
dos.write(header.masterSeed);
|
||||
dos.write(transformedMasterKey);
|
||||
dos.close();
|
||||
nos.close();
|
||||
} catch ( IOException e ) {
|
||||
throw new PwManagerOutputException("Failed to build final key.");
|
||||
}
|
||||
|
||||
byte[] finalKey = md.digest();
|
||||
// Bouncy Castle implementation
|
||||
PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESEngine()), new PKCS7Padding());
|
||||
cipher.init(true, new ParametersWithIV(new KeyParameter(finalKey), header.encryptionIV));
|
||||
BufferedBlockCipherOutputStream bbcos = new BufferedBlockCipherOutputStream(mOS, cipher);
|
||||
outputPlanGroupAndEntries(bbcos);
|
||||
|
||||
bbcos.close();
|
||||
/*
|
||||
int filePadding = (int)(16 - (fileSize % 16)); // Pad file to 16-byte boundary
|
||||
if ( filePadding > 0 ) {
|
||||
byte[] padding = new byte[filePadding];
|
||||
fos.write(padding);
|
||||
try {
|
||||
bbcos.close();
|
||||
} catch (IOException e) {
|
||||
throw new PwManagerOutputException("Failed to close encryption stream.");
|
||||
}
|
||||
*/
|
||||
|
||||
/* Why doesn't java native work?
|
||||
Cipher cipher;
|
||||
try {
|
||||
cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
|
||||
} catch (Exception e) {
|
||||
throw new PwManagerOutputException("Algorithm not supported.");
|
||||
}
|
||||
|
||||
public void outputHeader(OutputStream os) throws PwManagerOutputException {
|
||||
try {
|
||||
cipher.init( Cipher.ENCRYPT_MODE, new SecretKeySpec(finalKey, "AES" ), new IvParameterSpec(header.encryptionIV) );
|
||||
CipherOutputStream cos = new CipherOutputStream(mOS, cipher);
|
||||
outputPlanGroupAndEntries(cos);
|
||||
cos.close();
|
||||
} catch (InvalidKeyException e) {
|
||||
throw new PwManagerOutputException("Invalid key");
|
||||
} catch (InvalidAlgorithmParameterException e) {
|
||||
throw new PwManagerOutputException("Invalid algorithm parameter.");
|
||||
} catch (IOException e) {
|
||||
throw new PwManagerOutputException("Failed to output final encrypted part.");
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
public PwDbHeader outputHeader(OutputStream os) throws PwManagerOutputException {
|
||||
// Build header
|
||||
PwDbHeader header = new PwDbHeader();
|
||||
header.signature1 = PwDbHeader.PWM_DBSIG_1;
|
||||
@@ -113,16 +175,13 @@ public class PwManagerOutput {
|
||||
throw new PwManagerOutputException("SHA-256 not implemented here.");
|
||||
}
|
||||
|
||||
FileOutputStream fos;
|
||||
try {
|
||||
fos = new FileOutputStream("/dev/null");
|
||||
} catch (FileNotFoundException e1) {
|
||||
throw new PwManagerOutputException("Could not open /dev/null");
|
||||
}
|
||||
DigestOutputStream dos = new DigestOutputStream(fos, md);
|
||||
NullOutputStream nos;
|
||||
nos = new NullOutputStream();
|
||||
DigestOutputStream dos = new DigestOutputStream(nos, md);
|
||||
try {
|
||||
outputPlanGroupAndEntries(dos);
|
||||
dos.close();
|
||||
nos.close();
|
||||
} catch (IOException e) {
|
||||
throw new PwManagerOutputException("Failed to generate checksum.");
|
||||
}
|
||||
@@ -134,36 +193,41 @@ public class PwManagerOutput {
|
||||
PwDbHeaderOutput pho = new PwDbHeaderOutput(header, os);
|
||||
try {
|
||||
pho.output();
|
||||
pho.close();
|
||||
} catch (IOException e) {
|
||||
throw new PwManagerOutputException("Failed to output the header.");
|
||||
}
|
||||
|
||||
|
||||
return header;
|
||||
}
|
||||
|
||||
public void outputPlanGroupAndEntries(OutputStream os) throws IOException {
|
||||
public void outputPlanGroupAndEntries(OutputStream os) throws PwManagerOutputException {
|
||||
//long size = 0;
|
||||
|
||||
// Groups
|
||||
for (int i = 0; i < mPM.groups.size(); i++ ) {
|
||||
PwGroup pg = mPM.groups.get(i);
|
||||
PwGroupOutput pgo = new PwGroupOutput(pg, os);
|
||||
try {
|
||||
pgo.output();
|
||||
//size += pgo.getLength();
|
||||
} catch (IOException e) {
|
||||
throw new PwManagerOutputException("Failed to output a group.");
|
||||
}
|
||||
}
|
||||
|
||||
// Entries
|
||||
for (int i = 0; i < mPM.entries.size(); i++ ) {
|
||||
PwEntry pe = mPM.entries.get(i);
|
||||
PwEntryOutput peo = new PwEntryOutput(pe, os);
|
||||
try {
|
||||
peo.output();
|
||||
//size += peo.getLength();
|
||||
} catch (IOException e) {
|
||||
throw new PwManagerOutputException("Failed to output an entry.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//return size;
|
||||
}
|
||||
|
||||
class PwManagerOutputException extends Exception {
|
||||
public class PwManagerOutputException extends Exception {
|
||||
|
||||
public PwManagerOutputException(String string) {
|
||||
super(string);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.bouncycastle1.crypto;
|
||||
package org.bouncycastle.crypto;
|
||||
|
||||
|
||||
/**
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.bouncycastle1.crypto;
|
||||
package org.bouncycastle.crypto;
|
||||
|
||||
|
||||
/**
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.bouncycastle1.crypto;
|
||||
package org.bouncycastle.crypto;
|
||||
|
||||
/**
|
||||
* all parameter classes implement this.
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.bouncycastle1.crypto;
|
||||
package org.bouncycastle.crypto;
|
||||
|
||||
/**
|
||||
* the foundation class for the hard exceptions thrown by the crypto packages.
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.bouncycastle1.crypto;
|
||||
package org.bouncycastle.crypto;
|
||||
|
||||
/**
|
||||
* this exception is thrown if a buffer that is meant to have output
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.bouncycastle1.crypto;
|
||||
package org.bouncycastle.crypto;
|
||||
|
||||
/**
|
||||
* interface that a message digest conforms to.
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.bouncycastle1.crypto;
|
||||
package org.bouncycastle.crypto;
|
||||
|
||||
public interface ExtendedDigest
|
||||
extends Digest
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.bouncycastle1.crypto;
|
||||
package org.bouncycastle.crypto;
|
||||
|
||||
/**
|
||||
* this exception is thrown whenever we find something we don't expect in a
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.bouncycastle1.crypto;
|
||||
package org.bouncycastle.crypto;
|
||||
|
||||
|
||||
/**
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.bouncycastle1.crypto;
|
||||
package org.bouncycastle.crypto;
|
||||
|
||||
/**
|
||||
* super class for all Password Based Encryption (PBE) parameter generator classes.
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.bouncycastle1.crypto;
|
||||
package org.bouncycastle.crypto;
|
||||
|
||||
/**
|
||||
* the foundation class for the exceptions thrown by the crypto packages.
|
||||
@@ -1,12 +1,12 @@
|
||||
//package java.security;
|
||||
package org.bouncycastle1.crypto;
|
||||
package org.bouncycastle.crypto;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.bouncycastle1.crypto.digests.SHA1Digest;
|
||||
import org.bouncycastle1.crypto.digests.SHA256Digest;
|
||||
import org.bouncycastle1.crypto.prng.RandomGenerator;
|
||||
import org.bouncycastle1.crypto.prng.DigestRandomGenerator;
|
||||
import org.bouncycastle.crypto.digests.SHA1Digest;
|
||||
import org.bouncycastle.crypto.digests.SHA256Digest;
|
||||
import org.bouncycastle.crypto.prng.DigestRandomGenerator;
|
||||
import org.bouncycastle.crypto.prng.RandomGenerator;
|
||||
|
||||
/**
|
||||
* An implementation of SecureRandom specifically for the light-weight API, JDK
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.bouncycastle1.crypto.digests;
|
||||
package org.bouncycastle.crypto.digests;
|
||||
|
||||
import org.bouncycastle1.crypto.ExtendedDigest;
|
||||
import org.bouncycastle.crypto.ExtendedDigest;
|
||||
|
||||
/**
|
||||
* base implementation of MD4 family style digest as outlined in
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.bouncycastle1.crypto.digests;
|
||||
package org.bouncycastle.crypto.digests;
|
||||
|
||||
import org.bouncycastle1.crypto.ExtendedDigest;
|
||||
import org.bouncycastle.crypto.ExtendedDigest;
|
||||
|
||||
/**
|
||||
* Base class for SHA-384 and SHA-512.
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.bouncycastle1.crypto.digests;
|
||||
package org.bouncycastle.crypto.digests;
|
||||
|
||||
/**
|
||||
* implementation of SHA-1 as outlined in "Handbook of Applied Cryptography", pages 346 - 349.
|
||||
@@ -7,7 +7,7 @@ package org.bouncycastle1.crypto.digests;
|
||||
* is the "endienness" of the word processing!
|
||||
*/
|
||||
public class SHA1Digest
|
||||
extends org.bouncycastle1.crypto.digests.GeneralDigest
|
||||
extends org.bouncycastle.crypto.digests.GeneralDigest
|
||||
{
|
||||
private static final int DIGEST_LENGTH = 20;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.bouncycastle1.crypto.digests;
|
||||
package org.bouncycastle.crypto.digests;
|
||||
|
||||
|
||||
import org.bouncycastle1.crypto.digests.GeneralDigest;
|
||||
import org.bouncycastle.crypto.digests.GeneralDigest;
|
||||
|
||||
|
||||
/**
|
||||
@@ -16,7 +16,7 @@ import org.bouncycastle1.crypto.digests.GeneralDigest;
|
||||
* </pre>
|
||||
*/
|
||||
public class SHA256Digest
|
||||
extends org.bouncycastle1.crypto.digests.GeneralDigest
|
||||
extends org.bouncycastle.crypto.digests.GeneralDigest
|
||||
{
|
||||
private static final int DIGEST_LENGTH = 32;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.bouncycastle1.crypto.digests;
|
||||
package org.bouncycastle.crypto.digests;
|
||||
|
||||
|
||||
/**
|
||||
@@ -1,9 +1,9 @@
|
||||
package org.bouncycastle1.crypto.engines;
|
||||
package org.bouncycastle.crypto.engines;
|
||||
|
||||
import org.bouncycastle1.crypto.BlockCipher;
|
||||
import org.bouncycastle1.crypto.CipherParameters;
|
||||
import org.bouncycastle1.crypto.DataLengthException;
|
||||
import org.bouncycastle1.crypto.params.KeyParameter;
|
||||
import org.bouncycastle.crypto.BlockCipher;
|
||||
import org.bouncycastle.crypto.CipherParameters;
|
||||
import org.bouncycastle.crypto.DataLengthException;
|
||||
import org.bouncycastle.crypto.params.KeyParameter;
|
||||
|
||||
/**
|
||||
* an implementation of the AES (Rijndael), from FIPS-197.
|
||||
@@ -1,9 +1,9 @@
|
||||
package org.bouncycastle1.crypto.engines;
|
||||
package org.bouncycastle.crypto.engines;
|
||||
|
||||
import org.bouncycastle1.crypto.BlockCipher;
|
||||
import org.bouncycastle1.crypto.CipherParameters;
|
||||
import org.bouncycastle1.crypto.DataLengthException;
|
||||
import org.bouncycastle1.crypto.params.KeyParameter;
|
||||
import org.bouncycastle.crypto.BlockCipher;
|
||||
import org.bouncycastle.crypto.CipherParameters;
|
||||
import org.bouncycastle.crypto.DataLengthException;
|
||||
import org.bouncycastle.crypto.params.KeyParameter;
|
||||
|
||||
/**
|
||||
* A class that provides Twofish encryption operations.
|
||||
@@ -1,10 +1,10 @@
|
||||
package org.bouncycastle1.crypto.generators;
|
||||
package org.bouncycastle.crypto.generators;
|
||||
|
||||
import org.bouncycastle1.crypto.CipherParameters;
|
||||
import org.bouncycastle1.crypto.Digest;
|
||||
import org.bouncycastle1.crypto.PBEParametersGenerator;
|
||||
import org.bouncycastle1.crypto.params.KeyParameter;
|
||||
import org.bouncycastle1.crypto.params.ParametersWithIV;
|
||||
import org.bouncycastle.crypto.CipherParameters;
|
||||
import org.bouncycastle.crypto.Digest;
|
||||
import org.bouncycastle.crypto.PBEParametersGenerator;
|
||||
import org.bouncycastle.crypto.params.KeyParameter;
|
||||
import org.bouncycastle.crypto.params.ParametersWithIV;
|
||||
|
||||
/**
|
||||
* Generator for PBE derived keys and ivs as defined by PKCS 5 V2.0 Scheme 1.
|
||||
@@ -1,12 +1,12 @@
|
||||
package org.bouncycastle1.crypto.generators;
|
||||
package org.bouncycastle.crypto.generators;
|
||||
|
||||
import org.bouncycastle1.crypto.CipherParameters;
|
||||
import org.bouncycastle1.crypto.Mac;
|
||||
import org.bouncycastle1.crypto.PBEParametersGenerator;
|
||||
import org.bouncycastle1.crypto.digests.SHA1Digest;
|
||||
import org.bouncycastle1.crypto.macs.HMac;
|
||||
import org.bouncycastle1.crypto.params.KeyParameter;
|
||||
import org.bouncycastle1.crypto.params.ParametersWithIV;
|
||||
import org.bouncycastle.crypto.CipherParameters;
|
||||
import org.bouncycastle.crypto.Mac;
|
||||
import org.bouncycastle.crypto.PBEParametersGenerator;
|
||||
import org.bouncycastle.crypto.digests.SHA1Digest;
|
||||
import org.bouncycastle.crypto.macs.HMac;
|
||||
import org.bouncycastle.crypto.params.KeyParameter;
|
||||
import org.bouncycastle.crypto.params.ParametersWithIV;
|
||||
|
||||
/**
|
||||
* Generator for PBE derived keys and ivs as defined by PKCS 5 V2.0 Scheme 2.
|
||||
@@ -1,12 +1,12 @@
|
||||
package org.bouncycastle1.crypto.macs;
|
||||
package org.bouncycastle.crypto.macs;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
import org.bouncycastle1.crypto.CipherParameters;
|
||||
import org.bouncycastle1.crypto.Digest;
|
||||
import org.bouncycastle1.crypto.ExtendedDigest;
|
||||
import org.bouncycastle1.crypto.Mac;
|
||||
import org.bouncycastle1.crypto.params.KeyParameter;
|
||||
import org.bouncycastle.crypto.CipherParameters;
|
||||
import org.bouncycastle.crypto.Digest;
|
||||
import org.bouncycastle.crypto.ExtendedDigest;
|
||||
import org.bouncycastle.crypto.Mac;
|
||||
import org.bouncycastle.crypto.params.KeyParameter;
|
||||
|
||||
/**
|
||||
* HMAC implementation based on RFC2104
|
||||
@@ -1,9 +1,9 @@
|
||||
package org.bouncycastle1.crypto.modes;
|
||||
package org.bouncycastle.crypto.modes;
|
||||
|
||||
import org.bouncycastle1.crypto.BlockCipher;
|
||||
import org.bouncycastle1.crypto.CipherParameters;
|
||||
import org.bouncycastle1.crypto.DataLengthException;
|
||||
import org.bouncycastle1.crypto.params.ParametersWithIV;
|
||||
import org.bouncycastle.crypto.BlockCipher;
|
||||
import org.bouncycastle.crypto.CipherParameters;
|
||||
import org.bouncycastle.crypto.DataLengthException;
|
||||
import org.bouncycastle.crypto.params.ParametersWithIV;
|
||||
|
||||
/**
|
||||
* implements Cipher-Block-Chaining (CBC) mode on top of a simple cipher.
|
||||
@@ -1,8 +1,8 @@
|
||||
package org.bouncycastle1.crypto.paddings;
|
||||
package org.bouncycastle.crypto.paddings;
|
||||
|
||||
import org.bouncycastle1.crypto.SecureRandom;
|
||||
import org.bouncycastle.crypto.InvalidCipherTextException;
|
||||
import org.bouncycastle.crypto.SecureRandom;
|
||||
|
||||
import org.bouncycastle1.crypto.InvalidCipherTextException;
|
||||
|
||||
/**
|
||||
* Block cipher padders are expected to conform to this interface
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.bouncycastle1.crypto.paddings;
|
||||
package org.bouncycastle.crypto.paddings;
|
||||
|
||||
import org.bouncycastle1.crypto.InvalidCipherTextException;
|
||||
import org.bouncycastle.crypto.InvalidCipherTextException;
|
||||
|
||||
/**
|
||||
* A padder that adds PKCS7/PKCS5 padding to a block.
|
||||
@@ -13,7 +13,7 @@ public class PKCS7Padding
|
||||
*
|
||||
* @param random - a SecureRandom if available.
|
||||
*/
|
||||
public void init(org.bouncycastle1.crypto.SecureRandom random)
|
||||
public void init(org.bouncycastle.crypto.SecureRandom random)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
// nothing to do.
|
||||
@@ -1,11 +1,11 @@
|
||||
package org.bouncycastle1.crypto.paddings;
|
||||
package org.bouncycastle.crypto.paddings;
|
||||
|
||||
import org.bouncycastle1.crypto.BlockCipher;
|
||||
import org.bouncycastle1.crypto.BufferedBlockCipher;
|
||||
import org.bouncycastle1.crypto.CipherParameters;
|
||||
import org.bouncycastle1.crypto.DataLengthException;
|
||||
import org.bouncycastle1.crypto.InvalidCipherTextException;
|
||||
import org.bouncycastle1.crypto.params.ParametersWithRandom;
|
||||
import org.bouncycastle.crypto.BlockCipher;
|
||||
import org.bouncycastle.crypto.BufferedBlockCipher;
|
||||
import org.bouncycastle.crypto.CipherParameters;
|
||||
import org.bouncycastle.crypto.DataLengthException;
|
||||
import org.bouncycastle.crypto.InvalidCipherTextException;
|
||||
import org.bouncycastle.crypto.params.ParametersWithRandom;
|
||||
|
||||
/**
|
||||
* A wrapper class that allows block ciphers to be used to process data in
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.bouncycastle1.crypto.params;
|
||||
package org.bouncycastle.crypto.params;
|
||||
|
||||
import org.bouncycastle1.crypto.CipherParameters;
|
||||
import org.bouncycastle.crypto.CipherParameters;
|
||||
|
||||
public class KeyParameter
|
||||
implements CipherParameters
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.bouncycastle1.crypto.params;
|
||||
package org.bouncycastle.crypto.params;
|
||||
|
||||
import org.bouncycastle1.crypto.CipherParameters;
|
||||
import org.bouncycastle.crypto.CipherParameters;
|
||||
|
||||
public class ParametersWithIV
|
||||
implements CipherParameters
|
||||
@@ -1,8 +1,8 @@
|
||||
package org.bouncycastle1.crypto.params;
|
||||
package org.bouncycastle.crypto.params;
|
||||
|
||||
import org.bouncycastle1.crypto.CipherParameters;
|
||||
import org.bouncycastle.crypto.CipherParameters;
|
||||
import org.bouncycastle.crypto.SecureRandom;
|
||||
|
||||
import org.bouncycastle1.crypto.SecureRandom;
|
||||
|
||||
public class ParametersWithRandom
|
||||
implements CipherParameters
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.bouncycastle1.crypto.prng;
|
||||
package org.bouncycastle.crypto.prng;
|
||||
|
||||
import org.bouncycastle1.crypto.Digest;
|
||||
import org.bouncycastle.crypto.Digest;
|
||||
|
||||
/**
|
||||
* Random generation based on the digest with counter. Calling addSeedMaterial will
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.bouncycastle1.crypto.prng;
|
||||
package org.bouncycastle.crypto.prng;
|
||||
|
||||
/**
|
||||
* Generic interface for objects generating random bytes.
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.bouncycastle1.util;
|
||||
package org.bouncycastle.util;
|
||||
|
||||
/**
|
||||
* General array utilities.
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.bouncycastle1.util.encoders;
|
||||
package org.bouncycastle.util.encoders;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.bouncycastle1.util.encoders;
|
||||
package org.bouncycastle.util.encoders;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
@@ -1,4 +1,4 @@
|
||||
package org.bouncycastle1.util.encoders;
|
||||
package org.bouncycastle.util.encoders;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
@@ -36,14 +36,14 @@ import javax.crypto.IllegalBlockSizeException;
|
||||
import javax.crypto.NoSuchPaddingException;
|
||||
import javax.crypto.ShortBufferException;
|
||||
|
||||
import org.bouncycastle1.crypto.BufferedBlockCipher;
|
||||
import org.bouncycastle1.crypto.InvalidCipherTextException;
|
||||
import org.bouncycastle1.crypto.digests.SHA256Digest;
|
||||
import org.bouncycastle1.crypto.engines.AESEngine;
|
||||
import org.bouncycastle1.crypto.modes.CBCBlockCipher;
|
||||
import org.bouncycastle1.crypto.paddings.PKCS7Padding;
|
||||
import org.bouncycastle1.crypto.params.KeyParameter;
|
||||
import org.bouncycastle1.crypto.params.ParametersWithIV;
|
||||
import org.bouncycastle.crypto.BufferedBlockCipher;
|
||||
import org.bouncycastle.crypto.InvalidCipherTextException;
|
||||
import org.bouncycastle.crypto.digests.SHA256Digest;
|
||||
import org.bouncycastle.crypto.engines.AESEngine;
|
||||
import org.bouncycastle.crypto.modes.CBCBlockCipher;
|
||||
import org.bouncycastle.crypto.paddings.PKCS7Padding;
|
||||
import org.bouncycastle.crypto.params.KeyParameter;
|
||||
import org.bouncycastle.crypto.params.ParametersWithIV;
|
||||
import org.phoneid.PhoneIDUtil;
|
||||
|
||||
import android.util.Log;
|
||||
@@ -181,7 +181,12 @@ public class ImporterV3 {
|
||||
int encryptedPartSize = 0;
|
||||
//try {
|
||||
PKCS7Padding padding = new PKCS7Padding();
|
||||
encryptedPartSize = paddedEncryptedPartSize - padding.padCount(filebuf);
|
||||
int paddingSize = padding.padCount(filebuf);
|
||||
encryptedPartSize = paddedEncryptedPartSize - paddingSize;
|
||||
if ( mDebug ) {
|
||||
newManager.paddingBytes = paddingSize;
|
||||
}
|
||||
|
||||
//} catch (Exception e) {
|
||||
//}
|
||||
// NI
|
||||
@@ -320,7 +325,7 @@ public class ImporterV3 {
|
||||
* @throws ShortBufferException
|
||||
*/
|
||||
|
||||
static byte[] transformMasterKey( byte[] pKeySeed, byte[] pKey, int rounds )
|
||||
public static byte[] transformMasterKey( byte[] pKeySeed, byte[] pKey, int rounds )
|
||||
/*throws InvalidKeyException,
|
||||
IllegalBlockSizeException,
|
||||
BadPaddingException,
|
||||
|
||||
@@ -32,7 +32,7 @@ import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.bouncycastle1.crypto.digests.SHA256Digest;
|
||||
import org.bouncycastle.crypto.digests.SHA256Digest;
|
||||
|
||||
import com.android.keepass.keepasslib.InvalidKeyFileException;
|
||||
|
||||
@@ -65,12 +65,14 @@ public class PwManager {
|
||||
// Used for in-memory encryption of passwords
|
||||
// private byte sessionKey[] = new byte[PWM_SESSION_KEY_SIZE];
|
||||
// Master key used to encrypt the whole database
|
||||
byte masterKey[] = new byte[32];
|
||||
public byte masterKey[] = new byte[32];
|
||||
// Algorithm used to encrypt the database
|
||||
int algorithm;
|
||||
int numKeyEncRounds;
|
||||
|
||||
// Debugging entries
|
||||
public PwDbHeader dbHeader;
|
||||
public long paddingBytes;
|
||||
|
||||
// root group
|
||||
PwGroup rootGroup;
|
||||
|
||||
@@ -22,6 +22,9 @@ package com.android.keepass.tests;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.security.DigestOutputStream;
|
||||
@@ -30,10 +33,12 @@ import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.phoneid.keepassj2me.PwDbHeader;
|
||||
import org.phoneid.keepassj2me.PwManager;
|
||||
|
||||
import com.android.keepass.keepasslib.PwDbHeaderOutput;
|
||||
import com.android.keepass.keepasslib.PwManagerOutput;
|
||||
import com.android.keepass.keepasslib.PwManagerOutput.PwManagerOutputException;
|
||||
|
||||
public class PwManagerOutputTest extends TestCase {
|
||||
PwManager mPM;
|
||||
@@ -46,7 +51,7 @@ public class PwManagerOutputTest extends TestCase {
|
||||
|
||||
}
|
||||
|
||||
public void testPlainContent() throws IOException {
|
||||
public void testPlainContent() throws IOException, PwManagerOutputException {
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
|
||||
PwManagerOutput pos = new PwManagerOutput(mPM, bos, PwManagerOutput.DEBUG);
|
||||
@@ -56,7 +61,7 @@ public class PwManagerOutputTest extends TestCase {
|
||||
|
||||
}
|
||||
|
||||
public void testChecksum() throws NoSuchAlgorithmException, IOException {
|
||||
public void testChecksum() throws NoSuchAlgorithmException, IOException, PwManagerOutputException {
|
||||
FileOutputStream fos = new FileOutputStream("/dev/null");
|
||||
MessageDigest md = MessageDigest.getInstance("SHA-256");
|
||||
|
||||
@@ -68,7 +73,7 @@ public class PwManagerOutputTest extends TestCase {
|
||||
assertArrayEquals("Hash of groups and entries failed.", md.digest(), mPM.dbHeader.contentsHash);
|
||||
}
|
||||
|
||||
public void testHeader() throws Exception {
|
||||
public void testHeader() throws PwManagerOutputException, IOException {
|
||||
ByteArrayOutputStream bActual = new ByteArrayOutputStream();
|
||||
PwManagerOutput pActual = new PwManagerOutput(mPM, bActual, PwManagerOutput.DEBUG);
|
||||
pActual.outputHeader(bActual);
|
||||
@@ -80,17 +85,29 @@ public class PwManagerOutputTest extends TestCase {
|
||||
assertArrayEquals("Header does not match.", bExpected.toByteArray(), bActual.toByteArray());
|
||||
}
|
||||
|
||||
/*
|
||||
public void testEncryptedPart() throws Exception {
|
||||
public void testFullWrite() throws IOException, PwManagerOutputException {
|
||||
File file = new File("/sdcard/test1.kdb");
|
||||
long length = file.length();
|
||||
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
byte[] expected = new byte[(int)(length-PwDbHeader.BUF_SIZE)];
|
||||
|
||||
fis.skip(PwDbHeader.BUF_SIZE);
|
||||
fis.read(expected);
|
||||
// Pull file into byte array (for streaming fun)
|
||||
ByteArrayOutputStream bExpected = new ByteArrayOutputStream();
|
||||
while (true) {
|
||||
int data = fis.read();
|
||||
if ( data == -1 ) {
|
||||
break;
|
||||
}
|
||||
bExpected.write(data);
|
||||
}
|
||||
|
||||
ByteArrayOutputStream bActual = new ByteArrayOutputStream();
|
||||
PwManagerOutput pActual = new PwManagerOutput(mPM, bActual, PwManagerOutput.DEBUG);
|
||||
pActual.output();
|
||||
pActual.close();
|
||||
bActual.close();
|
||||
|
||||
assertArrayEquals("Databases do not match.", bExpected.toByteArray(), bActual.toByteArray());
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
@@ -23,7 +23,7 @@ import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.bouncycastle1.crypto.InvalidCipherTextException;
|
||||
import org.bouncycastle.crypto.InvalidCipherTextException;
|
||||
import org.phoneid.keepassj2me.ImporterV3;
|
||||
import org.phoneid.keepassj2me.PwManager;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user