mirror of https://github.com/m2049r/xmrwallet.git
Fix keystore null (#308)
* avoid crash if input to large * avoid NPE if wallet key not found
This commit is contained in:
parent
37244cb9e0
commit
7627e15a48
|
@ -66,6 +66,8 @@ public class BitcoinAddressValidator {
|
||||||
|
|
||||||
byte[] result = new byte[25];
|
byte[] result = new byte[25];
|
||||||
byte[] numBytes = num.toByteArray();
|
byte[] numBytes = num.toByteArray();
|
||||||
|
if (numBytes.length > result.length) return null;
|
||||||
|
|
||||||
if (num.bitLength() == 200) {
|
if (num.bitLength() == 200) {
|
||||||
System.arraycopy(numBytes, 1, result, 0, 25);
|
System.arraycopy(numBytes, 1, result, 0, 25);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -284,7 +284,9 @@ public class KeyStoreHelper {
|
||||||
|
|
||||||
private static byte[] decrypt(String alias, byte[] data) {
|
private static byte[] decrypt(String alias, byte[] data) {
|
||||||
try {
|
try {
|
||||||
PrivateKey privateKey = getPrivateKeyEntry(alias).getPrivateKey();
|
KeyStore.PrivateKeyEntry pke = getPrivateKeyEntry(alias);
|
||||||
|
if (pke == null) return null;
|
||||||
|
PrivateKey privateKey = pke.getPrivateKey();
|
||||||
Cipher cipher = Cipher.getInstance(SecurityConstants.CIPHER_RSA_ECB_PKCS1);
|
Cipher cipher = Cipher.getInstance(SecurityConstants.CIPHER_RSA_ECB_PKCS1);
|
||||||
|
|
||||||
cipher.init(Cipher.DECRYPT_MODE, privateKey);
|
cipher.init(Cipher.DECRYPT_MODE, privateKey);
|
||||||
|
@ -305,7 +307,8 @@ public class KeyStoreHelper {
|
||||||
*/
|
*/
|
||||||
private static byte[] signData(String alias, byte[] data) throws NoSuchAlgorithmException,
|
private static byte[] signData(String alias, byte[] data) throws NoSuchAlgorithmException,
|
||||||
InvalidKeyException, SignatureException {
|
InvalidKeyException, SignatureException {
|
||||||
|
KeyStore.PrivateKeyEntry pke = getPrivateKeyEntry(alias);
|
||||||
|
if (pke == null) return null;
|
||||||
PrivateKey privateKey = getPrivateKeyEntry(alias).getPrivateKey();
|
PrivateKey privateKey = getPrivateKeyEntry(alias).getPrivateKey();
|
||||||
Signature s = Signature.getInstance(SecurityConstants.SIGNATURE_SHA256withRSA);
|
Signature s = Signature.getInstance(SecurityConstants.SIGNATURE_SHA256withRSA);
|
||||||
s.initSign(privateKey);
|
s.initSign(privateKey);
|
||||||
|
|
Loading…
Reference in New Issue