@Test public void testSignZip() throws IOException, LocalRepoKeyStore.InitException, IndexUpdater.SigningException { Context context = ApplicationProvider.getApplicationContext(); File xmlIndexJarUnsigned = File.createTempFile(getClass().getName(), "unsigned.jar"); BufferedOutputStream bo = new BufferedOutputStream(new FileOutputStream(xmlIndexJarUnsigned)); JarOutputStream jo = new JarOutputStream(bo); JarEntry je = new JarEntry(IndexUpdater.DATA_FILE_NAME); jo.putNextEntry(je); InputStream inputStream = getClass().getClassLoader().getResourceAsStream("smallRepo.xml"); IOUtils.copy(inputStream, jo); jo.close(); bo.close(); LocalRepoKeyStore localRepoKeyStore = LocalRepoKeyStore.get(context); Certificate localCert = localRepoKeyStore.getCertificate(); assertFalse(TextUtils.isEmpty(Utils.calcFingerprint(localCert))); File xmlIndexJar = File.createTempFile(getClass().getName(), IndexUpdater.SIGNED_FILE_NAME); localRepoKeyStore.signZip(xmlIndexJarUnsigned, xmlIndexJar); JarFile jarFile = new JarFile(xmlIndexJar, true); JarEntry indexEntry = (JarEntry) jarFile.getEntry(IndexUpdater.DATA_FILE_NAME); byte[] data = IOUtils.toByteArray(jarFile.getInputStream(indexEntry)); assertEquals(17187, data.length); assertNotNull(IndexUpdater.getSigningCertFromJar(indexEntry)); }
public void signZip(File input, File output) { try { ZipSigner zipSigner = new ZipSigner(); X509Certificate cert = (X509Certificate) keyStore.getCertificate(INDEX_CERT_ALIAS); KeyPair kp = getKerplappKeypair(); PrivateKey priv = kp.getPrivate(); zipSigner.setKeys("kerplapp", cert, priv, DEFAULT_SIG_ALG, null); zipSigner.signZip(input.getAbsolutePath(), output.getAbsolutePath()); } catch (ClassNotFoundException | IllegalAccessException | InstantiationException | GeneralSecurityException | IOException e) { Log.e(TAG, "Unable to sign local repo index", e); } }
LocalRepoKeyStore { public void signZip(File input, File output) { try { ZipSigner zipSigner = new ZipSigner(); X509Certificate cert = (X509Certificate) keyStore.getCertificate(INDEX_CERT_ALIAS); KeyPair kp = getKerplappKeypair(); PrivateKey priv = kp.getPrivate(); zipSigner.setKeys("kerplapp", cert, priv, DEFAULT_SIG_ALG, null); zipSigner.signZip(input.getAbsolutePath(), output.getAbsolutePath()); } catch (ClassNotFoundException | IllegalAccessException | InstantiationException | GeneralSecurityException | IOException e) { Log.e(TAG, "Unable to sign local repo index", e); } } }
LocalRepoKeyStore { public void signZip(File input, File output) { try { ZipSigner zipSigner = new ZipSigner(); X509Certificate cert = (X509Certificate) keyStore.getCertificate(INDEX_CERT_ALIAS); KeyPair kp = getKerplappKeypair(); PrivateKey priv = kp.getPrivate(); zipSigner.setKeys("kerplapp", cert, priv, DEFAULT_SIG_ALG, null); zipSigner.signZip(input.getAbsolutePath(), output.getAbsolutePath()); } catch (ClassNotFoundException | IllegalAccessException | InstantiationException | GeneralSecurityException | IOException e) { Log.e(TAG, "Unable to sign local repo index", e); } } private  LocalRepoKeyStore(Context context); }
LocalRepoKeyStore { public void signZip(File input, File output) { try { ZipSigner zipSigner = new ZipSigner(); X509Certificate cert = (X509Certificate) keyStore.getCertificate(INDEX_CERT_ALIAS); KeyPair kp = getKerplappKeypair(); PrivateKey priv = kp.getPrivate(); zipSigner.setKeys("kerplapp", cert, priv, DEFAULT_SIG_ALG, null); zipSigner.signZip(input.getAbsolutePath(), output.getAbsolutePath()); } catch (ClassNotFoundException | IllegalAccessException | InstantiationException | GeneralSecurityException | IOException e) { Log.e(TAG, "Unable to sign local repo index", e); } } private  LocalRepoKeyStore(Context context); static LocalRepoKeyStore get(Context context); void setupHTTPSCertificate(); File getKeyStoreFile(); KeyStore getKeyStore(); KeyManager[] getKeyManagers(); void signZip(File input, File output); Certificate getCertificate(); }
LocalRepoKeyStore { public void signZip(File input, File output) { try { ZipSigner zipSigner = new ZipSigner(); X509Certificate cert = (X509Certificate) keyStore.getCertificate(INDEX_CERT_ALIAS); KeyPair kp = getKerplappKeypair(); PrivateKey priv = kp.getPrivate(); zipSigner.setKeys("kerplapp", cert, priv, DEFAULT_SIG_ALG, null); zipSigner.signZip(input.getAbsolutePath(), output.getAbsolutePath()); } catch (ClassNotFoundException | IllegalAccessException | InstantiationException | GeneralSecurityException | IOException e) { Log.e(TAG, "Unable to sign local repo index", e); } } private  LocalRepoKeyStore(Context context); static LocalRepoKeyStore get(Context context); void setupHTTPSCertificate(); File getKeyStoreFile(); KeyStore getKeyStore(); KeyManager[] getKeyManagers(); void signZip(File input, File output); Certificate getCertificate();  }