Search in sources :

Example 1 with NotRootedException

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();
}
Also used : FileOutputStream(java.io.FileOutputStream) NotRootedException(com.wuntee.oter.exception.NotRootedException) File(java.io.File) KeyStore(java.security.KeyStore) CertificateFactory(java.security.cert.CertificateFactory) FileInputStream(java.io.FileInputStream) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider) Certificate(java.security.cert.Certificate)

Aggregations

NotRootedException (com.wuntee.oter.exception.NotRootedException)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 KeyStore (java.security.KeyStore)1 Certificate (java.security.cert.Certificate)1 CertificateFactory (java.security.cert.CertificateFactory)1 BouncyCastleProvider (org.bouncycastle.jce.provider.BouncyCastleProvider)1