Search in sources :

Example 11 with SignatureInfo

use of com.android.apksig.internal.apk.SignatureInfo in project apksig by venshine.

the class V4SchemeSigner method getBestV2Digest.

private static byte[] getBestV2Digest(DataSource apk, ApkUtils.ZipSections zipSections) throws SignatureException {
    final Set<ContentDigestAlgorithm> contentDigestsToVerify = new HashSet<>(1);
    final Set<Integer> foundApkSigSchemeIds = new HashSet<>(1);
    final ApkSigningBlockUtils.Result result = new ApkSigningBlockUtils.Result(ApkSigningBlockUtils.VERSION_APK_SIGNATURE_SCHEME_V2);
    try {
        final SignatureInfo signatureInfo = ApkSigningBlockUtils.findSignature(apk, zipSections, APK_SIGNATURE_SCHEME_V2_BLOCK_ID, result);
        final ByteBuffer apkSignatureSchemeV2Block = signatureInfo.signatureBlock;
        V2SchemeVerifier.parseSigners(apkSignatureSchemeV2Block, contentDigestsToVerify, Collections.emptyMap(), foundApkSigSchemeIds, Integer.MAX_VALUE, Integer.MAX_VALUE, result);
    } catch (Exception e) {
        throw new SignatureException("Failed to extract and parse v2 block", e);
    }
    if (result.signers.size() != 1) {
        throw new SignatureException("Should only have one signer, errors: " + result.getErrors());
    }
    ApkSigningBlockUtils.Result.SignerInfo signer = result.signers.get(0);
    if (signer.containsErrors()) {
        throw new SignatureException("Parsing failed: " + signer.getErrors());
    }
    final List<ApkSigningBlockUtils.Result.SignerInfo.ContentDigest> contentDigests = signer.contentDigests;
    return pickBestDigest(contentDigests);
}
Also used : SignatureException(java.security.SignatureException) ApkSigningBlockUtils(com.android.apksig.internal.apk.ApkSigningBlockUtils) ByteBuffer(java.nio.ByteBuffer) SignatureException(java.security.SignatureException) IOException(java.io.IOException) ZipFormatException(com.android.apksig.zip.ZipFormatException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) CertificateEncodingException(java.security.cert.CertificateEncodingException) SignatureInfo(com.android.apksig.internal.apk.SignatureInfo) ContentDigestAlgorithm(com.android.apksig.internal.apk.ContentDigestAlgorithm) HashSet(java.util.HashSet)

Aggregations

SignatureInfo (com.android.apksig.internal.apk.SignatureInfo)11 ApkSigningBlockUtils (com.android.apksig.internal.apk.ApkSigningBlockUtils)7 ByteBuffer (java.nio.ByteBuffer)6 ZipFormatException (com.android.apksig.zip.ZipFormatException)5 ContentDigestAlgorithm (com.android.apksig.internal.apk.ContentDigestAlgorithm)4 IOException (java.io.IOException)4 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)4 ApkFormatException (com.android.apksig.apk.ApkFormatException)3 ApkSigResult (com.android.apksig.internal.apk.ApkSigResult)3 SignatureException (java.security.SignatureException)3 HashSet (java.util.HashSet)3 DataSource (com.android.apksig.util.DataSource)2 InvalidKeyException (java.security.InvalidKeyException)2 CertificateEncodingException (java.security.cert.CertificateEncodingException)2 EnumMap (java.util.EnumMap)2 ApkUtils (com.android.apksig.apk.ApkUtils)1 ApkSignerInfo (com.android.apksig.internal.apk.ApkSignerInfo)1 SignatureAlgorithm (com.android.apksig.internal.apk.SignatureAlgorithm)1 SignatureNotFoundException (com.android.apksig.internal.apk.SignatureNotFoundException)1 V3SigningCertificateLineage (com.android.apksig.internal.apk.v3.V3SigningCertificateLineage)1