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.config; 17 18 import com.ohos.hapsigntool.api.LocalizationAdapter; 19 import com.ohos.hapsigntool.api.model.Options; 20 import com.ohos.hapsigntool.hap.sign.SignatureAlgorithm; 21 import com.ohos.hapsigntool.signer.ISigner; 22 import com.ohos.hapsigntool.signer.SignerFactory; 23 24 import java.security.cert.X509CRL; 25 import java.security.cert.X509Certificate; 26 import java.util.HashMap; 27 import java.util.List; 28 import java.util.Map; 29 30 /** 31 * Sign config super class 32 * 33 * @since 2021-12-13 34 */ 35 public class SignerConfig { 36 /** 37 * params inputted by users 38 */ 39 private Options options; 40 41 /** 42 * certificate chain used for sign hap 43 */ 44 private List<X509Certificate> certificates; 45 46 /** 47 * certificate revocation list return from server 48 */ 49 private List<X509CRL> x509CRLs; 50 51 /** 52 * Signature Algorithms used for sign hap 53 */ 54 private List<SignatureAlgorithm> signatureAlgorithms; 55 56 /** 57 * parameters for sign hap 58 */ 59 private Map<String, String> signParamMap = new HashMap<String, String>(); 60 61 /** 62 * Get options. 63 * 64 * @return options 65 */ getOptions()66 public Options getOptions() { 67 return options; 68 } 69 70 /** 71 * set options. 72 */ setOptions(Options options)73 public void setOptions(Options options) { 74 this.options = options; 75 } 76 77 /** 78 * Get certificates. 79 * 80 * @return certificates 81 */ getCertificates()82 public List<X509Certificate> getCertificates() { 83 return certificates; 84 } 85 86 /** 87 * set certificate 88 */ setCertificates(List<X509Certificate> certificates)89 public void setCertificates(List<X509Certificate> certificates) { 90 this.certificates = certificates; 91 } 92 93 /** 94 * get crl 95 * 96 * @return crl list 97 */ getX509CRLs()98 public List<X509CRL> getX509CRLs() { 99 return x509CRLs; 100 } 101 102 /** 103 * set crl 104 */ setX509CRLs(List<X509CRL> crls)105 public void setX509CRLs(List<X509CRL> crls) { 106 this.x509CRLs = crls; 107 } 108 109 /** 110 * get signature algorithm 111 * 112 * @return signature algorithm 113 */ getSignatureAlgorithms()114 public List<SignatureAlgorithm> getSignatureAlgorithms() { 115 return signatureAlgorithms; 116 } 117 118 /** 119 * set signature algorithm 120 */ setSignatureAlgorithms(List<SignatureAlgorithm> signatureAlgorithms)121 public void setSignatureAlgorithms(List<SignatureAlgorithm> signatureAlgorithms) { 122 this.signatureAlgorithms = signatureAlgorithms; 123 } 124 125 /** 126 * get param map 127 * 128 * @return param map 129 */ getSignParamMap()130 public Map<String, String> getSignParamMap() { 131 return this.signParamMap; 132 } 133 134 /** 135 * set param map 136 */ fillParameters(Map<String, String> params)137 public void fillParameters(Map<String, String> params) { 138 this.signParamMap = params; 139 } 140 141 /** 142 * get signer 143 */ getSigner()144 public ISigner getSigner() { 145 return new SignerFactory().getSigner(new LocalizationAdapter(options)); 146 } 147 } 148