use of com.wuntee.oter.exception.NotRootedException in project otertool by wuntee.
the class AdbWorkshop method installCert.
public static void installCert(File certfile, String password) throws NotRootedException, Exception {
if (!AdbWorkshop.canGetRoot()) {
throw new NotRootedException();
}
Security.addProvider(new BouncyCastleProvider());
// Pull the keystore, and load it into a Keystore object
logger.debug("Pulling cacerts file");
File cacerts = AdbWorkshop.pullFile(OterStatics.ANDROID_CERT_FILE);
KeyStore ks = KeyStore.getInstance("BKS");
FileInputStream fis = new java.io.FileInputStream(cacerts);
ks.load(fis, password.toCharArray());
// Read the certificate, and add it to the certfile
logger.debug("Reading the cert, and adding it to a certfile: " + certfile.getName());
FileInputStream is = new FileInputStream(certfile);
CertificateFactory cf = CertificateFactory.getInstance("X.509");
Certificate cert = cf.generateCertificate(is);
ks.setCertificateEntry(certfile.getName(), cert);
// Write cacert back out
logger.debug("Writing temporary certfile to disk");
File localFile = AdbWorkshop.getTemporaryFile();
FileOutputStream fos = new java.io.FileOutputStream(localFile);
ks.store(fos, password.toCharArray());
// Mount FS as read/write
logger.debug("Mounting remote filesystem rw");
AdbWorkshop.mountFilesystemReadWrite();
// Change file permissions of current cacert
logger.debug("Changing permissions of certfile to 777");
AdbWorkshop.changeFilePermissions(OterStatics.ANDROID_CERT_FILE, "777");
// Push the new file back up
logger.debug("Pushing the file on to the device");
AdbWorkshop.pushFile(localFile, OterStatics.ANDROID_CERT_FILE);
// Change file permissions back
logger.debug("Changing permissions of certfile to 644");
AdbWorkshop.changeFilePermissions(OterStatics.ANDROID_CERT_FILE, "644");
// Deleting the temporary file
logger.debug("Removing local temporary file: " + localFile);
localFile.delete();
}
Aggregations