Skip to content

Instantly share code, notes, and snippets.

@jpstotz
Created November 6, 2019 08:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpstotz/81d46ce83592039371a8c92e13538c27 to your computer and use it in GitHub Desktop.
Save jpstotz/81d46ce83592039371a8c92e13538c27 to your computer and use it in GitHub Desktop.
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import android.util.Base64;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
public class OtaInfo {
public static void pollOtaCerts(Map<String, JsonElement> results) {
File keystore = new File("/system/etc/security/otacerts.zip");
List<String> otaCerts = new ArrayList<>();
ZipFile zip = null;
try {
zip = new ZipFile(keystore);
Enumeration<? extends ZipEntry> entries = zip.entries();
byte[] temp = new byte[4096];
MessageDigest md = MessageDigest.getInstance("SHA-1");
while (entries.hasMoreElements()) {
InputStream is = zip.getInputStream((ZipEntry) entries.nextElement());
md.reset();
while (true) {
int read = is.read(temp);
if (read <= 0) {
break;
}
md.update(temp, 0, read);
}
is.close();
otaCerts.add(Base64.encodeToString(md.digest(), 2));
}
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
} finally {
if (zip != null)
try {
zip.close();
} catch (IOException e) {
}
}
JsonElement certs = SystemInfoApp.GSON.toJsonTree(otaCerts);
File f = new File("/system/recovery-from-boot.p");
boolean otaInstalled = f.exists();
JsonObject ota = new JsonObject();
ota.add("otaInstalled", new JsonPrimitive(otaInstalled));
ota.add("certs", certs);
results.put("otaInfo", ota);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment