From 8abcba4f06b18a72e55c907e12490ea9ed3a6f7f Mon Sep 17 00:00:00 2001 From: wangzeyu Date: Tue, 10 Dec 2024 09:56:58 +0800 Subject: [PATCH 01/12] remove log4j Signed-off-by: wangzeyu --- hapsigntool/hap_sign_tool/pom.xml | 8 - .../com/ohos/hapsigntool/HapSignTool.java | 8 +- .../com/ohos/hapsigntoolcmd/HelpDocument.java | 4 +- .../src/main/resources/log.properties | 1 + .../src/main/resources/log4j2.xml | 49 ----- .../ohos/hapsigntoolcmd/ConcurrencyTest.java | 5 +- hapsigntool/hap_sign_tool_lib/pom.xml | 8 - .../adapter/LocalizationAdapter.java | 5 +- .../com/ohos/hapsigntool/api/CertTools.java | 6 +- .../hapsigntool/api/SignToolServiceImpl.java | 5 +- .../ohos/hapsigntool/cert/CertBuilder.java | 6 +- .../datastructure/HapInfoSegment.java | 5 - .../codesigning/datastructure/SignInfo.java | 12 +- .../sign/BcSignedDataGenerator.java | 5 +- .../codesigning/sign/CodeSigning.java | 20 +- .../codesigning/sign/PageInfoGenerator.java | 8 +- .../codesigning/sign/VerifyCodeSignature.java | 9 +- .../codesigning/utils/HapUtils.java | 7 +- .../com/ohos/hapsigntool/entity/Options.java | 5 +- .../hapsigntool/error/LogConfigException.java | 27 +++ .../hap/provider/LocalJKSSignProvider.java | 5 +- .../hap/provider/SignProvider.java | 13 +- .../hap/sign/BcPkcs7Generator.java | 5 +- .../ohos/hapsigntool/hap/sign/SignBin.java | 6 +- .../ohos/hapsigntool/hap/sign/SignElf.java | 6 +- .../ohos/hapsigntool/hap/utils/HapUtils.java | 7 +- .../hapsigntool/hap/verify/HapVerify.java | 42 ++-- .../hap/verify/VerifyAndParseProvision.java | 6 +- .../hapsigntool/hap/verify/VerifyElf.java | 15 +- .../hapsigntool/hap/verify/VerifyHap.java | 15 +- .../hapsigntool/profile/ProfileSignTool.java | 6 +- .../hapsigntool/profile/VerifyHelper.java | 6 +- .../ohos/hapsigntool/signer/LocalSigner.java | 5 +- .../hapsigntool/signer/SignerFactory.java | 20 +- .../hapsigntool/utils/CertChainUtils.java | 2 - .../com/ohos/hapsigntool/utils/CertUtils.java | 5 +- .../ohos/hapsigntool/utils/DigestUtils.java | 5 +- .../com/ohos/hapsigntool/utils/FileUtils.java | 7 +- .../com/ohos/hapsigntool/utils/HashUtils.java | 5 +- .../ohos/hapsigntool/utils/KeyPairTools.java | 5 +- .../hapsigntool/utils/KeyStoreHelper.java | 7 +- .../com/ohos/hapsigntool/utils/LogUtils.java | 198 ++++++++++++++++++ .../hapsigntool/utils/ParamProcessUtil.java | 4 +- .../hapsigntool/utils/SignToolFormatter.java | 50 +++++ .../java/com/ohos/hapsigntool/zip/Zip.java | 11 +- hapsigntool/pom.xml | 11 - 46 files changed, 411 insertions(+), 259 deletions(-) create mode 100644 hapsigntool/hap_sign_tool/src/main/resources/log.properties delete mode 100644 hapsigntool/hap_sign_tool/src/main/resources/log4j2.xml create mode 100644 hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/error/LogConfigException.java create mode 100644 hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java create mode 100644 hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/SignToolFormatter.java diff --git a/hapsigntool/hap_sign_tool/pom.xml b/hapsigntool/hap_sign_tool/pom.xml index b3c7031b..53a4466c 100644 --- a/hapsigntool/hap_sign_tool/pom.xml +++ b/hapsigntool/hap_sign_tool/pom.xml @@ -25,14 +25,6 @@ org.bouncycastle bcpkix-jdk18on - - org.apache.logging.log4j - log4j-core - - - org.apache.logging.log4j - log4j-api - org.junit.jupiter junit-jupiter-engine diff --git a/hapsigntool/hap_sign_tool/src/main/java/com/ohos/hapsigntool/HapSignTool.java b/hapsigntool/hap_sign_tool/src/main/java/com/ohos/hapsigntool/HapSignTool.java index adcfe646..35889e3f 100644 --- a/hapsigntool/hap_sign_tool/src/main/java/com/ohos/hapsigntool/HapSignTool.java +++ b/hapsigntool/hap_sign_tool/src/main/java/com/ohos/hapsigntool/HapSignTool.java @@ -27,15 +27,13 @@ import com.ohos.hapsigntool.error.CustomException; import com.ohos.hapsigntool.error.ERROR; import com.ohos.hapsigntool.error.ParamException; import com.ohos.hapsigntool.utils.FileUtils; +import com.ohos.hapsigntool.utils.LogUtils; import com.ohos.hapsigntool.utils.StringUtils; import com.ohos.hapsigntoolcmd.CmdUtil; import com.ohos.hapsigntoolcmd.CmdUtil.Method; import com.ohos.hapsigntoolcmd.HelpDocument; import com.ohos.hapsigntoolcmd.Params; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - import java.util.ArrayList; import java.util.List; import java.util.Locale; @@ -49,7 +47,7 @@ public final class HapSignTool { /** * Add log info. */ - private static final Logger LOGGER = LogManager.getLogger(HapSignTool.class); + private static final LogUtils LOGGER = new LogUtils(HapSignTool.class); /** * Tool version. @@ -127,7 +125,7 @@ public final class HapSignTool { ServiceApi api = new SignToolServiceImpl(); Params params = CmdUtil.convert2Params(args); LOGGER.debug(params.toString()); - LOGGER.info("Start {}", params.getMethod()); + LOGGER.info("Start " + params.getMethod()); boolean isSuccess = dispatchParams(params, api); if (isSuccess) { LOGGER.info(String.format("%s %s", params.getMethod(), "success")); diff --git a/hapsigntool/hap_sign_tool/src/main/java/com/ohos/hapsigntoolcmd/HelpDocument.java b/hapsigntool/hap_sign_tool/src/main/java/com/ohos/hapsigntoolcmd/HelpDocument.java index 7dbe3004..f5f71165 100644 --- a/hapsigntool/hap_sign_tool/src/main/java/com/ohos/hapsigntoolcmd/HelpDocument.java +++ b/hapsigntool/hap_sign_tool/src/main/java/com/ohos/hapsigntoolcmd/HelpDocument.java @@ -18,7 +18,7 @@ package com.ohos.hapsigntoolcmd; import com.ohos.hapsigntool.error.CustomException; import com.ohos.hapsigntool.error.ERROR; import com.ohos.hapsigntool.utils.FileUtils; -import org.apache.logging.log4j.Logger; +import com.ohos.hapsigntool.utils.LogUtils; import java.io.IOException; import java.io.InputStream; @@ -38,7 +38,7 @@ public final class HelpDocument { * * @param logger log4j */ - public static void printHelp(Logger logger) { + public static void printHelp(LogUtils logger) { ClassLoader classLoader = HelpDocument.class.getClassLoader(); if (classLoader == null) { return; diff --git a/hapsigntool/hap_sign_tool/src/main/resources/log.properties b/hapsigntool/hap_sign_tool/src/main/resources/log.properties new file mode 100644 index 00000000..848e7c92 --- /dev/null +++ b/hapsigntool/hap_sign_tool/src/main/resources/log.properties @@ -0,0 +1 @@ +level=info \ No newline at end of file diff --git a/hapsigntool/hap_sign_tool/src/main/resources/log4j2.xml b/hapsigntool/hap_sign_tool/src/main/resources/log4j2.xml deleted file mode 100644 index 87353ad6..00000000 --- a/hapsigntool/hap_sign_tool/src/main/resources/log4j2.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - ../logs - ../logs - ../logs - - %d{yyyy-MM-dd HH:mm:ss.SSS} [%t-%L] %-5level %logger{36} - %msg%n - %d{MM-dd HH:mm:ss} %-5level - %msg%n - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/hapsigntool/hap_sign_tool/src/test/java/com/ohos/hapsigntoolcmd/ConcurrencyTest.java b/hapsigntool/hap_sign_tool/src/test/java/com/ohos/hapsigntoolcmd/ConcurrencyTest.java index b991ebec..d7dc5a5f 100644 --- a/hapsigntool/hap_sign_tool/src/test/java/com/ohos/hapsigntoolcmd/ConcurrencyTest.java +++ b/hapsigntool/hap_sign_tool/src/test/java/com/ohos/hapsigntoolcmd/ConcurrencyTest.java @@ -27,8 +27,7 @@ import com.ohos.hapsigntool.HapSignTool; import com.ohos.hapsigntool.error.ERROR; import com.ohos.hapsigntool.utils.FileUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import com.ohos.hapsigntool.utils.LogUtils; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -77,7 +76,7 @@ public class ConcurrencyTest { private static final File TMP_DIR = new File("concurrentTest"); private static final List tmpSource = new ArrayList<>(); - private static final Logger log = LogManager.getLogger(ConcurrencyTest.class); + private static final LogUtils log = new LogUtils(ConcurrencyTest.class); /** * before test diff --git a/hapsigntool/hap_sign_tool_lib/pom.xml b/hapsigntool/hap_sign_tool_lib/pom.xml index 5672b662..d8ce6170 100644 --- a/hapsigntool/hap_sign_tool_lib/pom.xml +++ b/hapsigntool/hap_sign_tool_lib/pom.xml @@ -20,14 +20,6 @@ org.bouncycastle bcpkix-jdk18on - - org.apache.logging.log4j - log4j-core - - - org.apache.logging.log4j - log4j-api - org.junit.jupiter junit-jupiter-engine diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/adapter/LocalizationAdapter.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/adapter/LocalizationAdapter.java index 6f505b62..3528578d 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/adapter/LocalizationAdapter.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/adapter/LocalizationAdapter.java @@ -23,10 +23,9 @@ import com.ohos.hapsigntool.utils.KeyPairTools; import com.ohos.hapsigntool.utils.KeyStoreHelper; import com.ohos.hapsigntool.utils.CertUtils; import com.ohos.hapsigntool.utils.FileUtils; +import com.ohos.hapsigntool.utils.LogUtils; import com.ohos.hapsigntool.utils.StringUtils; import com.ohos.hapsigntool.utils.ValidateUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.bouncycastle.asn1.x500.X500Name; import org.bouncycastle.asn1.x509.KeyPurposeId; import org.bouncycastle.asn1.x509.KeyUsage; @@ -54,7 +53,7 @@ public class LocalizationAdapter { /** * Logger */ - private static final Logger logger = LogManager.getLogger(LocalizationAdapter.class); + private static final LogUtils logger = new LogUtils(LocalizationAdapter.class); /** * Params diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/api/CertTools.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/api/CertTools.java index 0d0ab3d5..f4f2abc1 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/api/CertTools.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/api/CertTools.java @@ -22,8 +22,8 @@ import com.ohos.hapsigntool.entity.Options; import com.ohos.hapsigntool.error.CustomException; import com.ohos.hapsigntool.error.ERROR; import com.ohos.hapsigntool.utils.CertUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; + +import com.ohos.hapsigntool.utils.LogUtils; import org.bouncycastle.asn1.x500.X500Name; import org.bouncycastle.asn1.x509.KeyPurposeId; import org.bouncycastle.asn1.x509.KeyUsage; @@ -58,7 +58,7 @@ public final class CertTools { /** * Logger. */ - private static final Logger LOGGER = LogManager.getLogger(ServiceApi.class); + private static final LogUtils LOGGER = new LogUtils(ServiceApi.class); private CertTools() { } diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/api/SignToolServiceImpl.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/api/SignToolServiceImpl.java index 7eee7c07..bb4d1895 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/api/SignToolServiceImpl.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/api/SignToolServiceImpl.java @@ -33,10 +33,9 @@ import com.ohos.hapsigntool.profile.model.VerificationResult; import com.ohos.hapsigntool.utils.CertUtils; import com.ohos.hapsigntool.utils.FileUtils; import com.ohos.hapsigntool.entity.ParamConstants; +import com.ohos.hapsigntool.utils.LogUtils; import com.ohos.hapsigntool.utils.StringUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.bouncycastle.jce.provider.BouncyCastleProvider; import java.io.File; @@ -69,7 +68,7 @@ public class SignToolServiceImpl implements ServiceApi { /** * Logger. */ - private static final Logger logger = LogManager.getLogger(ServiceApi.class); + private static final LogUtils logger = new LogUtils(ServiceApi.class); static { Security.addProvider(new BouncyCastleProvider()); diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/cert/CertBuilder.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/cert/CertBuilder.java index a9cc7b61..6ce87c49 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/cert/CertBuilder.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/cert/CertBuilder.java @@ -19,8 +19,8 @@ import com.ohos.hapsigntool.api.ServiceApi; import com.ohos.hapsigntool.error.CustomException; import com.ohos.hapsigntool.error.ERROR; import com.ohos.hapsigntool.utils.CertUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; + +import com.ohos.hapsigntool.utils.LogUtils; import org.bouncycastle.asn1.ASN1ObjectIdentifier; import org.bouncycastle.asn1.x500.X500Name; import org.bouncycastle.asn1.x509.BasicConstraints; @@ -58,7 +58,7 @@ public class CertBuilder { /** * Logger. */ - private static final Logger logger = LogManager.getLogger(ServiceApi.class); + private static final LogUtils logger = new LogUtils(ServiceApi.class); /** * issuer keyPair. diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/datastructure/HapInfoSegment.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/datastructure/HapInfoSegment.java index 42865040..783c1d16 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/datastructure/HapInfoSegment.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/datastructure/HapInfoSegment.java @@ -18,9 +18,6 @@ package com.ohos.hapsigntool.codesigning.datastructure; import com.ohos.hapsigntool.codesigning.exception.VerifyCodeSignException; import com.ohos.hapsigntool.codesigning.utils.NumberUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.util.Locale; @@ -37,8 +34,6 @@ import java.util.Locale; * @since 2023/09/08 */ public class HapInfoSegment { - private static final Logger LOGGER = LogManager.getLogger(HapInfoSegment.class); - private static final int MAGIC_NUM_BYTES = 4; /** diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/datastructure/SignInfo.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/datastructure/SignInfo.java index 748b92a2..81960807 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/datastructure/SignInfo.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/datastructure/SignInfo.java @@ -16,9 +16,7 @@ package com.ohos.hapsigntool.codesigning.datastructure; import com.ohos.hapsigntool.codesigning.exception.VerifyCodeSignException; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import com.ohos.hapsigntool.utils.LogUtils; import java.nio.ByteBuffer; import java.nio.ByteOrder; @@ -63,7 +61,7 @@ public class SignInfo { */ public static final int MAX_EXTENSION_NUM = 2; - private static final Logger LOGGER = LogManager.getLogger(SignInfo.class); + private static final LogUtils LOGGER = new LogUtils(SignInfo.class); /** * sign info structure without signature in bytes, refer to toByteArray() method @@ -247,8 +245,8 @@ public class SignInfo { bf.get(inSalt); int inExtensionNum = bf.getInt(); if (inExtensionNum < 0 || inExtensionNum > MAX_EXTENSION_NUM) { - LOGGER.info("The signature information may be generated by an new tool, extensionNum {} of SignInfo", - inExtensionNum); + LOGGER.info("The signature information may be generated by an new tool, extensionNum " + + inExtensionNum + " of SignInfo"); } int inExtensionOffset = bf.getInt(); if (inExtensionOffset < 0 || inExtensionOffset % 4 != 0) { @@ -298,7 +296,7 @@ public class SignInfo { bf.get(pageInfoExtension); inExtensionList.add(PageInfoExtension.fromByteArray(pageInfoExtension)); } else { - LOGGER.info("Invalid extensionType {} of SignInfo", extensionType); + LOGGER.info("Invalid extensionType " + extensionType + " of SignInfo"); } } return inExtensionList; diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/sign/BcSignedDataGenerator.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/sign/BcSignedDataGenerator.java index b2000228..a38aea41 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/sign/BcSignedDataGenerator.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/sign/BcSignedDataGenerator.java @@ -23,8 +23,7 @@ import com.ohos.hapsigntool.entity.Pair; import com.ohos.hapsigntool.entity.ContentDigestAlgorithm; import com.ohos.hapsigntool.entity.SignatureAlgorithm; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import com.ohos.hapsigntool.utils.LogUtils; import org.bouncycastle.asn1.ASN1EncodableVector; import org.bouncycastle.asn1.ASN1Encoding; import org.bouncycastle.asn1.ASN1Integer; @@ -75,7 +74,7 @@ public class BcSignedDataGenerator implements SignedDataGenerator { */ public static final String SIGNER_OID = "1.3.6.1.4.1.2011.2.376.1.4.1"; - private static final Logger LOGGER = LogManager.getLogger(BcSignedDataGenerator.class); + private static final LogUtils LOGGER = new LogUtils(BcSignedDataGenerator.class); private static final SignatureAlgorithmIdentifierFinder SIGN_ALG_ID_FINDER = new DefaultSignatureAlgorithmIdentifierFinder(); diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/sign/CodeSigning.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/sign/CodeSigning.java index ee95ce70..31fe3d35 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/sign/CodeSigning.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/sign/CodeSigning.java @@ -36,15 +36,13 @@ import com.ohos.hapsigntool.error.ProfileException; import com.ohos.hapsigntool.hap.config.SignerConfig; import com.ohos.hapsigntool.signer.LocalSigner; import com.ohos.hapsigntool.utils.FileUtils; +import com.ohos.hapsigntool.utils.LogUtils; import com.ohos.hapsigntool.utils.StringUtils; import com.ohos.hapsigntool.zip.EntryType; import com.ohos.hapsigntool.zip.Zip; import com.ohos.hapsigntool.zip.ZipEntry; import com.ohos.hapsigntool.zip.ZipEntryHeader; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -80,7 +78,7 @@ public class CodeSigning { */ public static final String HAP_SIGNATURE_ENTRY_NAME = "Hap"; - private static final Logger LOGGER = LogManager.getLogger(CodeSigning.class); + private static final LogUtils LOGGER = new LogUtils(CodeSigning.class); private final SignerConfig signConfig; @@ -275,7 +273,7 @@ public class CodeSigning { if (!hnpTypeMap.containsKey(hnpFileName)) { throw new CodeSignException("hnp should be described in module.json"); } - LOGGER.debug("Sign hnp name = {}", entryName); + LOGGER.debug("Sign hnp name = " + entryName); String type = hnpTypeMap.get(hnpFileName); String hnpOwnerId = ownerID; if ("public".equals(type)) { @@ -296,7 +294,7 @@ public class CodeSigning { } try (JarFile hnp = new JarFile(tempHnp, false)) { List elfEntries = getHnpLibEntries(hnp); - LOGGER.debug("{} elf num : {}", hnp.getName(), elfEntries.size()); + LOGGER.debug(hnp.getName() + " elf num : " + elfEntries.size()); List> nativeLibInfoList = elfEntries.stream().parallel().map(entry -> { String hnpElfPath = hnpEntry.getName() + "!/" + entry.getName(); try (InputStream inputStream = hnp.getInputStream(entry)) { @@ -306,7 +304,7 @@ public class CodeSigning { false, 0, ownerID); return (Pair.create(hnpElfPath, pairSignInfoAndMerkleTreeBytes.getFirst())); } catch (IOException | FsVerityDigestException | CodeSignException e) { - LOGGER.error("Sign hnp lib error, entry name = {}, msg : {}", hnpElfPath, e.getMessage()); + LOGGER.error("Sign hnp lib error, entry name = " + hnpElfPath + ", msg : " + e.getMessage()); } return null; }).collect(Collectors.toList()); @@ -317,9 +315,9 @@ public class CodeSigning { } finally { if (tempHnp.exists()) { if (tempHnp.delete()) { - LOGGER.debug("delete temp hnp file {}", tempHnp.getName()); + LOGGER.debug("delete temp hnp file " + tempHnp.getName()); } else { - LOGGER.error("delete temp hnp file error {}", tempHnp.getName()); + LOGGER.error("delete temp hnp file error " + tempHnp.getName()); } } } @@ -405,7 +403,7 @@ public class CodeSigning { private List> signFilesFromJar(List entryNames, JarFile hap, String ownerID) throws CodeSignException { List> nativeLibInfoList = entryNames.stream().parallel().map(name -> { - LOGGER.debug("Sign entry name = {}", name); + LOGGER.debug("Sign entry name = " + name); JarEntry inEntry = hap.getJarEntry(name); try (InputStream inputStream = hap.getInputStream(inEntry)) { long fileSize = inEntry.getSize(); @@ -415,7 +413,7 @@ public class CodeSigning { ownerID); return Pair.create(name, pairSignInfoAndMerkleTreeBytes.getFirst()); } catch (FsVerityDigestException | CodeSignException | IOException e) { - LOGGER.error("Sign lib error, entry name = {}, msg : {}", name, e.getMessage()); + LOGGER.error("Sign lib error, entry name = " + name + ", msg : " + e.getMessage()); } return null; }).collect(Collectors.toList()); diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/sign/PageInfoGenerator.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/sign/PageInfoGenerator.java index 7ddfd52c..e157e04a 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/sign/PageInfoGenerator.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/sign/PageInfoGenerator.java @@ -23,14 +23,12 @@ import com.ohos.hapsigntool.codesigning.exception.ElfFormatException; import com.ohos.hapsigntool.codesigning.utils.NumberUtils; import com.ohos.hapsigntool.error.HapFormatException; import com.ohos.hapsigntool.utils.FileUtils; +import com.ohos.hapsigntool.utils.LogUtils; import com.ohos.hapsigntool.zip.EntryType; import com.ohos.hapsigntool.zip.Zip; import com.ohos.hapsigntool.zip.ZipEntry; import com.ohos.hapsigntool.zip.ZipEntryHeader; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -55,7 +53,7 @@ public class PageInfoGenerator { private static final byte ELF_M_CODE = 1; - private static final Logger LOGGER = LogManager.getLogger(PageInfoGenerator.class); + private static final LogUtils LOGGER = new LogUtils(PageInfoGenerator.class); private long maxEntryDataOffset = 0L; @@ -106,7 +104,7 @@ public class PageInfoGenerator { try (InputStream stream = hap.getInputStream(libEntry)) { ElfFile elfFile = new ElfFile(stream); if (!elfFile.isElfFile()) { - LOGGER.info("{} not ELF file", libFileName); + LOGGER.info(libFileName + " not ELF file"); return; } List elfPHeaders = elfFile.filterExecPHeaders(); diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/sign/VerifyCodeSignature.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/sign/VerifyCodeSignature.java index 4c4a401b..8e39671b 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/sign/VerifyCodeSignature.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/sign/VerifyCodeSignature.java @@ -32,10 +32,9 @@ import com.ohos.hapsigntool.codesigning.utils.CmsUtils; import com.ohos.hapsigntool.codesigning.utils.HapUtils; import com.ohos.hapsigntool.entity.Pair; import com.ohos.hapsigntool.error.ProfileException; +import com.ohos.hapsigntool.utils.LogUtils; import com.ohos.hapsigntool.utils.StringUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.bouncycastle.asn1.ASN1ObjectIdentifier; import org.bouncycastle.asn1.cms.Attribute; import org.bouncycastle.asn1.cms.AttributeTable; @@ -64,7 +63,7 @@ import java.util.zip.ZipInputStream; * @since 2023/09/08 */ public class VerifyCodeSignature { - private static final Logger LOGGER = LogManager.getLogger(VerifyCodeSignature.class); + private static final LogUtils LOGGER = new LogUtils(VerifyCodeSignature.class); private static void checkOwnerID(byte[] signature, String profileOwnerID, String profileType) throws CMSException, VerifyCodeSignException { @@ -221,7 +220,7 @@ public class VerifyCodeSignature { hnpEntryNames.add(filePath[0]); hnpLibSignInfoMap.put(entryName, signInfo); } else { - LOGGER.info("verify lib: {}", entryName); + LOGGER.info("verify lib: " + entryName); verifyHapLib(inputJar, entryName, signInfo, pairResult); } } @@ -271,7 +270,7 @@ public class VerifyCodeSignature { if (!hnpLibSignInfoMap.containsKey(libPath)) { continue; } - LOGGER.info("verify lib: {}", libPath); + LOGGER.info("verify lib: " + libPath); SignInfo signInfo = hnpLibSignInfoMap.get(libPath); byte[] entrySig = signInfo.getSignature(); long dataSize = signInfo.getDataSize(); diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/utils/HapUtils.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/utils/HapUtils.java index 1b42e15d..cd13b0b1 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/utils/HapUtils.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/utils/HapUtils.java @@ -25,8 +25,7 @@ import com.google.gson.JsonSyntaxException; import com.google.gson.stream.JsonReader; import com.ohos.hapsigntool.entity.Pair; import com.ohos.hapsigntool.error.ProfileException; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import com.ohos.hapsigntool.utils.LogUtils; import java.io.File; import java.io.IOException; @@ -59,7 +58,7 @@ public class HapUtils { */ public static final String HAP_SHARED_OWNER_ID = "SHARED_LIB_ID"; - private static final Logger LOGGER = LogManager.getLogger(HapUtils.class); + private static final LogUtils LOGGER = new LogUtils(HapUtils.class); private static final String COMPRESS_NATIVE_LIBS_OPTION = "compressNativeLibs"; @@ -193,7 +192,7 @@ public class HapUtils { LOGGER.error(e.getMessage()); throw new ProfileException("profile json is invalid"); } - LOGGER.info("profile type is: {}", profileType); + LOGGER.info("profile type is: " + profileType); return Pair.create(ownerID, profileType); } diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/entity/Options.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/entity/Options.java index e7335ead..6f5b13fc 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/entity/Options.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/entity/Options.java @@ -17,8 +17,7 @@ package com.ohos.hapsigntool.entity; import com.ohos.hapsigntool.error.CustomException; import com.ohos.hapsigntool.error.ERROR; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import com.ohos.hapsigntool.utils.LogUtils; import java.util.HashMap; @@ -248,7 +247,7 @@ public class Options extends HashMap { /** * Logger. */ - private static final Logger logger = LogManager.getLogger(Options.class); + private static final LogUtils logger = new LogUtils(Options.class); /** diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/error/LogConfigException.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/error/LogConfigException.java new file mode 100644 index 00000000..2ac69574 --- /dev/null +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/error/LogConfigException.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.ohos.hapsigntool.error; + +/** + * LogConfigException + * + * @since 2024/12/08 + */ +public class LogConfigException extends Exception { + public LogConfigException(String message) { + super(message); + } +} diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/provider/LocalJKSSignProvider.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/provider/LocalJKSSignProvider.java index b2a36d96..e72a1556 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/provider/LocalJKSSignProvider.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/provider/LocalJKSSignProvider.java @@ -20,11 +20,10 @@ import com.ohos.hapsigntool.error.InvalidParamsException; import com.ohos.hapsigntool.error.MissingParamsException; import com.ohos.hapsigntool.utils.FileUtils; import com.ohos.hapsigntool.entity.ParamConstants; +import com.ohos.hapsigntool.utils.LogUtils; import com.ohos.hapsigntool.utils.ParamProcessUtil; import com.ohos.hapsigntool.utils.StringUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import java.io.File; import java.io.FileInputStream; @@ -42,7 +41,7 @@ import java.util.Set; * @since 2021/12/22 */ public class LocalJKSSignProvider extends SignProvider { - private static final Logger LOGGER = LogManager.getLogger(LocalJKSSignProvider.class); + private static final LogUtils LOGGER = new LogUtils(LocalJKSSignProvider.class); @Override public Optional getCrl() { diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/provider/SignProvider.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/provider/SignProvider.java index 8b00c53c..f4b2b42e 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/provider/SignProvider.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/provider/SignProvider.java @@ -46,6 +46,7 @@ import com.ohos.hapsigntool.utils.EscapeCharacter; import com.ohos.hapsigntool.utils.FileUtils; import com.ohos.hapsigntool.hap.utils.HapUtils; import com.ohos.hapsigntool.entity.ParamConstants; +import com.ohos.hapsigntool.utils.LogUtils; import com.ohos.hapsigntool.utils.ParamProcessUtil; import com.ohos.hapsigntool.utils.StringUtils; import com.ohos.hapsigntool.zip.ByteBufferZipDataInput; @@ -57,8 +58,6 @@ import com.ohos.hapsigntool.zip.ZipDataOutput; import com.ohos.hapsigntool.zip.ZipFileInfo; import com.ohos.hapsigntool.zip.ZipUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.bouncycastle.asn1.x500.RDN; import org.bouncycastle.asn1.x500.X500Name; import org.bouncycastle.asn1.x500.style.BCStyle; @@ -93,7 +92,7 @@ import java.util.Set; * @since 2021-12-14 */ public abstract class SignProvider { - private static final Logger LOGGER = LogManager.getLogger(SignProvider.class); + private static final LogUtils LOGGER = new LogUtils(SignProvider.class); private static final List VALID_SIGN_ALG_NAME = new ArrayList(); private static final List PARAMETERS_NEED_ESCAPE = new ArrayList(); private static final long TIMESTAMP = 1230768000000L; @@ -480,13 +479,13 @@ public abstract class SignProvider { private void printErrorLog(Exception exception) { if (exception != null) { - LOGGER.error("hap-sign-tool: error: {}", exception.getMessage(), exception); + LOGGER.error("hap-sign-tool: error: " + exception.getMessage(), exception); } } private void printErrorLogWithoutStack(Exception exception) { if (exception != null) { - LOGGER.error("hap-sign-tool: error: {}", exception.getMessage()); + LOGGER.error("hap-sign-tool: error: " + exception.getMessage()); } } @@ -518,7 +517,7 @@ public abstract class SignProvider { long start = System.currentTimeMillis(); zip.toFile(tmpOutput.getCanonicalPath()); long end = System.currentTimeMillis(); - LOGGER.debug("zip to file use {} ms", end - start); + LOGGER.debug("zip to file use " + (end - start) + " ms"); return zip; } @@ -650,7 +649,7 @@ public abstract class SignProvider { throw new ProfileException("input certificates do not match with profile!"); } String cn = getCertificateCN(certInProfile); - LOGGER.info("certificate in profile: {}", cn); + LOGGER.info("certificate in profile: " + cn); if (cn.isEmpty()) { throw new ProfileException("Common name of certificate is empty!"); } diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/sign/BcPkcs7Generator.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/sign/BcPkcs7Generator.java index ad4cda15..91854872 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/sign/BcPkcs7Generator.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/sign/BcPkcs7Generator.java @@ -22,8 +22,7 @@ import com.ohos.hapsigntool.entity.Pair; import com.ohos.hapsigntool.error.SignatureException; import com.ohos.hapsigntool.hap.verify.VerifyUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import com.ohos.hapsigntool.utils.LogUtils; import org.bouncycastle.asn1.ASN1EncodableVector; import org.bouncycastle.asn1.ASN1Encoding; import org.bouncycastle.asn1.ASN1Integer; @@ -72,7 +71,7 @@ import java.util.List; * @since 2021/12/21 */ public class BcPkcs7Generator implements Pkcs7Generator { - private static final Logger LOGGER = LogManager.getLogger(BcPkcs7Generator.class); + private static final LogUtils LOGGER = new LogUtils(BcPkcs7Generator.class); private static final SignatureAlgorithmIdentifierFinder SIGN_ALG_FINDER = new DefaultSignatureAlgorithmIdentifierFinder(); private static final DigestAlgorithmIdentifierFinder DIGEST_ALG_FINDER = diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/sign/SignBin.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/sign/SignBin.java index 8c776060..217547e6 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/sign/SignBin.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/sign/SignBin.java @@ -25,11 +25,9 @@ import com.ohos.hapsigntool.error.SignatureException; import com.ohos.hapsigntool.utils.FileUtils; import com.ohos.hapsigntool.utils.HashUtils; import com.ohos.hapsigntool.entity.ParamConstants; +import com.ohos.hapsigntool.utils.LogUtils; import com.ohos.hapsigntool.utils.ParamProcessUtil; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - import java.io.DataOutputStream; import java.io.File; import java.io.FileOutputStream; @@ -42,7 +40,7 @@ import java.util.Map; * @since 2021/12/21 */ public class SignBin { - private static final Logger LOGGER = LogManager.getLogger(SignBin.class); + private static final LogUtils LOGGER = new LogUtils(SignBin.class); /** * Constructor of Method diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/sign/SignElf.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/sign/SignElf.java index bc0b646c..6f2256aa 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/sign/SignElf.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/sign/SignElf.java @@ -28,12 +28,10 @@ import com.ohos.hapsigntool.error.HapFormatException; import com.ohos.hapsigntool.error.ProfileException; import com.ohos.hapsigntool.utils.FileUtils; import com.ohos.hapsigntool.entity.ParamConstants; +import com.ohos.hapsigntool.utils.LogUtils; import com.ohos.hapsigntool.utils.ParamProcessUtil; import com.ohos.hapsigntool.utils.StringUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - import java.io.DataOutputStream; import java.io.File; import java.io.FileInputStream; @@ -55,7 +53,7 @@ public class SignElf { */ public static final char CODESIGN_BLOCK_TYPE = 3; - private static final Logger LOGGER = LogManager.getLogger(SignElf.class); + private static final LogUtils LOGGER = new LogUtils(SignElf.class); private static final String CODESIGN_OFF = "0"; diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/utils/HapUtils.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/utils/HapUtils.java index d5ce7655..fe6c495c 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/utils/HapUtils.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/utils/HapUtils.java @@ -19,13 +19,12 @@ import com.ohos.hapsigntool.entity.Pair; import com.ohos.hapsigntool.hap.entity.SigningBlock; import com.ohos.hapsigntool.error.SignatureNotFoundException; import com.ohos.hapsigntool.entity.ContentDigestAlgorithm; +import com.ohos.hapsigntool.utils.LogUtils; import com.ohos.hapsigntool.zip.MessageDigestZipDataOutput; import com.ohos.hapsigntool.zip.ZipDataInput; import com.ohos.hapsigntool.zip.ZipDataOutput; import com.ohos.hapsigntool.zip.ZipFileInfo; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.bouncycastle.util.Arrays; import java.io.ByteArrayOutputStream; @@ -50,7 +49,7 @@ import java.util.Set; * @since 2021/12/20 */ public class HapUtils { - private static final Logger LOGGER = LogManager.getLogger(HapUtils.class); + private static final LogUtils LOGGER = new LogUtils(HapUtils.class); /** * ID of hap signature blocks of version 1 @@ -519,7 +518,7 @@ public class HapUtils { hapSignBlockMagicLo, hapSignBlockMagicHi, version, centralDirectoryStartOffset); ByteBuffer hapSigningBlockByteBuffer = hap.createByteBuffer(hapSigningBlockOffset, (int) hapSigBlockSize) .order(ByteOrder.LITTLE_ENDIAN); - LOGGER.info("Find Hap Signing Block success, version: {}, block count: {}", version, blockCount); + LOGGER.info("Find Hap Signing Block success, version: " + version + ", block count: " + blockCount); return new HapSignBlockInfo(hapSigningBlockOffset, version, hapSigningBlockByteBuffer); } diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/HapVerify.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/HapVerify.java index 6707caa4..d3ec26aa 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/HapVerify.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/HapVerify.java @@ -20,10 +20,9 @@ import com.ohos.hapsigntool.entity.ContentDigestAlgorithm; import com.ohos.hapsigntool.entity.SignatureAlgorithm; import com.ohos.hapsigntool.utils.DigestUtils; import com.ohos.hapsigntool.hap.utils.HapUtils; +import com.ohos.hapsigntool.utils.LogUtils; import com.ohos.hapsigntool.zip.ZipDataInput; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.bouncycastle.cert.X509CRLHolder; import org.bouncycastle.cert.X509CertificateHolder; import org.bouncycastle.cert.jcajce.JcaX509CRLConverter; @@ -73,7 +72,7 @@ import java.util.Set; * @since 2021/12/22 */ public class HapVerify { - private static final Logger LOGGER = LogManager.getLogger(HapVerify.class); + private static final LogUtils LOGGER = new LogUtils(HapVerify.class); private static final DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @@ -154,8 +153,8 @@ public class HapVerify { } X509CRLEntry entry = crl.getRevokedCertificate(cert); if (entry != null) { - LOGGER.info("cert(subject DN = {}) is revoked by crl (IssuerDN = {})", - cert.getSubjectDN().getName(), crl.getIssuerDN().getName()); + LOGGER.info("cert(subject DN = " + cert.getSubjectDN().getName() + + ") is revoked by crl (IssuerDN = " + crl.getIssuerDN().getName() + ")"); isRet = false; break; } @@ -289,7 +288,8 @@ public class HapVerify { } if (isPrintCert) { for (int i = 0; i < certificateList.size(); i++) { - LOGGER.info("+++++++++++++++++++++++++++certificate #{} +++++++++++++++++++++++++++++++", i); + LOGGER.info("+++++++++++++++++++++++++++certificate #" + + i + "+++++++++++++++++++++++++++++++"); printCert(certificateList.get(i)); } } @@ -356,7 +356,7 @@ public class HapVerify { */ int signBlockVersion = digestDatas.getInt(); int signBlockCount = digestDatas.getInt(); - LOGGER.info("version is: {}, number of block is: {}", signBlockVersion, signBlockCount); + LOGGER.info("version is: " + signBlockVersion + " , number of block is: {}" + signBlockCount); int digestBlockLen = digestDatas.getInt(); int signatureAlgId = digestDatas.getInt(); int digestDataLen = digestDatas.getInt(); @@ -384,12 +384,13 @@ public class HapVerify { if (!Arrays.equals(actualDigest, exceptDigest)) { isResult = false; LOGGER.error( - "digest data do not match! DigestAlgorithm: {}, actualDigest: <{}> VS exceptDigest : <{}>", - digestAlg.getDigestAlgorithm(), - HapUtils.toHex(actualDigest, ""), - HapUtils.toHex(exceptDigest, "")); + "digest data do not match! DigestAlgorithm: " + + digestAlg.getDigestAlgorithm() + ", actualDigest: <" + + HapUtils.toHex(actualDigest, "") + + "> VS exceptDigest : <" + HapUtils.toHex(exceptDigest, "") +">"); } - LOGGER.info("Digest verify result: {}, DigestAlgorithm: {}", isResult, digestAlg.getDigestAlgorithm()); + LOGGER.info("Digest verify result: " + isResult + + ", DigestAlgorithm: " + digestAlg.getDigestAlgorithm()); } return isResult; } @@ -397,15 +398,16 @@ public class HapVerify { private void printCert(X509Certificate cert) throws CertificateEncodingException { byte[] encodedCert = cert.getEncoded(); - LOGGER.info("Subject: {}", cert.getSubjectX500Principal()); - LOGGER.info("Issuer: {}", cert.getIssuerX500Principal()); - LOGGER.info("SerialNumber: {}", cert.getSerialNumber().toString(16)); - LOGGER.info("Validity: {} ~ {}", formatDateTime(cert.getNotBefore()), formatDateTime(cert.getNotAfter())); - LOGGER.info("SHA256: {}", HapUtils.toHex(DigestUtils.sha256Digest(encodedCert), ":")); - LOGGER.info("Signature Algorithm: {}", cert.getSigAlgName()); + LOGGER.info("Subject: " + cert.getSubjectX500Principal()); + LOGGER.info("Issuer: " + cert.getIssuerX500Principal()); + LOGGER.info("SerialNumber: " + cert.getSerialNumber().toString(16)); + LOGGER.info("Validity: " + formatDateTime(cert.getNotBefore()) + + " ~ " + formatDateTime(cert.getNotAfter())); + LOGGER.info("SHA256: " + HapUtils.toHex(DigestUtils.sha256Digest(encodedCert), ":")); + LOGGER.info("Signature Algorithm: " + cert.getSigAlgName()); PublicKey publicKey = cert.getPublicKey(); - LOGGER.info("Key: {}, key length: {} bits", publicKey.getAlgorithm(), getKeySize(publicKey)); - LOGGER.info("Cert Version: V{}", cert.getVersion()); + LOGGER.info("Key: " + publicKey.getAlgorithm() + ", key length: {} bits" + getKeySize(publicKey)); + LOGGER.info("Cert Version: V" + cert.getVersion()); } private int getKeySize(PublicKey publicKey) { diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/VerifyAndParseProvision.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/VerifyAndParseProvision.java index 0ffed2bf..b6fe5d7d 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/VerifyAndParseProvision.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/VerifyAndParseProvision.java @@ -16,8 +16,8 @@ package com.ohos.hapsigntool.hap.verify; import com.ohos.hapsigntool.utils.FileUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; + +import com.ohos.hapsigntool.utils.LogUtils; import org.bouncycastle.cms.CMSException; import org.bouncycastle.cms.CMSSignedData; @@ -32,7 +32,7 @@ import java.security.SignatureException; * @since 2021/12/21 */ public class VerifyAndParseProvision { - private static final Logger LOGGER = LogManager.getLogger(VerifyAndParseProvision.class); + private static final LogUtils LOGGER = new LogUtils(VerifyAndParseProvision.class); /** * verify signatures of provision and output unsigned provision diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/VerifyElf.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/VerifyElf.java index 9d8c6177..7894528b 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/VerifyElf.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/VerifyElf.java @@ -28,10 +28,9 @@ import com.ohos.hapsigntool.error.ProfileException; import com.ohos.hapsigntool.hap.sign.SignElf; import com.ohos.hapsigntool.utils.FileUtils; import com.ohos.hapsigntool.entity.ParamConstants; +import com.ohos.hapsigntool.utils.LogUtils; import com.ohos.hapsigntool.utils.StringUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.bouncycastle.cms.CMSException; import org.bouncycastle.cms.CMSSignedData; import org.bouncycastle.jce.provider.BouncyCastleProvider; @@ -58,7 +57,7 @@ import java.util.Map; * @since 2023/11/23 */ public class VerifyElf { - private static final Logger LOGGER = LogManager.getLogger(VerifyElf.class); + private static final LogUtils LOGGER = new LogUtils(VerifyElf.class); static { Security.addProvider(new BouncyCastleProvider()); @@ -89,15 +88,15 @@ public class VerifyElf { */ public boolean checkParams(Options options) { if (!options.containsKey(ParamConstants.PARAM_VERIFY_CERTCHAIN_FILE)) { - LOGGER.error("Missing parameter: {}", ParamConstants.PARAM_VERIFY_CERTCHAIN_FILE); + LOGGER.error("Missing parameter: " + ParamConstants.PARAM_VERIFY_CERTCHAIN_FILE); return false; } if (!options.containsKey(ParamConstants.PARAM_VERIFY_PROFILE_FILE)) { - LOGGER.error("Missing parameter: {}", ParamConstants.PARAM_VERIFY_PROFILE_FILE); + LOGGER.error("Missing parameter: " + ParamConstants.PARAM_VERIFY_PROFILE_FILE); return false; } if (!options.containsKey(ParamConstants.PARAM_VERIFY_PROOF_FILE)) { - LOGGER.warn("Missing parameter: {}", ParamConstants.PARAM_VERIFY_PROOF_FILE); + LOGGER.warn("Missing parameter: " + ParamConstants.PARAM_VERIFY_PROOF_FILE); } return true; } @@ -127,7 +126,7 @@ public class VerifyElf { } verifyResult = verifyElf(filePath); if (!verifyResult.isVerified()) { - LOGGER.error("verify: {}", verifyResult.getMessage()); + LOGGER.error("verify: " + verifyResult.getMessage()); throw new IOException(); } String outputCertPath = options.getString(ParamConstants.PARAM_VERIFY_CERTCHAIN_FILE); @@ -147,7 +146,7 @@ public class VerifyElf { return false; } - LOGGER.info("verify: {}", verifyResult.getMessage()); + LOGGER.info("verify: " + verifyResult.getMessage()); return true; } diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/VerifyHap.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/VerifyHap.java index 7affc004..689cc8e1 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/VerifyHap.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/VerifyHap.java @@ -27,6 +27,7 @@ import com.ohos.hapsigntool.error.SignatureNotFoundException; import com.ohos.hapsigntool.utils.FileUtils; import com.ohos.hapsigntool.hap.utils.HapUtils; import com.ohos.hapsigntool.entity.ParamConstants; +import com.ohos.hapsigntool.utils.LogUtils; import com.ohos.hapsigntool.utils.StringUtils; import com.ohos.hapsigntool.zip.ByteBufferZipDataInput; import com.ohos.hapsigntool.zip.RandomAccessFileZipDataInput; @@ -35,8 +36,6 @@ import com.ohos.hapsigntool.zip.ZipDataInput; import com.ohos.hapsigntool.zip.ZipFileInfo; import com.ohos.hapsigntool.zip.ZipUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.bouncycastle.cms.CMSException; import org.bouncycastle.cms.CMSSignedData; import org.bouncycastle.jce.provider.BouncyCastleProvider; @@ -67,7 +66,7 @@ import java.util.stream.Collectors; * @since 2021/12/23 */ public class VerifyHap { - private static final Logger LOGGER = LogManager.getLogger(VerifyHap.class); + private static final LogUtils LOGGER = new LogUtils(VerifyHap.class); private static final int ZIP_HEAD_OF_SIGNING_BLOCK_LENGTH = 32; private static final int ZIP_HEAD_OF_SIGNING_BLOCK_COUNT_OFFSET_REVERSE = 28; private static final int ZIP_HEAD_OF_SUBSIGNING_BLOCK_LENGTH = 12; @@ -111,15 +110,15 @@ public class VerifyHap { */ public boolean checkParams(Options options) { if (!options.containsKey(ParamConstants.PARAM_VERIFY_CERTCHAIN_FILE)) { - LOGGER.error("Missing parameter: {}", ParamConstants.PARAM_VERIFY_CERTCHAIN_FILE); + LOGGER.error("Missing parameter: " + ParamConstants.PARAM_VERIFY_CERTCHAIN_FILE); return false; } if (!options.containsKey(ParamConstants.PARAM_VERIFY_PROFILE_FILE)) { - LOGGER.error("Missing parameter: {}", ParamConstants.PARAM_VERIFY_PROFILE_FILE); + LOGGER.error("Missing parameter: " + ParamConstants.PARAM_VERIFY_PROFILE_FILE); return false; } if (!options.containsKey(ParamConstants.PARAM_VERIFY_PROOF_FILE)) { - LOGGER.warn("Missing parameter: {}", ParamConstants.PARAM_VERIFY_PROOF_FILE); + LOGGER.warn("Missing parameter: " + ParamConstants.PARAM_VERIFY_PROOF_FILE); } return true; } @@ -149,7 +148,7 @@ public class VerifyHap { } verifyResult = verifyHap(filePath); if (!verifyResult.isVerified()) { - LOGGER.error("verify: {}", verifyResult.getMessage()); + LOGGER.error("verify: " + verifyResult.getMessage()); throw new IOException(); } String outputCertPath = options.getString(ParamConstants.PARAM_VERIFY_CERTCHAIN_FILE); @@ -171,7 +170,7 @@ public class VerifyHap { return false; } - LOGGER.info("verify: {}", verifyResult.getMessage()); + LOGGER.info("verify: "+ verifyResult.getMessage()); return true; } diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/profile/ProfileSignTool.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/profile/ProfileSignTool.java index a7803983..a9b28a5a 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/profile/ProfileSignTool.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/profile/ProfileSignTool.java @@ -22,9 +22,9 @@ import com.ohos.hapsigntool.error.VerifyException; import com.ohos.hapsigntool.profile.model.VerificationResult; import com.ohos.hapsigntool.signer.ISigner; import com.ohos.hapsigntool.signer.SignerFactory; +import com.ohos.hapsigntool.utils.LogUtils; import com.ohos.hapsigntool.utils.ValidateUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; + import org.bouncycastle.asn1.ASN1EncodableVector; import org.bouncycastle.asn1.ASN1Set; import org.bouncycastle.asn1.BERSet; @@ -73,7 +73,7 @@ public final class ProfileSignTool { /** * logger */ - private static final Logger LOGGER = LogManager.getLogger(ProfileSignTool.class); + private static final LogUtils LOGGER = new LogUtils(ProfileSignTool.class); private ProfileSignTool() { } diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/profile/VerifyHelper.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/profile/VerifyHelper.java index ab36eefe..19efcc7a 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/profile/VerifyHelper.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/profile/VerifyHelper.java @@ -24,9 +24,9 @@ import com.ohos.hapsigntool.profile.model.VerificationResult; import com.ohos.hapsigntool.utils.CertChainUtils; import com.ohos.hapsigntool.utils.CertUtils; import com.ohos.hapsigntool.utils.FileUtils; +import com.ohos.hapsigntool.utils.LogUtils; import com.ohos.hapsigntool.utils.ValidateUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; + import org.bouncycastle.asn1.ASN1Encodable; import org.bouncycastle.asn1.ASN1Set; import org.bouncycastle.asn1.cms.Attribute; @@ -67,7 +67,7 @@ public class VerifyHelper implements IProvisionVerifier { /** * LOGGER. */ - private static final Logger LOGGER = LogManager.getLogger(VerifyHelper.class); + private static final LogUtils LOGGER = new LogUtils(VerifyHelper.class); /** * Signed provision profile verifier. diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/signer/LocalSigner.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/signer/LocalSigner.java index d71d7748..d6f5ed93 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/signer/LocalSigner.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/signer/LocalSigner.java @@ -17,8 +17,7 @@ package com.ohos.hapsigntool.signer; import com.ohos.hapsigntool.error.CustomException; import com.ohos.hapsigntool.error.ERROR; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import com.ohos.hapsigntool.utils.LogUtils; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; @@ -41,7 +40,7 @@ public class LocalSigner implements ISigner { /** * logger of LocalSigner */ - private static final Logger logger = LogManager.getLogger(LocalSigner.class); + private static final LogUtils logger = new LogUtils(LocalSigner.class); /** * PrivateKey. diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/signer/SignerFactory.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/signer/SignerFactory.java index 22e6c4a6..36d36a5c 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/signer/SignerFactory.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/signer/SignerFactory.java @@ -18,11 +18,9 @@ package com.ohos.hapsigntool.signer; import com.ohos.hapsigntool.adapter.LocalizationAdapter; import com.ohos.hapsigntool.error.CustomException; import com.ohos.hapsigntool.error.ERROR; +import com.ohos.hapsigntool.utils.LogUtils; import com.ohos.hapsigntool.utils.StringUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -46,7 +44,7 @@ import java.util.Properties; * @since 2021/12/28 */ public class SignerFactory { - private static final Logger LOGGER = LogManager.getLogger(SignerFactory.class); + private static final LogUtils LOGGER = new LogUtils(SignerFactory.class); private static final Map SIGNER_LOADERS = new HashMap<>(); @@ -83,7 +81,7 @@ public class SignerFactory { plugin = new File(classLocation, signerPlugin); } if (!plugin.exists() || !plugin.isFile()) { - LOGGER.warn("can not find signerPlugin or not a file by param signerPlugin = {}", signerPlugin); + LOGGER.warn("can not find signerPlugin or not a file by param signerPlugin = " + signerPlugin); return Optional.empty(); } Optional url = fileToUrl(plugin); @@ -94,14 +92,14 @@ public class SignerFactory { ClassLoader classLoader = generateSignerClassLoader(url.get()); try (InputStream inputStream = classLoader.getResourceAsStream("signer.properties")) { if (inputStream == null) { - LOGGER.warn("can not find entry signer.properties in {}", plugin); + LOGGER.warn("can not find entry signer.properties in " + plugin); return Optional.empty(); } Properties properties = new Properties(); properties.load(inputStream); String implClassName = properties.getProperty(ISigner.class.getName()); if (StringUtils.isEmpty(implClassName)) { - LOGGER.warn("can not find {} in signer.properties", ISigner.class.getName()); + LOGGER.warn("can not find " + ISigner.class.getName() + " in signer.properties"); return Optional.empty(); } Class implClass = classLoader.loadClass(implClassName); @@ -113,20 +111,20 @@ public class SignerFactory { } } catch (IOException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) { - LOGGER.warn("load remote signer from {} failed, msg: {}", signerPlugin, e.getMessage()); + LOGGER.warn("load remote signer from " + signerPlugin + " failed, msg: " + e.getMessage()); } return Optional.empty(); } private Optional fileToUrl(File file) { if (!file.exists()) { - LOGGER.warn("{} is not exists", file); + LOGGER.warn(file + " is not exists"); return Optional.empty(); } try { return Optional.of(file.toURI().toURL()); } catch (MalformedURLException e) { - LOGGER.warn("{} can not convert to valid url, msg: {}", file, e.getMessage()); + LOGGER.warn(file + " can not convert to valid url, msg: " + e.getMessage()); } return Optional.empty(); } @@ -139,7 +137,7 @@ public class SignerFactory { try { jarPath = URLDecoder.decode(URLEncoder.encode(jarPath, "utf-8"), "utf-8"); } catch (UnsupportedEncodingException | IllegalArgumentException e) { - LOGGER.warn("decode class location failed, will ignored. msg :{}", e.getMessage()); + LOGGER.warn("decode class location failed, will ignored. msg :" + e.getMessage()); } File jarFile = new File(jarPath); if (!jarFile.exists()) { diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/CertChainUtils.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/CertChainUtils.java index f6c658da..fe8e8ece 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/CertChainUtils.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/CertChainUtils.java @@ -18,8 +18,6 @@ package com.ohos.hapsigntool.utils; import com.ohos.hapsigntool.error.CustomException; import com.ohos.hapsigntool.error.ERROR; import com.ohos.hapsigntool.error.VerifyException; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import javax.security.auth.x500.X500Principal; import java.io.IOException; diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/CertUtils.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/CertUtils.java index 313c4741..83410b1c 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/CertUtils.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/CertUtils.java @@ -18,8 +18,7 @@ package com.ohos.hapsigntool.utils; import com.ohos.hapsigntool.error.CustomException; import com.ohos.hapsigntool.error.ERROR; import com.ohos.hapsigntool.error.VerifyCertificateChainException; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; + import org.bouncycastle.asn1.x500.X500Name; import org.bouncycastle.asn1.x509.KeyPurposeId; import org.bouncycastle.asn1.x509.KeyUsage; @@ -56,7 +55,7 @@ public final class CertUtils { /** * Logger. */ - private static final Logger LOGGER = LogManager.getLogger(CertUtils.class); + private static final LogUtils LOGGER = new LogUtils(CertUtils.class); /** * Max length to print certificate string. diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/DigestUtils.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/DigestUtils.java index 51945298..786d4bba 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/DigestUtils.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/DigestUtils.java @@ -15,9 +15,6 @@ package com.ohos.hapsigntool.utils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - import java.io.ByteArrayInputStream; import java.io.UnsupportedEncodingException; import java.security.MessageDigest; @@ -37,7 +34,7 @@ import java.util.Base64; * @since 2021-12-13 */ public class DigestUtils { - private static final Logger LOGGER = LogManager.getLogger(DigestUtils.class); + private static final LogUtils LOGGER = new LogUtils(DigestUtils.class); /** * Constructor of Method diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/FileUtils.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/FileUtils.java index bb7d713a..3a4a5409 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/FileUtils.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/FileUtils.java @@ -20,9 +20,6 @@ import com.google.gson.GsonBuilder; import com.ohos.hapsigntool.error.CustomException; import com.ohos.hapsigntool.error.ERROR; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - import java.io.BufferedWriter; import java.io.ByteArrayOutputStream; import java.io.Closeable; @@ -47,7 +44,7 @@ public final class FileUtils { /** * LOGGER. */ - private static final Logger LOGGER = LogManager.getLogger(FileUtils.class); + private static final LogUtils LOGGER = new LogUtils(FileUtils.class); /** * add GSON static. @@ -499,7 +496,7 @@ public final class FileUtils { try { Files.delete(file.toPath()); } catch (IOException e) { - LOGGER.warn("delete file '{}' error, error message: {}", file, e.getMessage()); + LOGGER.warn("delete file '" + file + "' error, error message: " + e.getMessage()); } } } diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/HashUtils.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/HashUtils.java index 2874bf1b..51b39b35 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/HashUtils.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/HashUtils.java @@ -15,9 +15,6 @@ package com.ohos.hapsigntool.utils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; @@ -34,7 +31,7 @@ import java.util.Map; * @since 2021/12/21 */ public class HashUtils { - private static final Logger LOGGER = LogManager.getLogger(HashUtils.class); + private static final LogUtils LOGGER = new LogUtils(HashUtils.class); private static final int HASH_LEN = 4096; private static final Map ALG_METHOD = new HashMap<>(); diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/KeyPairTools.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/KeyPairTools.java index 7fd288ea..7b84b73f 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/KeyPairTools.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/KeyPairTools.java @@ -17,8 +17,7 @@ package com.ohos.hapsigntool.utils; import com.ohos.hapsigntool.error.CustomException; import com.ohos.hapsigntool.error.ERROR; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; + import org.bouncycastle.util.encoders.Base64; import java.security.Key; @@ -81,7 +80,7 @@ public final class KeyPairTools { /** * Logger. */ - private static final Logger LOGGER = LogManager.getLogger(KeyPairTools.class); + private static final LogUtils LOGGER = new LogUtils(KeyPairTools.class); private KeyPairTools() {} diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/KeyStoreHelper.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/KeyStoreHelper.java index 3d87ebba..f8ace3fe 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/KeyStoreHelper.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/KeyStoreHelper.java @@ -17,8 +17,7 @@ package com.ohos.hapsigntool.utils; import com.ohos.hapsigntool.error.CustomException; import com.ohos.hapsigntool.error.ERROR; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; + import org.bouncycastle.asn1.x500.X500NameBuilder; import org.bouncycastle.asn1.x500.style.BCStyle; import org.bouncycastle.cert.X509v3CertificateBuilder; @@ -81,7 +80,7 @@ public class KeyStoreHelper { /** * Use LogManager to show log instead of use "System.out.print" to show log. */ - private static final Logger logger = LogManager.getLogger(KeyStoreHelper.class); + private static final LogUtils logger = new LogUtils(KeyStoreHelper.class); /** * Field keyStorePath. @@ -117,7 +116,7 @@ public class KeyStoreHelper { FileInputStream fis = null; try { if (FileUtils.isFileExist(keyStorePath)) { - logger.info("{} is exist. Try to load it with given passwd", keyStorePath); + logger.info(keyStorePath + " is exist. Try to load it with given passwd"); fis = new FileInputStream(keyStorePath); keyStore.load(fis, pwd); } else { diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java new file mode 100644 index 00000000..9666b522 --- /dev/null +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java @@ -0,0 +1,198 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.ohos.hapsigntool.utils; + +import com.ohos.hapsigntool.error.LogConfigException; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.security.CodeSource; +import java.security.ProtectionDomain; +import java.util.HashMap; +import java.util.Map; +import java.util.Properties; +import java.util.logging.ConsoleHandler; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Hap Sign Tool LogUtils + * + * @since 2024/12/08 + */ +public class LogUtils { + private static Logger logger; + private static Level level; + private static final Map LEVEL_MAP = new HashMap<>(); + private static final String DEFAULT_LEVEL = "info"; + + static { + LEVEL_MAP.put(DEFAULT_LEVEL, Level.INFO); + LEVEL_MAP.put("debug", Level.CONFIG); + LEVEL_MAP.put("warn", Level.WARNING); + LEVEL_MAP.put("error", Level.SEVERE); + String configFileName = "log.config"; + + try { + level = LEVEL_MAP.get(getJarConfig(configFileName)); + } catch (LogConfigException e) { + level = LEVEL_MAP.get(getResourceConfig(configFileName)); + } + } + + private static String getJarConfig(String configFileName) throws LogConfigException { + String parent = getString(); + if (parent == null) { + throw new LogConfigException("read jar path failed"); + } + File config = new File(parent, configFileName); + if (!config.exists()) { + throw new LogConfigException("read jar path failed"); + } + try (FileInputStream fis = new FileInputStream(config)) { + return getLevelByInStream(fis); + } catch (IOException e) { + throw new LogConfigException("read jar path failed"); + } + } + + private static String getString() throws LogConfigException { + ProtectionDomain protectionDomain = LogUtils.class.getProtectionDomain(); + if (protectionDomain == null) { + throw new LogConfigException("read jar path failed"); + } + CodeSource codeSource = protectionDomain.getCodeSource(); + if (codeSource == null) { + throw new LogConfigException("read jar path failed"); + } + URL location = codeSource.getLocation(); + if (location == null) { + throw new LogConfigException("read jar path failed"); + } + String jarPath = location.getFile(); + if (jarPath == null) { + throw new LogConfigException("read jar path failed"); + } + return new File(jarPath).getParent(); + } + + private static String getResourceConfig(String configFileName) { + try (InputStream inputStream = LogUtils.class.getClassLoader().getResourceAsStream(configFileName)) { + if (inputStream == null) { + return DEFAULT_LEVEL; + } else { + return getLevelByInStream(inputStream); + } + } catch (IOException e) { + return DEFAULT_LEVEL; + } + } + + private static String getLevelByInStream(InputStream is) throws IOException { + Properties prop = new Properties(); + prop.load(is); + Object levelConfig = prop.get("level"); + if (levelConfig instanceof String) { + return (String) levelConfig; + } + return DEFAULT_LEVEL; + } + + + /** + * format log utils constructor. + * + * @param clazz class + */ + public LogUtils(Class clazz) { + logger = Logger.getLogger(clazz.getName()); + logger.setUseParentHandlers(false); + ConsoleHandler consoleHandler = new ConsoleHandler(); + SignToolFormatter signToolFormatter = new SignToolFormatter(); + consoleHandler.setFormatter(signToolFormatter); + logger.addHandler(consoleHandler); + logger.setLevel(level); + } + + /** + * print info log + * + * @param log log string + */ + public void info(String log) { + logger.info(" INFO - " + log); + } + + /** + * print warn log + * + * @param log log string + */ + public void warn(String log) { + logger.warning(" WARN - " + log); + } + + /** + * print warn log + * + * @param log log string + * @param e throwable + */ + public void warn(String log, Throwable e) { + logger.log(Level.WARNING, e, () -> " DEBUG - " + log); + } + + /** + * print debug log + * + * @param log log string + */ + public void debug(String log) { + logger.config(" DEBUG - " + log); + } + + /** + * print debug log + * + * @param log log string + * @param e throwable + */ + public void debug(String log, Throwable e) { + logger.log(Level.CONFIG, e, () -> " DEBUG - " + log); + } + + /** + * print error log + * + * @param log log string + */ + public void error(String log) { + logger.severe(" ERROR - " + log); + } + + /** + * print error log + * + * @param log log string + * @param e throwable + */ + public void error(String log, Throwable e) { + logger.log(Level.SEVERE, e, () -> " ERROR - " + log); + } +} diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/ParamProcessUtil.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/ParamProcessUtil.java index 875560b1..b62b7ae8 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/ParamProcessUtil.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/ParamProcessUtil.java @@ -17,8 +17,6 @@ package com.ohos.hapsigntool.utils; import com.ohos.hapsigntool.entity.ParamConstants; import com.ohos.hapsigntool.entity.SignatureAlgorithm; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import java.io.File; import java.io.IOException; @@ -33,7 +31,7 @@ import java.util.Set; * @since 2021/12/21 */ public class ParamProcessUtil { - private static final Logger LOGGER = LogManager.getLogger(ParamProcessUtil.class); + private static final LogUtils LOGGER = new LogUtils(ParamProcessUtil.class); private ParamProcessUtil() { } diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/SignToolFormatter.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/SignToolFormatter.java new file mode 100644 index 00000000..6591c7fd --- /dev/null +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/SignToolFormatter.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2024-2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.ohos.hapsigntool.utils; + + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.logging.Formatter; +import java.util.logging.LogRecord; + +/** + * Hap Sign Tool Log Formatter + * + * @since 2024/12/08 + */ +public class SignToolFormatter extends Formatter { + private final static DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS"); + + + /** + * format log. + * + * @param record record + * @return Log Format String + */ + @Override + public String format(LogRecord record) { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder + .append(DATE_FORMAT.format(new Date(record.getMillis()))) + .append(" ") + .append(formatMessage(record)) + .append(System.lineSeparator()); + return stringBuilder.toString(); + } +} diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/zip/Zip.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/zip/Zip.java index ee69e770..5b010636 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/zip/Zip.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/zip/Zip.java @@ -20,8 +20,7 @@ import com.ohos.hapsigntool.error.ERROR; import com.ohos.hapsigntool.error.ZipException; import com.ohos.hapsigntool.utils.FileUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import com.ohos.hapsigntool.utils.LogUtils; import java.io.File; import java.io.FileOutputStream; @@ -38,7 +37,7 @@ import java.util.Optional; * @since 2023/12/02 */ public class Zip { - private static final Logger LOGGER = LogManager.getLogger(Zip.class); + private static final LogUtils LOGGER = new LogUtils(Zip.class); /** * file is uncompress file flag @@ -80,11 +79,11 @@ public class Zip { endOfCentralDirectory = getZipEndOfCentralDirectory(inputFile); cDOffset = endOfCentralDirectory.getOffset(); long eocdEnd = System.currentTimeMillis(); - LOGGER.debug("getZipEndOfCentralDirectory use {} ms", eocdEnd - start); + LOGGER.debug("getZipEndOfCentralDirectory use " + (eocdEnd - start) + "ms"); // 2. use eocd's cd offset, get cd data getZipCentralDirectory(inputFile); long cdEnd = System.currentTimeMillis(); - LOGGER.debug("getZipCentralDirectory use {} ms", cdEnd - start); + LOGGER.debug("getZipCentralDirectory use " + (cdEnd - start) +" ms"); // 3. use cd's entry offset and file size, get entry data getZipEntries(inputFile); ZipEntry endEntry = zipEntries.get(zipEntries.size() - 1); @@ -92,7 +91,7 @@ public class Zip { ZipEntryData endEntryData = endEntry.getZipEntryData(); signingOffset = endCD.getOffset() + endEntryData.getLength(); long entryEnd = System.currentTimeMillis(); - LOGGER.debug("getZipEntries use {} ms", entryEnd - start); + LOGGER.debug("getZipEntries use " + (entryEnd - start) +" ms"); // 4. file all data - eocd - cd - entry = sign block signingBlock = getSigningBlock(inputFile); } catch (IOException e) { diff --git a/hapsigntool/pom.xml b/hapsigntool/pom.xml index bd3ee165..4c6137b7 100644 --- a/hapsigntool/pom.xml +++ b/hapsigntool/pom.xml @@ -14,7 +14,6 @@ 8 UTF-8 4.0 - 2.23.1 5.9.2 @@ -35,16 +34,6 @@ bcpkix-jdk18on 1.78.1 - - org.apache.logging.log4j - log4j-core - ${log4j-version} - - - org.apache.logging.log4j - log4j-api - ${log4j-version} - org.junit.jupiter junit-jupiter-engine -- Gitee From a001de089a88b28aeef5877066029434c4fac136 Mon Sep 17 00:00:00 2001 From: wangzeyu Date: Tue, 10 Dec 2024 11:12:37 +0800 Subject: [PATCH 02/12] remove log4j Signed-off-by: wangzeyu --- hapsigntool/hap_sign_tool/pom.xml | 8 ++++++++ hapsigntool/hap_sign_tool_lib/pom.xml | 8 ++++++++ .../com/ohos/hapsigntool/utils/SignToolFormatter.java | 2 +- hapsigntool/pom.xml | 11 +++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/hapsigntool/hap_sign_tool/pom.xml b/hapsigntool/hap_sign_tool/pom.xml index 53a4466c..b3c7031b 100644 --- a/hapsigntool/hap_sign_tool/pom.xml +++ b/hapsigntool/hap_sign_tool/pom.xml @@ -25,6 +25,14 @@ org.bouncycastle bcpkix-jdk18on + + org.apache.logging.log4j + log4j-core + + + org.apache.logging.log4j + log4j-api + org.junit.jupiter junit-jupiter-engine diff --git a/hapsigntool/hap_sign_tool_lib/pom.xml b/hapsigntool/hap_sign_tool_lib/pom.xml index d8ce6170..5672b662 100644 --- a/hapsigntool/hap_sign_tool_lib/pom.xml +++ b/hapsigntool/hap_sign_tool_lib/pom.xml @@ -20,6 +20,14 @@ org.bouncycastle bcpkix-jdk18on + + org.apache.logging.log4j + log4j-core + + + org.apache.logging.log4j + log4j-api + org.junit.jupiter junit-jupiter-engine diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/SignToolFormatter.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/SignToolFormatter.java index 6591c7fd..8da73a63 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/SignToolFormatter.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/SignToolFormatter.java @@ -28,7 +28,7 @@ import java.util.logging.LogRecord; * @since 2024/12/08 */ public class SignToolFormatter extends Formatter { - private final static DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss.SSS"); + private final static DateFormat DATE_FORMAT = new SimpleDateFormat("MM-dd HH:mm:ss.SSS"); /** diff --git a/hapsigntool/pom.xml b/hapsigntool/pom.xml index 4c6137b7..bd3ee165 100644 --- a/hapsigntool/pom.xml +++ b/hapsigntool/pom.xml @@ -14,6 +14,7 @@ 8 UTF-8 4.0 + 2.23.1 5.9.2 @@ -34,6 +35,16 @@ bcpkix-jdk18on 1.78.1 + + org.apache.logging.log4j + log4j-core + ${log4j-version} + + + org.apache.logging.log4j + log4j-api + ${log4j-version} + org.junit.jupiter junit-jupiter-engine -- Gitee From 827fafb61670c265f3868569f6cd636f6396eff6 Mon Sep 17 00:00:00 2001 From: wangzeyu Date: Wed, 18 Dec 2024 11:24:51 +0800 Subject: [PATCH 03/12] remove log4j Signed-off-by: wangzeyu --- .../main/java/com/ohos/hapsigntool/hap/verify/HapVerify.java | 4 ++-- .../src/main/java/com/ohos/hapsigntool/utils/FileUtils.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/HapVerify.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/HapVerify.java index d3ec26aa..35df2b87 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/HapVerify.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/HapVerify.java @@ -74,7 +74,7 @@ import java.util.Set; public class HapVerify { private static final LogUtils LOGGER = new LogUtils(HapVerify.class); - private static final DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + private static final DateFormat FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private ZipDataInput beforeApkSigningBlock; @@ -429,7 +429,7 @@ public class HapVerify { private String formatDateTime(Date date) { if (date != null) { - return format.format(date); + return FORMAT.format(date); } return ""; } diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/FileUtils.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/FileUtils.java index 3a4a5409..242b4df1 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/FileUtils.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/FileUtils.java @@ -212,7 +212,7 @@ public final class FileUtils { * @throws IOException Write failed */ public static void write(byte[] content, File output) throws IOException { - if (output.exists() && !output.canWrite()) { + if (output.exists() && !output.canWrite()) { CustomException.throwException(ERROR.WRITE_FILE_ERROR, "No permission to write file " + output.getCanonicalPath()); } -- Gitee From f7fda7ea5d4b7b82ce273e66e2b09072072ba88b Mon Sep 17 00:00:00 2001 From: wangzeyu Date: Wed, 18 Dec 2024 17:24:43 +0800 Subject: [PATCH 04/12] remove log4j Signed-off-by: wangzeyu --- .../main/java/com/ohos/hapsigntool/hap/verify/HapVerify.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/HapVerify.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/HapVerify.java index 35df2b87..47109d44 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/HapVerify.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/HapVerify.java @@ -356,7 +356,7 @@ public class HapVerify { */ int signBlockVersion = digestDatas.getInt(); int signBlockCount = digestDatas.getInt(); - LOGGER.info("version is: " + signBlockVersion + " , number of block is: {}" + signBlockCount); + LOGGER.info("version is: " + signBlockVersion + " , number of block is:" + signBlockCount); int digestBlockLen = digestDatas.getInt(); int signatureAlgId = digestDatas.getInt(); int digestDataLen = digestDatas.getInt(); @@ -406,7 +406,7 @@ public class HapVerify { LOGGER.info("SHA256: " + HapUtils.toHex(DigestUtils.sha256Digest(encodedCert), ":")); LOGGER.info("Signature Algorithm: " + cert.getSigAlgName()); PublicKey publicKey = cert.getPublicKey(); - LOGGER.info("Key: " + publicKey.getAlgorithm() + ", key length: {} bits" + getKeySize(publicKey)); + LOGGER.info("Key: " + publicKey.getAlgorithm() + ", key length: " + + getKeySize(publicKey) + " bits" ); LOGGER.info("Cert Version: V" + cert.getVersion()); } -- Gitee From 2f2d463337239c1d6bb652dedcf09e3f77144010 Mon Sep 17 00:00:00 2001 From: wangzeyu Date: Thu, 19 Dec 2024 12:11:09 +0800 Subject: [PATCH 05/12] replace {} str Signed-off-by: wangzeyu --- .../com/ohos/hapsigntool/HapSignTool.java | 2 +- .../codesigning/datastructure/SignInfo.java | 6 +- .../codesigning/sign/CodeSigning.java | 14 +- .../codesigning/sign/PageInfoGenerator.java | 2 +- .../codesigning/sign/VerifyCodeSignature.java | 4 +- .../codesigning/utils/HapUtils.java | 2 +- .../hap/provider/SignProvider.java | 6 +- .../ohos/hapsigntool/hap/utils/HapUtils.java | 2 +- .../hapsigntool/hap/verify/HapVerify.java | 37 ++- .../hapsigntool/hap/verify/VerifyElf.java | 10 +- .../hapsigntool/hap/verify/VerifyHap.java | 10 +- .../hapsigntool/signer/SignerFactory.java | 14 +- .../com/ohos/hapsigntool/utils/FileUtils.java | 2 +- .../hapsigntool/utils/KeyStoreHelper.java | 2 +- .../com/ohos/hapsigntool/utils/LogUtils.java | 257 ++++++++++++++---- .../java/com/ohos/hapsigntool/zip/Zip.java | 6 +- 16 files changed, 256 insertions(+), 120 deletions(-) diff --git a/hapsigntool/hap_sign_tool/src/main/java/com/ohos/hapsigntool/HapSignTool.java b/hapsigntool/hap_sign_tool/src/main/java/com/ohos/hapsigntool/HapSignTool.java index 35889e3f..b7a2f51a 100644 --- a/hapsigntool/hap_sign_tool/src/main/java/com/ohos/hapsigntool/HapSignTool.java +++ b/hapsigntool/hap_sign_tool/src/main/java/com/ohos/hapsigntool/HapSignTool.java @@ -125,7 +125,7 @@ public final class HapSignTool { ServiceApi api = new SignToolServiceImpl(); Params params = CmdUtil.convert2Params(args); LOGGER.debug(params.toString()); - LOGGER.info("Start " + params.getMethod()); + LOGGER.info("Start {}", params.getMethod()); boolean isSuccess = dispatchParams(params, api); if (isSuccess) { LOGGER.info(String.format("%s %s", params.getMethod(), "success")); diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/datastructure/SignInfo.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/datastructure/SignInfo.java index 81960807..d74ae627 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/datastructure/SignInfo.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/datastructure/SignInfo.java @@ -245,8 +245,8 @@ public class SignInfo { bf.get(inSalt); int inExtensionNum = bf.getInt(); if (inExtensionNum < 0 || inExtensionNum > MAX_EXTENSION_NUM) { - LOGGER.info("The signature information may be generated by an new tool, extensionNum " - + inExtensionNum + " of SignInfo"); + LOGGER.info("The signature information may be generated by an new tool, extensionNum {} of SignInfo", + inExtensionNum); } int inExtensionOffset = bf.getInt(); if (inExtensionOffset < 0 || inExtensionOffset % 4 != 0) { @@ -296,7 +296,7 @@ public class SignInfo { bf.get(pageInfoExtension); inExtensionList.add(PageInfoExtension.fromByteArray(pageInfoExtension)); } else { - LOGGER.info("Invalid extensionType " + extensionType + " of SignInfo"); + LOGGER.info("Invalid extensionType {} of SignInfo", extensionType); } } return inExtensionList; diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/sign/CodeSigning.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/sign/CodeSigning.java index 31fe3d35..b73cd5e4 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/sign/CodeSigning.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/sign/CodeSigning.java @@ -273,7 +273,7 @@ public class CodeSigning { if (!hnpTypeMap.containsKey(hnpFileName)) { throw new CodeSignException("hnp should be described in module.json"); } - LOGGER.debug("Sign hnp name = " + entryName); + LOGGER.debug("Sign hnp name = {}", entryName); String type = hnpTypeMap.get(hnpFileName); String hnpOwnerId = ownerID; if ("public".equals(type)) { @@ -294,7 +294,7 @@ public class CodeSigning { } try (JarFile hnp = new JarFile(tempHnp, false)) { List elfEntries = getHnpLibEntries(hnp); - LOGGER.debug(hnp.getName() + " elf num : " + elfEntries.size()); + LOGGER.debug("{} elf num : {}", hnp.getName(), elfEntries.size()); List> nativeLibInfoList = elfEntries.stream().parallel().map(entry -> { String hnpElfPath = hnpEntry.getName() + "!/" + entry.getName(); try (InputStream inputStream = hnp.getInputStream(entry)) { @@ -304,7 +304,7 @@ public class CodeSigning { false, 0, ownerID); return (Pair.create(hnpElfPath, pairSignInfoAndMerkleTreeBytes.getFirst())); } catch (IOException | FsVerityDigestException | CodeSignException e) { - LOGGER.error("Sign hnp lib error, entry name = " + hnpElfPath + ", msg : " + e.getMessage()); + LOGGER.error("Sign hnp lib error, entry name = {}, msg : {}", hnpElfPath, e.getMessage()); } return null; }).collect(Collectors.toList()); @@ -315,9 +315,9 @@ public class CodeSigning { } finally { if (tempHnp.exists()) { if (tempHnp.delete()) { - LOGGER.debug("delete temp hnp file " + tempHnp.getName()); + LOGGER.debug("delete temp hnp file {}", tempHnp.getName()); } else { - LOGGER.error("delete temp hnp file error " + tempHnp.getName()); + LOGGER.error("delete temp hnp file error {}", tempHnp.getName()); } } } @@ -403,7 +403,7 @@ public class CodeSigning { private List> signFilesFromJar(List entryNames, JarFile hap, String ownerID) throws CodeSignException { List> nativeLibInfoList = entryNames.stream().parallel().map(name -> { - LOGGER.debug("Sign entry name = " + name); + LOGGER.debug("Sign entry name = {}", name); JarEntry inEntry = hap.getJarEntry(name); try (InputStream inputStream = hap.getInputStream(inEntry)) { long fileSize = inEntry.getSize(); @@ -413,7 +413,7 @@ public class CodeSigning { ownerID); return Pair.create(name, pairSignInfoAndMerkleTreeBytes.getFirst()); } catch (FsVerityDigestException | CodeSignException | IOException e) { - LOGGER.error("Sign lib error, entry name = " + name + ", msg : " + e.getMessage()); + LOGGER.error("Sign lib error, entry name = {}, msg : {}", name, e.getMessage()); } return null; }).collect(Collectors.toList()); diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/sign/PageInfoGenerator.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/sign/PageInfoGenerator.java index e157e04a..d00b7fee 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/sign/PageInfoGenerator.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/sign/PageInfoGenerator.java @@ -104,7 +104,7 @@ public class PageInfoGenerator { try (InputStream stream = hap.getInputStream(libEntry)) { ElfFile elfFile = new ElfFile(stream); if (!elfFile.isElfFile()) { - LOGGER.info(libFileName + " not ELF file"); + LOGGER.info("{} not ELF file", libFileName); return; } List elfPHeaders = elfFile.filterExecPHeaders(); diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/sign/VerifyCodeSignature.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/sign/VerifyCodeSignature.java index 8e39671b..88701454 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/sign/VerifyCodeSignature.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/sign/VerifyCodeSignature.java @@ -220,7 +220,7 @@ public class VerifyCodeSignature { hnpEntryNames.add(filePath[0]); hnpLibSignInfoMap.put(entryName, signInfo); } else { - LOGGER.info("verify lib: " + entryName); + LOGGER.info("verify lib: {}", entryName); verifyHapLib(inputJar, entryName, signInfo, pairResult); } } @@ -270,7 +270,7 @@ public class VerifyCodeSignature { if (!hnpLibSignInfoMap.containsKey(libPath)) { continue; } - LOGGER.info("verify lib: " + libPath); + LOGGER.info("verify lib: {}", libPath); SignInfo signInfo = hnpLibSignInfoMap.get(libPath); byte[] entrySig = signInfo.getSignature(); long dataSize = signInfo.getDataSize(); diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/utils/HapUtils.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/utils/HapUtils.java index cd13b0b1..08ffbdab 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/utils/HapUtils.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/utils/HapUtils.java @@ -192,7 +192,7 @@ public class HapUtils { LOGGER.error(e.getMessage()); throw new ProfileException("profile json is invalid"); } - LOGGER.info("profile type is: " + profileType); + LOGGER.info("profile type is: {}", profileType); return Pair.create(ownerID, profileType); } diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/provider/SignProvider.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/provider/SignProvider.java index f4b2b42e..add2abdd 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/provider/SignProvider.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/provider/SignProvider.java @@ -485,7 +485,7 @@ public abstract class SignProvider { private void printErrorLogWithoutStack(Exception exception) { if (exception != null) { - LOGGER.error("hap-sign-tool: error: " + exception.getMessage()); + LOGGER.error("hap-sign-tool: error: {}", exception.getMessage()); } } @@ -517,7 +517,7 @@ public abstract class SignProvider { long start = System.currentTimeMillis(); zip.toFile(tmpOutput.getCanonicalPath()); long end = System.currentTimeMillis(); - LOGGER.debug("zip to file use " + (end - start) + " ms"); + LOGGER.debug("zip to file use {} ms", end - start); return zip; } @@ -649,7 +649,7 @@ public abstract class SignProvider { throw new ProfileException("input certificates do not match with profile!"); } String cn = getCertificateCN(certInProfile); - LOGGER.info("certificate in profile: " + cn); + LOGGER.info("certificate in profile: {}", cn); if (cn.isEmpty()) { throw new ProfileException("Common name of certificate is empty!"); } diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/utils/HapUtils.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/utils/HapUtils.java index fe6c495c..759480bd 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/utils/HapUtils.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/utils/HapUtils.java @@ -518,7 +518,7 @@ public class HapUtils { hapSignBlockMagicLo, hapSignBlockMagicHi, version, centralDirectoryStartOffset); ByteBuffer hapSigningBlockByteBuffer = hap.createByteBuffer(hapSigningBlockOffset, (int) hapSigBlockSize) .order(ByteOrder.LITTLE_ENDIAN); - LOGGER.info("Find Hap Signing Block success, version: " + version + ", block count: " + blockCount); + LOGGER.info("Find Hap Signing Block success, version: {}, block count: {}", version, blockCount); return new HapSignBlockInfo(hapSigningBlockOffset, version, hapSigningBlockByteBuffer); } diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/HapVerify.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/HapVerify.java index 47109d44..0ca1d90e 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/HapVerify.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/HapVerify.java @@ -153,8 +153,8 @@ public class HapVerify { } X509CRLEntry entry = crl.getRevokedCertificate(cert); if (entry != null) { - LOGGER.info("cert(subject DN = " + cert.getSubjectDN().getName() + - ") is revoked by crl (IssuerDN = " + crl.getIssuerDN().getName() + ")"); + LOGGER.info("cert(subject DN = {}) is revoked by crl (IssuerDN = {})", + cert.getSubjectDN().getName(), crl.getIssuerDN().getName()); isRet = false; break; } @@ -288,8 +288,7 @@ public class HapVerify { } if (isPrintCert) { for (int i = 0; i < certificateList.size(); i++) { - LOGGER.info("+++++++++++++++++++++++++++certificate #" - + i + "+++++++++++++++++++++++++++++++"); + LOGGER.info("+++++++++++++++++++++++++++certificate #{} +++++++++++++++++++++++++++++++", i); printCert(certificateList.get(i)); } } @@ -356,7 +355,7 @@ public class HapVerify { */ int signBlockVersion = digestDatas.getInt(); int signBlockCount = digestDatas.getInt(); - LOGGER.info("version is: " + signBlockVersion + " , number of block is:" + signBlockCount); + LOGGER.info("version is: {}, number of block is: {}", signBlockVersion, signBlockCount); int digestBlockLen = digestDatas.getInt(); int signatureAlgId = digestDatas.getInt(); int digestDataLen = digestDatas.getInt(); @@ -384,13 +383,12 @@ public class HapVerify { if (!Arrays.equals(actualDigest, exceptDigest)) { isResult = false; LOGGER.error( - "digest data do not match! DigestAlgorithm: " - + digestAlg.getDigestAlgorithm() + ", actualDigest: <" - + HapUtils.toHex(actualDigest, "") - + "> VS exceptDigest : <" + HapUtils.toHex(exceptDigest, "") +">"); + "digest data do not match! DigestAlgorithm: {}, actualDigest: <{}> VS exceptDigest : <{}>", + digestAlg.getDigestAlgorithm(), + HapUtils.toHex(actualDigest, ""), + HapUtils.toHex(exceptDigest, "")); } - LOGGER.info("Digest verify result: " + isResult - + ", DigestAlgorithm: " + digestAlg.getDigestAlgorithm()); + LOGGER.info("Digest verify result: {}, DigestAlgorithm: {}", isResult, digestAlg.getDigestAlgorithm()); } return isResult; } @@ -398,16 +396,15 @@ public class HapVerify { private void printCert(X509Certificate cert) throws CertificateEncodingException { byte[] encodedCert = cert.getEncoded(); - LOGGER.info("Subject: " + cert.getSubjectX500Principal()); - LOGGER.info("Issuer: " + cert.getIssuerX500Principal()); - LOGGER.info("SerialNumber: " + cert.getSerialNumber().toString(16)); - LOGGER.info("Validity: " + formatDateTime(cert.getNotBefore()) - + " ~ " + formatDateTime(cert.getNotAfter())); - LOGGER.info("SHA256: " + HapUtils.toHex(DigestUtils.sha256Digest(encodedCert), ":")); - LOGGER.info("Signature Algorithm: " + cert.getSigAlgName()); + LOGGER.info("Subject: {}", cert.getSubjectX500Principal()); + LOGGER.info("Issuer: {}", cert.getIssuerX500Principal()); + LOGGER.info("SerialNumber: {}", cert.getSerialNumber().toString(16)); + LOGGER.info("Validity: {} ~ {}", formatDateTime(cert.getNotBefore()), formatDateTime(cert.getNotAfter())); + LOGGER.info("SHA256: {}", HapUtils.toHex(DigestUtils.sha256Digest(encodedCert), ":")); + LOGGER.info("Signature Algorithm: {}", cert.getSigAlgName()); PublicKey publicKey = cert.getPublicKey(); - LOGGER.info("Key: " + publicKey.getAlgorithm() + ", key length: " + + getKeySize(publicKey) + " bits" ); - LOGGER.info("Cert Version: V" + cert.getVersion()); + LOGGER.info("Key: {}, key length: {} bits", publicKey.getAlgorithm(), getKeySize(publicKey)); + LOGGER.info("Cert Version: V{}", cert.getVersion()); } private int getKeySize(PublicKey publicKey) { diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/VerifyElf.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/VerifyElf.java index 7894528b..cbcaaa2a 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/VerifyElf.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/VerifyElf.java @@ -88,15 +88,15 @@ public class VerifyElf { */ public boolean checkParams(Options options) { if (!options.containsKey(ParamConstants.PARAM_VERIFY_CERTCHAIN_FILE)) { - LOGGER.error("Missing parameter: " + ParamConstants.PARAM_VERIFY_CERTCHAIN_FILE); + LOGGER.error("Missing parameter: {}", ParamConstants.PARAM_VERIFY_CERTCHAIN_FILE); return false; } if (!options.containsKey(ParamConstants.PARAM_VERIFY_PROFILE_FILE)) { - LOGGER.error("Missing parameter: " + ParamConstants.PARAM_VERIFY_PROFILE_FILE); + LOGGER.error("Missing parameter: {}", ParamConstants.PARAM_VERIFY_PROFILE_FILE); return false; } if (!options.containsKey(ParamConstants.PARAM_VERIFY_PROOF_FILE)) { - LOGGER.warn("Missing parameter: " + ParamConstants.PARAM_VERIFY_PROOF_FILE); + LOGGER.warn("Missing parameter: {}", ParamConstants.PARAM_VERIFY_PROOF_FILE); } return true; } @@ -126,7 +126,7 @@ public class VerifyElf { } verifyResult = verifyElf(filePath); if (!verifyResult.isVerified()) { - LOGGER.error("verify: " + verifyResult.getMessage()); + LOGGER.error("verify: {}", verifyResult.getMessage()); throw new IOException(); } String outputCertPath = options.getString(ParamConstants.PARAM_VERIFY_CERTCHAIN_FILE); @@ -146,7 +146,7 @@ public class VerifyElf { return false; } - LOGGER.info("verify: " + verifyResult.getMessage()); + LOGGER.info("verify: {}", verifyResult.getMessage()); return true; } diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/VerifyHap.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/VerifyHap.java index 689cc8e1..cce11d73 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/VerifyHap.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/verify/VerifyHap.java @@ -110,15 +110,15 @@ public class VerifyHap { */ public boolean checkParams(Options options) { if (!options.containsKey(ParamConstants.PARAM_VERIFY_CERTCHAIN_FILE)) { - LOGGER.error("Missing parameter: " + ParamConstants.PARAM_VERIFY_CERTCHAIN_FILE); + LOGGER.error("Missing parameter: {}", ParamConstants.PARAM_VERIFY_CERTCHAIN_FILE); return false; } if (!options.containsKey(ParamConstants.PARAM_VERIFY_PROFILE_FILE)) { - LOGGER.error("Missing parameter: " + ParamConstants.PARAM_VERIFY_PROFILE_FILE); + LOGGER.error("Missing parameter: {}", ParamConstants.PARAM_VERIFY_PROFILE_FILE); return false; } if (!options.containsKey(ParamConstants.PARAM_VERIFY_PROOF_FILE)) { - LOGGER.warn("Missing parameter: " + ParamConstants.PARAM_VERIFY_PROOF_FILE); + LOGGER.warn("Missing parameter: {}", ParamConstants.PARAM_VERIFY_PROOF_FILE); } return true; } @@ -148,7 +148,7 @@ public class VerifyHap { } verifyResult = verifyHap(filePath); if (!verifyResult.isVerified()) { - LOGGER.error("verify: " + verifyResult.getMessage()); + LOGGER.error("verify: {}", verifyResult.getMessage()); throw new IOException(); } String outputCertPath = options.getString(ParamConstants.PARAM_VERIFY_CERTCHAIN_FILE); @@ -170,7 +170,7 @@ public class VerifyHap { return false; } - LOGGER.info("verify: "+ verifyResult.getMessage()); + LOGGER.info("verify: {}", verifyResult.getMessage()); return true; } diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/signer/SignerFactory.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/signer/SignerFactory.java index 36d36a5c..bd62263d 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/signer/SignerFactory.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/signer/SignerFactory.java @@ -81,7 +81,7 @@ public class SignerFactory { plugin = new File(classLocation, signerPlugin); } if (!plugin.exists() || !plugin.isFile()) { - LOGGER.warn("can not find signerPlugin or not a file by param signerPlugin = " + signerPlugin); + LOGGER.warn("can not find signerPlugin or not a file by param signerPlugin = {}", signerPlugin); return Optional.empty(); } Optional url = fileToUrl(plugin); @@ -92,14 +92,14 @@ public class SignerFactory { ClassLoader classLoader = generateSignerClassLoader(url.get()); try (InputStream inputStream = classLoader.getResourceAsStream("signer.properties")) { if (inputStream == null) { - LOGGER.warn("can not find entry signer.properties in " + plugin); + LOGGER.warn("can not find entry signer.properties in {}", plugin); return Optional.empty(); } Properties properties = new Properties(); properties.load(inputStream); String implClassName = properties.getProperty(ISigner.class.getName()); if (StringUtils.isEmpty(implClassName)) { - LOGGER.warn("can not find " + ISigner.class.getName() + " in signer.properties"); + LOGGER.warn("can not find {} in signer.properties", ISigner.class.getName()); return Optional.empty(); } Class implClass = classLoader.loadClass(implClassName); @@ -111,20 +111,20 @@ public class SignerFactory { } } catch (IOException | ClassNotFoundException | NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) { - LOGGER.warn("load remote signer from " + signerPlugin + " failed, msg: " + e.getMessage()); + LOGGER.warn("load remote signer from {} failed, msg: {}", signerPlugin, e.getMessage()); } return Optional.empty(); } private Optional fileToUrl(File file) { if (!file.exists()) { - LOGGER.warn(file + " is not exists"); + LOGGER.warn("{} is not exists", file); return Optional.empty(); } try { return Optional.of(file.toURI().toURL()); } catch (MalformedURLException e) { - LOGGER.warn(file + " can not convert to valid url, msg: " + e.getMessage()); + LOGGER.warn("{} can not convert to valid url, msg: {}", file, e.getMessage()); } return Optional.empty(); } @@ -137,7 +137,7 @@ public class SignerFactory { try { jarPath = URLDecoder.decode(URLEncoder.encode(jarPath, "utf-8"), "utf-8"); } catch (UnsupportedEncodingException | IllegalArgumentException e) { - LOGGER.warn("decode class location failed, will ignored. msg :" + e.getMessage()); + LOGGER.warn("decode class location failed, will ignored. msg :{}", e.getMessage()); } File jarFile = new File(jarPath); if (!jarFile.exists()) { diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/FileUtils.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/FileUtils.java index 242b4df1..ef0d98cb 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/FileUtils.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/FileUtils.java @@ -496,7 +496,7 @@ public final class FileUtils { try { Files.delete(file.toPath()); } catch (IOException e) { - LOGGER.warn("delete file '" + file + "' error, error message: " + e.getMessage()); + LOGGER.warn("delete file '{}' error, error message: {}", file, e.getMessage()); } } } diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/KeyStoreHelper.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/KeyStoreHelper.java index f8ace3fe..ed09baa8 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/KeyStoreHelper.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/KeyStoreHelper.java @@ -116,7 +116,7 @@ public class KeyStoreHelper { FileInputStream fis = null; try { if (FileUtils.isFileExist(keyStorePath)) { - logger.info(keyStorePath + " is exist. Try to load it with given passwd"); + logger.info("{} is exist. Try to load it with given passwd", keyStorePath); fis = new FileInputStream(keyStorePath); keyStore.load(fis, pwd); } else { diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java index 9666b522..a1d12da8 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java @@ -30,6 +30,8 @@ import java.util.Properties; import java.util.logging.ConsoleHandler; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * Hap Sign Tool LogUtils @@ -41,6 +43,7 @@ public class LogUtils { private static Level level; private static final Map LEVEL_MAP = new HashMap<>(); private static final String DEFAULT_LEVEL = "info"; + private static final Pattern PATTERN = Pattern.compile("\\{}"); static { LEVEL_MAP.put(DEFAULT_LEVEL, Level.INFO); @@ -56,65 +59,6 @@ public class LogUtils { } } - private static String getJarConfig(String configFileName) throws LogConfigException { - String parent = getString(); - if (parent == null) { - throw new LogConfigException("read jar path failed"); - } - File config = new File(parent, configFileName); - if (!config.exists()) { - throw new LogConfigException("read jar path failed"); - } - try (FileInputStream fis = new FileInputStream(config)) { - return getLevelByInStream(fis); - } catch (IOException e) { - throw new LogConfigException("read jar path failed"); - } - } - - private static String getString() throws LogConfigException { - ProtectionDomain protectionDomain = LogUtils.class.getProtectionDomain(); - if (protectionDomain == null) { - throw new LogConfigException("read jar path failed"); - } - CodeSource codeSource = protectionDomain.getCodeSource(); - if (codeSource == null) { - throw new LogConfigException("read jar path failed"); - } - URL location = codeSource.getLocation(); - if (location == null) { - throw new LogConfigException("read jar path failed"); - } - String jarPath = location.getFile(); - if (jarPath == null) { - throw new LogConfigException("read jar path failed"); - } - return new File(jarPath).getParent(); - } - - private static String getResourceConfig(String configFileName) { - try (InputStream inputStream = LogUtils.class.getClassLoader().getResourceAsStream(configFileName)) { - if (inputStream == null) { - return DEFAULT_LEVEL; - } else { - return getLevelByInStream(inputStream); - } - } catch (IOException e) { - return DEFAULT_LEVEL; - } - } - - private static String getLevelByInStream(InputStream is) throws IOException { - Properties prop = new Properties(); - prop.load(is); - Object levelConfig = prop.get("level"); - if (levelConfig instanceof String) { - return (String) levelConfig; - } - return DEFAULT_LEVEL; - } - - /** * format log utils constructor. * @@ -139,6 +83,27 @@ public class LogUtils { logger.info(" INFO - " + log); } + /** + * print info log + * + * @param log log string + * @param arg arg + */ + public void info(String log, Object arg) { + logger.info(" INFO - " + replaceArgs(log, arg)); + } + + /** + * print info log + * + * @param log log string + * @param arg1 arg + * @param arg2 arg + */ + public void info(String log, Object arg1, Object arg2) { + logger.info(" INFO - " + replaceArgs(log, arg1, arg2)); + } + /** * print warn log * @@ -148,6 +113,38 @@ public class LogUtils { logger.warning(" WARN - " + log); } + /** + * print warn log + * + * @param log log string + * @param arg arg + */ + public void warn(String log, Object arg) { + logger.warning(" WARN - " + replaceArgs(log, arg)); + } + + /** + * print warn log + * + * @param log log string + * @param arg arg + * @param e throwable + */ + public void warn(String log, Object arg, Throwable e) { + logger.log(Level.WARNING, e, () -> " DEBUG - " + replaceArgs(log, arg)); + } + + /** + * print warn log + * + * @param log log string + * @param arg1 arg + * @param arg2 arg + */ + public void warn(String log, Object arg1, Object arg2) { + logger.warning(" WARN - " + replaceArgs(log, arg1, arg2)); + } + /** * print warn log * @@ -167,6 +164,17 @@ public class LogUtils { logger.config(" DEBUG - " + log); } + /** + * print debug log + * + * @param log log string + * @param arg1 arg + * @param arg2 arg + */ + public void debug(String log, Object arg1, Object arg2) { + logger.warning(" WARN - " + replaceArgs(log, arg1, arg2)); + } + /** * print debug log * @@ -177,6 +185,16 @@ public class LogUtils { logger.log(Level.CONFIG, e, () -> " DEBUG - " + log); } + /** + * print debug log + * + * @param log log string + * @param arg arg + */ + public void debug(String log, Object arg) { + logger.config(" DEBUG - " + replaceArgs(log, arg)); + } + /** * print error log * @@ -195,4 +213,125 @@ public class LogUtils { public void error(String log, Throwable e) { logger.log(Level.SEVERE, e, () -> " ERROR - " + log); } + + /** + * print error log + * + * @param log log string + * @param arg arg + * @param e throwable + */ + public void error(String log, Object arg, Throwable e) { + logger.log(Level.SEVERE, e, () -> " ERROR - " + replaceArgs(log, arg)); + } + + /** + * print error log + * + * @param log log string + * @param arg arg + */ + public void error(String log, Object arg) { + logger.severe(" ERROR - " + replaceArgs(log, arg)); + } + + /** + * print error log + * + * @param log log string + * @param arg1 arg + * @param arg2 arg + */ + public void error(String log, Object arg1, Object arg2) { + logger.severe(" ERROR - " + replaceArgs(log, arg1, arg2)); + } + + /** + * print error log + * + * @param log log string + * @param arg1 arg + * @param arg2 arg + * @param arg3 arg + */ + public void error(String log, Object arg1, Object arg2, Object arg3) { + logger.severe(" ERROR - " + replaceArgs(log, arg1, arg2, arg3)); + } + + public static void main(String[] args) { + new LogUtils(LogUtils.class).error("aaa {} bbb {} {}", "a", "b", "c"); + } + + private static String replaceArgs(String line, Object... args) { + + Matcher matcher = PATTERN.matcher(line); + String result = line; + if (!matcher.find()) { + return line; + } + for (Object arg : args) { + Matcher m = PATTERN.matcher(result); + result = m.replaceFirst(arg.toString()); + } + return result; + } + + private static String getJarConfig(String configFileName) throws LogConfigException { + String parent = getString(); + if (parent == null) { + throw new LogConfigException("read jar path failed"); + } + File config = new File(parent, configFileName); + if (!config.exists()) { + throw new LogConfigException("read jar path failed"); + } + try (FileInputStream fis = new FileInputStream(config)) { + return getLevelByInStream(fis); + } catch (IOException e) { + throw new LogConfigException("read jar path failed"); + } + } + + private static String getString() throws LogConfigException { + ProtectionDomain protectionDomain = LogUtils.class.getProtectionDomain(); + if (protectionDomain == null) { + throw new LogConfigException("read jar path failed"); + } + CodeSource codeSource = protectionDomain.getCodeSource(); + if (codeSource == null) { + throw new LogConfigException("read jar path failed"); + } + URL location = codeSource.getLocation(); + if (location == null) { + throw new LogConfigException("read jar path failed"); + } + String jarPath = location.getFile(); + if (jarPath == null) { + throw new LogConfigException("read jar path failed"); + } + return new File(jarPath).getParent(); + } + + private static String getResourceConfig(String configFileName) { + try (InputStream inputStream = LogUtils.class.getClassLoader().getResourceAsStream(configFileName)) { + if (inputStream == null) { + return DEFAULT_LEVEL; + } else { + return getLevelByInStream(inputStream); + } + } catch (IOException e) { + return DEFAULT_LEVEL; + } + } + + private static String getLevelByInStream(InputStream is) throws IOException { + Properties prop = new Properties(); + prop.load(is); + Object levelConfig = prop.get("level"); + if (levelConfig instanceof String) { + return (String) levelConfig; + } + return DEFAULT_LEVEL; + } + } diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/zip/Zip.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/zip/Zip.java index 5b010636..276842bf 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/zip/Zip.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/zip/Zip.java @@ -79,11 +79,11 @@ public class Zip { endOfCentralDirectory = getZipEndOfCentralDirectory(inputFile); cDOffset = endOfCentralDirectory.getOffset(); long eocdEnd = System.currentTimeMillis(); - LOGGER.debug("getZipEndOfCentralDirectory use " + (eocdEnd - start) + "ms"); + LOGGER.debug("getZipEndOfCentralDirectory use {} ms", eocdEnd - start); // 2. use eocd's cd offset, get cd data getZipCentralDirectory(inputFile); long cdEnd = System.currentTimeMillis(); - LOGGER.debug("getZipCentralDirectory use " + (cdEnd - start) +" ms"); + LOGGER.debug("getZipCentralDirectory use {} ms", cdEnd - start); // 3. use cd's entry offset and file size, get entry data getZipEntries(inputFile); ZipEntry endEntry = zipEntries.get(zipEntries.size() - 1); @@ -91,7 +91,7 @@ public class Zip { ZipEntryData endEntryData = endEntry.getZipEntryData(); signingOffset = endCD.getOffset() + endEntryData.getLength(); long entryEnd = System.currentTimeMillis(); - LOGGER.debug("getZipEntries use " + (entryEnd - start) +" ms"); + LOGGER.debug("getZipEntries use {} ms", entryEnd - start); // 4. file all data - eocd - cd - entry = sign block signingBlock = getSigningBlock(inputFile); } catch (IOException e) { -- Gitee From 13b0a1233bada992e1e030c511a278d83cc8bd95 Mon Sep 17 00:00:00 2001 From: wangzeyu Date: Thu, 19 Dec 2024 12:14:47 +0800 Subject: [PATCH 06/12] replace {} str Signed-off-by: wangzeyu --- .../ohos/hapsigntool/codesigning/datastructure/SignInfo.java | 2 +- .../java/com/ohos/hapsigntool/hap/provider/SignProvider.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/datastructure/SignInfo.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/datastructure/SignInfo.java index d74ae627..0763cc05 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/datastructure/SignInfo.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/codesigning/datastructure/SignInfo.java @@ -246,7 +246,7 @@ public class SignInfo { int inExtensionNum = bf.getInt(); if (inExtensionNum < 0 || inExtensionNum > MAX_EXTENSION_NUM) { LOGGER.info("The signature information may be generated by an new tool, extensionNum {} of SignInfo", - inExtensionNum); + inExtensionNum); } int inExtensionOffset = bf.getInt(); if (inExtensionOffset < 0 || inExtensionOffset % 4 != 0) { diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/provider/SignProvider.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/provider/SignProvider.java index add2abdd..2193f385 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/provider/SignProvider.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/hap/provider/SignProvider.java @@ -479,7 +479,7 @@ public abstract class SignProvider { private void printErrorLog(Exception exception) { if (exception != null) { - LOGGER.error("hap-sign-tool: error: " + exception.getMessage(), exception); + LOGGER.error("hap-sign-tool: error: {}", exception.getMessage(), exception); } } -- Gitee From e3ff9fb97bc7c61439874481397135d341d7cfcf Mon Sep 17 00:00:00 2001 From: wangzeyu Date: Thu, 19 Dec 2024 15:35:02 +0800 Subject: [PATCH 07/12] replace {} str Signed-off-by: wangzeyu --- .../src/main/java/com/ohos/hapsigntool/utils/LogUtils.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java index a1d12da8..8921a1bd 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java @@ -258,10 +258,6 @@ public class LogUtils { logger.severe(" ERROR - " + replaceArgs(log, arg1, arg2, arg3)); } - public static void main(String[] args) { - new LogUtils(LogUtils.class).error("aaa {} bbb {} {}", "a", "b", "c"); - } - private static String replaceArgs(String line, Object... args) { Matcher matcher = PATTERN.matcher(line); -- Gitee From 062c891b990fed0eac8a33805c817671618b6539 Mon Sep 17 00:00:00 2001 From: wangzeyu Date: Thu, 19 Dec 2024 17:04:34 +0800 Subject: [PATCH 08/12] replace {} str Signed-off-by: wangzeyu --- .../src/main/java/com/ohos/hapsigntool/utils/LogUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java index 8921a1bd..c8a93c3e 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java @@ -267,7 +267,7 @@ public class LogUtils { } for (Object arg : args) { Matcher m = PATTERN.matcher(result); - result = m.replaceFirst(arg.toString()); + result = m.replaceFirst(String.valueOf(arg)); } return result; } -- Gitee From 435c574d1c2c327948f4198c445299066975a6ce Mon Sep 17 00:00:00 2001 From: wangzeyu Date: Fri, 20 Dec 2024 10:04:53 +0800 Subject: [PATCH 09/12] replace {} str Signed-off-by: wangzeyu --- .../java/com/ohos/hapsigntool/utils/LogUtils.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java index c8a93c3e..60269f65 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java @@ -55,7 +55,7 @@ public class LogUtils { try { level = LEVEL_MAP.get(getJarConfig(configFileName)); } catch (LogConfigException e) { - level = LEVEL_MAP.get(getResourceConfig(configFileName)); + level = LEVEL_MAP.get(getDefaultLogLevel(configFileName)); } } @@ -273,7 +273,7 @@ public class LogUtils { } private static String getJarConfig(String configFileName) throws LogConfigException { - String parent = getString(); + String parent = getJarDirectory(); if (parent == null) { throw new LogConfigException("read jar path failed"); } @@ -282,13 +282,13 @@ public class LogUtils { throw new LogConfigException("read jar path failed"); } try (FileInputStream fis = new FileInputStream(config)) { - return getLevelByInStream(fis); + return getLogLevel(fis); } catch (IOException e) { throw new LogConfigException("read jar path failed"); } } - private static String getString() throws LogConfigException { + private static String getJarDirectory() throws LogConfigException { ProtectionDomain protectionDomain = LogUtils.class.getProtectionDomain(); if (protectionDomain == null) { throw new LogConfigException("read jar path failed"); @@ -308,19 +308,19 @@ public class LogUtils { return new File(jarPath).getParent(); } - private static String getResourceConfig(String configFileName) { + private static String getDefaultLogLevel(String configFileName) { try (InputStream inputStream = LogUtils.class.getClassLoader().getResourceAsStream(configFileName)) { if (inputStream == null) { return DEFAULT_LEVEL; } else { - return getLevelByInStream(inputStream); + return getLogLevel(inputStream); } } catch (IOException e) { return DEFAULT_LEVEL; } } - private static String getLevelByInStream(InputStream is) throws IOException { + private static String getLogLevel(InputStream is) throws IOException { Properties prop = new Properties(); prop.load(is); Object levelConfig = prop.get("level"); -- Gitee From e9add71d8afe6aeecc692b54f56d803baac8c944 Mon Sep 17 00:00:00 2001 From: wangzeyu Date: Fri, 20 Dec 2024 10:08:31 +0800 Subject: [PATCH 10/12] replace {} str Signed-off-by: wangzeyu --- .../utils/{SignToolFormatter.java => LogFormatter.java} | 2 +- .../src/main/java/com/ohos/hapsigntool/utils/LogUtils.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/{SignToolFormatter.java => LogFormatter.java} (96%) diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/SignToolFormatter.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogFormatter.java similarity index 96% rename from hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/SignToolFormatter.java rename to hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogFormatter.java index 8da73a63..344a730d 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/SignToolFormatter.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogFormatter.java @@ -27,7 +27,7 @@ import java.util.logging.LogRecord; * * @since 2024/12/08 */ -public class SignToolFormatter extends Formatter { +public class LogFormatter extends Formatter { private final static DateFormat DATE_FORMAT = new SimpleDateFormat("MM-dd HH:mm:ss.SSS"); diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java index 60269f65..1e71ad2c 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java @@ -68,8 +68,8 @@ public class LogUtils { logger = Logger.getLogger(clazz.getName()); logger.setUseParentHandlers(false); ConsoleHandler consoleHandler = new ConsoleHandler(); - SignToolFormatter signToolFormatter = new SignToolFormatter(); - consoleHandler.setFormatter(signToolFormatter); + LogFormatter logFormatter = new LogFormatter(); + consoleHandler.setFormatter(logFormatter); logger.addHandler(consoleHandler); logger.setLevel(level); } -- Gitee From 74e7984eec2520afd09a354b8b741c902877a1d5 Mon Sep 17 00:00:00 2001 From: wangzeyu Date: Fri, 20 Dec 2024 14:46:24 +0800 Subject: [PATCH 11/12] replace {} str Signed-off-by: wangzeyu --- .../java/com/ohos/hapsigntool/utils/LogUtils.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java index 1e71ad2c..d77664fa 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java @@ -275,31 +275,31 @@ public class LogUtils { private static String getJarConfig(String configFileName) throws LogConfigException { String parent = getJarDirectory(); if (parent == null) { - throw new LogConfigException("read jar path failed"); + throw new LogConfigException("get jar Parent failed"); } File config = new File(parent, configFileName); if (!config.exists()) { - throw new LogConfigException("read jar path failed"); + throw new LogConfigException("can not find config file"); } try (FileInputStream fis = new FileInputStream(config)) { return getLogLevel(fis); } catch (IOException e) { - throw new LogConfigException("read jar path failed"); + throw new LogConfigException("read config file failed"); } } private static String getJarDirectory() throws LogConfigException { ProtectionDomain protectionDomain = LogUtils.class.getProtectionDomain(); if (protectionDomain == null) { - throw new LogConfigException("read jar path failed"); + throw new LogConfigException("get jar protect domain failed"); } CodeSource codeSource = protectionDomain.getCodeSource(); if (codeSource == null) { - throw new LogConfigException("read jar path failed"); + throw new LogConfigException("read jar code path failed"); } URL location = codeSource.getLocation(); if (location == null) { - throw new LogConfigException("read jar path failed"); + throw new LogConfigException("read jar code source location failed"); } String jarPath = location.getFile(); if (jarPath == null) { -- Gitee From a716367bb57abd0cc30dc5bbd89f4232bb9c203c Mon Sep 17 00:00:00 2001 From: wangzeyu Date: Fri, 20 Dec 2024 14:49:22 +0800 Subject: [PATCH 12/12] replace {} str Signed-off-by: wangzeyu --- .../src/main/java/com/ohos/hapsigntool/utils/LogUtils.java | 1 - 1 file changed, 1 deletion(-) diff --git a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java index d77664fa..9a061099 100644 --- a/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java +++ b/hapsigntool/hap_sign_tool_lib/src/main/java/com/ohos/hapsigntool/utils/LogUtils.java @@ -259,7 +259,6 @@ public class LogUtils { } private static String replaceArgs(String line, Object... args) { - Matcher matcher = PATTERN.matcher(line); String result = line; if (!matcher.find()) { -- Gitee