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 20 import org.bouncycastle.cert.X509CertificateHolder; 21 import org.bouncycastle.cms.SignerInformation; 22 import org.bouncycastle.util.Store; 23 24 import java.security.cert.X509CRL; 25 import java.security.cert.X509Certificate; 26 import java.util.List; 27 28 /** 29 * Indicate result of verify hap. 30 * 31 * @since 2021/12/22 32 */ 33 public class VerifyResult { 34 /** 35 * Return code of verification success. 36 */ 37 public static final int RET_SUCCESS = 10000; 38 39 /** 40 * Return code of unknown error. 41 */ 42 public static final int RET_UNKNOWN_ERROR = 10001; 43 44 /** 45 * Return code of IO error. 46 */ 47 public static final int RET_IO_ERROR = 10002; 48 49 /** 50 * Return code of file format error. 51 */ 52 public static final int RET_UNSUPPORTED_FORMAT_ERROR = 10003; 53 54 /** 55 * Return code of file not found error. 56 */ 57 public static final int RET_FILE_NOT_FOUND_ERROR = 10004; 58 59 /** 60 * Return code of encoding certificates errors. 61 */ 62 public static final int RET_CERTIFICATE_ENCODING_ERROR = 10005; 63 64 /** 65 * Return code of unsupported algorithm error. 66 */ 67 public static final int RET_UNSUPPORTED_ALGORITHM_ERROR = 10006; 68 69 /** 70 * Return code of digest error. 71 */ 72 public static final int RET_DIGEST_ERROR = 10007; 73 74 /** 75 * Return code of signatures not found error. 76 */ 77 public static final int RET_SIGNATURE_NOT_FOUND_ERROR = 10008; 78 79 /** 80 * Return code of signatures verify error. 81 */ 82 public static final int RET_SIGNATURE_ERROR = 10009; 83 84 /** 85 * Return code of certificate revoked error. 86 */ 87 public static final int RET_CERTIFICATE_REVOKED = 10010; 88 89 /** 90 * Return code of certificate revoked error. 91 */ 92 public static final int RET_CRL_ERROR = 10011; 93 94 /** 95 * Return code of file code sign data error. 96 */ 97 public static final int RET_CODESIGN_DATA_ERROR = 10012; 98 99 /** 100 * Return code of verify code sign error. 101 */ 102 public static final int RET_CODE_SIGN_BLOCK_ERROR = 10013; 103 104 private boolean isResult; 105 private int code; 106 private String message; 107 108 private List<X509Certificate> certificates; 109 110 private List<X509CRL> crls; 111 112 private List<SignerInformation> signerInfos; 113 114 private List<SigningBlock> optionalBlocks; 115 116 private Store<X509CertificateHolder> certificateHolderStore; 117 118 private int signBlockVersion; 119 120 private byte[] profile; 121 122 /** 123 * Empty constructor 124 */ VerifyResult()125 public VerifyResult() { 126 } 127 128 /** 129 * Verify result constructor 130 * 131 * @param isResult verify result 132 * @param code error code 133 * @param message error message 134 */ VerifyResult(boolean isResult, int code, String message)135 public VerifyResult(boolean isResult, int code, String message) { 136 this.isResult = isResult; 137 this.code = code; 138 this.message = message; 139 } 140 isVerified()141 public boolean isVerified() { 142 return isResult; 143 } 144 setIsResult(boolean isResult)145 public void setIsResult(boolean isResult) { 146 this.isResult = isResult; 147 } 148 getCode()149 public int getCode() { 150 return code; 151 } 152 setCode(int code)153 public void setCode(int code) { 154 this.code = code; 155 } 156 getMessage()157 public String getMessage() { 158 return message; 159 } 160 setMessage(String message)161 public void setMessage(String message) { 162 this.message = message; 163 } 164 getCertificates()165 public List<X509Certificate> getCertificates() { 166 return certificates; 167 } 168 setCertificates(List<X509Certificate> certificates)169 public void setCertificates(List<X509Certificate> certificates) { 170 this.certificates = certificates; 171 } 172 getCrls()173 public List<X509CRL> getCrls() { 174 return crls; 175 } 176 setCrls(List<X509CRL> crls)177 public void setCrls(List<X509CRL> crls) { 178 this.crls = crls; 179 } 180 getSignerInfos()181 public List<SignerInformation> getSignerInfos() { 182 return signerInfos; 183 } 184 setSignerInfos(List<SignerInformation> signerInfos)185 public void setSignerInfos(List<SignerInformation> signerInfos) { 186 this.signerInfos = signerInfos; 187 } 188 getOptionalBlocks()189 public List<SigningBlock> getOptionalBlocks() { 190 return optionalBlocks; 191 } 192 setOptionalBlocks(List<SigningBlock> optionalBlocks)193 public void setOptionalBlocks(List<SigningBlock> optionalBlocks) { 194 this.optionalBlocks = optionalBlocks; 195 } 196 getCertificateHolderStore()197 public Store<X509CertificateHolder> getCertificateHolderStore() { 198 return certificateHolderStore; 199 } 200 setCertificateHolderStore(Store<X509CertificateHolder> certificateHolderStore)201 public void setCertificateHolderStore(Store<X509CertificateHolder> certificateHolderStore) { 202 this.certificateHolderStore = certificateHolderStore; 203 } 204 getSignBlockVersion()205 public int getSignBlockVersion() { 206 return signBlockVersion; 207 } 208 setSignBlockVersion(int signBlockVersion)209 public void setSignBlockVersion(int signBlockVersion) { 210 this.signBlockVersion = signBlockVersion; 211 } 212 getProfile()213 public byte[] getProfile() { 214 return profile; 215 } 216 setProfile(byte[] profile)217 public void setProfile(byte[] profile) { 218 this.profile = profile; 219 } 220 } 221