Search in sources :

Example 1 with ApkSignerInfo

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

the class V2SourceStampVerifier method verify.

/**
 * Verifies the provided APK's SourceStamp signatures and outputs the results into the provided
 * {@code result}. APK is considered verified only if there are no errors reported in the {@code
 * result}. See {@link #verify(DataSource, ZipSections, byte[], Map, int, int)} for
 * more information about the contract of this method.
 */
private static void verify(ByteBuffer sourceStampBlock, byte[] sourceStampCertificateDigest, Map<Integer, Map<ContentDigestAlgorithm, byte[]>> signatureSchemeApkContentDigests, int minSdkVersion, int maxSdkVersion, ApkSigResult result) throws NoSuchAlgorithmException {
    ApkSignerInfo signerInfo = new ApkSignerInfo();
    result.mSigners.add(signerInfo);
    try {
        CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
        ByteBuffer sourceStampBlockData = ApkSigningBlockUtilsLite.getLengthPrefixedSlice(sourceStampBlock);
        SourceStampVerifier.verifyV2SourceStamp(sourceStampBlockData, certFactory, signerInfo, getSignatureSchemeDigests(signatureSchemeApkContentDigests), sourceStampCertificateDigest, minSdkVersion, maxSdkVersion);
        result.verified = !result.containsErrors() && !result.containsWarnings();
    } catch (CertificateException e) {
        throw new IllegalStateException("Failed to obtain X.509 CertificateFactory", e);
    } catch (ApkFormatException | BufferUnderflowException e) {
        signerInfo.addWarning(ApkVerificationIssue.SOURCE_STAMP_MALFORMED_SIGNATURE);
    }
}
Also used : ApkFormatException(com.android.apksig.apk.ApkFormatException) ApkSignerInfo(com.android.apksig.internal.apk.ApkSignerInfo) CertificateException(java.security.cert.CertificateException) CertificateFactory(java.security.cert.CertificateFactory) ByteBuffer(java.nio.ByteBuffer) BufferUnderflowException(java.nio.BufferUnderflowException)

Aggregations

ApkFormatException (com.android.apksig.apk.ApkFormatException)1 ApkSignerInfo (com.android.apksig.internal.apk.ApkSignerInfo)1 BufferUnderflowException (java.nio.BufferUnderflowException)1 ByteBuffer (java.nio.ByteBuffer)1 CertificateException (java.security.cert.CertificateException)1 CertificateFactory (java.security.cert.CertificateFactory)1