1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.apksig.internal.apk; 18 19 import com.android.apksig.ApkVerificationIssue; 20 21 import java.security.cert.X509Certificate; 22 import java.util.ArrayList; 23 import java.util.List; 24 25 /** 26 * Base implementation of an APK signer. 27 */ 28 public class ApkSignerInfo { 29 public int index; 30 public long timestamp; 31 public List<X509Certificate> certs = new ArrayList<>(); 32 public List<X509Certificate> certificateLineage = new ArrayList<>(); 33 34 private final List<ApkVerificationIssue> mInfoMessages = new ArrayList<>(); 35 private final List<ApkVerificationIssue> mWarnings = new ArrayList<>(); 36 private final List<ApkVerificationIssue> mErrors = new ArrayList<>(); 37 38 /** 39 * Adds a new {@link ApkVerificationIssue} as an error to this signer using the provided {@code 40 * issueId} and {@code params}. 41 */ addError(int issueId, Object... params)42 public void addError(int issueId, Object... params) { 43 mErrors.add(new ApkVerificationIssue(issueId, params)); 44 } 45 46 /** 47 * Adds a new {@link ApkVerificationIssue} as a warning to this signer using the provided {@code 48 * issueId} and {@code params}. 49 */ addWarning(int issueId, Object... params)50 public void addWarning(int issueId, Object... params) { 51 mWarnings.add(new ApkVerificationIssue(issueId, params)); 52 } 53 54 /** 55 * Adds a new {@link ApkVerificationIssue} as an info message to this signer config using the 56 * provided {@code issueId} and {@code params}. 57 */ addInfoMessage(int issueId, Object... params)58 public void addInfoMessage(int issueId, Object... params) { 59 mInfoMessages.add(new ApkVerificationIssue(issueId, params)); 60 } 61 62 /** 63 * Returns {@code true} if any errors were encountered during verification for this signer. 64 */ containsErrors()65 public boolean containsErrors() { 66 return !mErrors.isEmpty(); 67 } 68 69 /** 70 * Returns {@code true} if any warnings were encountered during verification for this signer. 71 */ containsWarnings()72 public boolean containsWarnings() { 73 return !mWarnings.isEmpty(); 74 } 75 76 /** 77 * Returns {@code true} if any info messages were encountered during verification of this 78 * signer. 79 */ containsInfoMessages()80 public boolean containsInfoMessages() { 81 return !mInfoMessages.isEmpty(); 82 } 83 84 /** 85 * Returns the errors encountered during verification for this signer. 86 */ getErrors()87 public List<? extends ApkVerificationIssue> getErrors() { 88 return mErrors; 89 } 90 91 /** 92 * Returns the warnings encountered during verification for this signer. 93 */ getWarnings()94 public List<? extends ApkVerificationIssue> getWarnings() { 95 return mWarnings; 96 } 97 98 /** 99 * Returns the info messages encountered during verification of this signer. 100 */ getInfoMessages()101 public List<? extends ApkVerificationIssue> getInfoMessages() { 102 return mInfoMessages; 103 } 104 } 105