1 /* 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 package com.ohos.hapsigntool.hap.verify; 17 18 import com.ohos.hapsigntool.hap.entity.SigningBlock; 19 import org.bouncycastle.cert.X509CertificateHolder; 20 import org.bouncycastle.cms.SignerInformation; 21 import org.bouncycastle.util.Store; 22 23 import java.security.cert.X509CRL; 24 import java.security.cert.X509Certificate; 25 import java.util.List; 26 27 /** 28 * Indicate result of verify hap. 29 * 30 * @since 2021/12/22 31 */ 32 public class VerifyResult { 33 /** 34 * Return code of verify success. 35 */ 36 public static final int RET_SUCCESS = 10000; 37 38 /** 39 * Return code of unknown error. 40 */ 41 public static final int RET_UNKNOWN_ERROR = 10001; 42 43 /** 44 * Return code of IO error. 45 */ 46 public static final int RET_IO_ERROR = 10002; 47 48 /** 49 * Return code of file format error. 50 */ 51 public static final int RET_UNSUPPORTED_FORMAT_ERROR = 10003; 52 53 /** 54 * Return code of file not found error. 55 */ 56 public static final int RET_FILE_NOT_FOUND_ERROR = 10004; 57 58 /** 59 * Return code of encoding certificates errors. 60 */ 61 public static final int RET_CERTIFICATE_ENCODING_ERROR = 10005; 62 63 /** 64 * Return code of unsupported algorithm error. 65 */ 66 public static final int RET_UNSUPPORTED_ALGORITHM_ERROR = 10006; 67 68 /** 69 * Return code of digest error. 70 */ 71 public static final int RET_DIGEST_ERROR = 10007; 72 73 /** 74 * Return code of signatures not found error. 75 */ 76 public static final int RET_SIGNATURE_NOT_FOUND_ERROR = 10008; 77 78 /** 79 * Return code of signatures verify error. 80 */ 81 public static final int RET_SIGNATURE_ERROR = 10009; 82 83 /** 84 * Return code of certificate revoked error. 85 */ 86 public static final int RET_CERTIFICATE_REVOKED = 10010; 87 88 /** 89 * Return code of certificate revoked error. 90 */ 91 public static final int RET_CRL_ERROR = 10011; 92 93 private boolean result; 94 private int code; 95 private String message; 96 97 private List<X509Certificate> certificates; 98 99 private List<X509CRL> crls; 100 101 private List<SignerInformation> signerInfos; 102 103 private List<SigningBlock> optionalBlocks; 104 105 private Store<X509CertificateHolder> certificateHolderStore; 106 VerifyResult()107 public VerifyResult() { 108 } 109 VerifyResult(boolean result, int code, String message)110 public VerifyResult(boolean result, int code, String message) { 111 this.result = result; 112 this.code = code; 113 this.message = message; 114 } 115 isVerified()116 public boolean isVerified() { 117 return result; 118 } 119 setResult(boolean result)120 public void setResult(boolean result) { 121 this.result = result; 122 } 123 getCode()124 public int getCode() { 125 return code; 126 } 127 setCode(int code)128 public void setCode(int code) { 129 this.code = code; 130 } 131 getMessage()132 public String getMessage() { 133 return message; 134 } 135 setMessage(String message)136 public void setMessage(String message) { 137 this.message = message; 138 } 139 getCertificates()140 public List<X509Certificate> getCertificates() { 141 return certificates; 142 } 143 setCertificates(List<X509Certificate> certificates)144 public void setCertificates(List<X509Certificate> certificates) { 145 this.certificates = certificates; 146 } 147 getCrls()148 public List<X509CRL> getCrls() { 149 return crls; 150 } 151 setCrls(List<X509CRL> crls)152 public void setCrls(List<X509CRL> crls) { 153 this.crls = crls; 154 } 155 getSignerInfos()156 public List<SignerInformation> getSignerInfos() { 157 return signerInfos; 158 } 159 setSignerInfos(List<SignerInformation> signerInfos)160 public void setSignerInfos(List<SignerInformation> signerInfos) { 161 this.signerInfos = signerInfos; 162 } 163 getOptionalBlocks()164 public List<SigningBlock> getOptionalBlocks() { 165 return optionalBlocks; 166 } 167 setOptionalBlocks(List<SigningBlock> optionalBlocks)168 public void setOptionalBlocks(List<SigningBlock> optionalBlocks) { 169 this.optionalBlocks = optionalBlocks; 170 } 171 getCertificateHolderStore()172 public Store<X509CertificateHolder> getCertificateHolderStore() { 173 return certificateHolderStore; 174 } 175 setCertificateHolderStore(Store<X509CertificateHolder> certificateHolderStore)176 public void setCertificateHolderStore(Store<X509CertificateHolder> certificateHolderStore) { 177 this.certificateHolderStore = certificateHolderStore; 178 } 179 } 180