From ff638f916a9eeb7dae8978768af27dbf0d665307 Mon Sep 17 00:00:00 2001 From: Wang Han <416810799@qq.com> Date: Sun, 14 Jul 2024 23:12:57 +0800 Subject: [PATCH] Clean up logprints --- app/src/main/cpp/main.cpp | 2 +- .../CustomKeyStoreKeyPairGeneratorSpi.java | 21 ++++++++++--------- .../keystoreinjection/CustomKeyStoreSpi.java | 6 +++--- .../keystoreinjection/CustomProvider.java | 6 ++++-- .../aviraxp/keystoreinjection/EntryPoint.java | 10 +++------ 5 files changed, 22 insertions(+), 23 deletions(-) diff --git a/app/src/main/cpp/main.cpp b/app/src/main/cpp/main.cpp index aa9c369..079eda2 100644 --- a/app/src/main/cpp/main.cpp +++ b/app/src/main/cpp/main.cpp @@ -6,7 +6,7 @@ #include #include "zygisk.hpp" -#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, "PIF", __VA_ARGS__) +#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, "KeystoreInjection", __VA_ARGS__) #define CLASSES_DEX "/data/adb/modules/keystoreinjection/classes.dex" #define APPLIST_FILE_PATH "/data/adb/keystoreinjection/targetlist" diff --git a/app/src/main/java/io/github/aviraxp/keystoreinjection/CustomKeyStoreKeyPairGeneratorSpi.java b/app/src/main/java/io/github/aviraxp/keystoreinjection/CustomKeyStoreKeyPairGeneratorSpi.java index 9bef2ac..5979c7e 100644 --- a/app/src/main/java/io/github/aviraxp/keystoreinjection/CustomKeyStoreKeyPairGeneratorSpi.java +++ b/app/src/main/java/io/github/aviraxp/keystoreinjection/CustomKeyStoreKeyPairGeneratorSpi.java @@ -4,6 +4,7 @@ import android.os.Build; import android.security.keystore.KeyGenParameterSpec; import android.security.keystore.KeyProperties; +import android.util.Log; import org.bouncycastle.asn1.ASN1Boolean; import org.bouncycastle.asn1.ASN1Encodable; @@ -75,7 +76,7 @@ public void initialize(int keysize, SecureRandom random) { baseGenerator = KeyPairGenerator.getInstance("OLD" + requestedAlgo, Security.getProvider(KEYSTORE)); baseGenerator.initialize(keysize, random); } catch (Exception e) { - EntryPoint.LOG("Failed to load OLD KeyPairGen: " + e); + Log.e("KeystoreInjection", Log.getStackTraceString(e)); } } @@ -86,13 +87,13 @@ public void initialize(AlgorithmParameterSpec params, SecureRandom random) { baseGenerator = KeyPairGenerator.getInstance("OLD" + requestedAlgo, Security.getProvider(KEYSTORE)); baseGenerator.initialize(params, random); } catch (Exception e) { - EntryPoint.LOG("Failed to load OLD KeyPairGen: " + e); + Log.e("KeystoreInjection", Log.getStackTraceString(e)); } } @Override public KeyPair generateKeyPair() { - EntryPoint.LOG("Requested KeyPair with alias: " + params.getKeystoreAlias()); + Log.d("KeystoreInjection", "Requested KeyPair with alias: " + params.getKeystoreAlias()); KeyPair rootKP; X500Name issuer; int size = params.getKeySize(); @@ -100,19 +101,19 @@ public KeyPair generateKeyPair() { KeyPair kp = null; try { if (Objects.equals(requestedAlgo, KeyProperties.KEY_ALGORITHM_EC)) { - EntryPoint.LOG("GENERATING EC KEYPAIR OF SIZE " + size); + Log.d("KeystoreInjection", "Generating EC keypair of size" + size); kp = buildECKeyPair(); Keybox k = EntryPoint.box("ecdsa"); rootKP = k.keypair(); issuer = k.certificateChainSubject().getFirst(); } else if (Objects.equals(requestedAlgo, KeyProperties.KEY_ALGORITHM_RSA)) { - EntryPoint.LOG("GENERATING RSA KEYPAIR OF SIZE " + size); + Log.d("KeystoreInjection", "Generating RSA keypair of size" + size); kp = buildRSAKeyPair(); Keybox k = EntryPoint.box("rsa"); rootKP = k.keypair(); issuer = k.certificateChainSubject().getFirst(); } else { - EntryPoint.LOG("UNSUPPORTED ALOGRITHM: " + requestedAlgo); + Log.d("KeystoreInjection", "Unsupported algorithm" + requestedAlgo); return kp; } @@ -134,9 +135,9 @@ public KeyPair generateKeyPair() { } X509CertificateHolder certHolder = certBuilder.build(contentSigner); EntryPoint.append(params.getKeystoreAlias(), new JcaX509CertificateConverter().getCertificate(certHolder)); - EntryPoint.LOG("Successfully generated X500 Cert for alias: " + params.getKeystoreAlias()); + Log.d("KeystoreInjection", "Successfully generated X500 Cert for alias: " + params.getKeystoreAlias()); } catch (Throwable t) { - EntryPoint.LOG(t.toString()); + Log.e("KeystoreInjection", Log.getStackTraceString(t)); } return kp; } @@ -213,7 +214,7 @@ private Extension createExtension(int size) { return new Extension(new ASN1ObjectIdentifier("1.3.6.1.4.1.11129.2.1.17"), false, keyDescriptionOctetStr); } catch (Throwable t) { - EntryPoint.LOG(t.toString()); + Log.e("KeystoreInjection", Log.getStackTraceString(t)); } return null; } @@ -354,7 +355,7 @@ public String getSystemProperty(String key) { value = (String) Class.forName("android.os.SystemProperties") .getMethod("get", String.class).invoke(null, key); } catch (Throwable t) { - EntryPoint.LOG(t.toString()); + Log.e("KeystoreInjection", Log.getStackTraceString(t)); } return value; diff --git a/app/src/main/java/io/github/aviraxp/keystoreinjection/CustomKeyStoreSpi.java b/app/src/main/java/io/github/aviraxp/keystoreinjection/CustomKeyStoreSpi.java index bc81237..0c6dc5e 100644 --- a/app/src/main/java/io/github/aviraxp/keystoreinjection/CustomKeyStoreSpi.java +++ b/app/src/main/java/io/github/aviraxp/keystoreinjection/CustomKeyStoreSpi.java @@ -28,10 +28,10 @@ public Key engineGetKey(String alias, char[] password) throws NoSuchAlgorithmExc @Override public Certificate[] engineGetCertificateChain(String alias) { - EntryPoint.LOG("GetChain Certificate alias requested: " + alias); + Log.d("KeystoreInjection", "GetChain Certificate alias requested: " + alias); Certificate leaf = EntryPoint.retrieve(alias); if (leaf != null) { - EntryPoint.LOG("GetChain alias certificates: " + leaf.getType() + " " + leaf.hashCode() + " "); + Log.d("KeystoreInjection", "GetChain alias certificates: " + leaf.getType() + " " + leaf.hashCode() + " "); LinkedList certificateList = new LinkedList<>(); try { @@ -41,7 +41,7 @@ public Certificate[] engineGetCertificateChain(String alias) { certificateList.addAll((Objects.requireNonNull(EntryPoint.box("rsa"))).certificateChain()); } } catch (Throwable t) { - Log.e("GetChain unable to ", t.toString()); + Log.e("KeystoreInjection", Log.getStackTraceString(t)); } certificateList.addFirst(leaf); diff --git a/app/src/main/java/io/github/aviraxp/keystoreinjection/CustomProvider.java b/app/src/main/java/io/github/aviraxp/keystoreinjection/CustomProvider.java index 85052df..34a018f 100644 --- a/app/src/main/java/io/github/aviraxp/keystoreinjection/CustomProvider.java +++ b/app/src/main/java/io/github/aviraxp/keystoreinjection/CustomProvider.java @@ -1,5 +1,7 @@ package io.github.aviraxp.keystoreinjection; +import android.util.Log; + import java.security.Provider; public final class CustomProvider extends Provider { @@ -9,7 +11,7 @@ public CustomProvider(Provider provider) { putAll(provider); put("KeyStore.AndroidKeyStore", CustomKeyStoreSpi.class.getName()); - EntryPoint.LOG("Loading new provider"); + Log.d("KeystoreInjection", "Loading new provider"); put("KeyPairGenerator.EC", CustomKeyStoreKeyPairGeneratorSpi.EC.class.getName()); put("KeyPairGenerator.RSA", CustomKeyStoreKeyPairGeneratorSpi.RSA.class.getName()); put("KeyPairGenerator.OLDEC", provider.get("KeyPairGenerator.EC")); @@ -18,7 +20,7 @@ public CustomProvider(Provider provider) { @Override public synchronized Service getService(String type, String algorithm) { - EntryPoint.LOG(String.format("Service: '%s' | Algorithm: '%s'", type, algorithm)); + Log.d("KeystoreInjection", String.format("Service: '%s' | Algorithm: '%s'", type, algorithm)); return super.getService(type, algorithm); } } diff --git a/app/src/main/java/io/github/aviraxp/keystoreinjection/EntryPoint.java b/app/src/main/java/io/github/aviraxp/keystoreinjection/EntryPoint.java index 19731df..27461e6 100644 --- a/app/src/main/java/io/github/aviraxp/keystoreinjection/EntryPoint.java +++ b/app/src/main/java/io/github/aviraxp/keystoreinjection/EntryPoint.java @@ -29,7 +29,7 @@ public final class EntryPoint { CustomKeyStoreSpi.keyStoreSpi = (KeyStoreSpi) keyStoreSpi.get(keyStore); } catch (Throwable t) { - LOG("Couldn't get keyStoreSpi: " + t); + Log.e("KeystoreInjection", Log.getStackTraceString(t)); } Provider provider = Security.getProvider("AndroidKeyStore"); @@ -58,7 +58,7 @@ public static void receiveXml(String data) { LinkedList certificateChainHolders = new LinkedList<>(); for (int j = 0; j < numberOfCertificates; j++) { - Map certData= xmlParser.obtainPath( + Map certData = xmlParser.obtainPath( "AndroidAttestation.Keybox.Key[" + i + "].CertificateChain.Certificate[" + j + "]"); certificateChain.add(CertUtils.parseCert(certData.get("text"))); certificateChainHolders.add(CertUtils.parseCertSubject(certData.get("text"))); @@ -67,7 +67,7 @@ public static void receiveXml(String data) { CertUtils.parsePrivateKey(privateKey), certificateChain, certificateChainHolders)); } } catch (Throwable t) { - LOG("Error loading xml file: " + t); + Log.e("KeystoreInjection", Log.getStackTraceString(t)); } } @@ -82,8 +82,4 @@ static Certificate retrieve(String a) { static Keybox box(String type) { return certs.get(type); } - - static void LOG(String msg) { - Log.d("KeystoreInjection", msg); - } }