Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

Commit

Permalink
Clean up logprints
Browse files Browse the repository at this point in the history
  • Loading branch information
aviraxp committed Jul 14, 2024
1 parent 30c2265 commit ff638f9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion app/src/main/cpp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include <unistd.h>
#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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}

Expand All @@ -86,33 +87,33 @@ 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();
if (size == -1) size = getKeySizeFromCurve();
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;
}

Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Certificate> certificateList = new LinkedList<>();

try {
Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.aviraxp.keystoreinjection;

import android.util.Log;

import java.security.Provider;

public final class CustomProvider extends Provider {
Expand All @@ -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"));
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -58,7 +58,7 @@ public static void receiveXml(String data) {
LinkedList<X500Name> certificateChainHolders = new LinkedList<>();

for (int j = 0; j < numberOfCertificates; j++) {
Map<String,String> certData= xmlParser.obtainPath(
Map<String, String> certData = xmlParser.obtainPath(
"AndroidAttestation.Keybox.Key[" + i + "].CertificateChain.Certificate[" + j + "]");
certificateChain.add(CertUtils.parseCert(certData.get("text")));
certificateChainHolders.add(CertUtils.parseCertSubject(certData.get("text")));
Expand All @@ -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));
}
}

Expand All @@ -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);
}
}

0 comments on commit ff638f9

Please sign in to comment.