diff --git a/README.md b/README.md index 2fd15e32da15ea27d045b7034dc1cd09ce8980de..b9432d47e5e329b1e4402bdaa9c0e0493f665ed3 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ The application integrity verification module provides an inter-subsystem API, w -

int HapVerify(const std::string& filePath, HapVerifyResult& hapVerifyResult)

+

int32_t HapVerify(const std::string& filePath, HapVerifyResult& hapVerifyResult)

Verifies application integrity and identifies the application source.

diff --git a/README_zh.md b/README_zh.md index 51feaf4c572cc135a93715fbe47c419d38b5a8d4..3a97d07d050879269dcebce87d24f45ad01e5169 100644 --- a/README_zh.md +++ b/README_zh.md @@ -59,7 +59,7 @@ -

int HapVerify(const std::string& filePath, HapVerifyResult& hapVerifyResult)

+

int32_t HapVerify(const std::string& filePath, HapVerifyResult& hapVerifyResult)

校验应用完整性,识别应用来源

diff --git a/interfaces/innerkits/appverify/include/common/data_source.h b/interfaces/innerkits/appverify/include/common/data_source.h index 482a2fa2b58036a98f78eea63853336ce51b2498..8ceb94e10e34162d5717bcbc5ca0ab473d93a0df 100644 --- a/interfaces/innerkits/appverify/include/common/data_source.h +++ b/interfaces/innerkits/appverify/include/common/data_source.h @@ -27,7 +27,7 @@ public: virtual bool HasRemaining() const = 0; virtual long long Remaining() const = 0; virtual void Reset() = 0; - virtual bool ReadDataAndDigestUpdate(const DigestParameter& digestParam, int chunkSize) = 0; + virtual bool ReadDataAndDigestUpdate(const DigestParameter& digestParam, int32_t chunkSize) = 0; }; } // namespace Verify } // namespace Security diff --git a/interfaces/innerkits/appverify/include/common/hap_byte_buffer_data_source.h b/interfaces/innerkits/appverify/include/common/hap_byte_buffer_data_source.h index 7036e9d4c2f27fdbf18e737a303474f0c06053ae..22aaa8325639a7eddd699ff5b1c6d210d3c8d33a 100644 --- a/interfaces/innerkits/appverify/include/common/hap_byte_buffer_data_source.h +++ b/interfaces/innerkits/appverify/include/common/hap_byte_buffer_data_source.h @@ -30,7 +30,7 @@ public: bool HasRemaining() const override; long long Remaining() const override; void Reset() override; - bool ReadDataAndDigestUpdate(const DigestParameter& digestParam, int chunkSize) override; + bool ReadDataAndDigestUpdate(const DigestParameter& digestParam, int32_t chunkSize) override; private: HapByteBuffer& hapByteBuffer; diff --git a/interfaces/innerkits/appverify/include/common/hap_file_data_source.h b/interfaces/innerkits/appverify/include/common/hap_file_data_source.h index 2594d31835be810659a4578b0333cccd1063242a..01674711574688c21ba6c88e0bd54d486bb0ad3e 100644 --- a/interfaces/innerkits/appverify/include/common/hap_file_data_source.h +++ b/interfaces/innerkits/appverify/include/common/hap_file_data_source.h @@ -29,7 +29,7 @@ public: bool HasRemaining() const override; long long Remaining() const override; void Reset() override; - bool ReadDataAndDigestUpdate(const DigestParameter& digestParam, int chunkSize) override; + bool ReadDataAndDigestUpdate(const DigestParameter& digestParam, int32_t chunkSize) override; private: RandomAccessFile& hapFileRandomAccess; diff --git a/interfaces/innerkits/appverify/include/common/hap_verify_log.h b/interfaces/innerkits/appverify/include/common/hap_verify_log.h index 370d88e1bb34a3af4df327a7125e7f6904c01e1a..c1c430b1c7a460b0ca018357b83b35a056e224e8 100644 --- a/interfaces/innerkits/appverify/include/common/hap_verify_log.h +++ b/interfaces/innerkits/appverify/include/common/hap_verify_log.h @@ -21,7 +21,7 @@ namespace OHOS { namespace Security { namespace Verify { -static constexpr unsigned int SECURITY_DOMAIN = 0xD002F00; +static constexpr uint32_t SECURITY_DOMAIN = 0xD002F00; static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, SECURITY_DOMAIN, "HapVerify"}; #define HAPVERIFY_LOG_DEBUG(label, fmt, ...) \ diff --git a/interfaces/innerkits/appverify/include/common/random_access_file.h b/interfaces/innerkits/appverify/include/common/random_access_file.h index ce48c8e6d7ff8140e280bce3b0d60a9dfa916d64..ada93b2bd2c14c300d8a7d48638a557fd35e4947 100644 --- a/interfaces/innerkits/appverify/include/common/random_access_file.h +++ b/interfaces/innerkits/appverify/include/common/random_access_file.h @@ -24,8 +24,8 @@ namespace Security { namespace Verify { struct MmapInfo { long long mmapPosition; - int readMoreLen; - int mmapSize; + int32_t readMoreLen; + int32_t mmapSize; char* mapAddr; }; @@ -36,15 +36,15 @@ public: DLL_EXPORT bool Init(const std::string& filePath); DLL_EXPORT long long GetLength() const; DLL_EXPORT long long ReadFileFullyFromOffset(HapByteBuffer& buffer, long long offset); - DLL_EXPORT long long ReadFileFullyFromOffset(char buf[], long long offset, int bufCapacity); - bool ReadFileFromOffsetAndDigestUpdate(const DigestParameter& digestParam, int chunkSize, long long offset); + DLL_EXPORT long long ReadFileFullyFromOffset(char buf[], long long offset, int32_t bufCapacity); + bool ReadFileFromOffsetAndDigestUpdate(const DigestParameter& digestParam, int32_t chunkSize, long long offset); private: - long long DoMMap(int bufCapacity, long long offset, MmapInfo& mmapInfo); + long long DoMMap(int32_t bufCapacity, long long offset, MmapInfo& mmapInfo); bool CheckLittleEndian(); - static const int FILE_OPEN_FAIL_ERROR_NUM; - static int memoryPageSize; - int fd; + static const int32_t FILE_OPEN_FAIL_ERROR_NUM; + static int32_t memoryPageSize; + int32_t fd; long long fileLength; }; } // namespace Verify diff --git a/interfaces/innerkits/appverify/include/init/trusted_source_manager.h b/interfaces/innerkits/appverify/include/init/trusted_source_manager.h index 7f8fedc34eba8bb200599cdc9cd38ef9df9a0bf8..ee5aa18209a6e0db2ac6ee4760a44013a252b73e 100644 --- a/interfaces/innerkits/appverify/include/init/trusted_source_manager.h +++ b/interfaces/innerkits/appverify/include/init/trusted_source_manager.h @@ -33,7 +33,7 @@ struct HapAppSourceInfo { std::string profileSigningCertificate; std::string profileDebugSigningCertificate; std::string issuer; - int maxCertsPath; + int32_t maxCertsPath; StringVec critialcalCertExtension; }; @@ -47,7 +47,7 @@ public: DLL_EXPORT bool EnableDebug(); DLL_EXPORT void DisableDebug(); DLL_EXPORT MatchingResult IsTrustedSource(const std::string& certSubject, const std::string& certIssuer, - HapBlobType blobType, int certListPath) const; + HapBlobType blobType, int32_t certListPath) const; private: TrustedSourceManager(); @@ -62,7 +62,7 @@ private: bool ParseTrustedAppSourceJson(SourceInfoVec& trustedAppSources, const JsonObjVec& trustedAppSourceJson); std::string EncapTrustedAppSourceString(const HapAppSourceInfo& appSourceInfo); MatchingResult MatchTrustedSource(const SourceInfoVec& trustedAppSources, const std::string& certSubject, - const std::string& certIssuer, HapBlobType blobType, int certListPath) const; + const std::string& certIssuer, HapBlobType blobType, int32_t certListPath) const; MatchingStates TrustedSourceListCompare(const std::string& certSubject, const std::string& certIssuer, const HapAppSourceInfo& appSource, HapBlobType blobType) const; TrustedSources GetTrustedSource(std::string& sourceName); diff --git a/interfaces/innerkits/appverify/include/init/trusted_ticket_manager.h b/interfaces/innerkits/appverify/include/init/trusted_ticket_manager.h index ab4a124d56c7b1f78548afad8d733d5078d02d6d..d77da42b6ef00f5cc4d98d0bf785fd97ee55996b 100644 --- a/interfaces/innerkits/appverify/include/init/trusted_ticket_manager.h +++ b/interfaces/innerkits/appverify/include/init/trusted_ticket_manager.h @@ -30,7 +30,7 @@ struct HapTicketSourceInfo { std::string sourceName; std::string ticketSigningCert; std::string issuer; - int maxCertsPath; + int32_t maxCertsPath; StringVec critialcalCertExtension; }; @@ -42,7 +42,7 @@ public: DLL_EXPORT bool Init(); DLL_EXPORT void Recovery(); DLL_EXPORT MatchingResult IsTrustedSource(const std::string& certSubject, const std::string& certIssuer, - int certListPath) const; + int32_t certListPath) const; private: TrustedTicketManager(); @@ -58,7 +58,7 @@ private: const JsonObjVec& trustedTicketJson); std::string EncapTrustedTicketSourceString(const HapTicketSourceInfo& ticketSourceInfo); MatchingResult MatchTrustedSource(const TicketSourceInfoVec& trustedTicketSources, const std::string& certSubject, - const std::string& certIssuer, int certListPath) const; + const std::string& certIssuer, int32_t certListPath) const; MatchingStates TrustedSourceListCompare(const std::string& certSubject, const std::string& certIssuer, const HapTicketSourceInfo& TicketSource) const; bool MatchSubject(const std::string& trustedSource, const std::string& certSubject) const; diff --git a/interfaces/innerkits/appverify/include/interfaces/hap_verify.h b/interfaces/innerkits/appverify/include/interfaces/hap_verify.h index 7b7d3249beaea64f3891ad5a326f157360b60053..ab11015a8aeddf7942af7dbf54e954ecaf8f6962 100644 --- a/interfaces/innerkits/appverify/include/interfaces/hap_verify.h +++ b/interfaces/innerkits/appverify/include/interfaces/hap_verify.h @@ -25,8 +25,8 @@ namespace Security { namespace Verify { DLL_EXPORT bool EnableDebugMode(); DLL_EXPORT void DisableDebugMode(); -DLL_EXPORT int HapVerify(const std::string& filePath, HapVerifyResult& hapVerifyResult); -DLL_EXPORT int ParseHapProfile(const std::string& filePath, HapVerifyResult& hapVerifyV1Result); +DLL_EXPORT int32_t HapVerify(const std::string& filePath, HapVerifyResult& hapVerifyResult); +DLL_EXPORT int32_t ParseHapProfile(const std::string& filePath, HapVerifyResult& hapVerifyV1Result); DLL_EXPORT void SetDevMode(DevMode devMode); } // namespace Verify } // namespace Security diff --git a/interfaces/innerkits/appverify/include/interfaces/hap_verify_result.h b/interfaces/innerkits/appverify/include/interfaces/hap_verify_result.h index be446565832653a32a1eeffa3bc69bedb3b0cada..193f401e5695aafce9415e8795a9045d15d88e3b 100644 --- a/interfaces/innerkits/appverify/include/interfaces/hap_verify_result.h +++ b/interfaces/innerkits/appverify/include/interfaces/hap_verify_result.h @@ -55,7 +55,7 @@ enum GetOptionalBlockResultCode { }; struct OptionalBlock { - int optionalType; + int32_t optionalType; HapByteBuffer optionalBlockValue; }; @@ -63,13 +63,13 @@ class HapVerifyResult { public: DLL_EXPORT HapVerifyResult(); DLL_EXPORT ~HapVerifyResult(); - DLL_EXPORT int GetVersion() const; - DLL_EXPORT void SetVersion(int signatureVersion); + DLL_EXPORT int32_t GetVersion() const; + DLL_EXPORT void SetVersion(int32_t signatureVersion); DLL_EXPORT void SetPkcs7SignBlock(const HapByteBuffer& pkcs7); DLL_EXPORT void SetPkcs7ProfileBlock(const HapByteBuffer& pkcs7); DLL_EXPORT void SetOptionalBlocks(const std::vector& option); DLL_EXPORT void SetProvisionInfo(const ProvisionInfo& info); - DLL_EXPORT int GetProperty(std::string& property) const; + DLL_EXPORT int32_t GetProperty(std::string& property) const; DLL_EXPORT ProvisionInfo GetProvisionInfo() const; DLL_EXPORT std::vector GetPublicKey() const; DLL_EXPORT std::vector GetSignature() const; @@ -77,10 +77,10 @@ public: void SetSignature(const std::vector& inputSignatures); private: - DLL_EXPORT int GetBlockFromOptionalBlocks(int blockType, std::string& block) const; + DLL_EXPORT int32_t GetBlockFromOptionalBlocks(int32_t blockType, std::string& block) const; private: - int version; + int32_t version; std::vector publicKeys; std::vector signatures; HapByteBuffer pkcs7SignBlock; diff --git a/interfaces/innerkits/appverify/include/util/digest_parameter.h b/interfaces/innerkits/appverify/include/util/digest_parameter.h index 65510b6c53414829a29891507271eaa90c69e761..31fbec212273ab48b248bb0e5bb3dc3817171144 100644 --- a/interfaces/innerkits/appverify/include/util/digest_parameter.h +++ b/interfaces/innerkits/appverify/include/util/digest_parameter.h @@ -31,7 +31,7 @@ public: DLL_EXPORT DigestParameter& operator = (const DigestParameter& other); public: - int digestOutputSizeBytes; + int32_t digestOutputSizeBytes; const EVP_MD* md; EVP_MD_CTX* ptrCtx; }; diff --git a/interfaces/innerkits/appverify/include/util/hap_cert_verify_openssl_utils.h b/interfaces/innerkits/appverify/include/util/hap_cert_verify_openssl_utils.h index 6305b402db7dd063b6dc15850de6071d47145363..7b86e08095747fb244bc7b07b6f0b8f14abeaeb7 100644 --- a/interfaces/innerkits/appverify/include/util/hap_cert_verify_openssl_utils.h +++ b/interfaces/innerkits/appverify/include/util/hap_cert_verify_openssl_utils.h @@ -31,7 +31,7 @@ class HapCertVerifyOpensslUtils { public: DLL_EXPORT static X509* GetX509CertFromPemString(const std::string& pemString); DLL_EXPORT static X509* GetX509CertFromBase64String(const std::string& base64String); - DLL_EXPORT static X509_CRL* GetX509CrlFromDerBuffer(const HapByteBuffer& crlBuffer, int offset, int len); + DLL_EXPORT static X509_CRL* GetX509CrlFromDerBuffer(const HapByteBuffer& crlBuffer, int32_t offset, int32_t len); DLL_EXPORT static void GenerateCertSignFromCertStack(STACK_OF(X509)* certs, CertSign& certVisitSign); DLL_EXPORT static void ClearCertVisitSign(CertSign& certVisitSign); DLL_EXPORT static bool GetCertsChain(CertChain& certsChain, CertSign& certVisitSign); @@ -48,12 +48,12 @@ public: DLL_EXPORT static bool GetFingerprintBase64FromPemCert(const std::string& certStr, std::string& fingerprint); DLL_EXPORT static bool X509NameCompare(const X509_NAME* a, const X509_NAME* b); DLL_EXPORT static bool GetPublickeyBase64(const X509* cert, std::string& publicKey); - DLL_EXPORT static int CalculateLenAfterBase64Encode(int len); + DLL_EXPORT static int32_t CalculateLenAfterBase64Encode(int32_t len); private: DLL_EXPORT static X509* FindCertOfIssuer(X509* cert, CertSign& certVisitSign); DLL_EXPORT static std::string GetDnToString(X509_NAME* name); - DLL_EXPORT static void GetTextFromX509Name(X509_NAME* name, int nId, std::string& text); + DLL_EXPORT static void GetTextFromX509Name(X509_NAME* name, int32_t nId, std::string& text); DLL_EXPORT static X509_CRL* GetCrlBySignedCertIssuer(STACK_OF(X509_CRL)* crls, const X509* cert); DLL_EXPORT static bool CheckSignTimeInValidPeriod(const ASN1_TYPE* signTime, const ASN1_TIME* notBefore, const ASN1_TIME* notAfter); @@ -61,11 +61,11 @@ private: DLL_EXPORT static bool CheckAsn1TypeIsValid(const ASN1_TYPE* asn1Type); private: - static const unsigned int MIN_CERT_CHAIN_LEN_NEED_VERIFY_CRL; - static const int OPENSSL_READ_CRL_MAX_TIME; - static const int OPENSSL_READ_CRL_LEN_EACH_TIME; - static const int BASE64_ENCODE_LEN_OF_EACH_GROUP_DATA; - static const int BASE64_ENCODE_PACKET_LEN; + static const uint32_t MIN_CERT_CHAIN_LEN_NEED_VERIFY_CRL; + static const int32_t OPENSSL_READ_CRL_MAX_TIME; + static const int32_t OPENSSL_READ_CRL_LEN_EACH_TIME; + static const int32_t BASE64_ENCODE_LEN_OF_EACH_GROUP_DATA; + static const int32_t BASE64_ENCODE_PACKET_LEN; }; } // namespace Verify } // namespace Security diff --git a/interfaces/innerkits/appverify/include/util/hap_signing_block_utils.h b/interfaces/innerkits/appverify/include/util/hap_signing_block_utils.h index 05632a5ac5604d11046c08d616016594df082820..8b3d156a9a2889caf4cd1afc210a7adfcdc11361 100644 --- a/interfaces/innerkits/appverify/include/util/hap_signing_block_utils.h +++ b/interfaces/innerkits/appverify/include/util/hap_signing_block_utils.h @@ -30,7 +30,7 @@ namespace OHOS { namespace Security { namespace Verify { -constexpr int ZIP_CHUNK_DIGEST_PRIFIX_LEN = 5; +constexpr int32_t ZIP_CHUNK_DIGEST_PRIFIX_LEN = 5; enum HapBlobType { HAP_SIGN_BLOB = 0x20000000, @@ -40,23 +40,23 @@ enum HapBlobType { }; struct HapSignBlockHead { - int version; - int blockCount; + int32_t version; + int32_t blockCount; long long hapSignBlockSize; long long hapSignBlockMagicLo; long long hapSignBlockMagicHi; }; struct HapSubSignBlockHead { - unsigned int type; - unsigned int length; - unsigned int offset; + uint32_t type; + uint32_t length; + uint32_t offset; }; class HapSigningBlockUtils { public: DLL_EXPORT static bool FindHapSignature(RandomAccessFile& hapFile, SignatureInfo& signInfo); - DLL_EXPORT static bool GetOptionalBlockIndex(std::vector& optionBlocks, int type, int& index); + DLL_EXPORT static bool GetOptionalBlockIndex(std::vector& optionBlocks, int32_t type, int& index); DLL_EXPORT static bool VerifyHapIntegrity(Pkcs7Context& digestInfo, RandomAccessFile& hapFile, SignatureInfo& signInfo); @@ -65,21 +65,21 @@ private: DLL_EXPORT static const long long HAP_SIG_BLOCK_MAGIC_LOW_OLD; DLL_EXPORT static const long long HAP_SIG_BLOCK_MAGIC_HIGH; DLL_EXPORT static const long long HAP_SIG_BLOCK_MAGIC_LOW; - DLL_EXPORT static const int ZIP_HEAD_OF_SIGNING_BLOCK_LENGTH; - DLL_EXPORT static const int ZIP_EOCD_SEGMENT_FLAG; + DLL_EXPORT static const int32_t ZIP_HEAD_OF_SIGNING_BLOCK_LENGTH; + DLL_EXPORT static const int32_t ZIP_EOCD_SEGMENT_FLAG; static const long long CHUNK_SIZE; - static const int HAP_SIG_BLOCK_MIN_SIZE; - static const int ZIP_EOCD_SEG_MIN_SIZE; - static const int ZIP_EOCD_COMMENT_LENGTH_OFFSET; - static const int ZIP_CD_OFFSET_IN_EOCD; - static const int ZIP_CD_SIZE_OFFSET_IN_EOCD; - static const int ZIP_BLOCKS_NUM_NEED_DIGEST; + static const int32_t HAP_SIG_BLOCK_MIN_SIZE; + static const int32_t ZIP_EOCD_SEG_MIN_SIZE; + static const int32_t ZIP_EOCD_COMMENT_LENGTH_OFFSET; + static const int32_t ZIP_CD_OFFSET_IN_EOCD; + static const int32_t ZIP_CD_SIZE_OFFSET_IN_EOCD; + static const int32_t ZIP_BLOCKS_NUM_NEED_DIGEST; static const char ZIP_FIRST_LEVEL_CHUNK_PREFIX; static const char ZIP_SECOND_LEVEL_CHUNK_PREFIX; /* the specifications of hap sign block */ static constexpr long long MAX_HAP_SIGN_BLOCK_SIZE = 1024 * 1024 * 10LL; // 10MB - static constexpr int MAX_BLOCK_COUNT = 10; - static constexpr int VERSION_FOR_NEW_MAGIC_NUM = 3; + static constexpr int32_t MAX_BLOCK_COUNT = 10; + static constexpr int32_t VERSION_FOR_NEW_MAGIC_NUM = 3; private: DLL_EXPORT static bool FindEocdInHap(RandomAccessFile& hapFile, std::pair& eocd); @@ -90,21 +90,21 @@ private: long long& centralDirectoryOffset); static bool FindHapSigningBlock(RandomAccessFile& hapFile, long long centralDirOffset, SignatureInfo& signInfo); - static bool FindHapSubSigningBlock(RandomAccessFile& hapFile, int blockCount, + static bool FindHapSubSigningBlock(RandomAccessFile& hapFile, int32_t blockCount, long long blockArrayLen, long long hapSignBlockOffset, SignatureInfo& signInfo); DLL_EXPORT static bool ClassifyHapSubSigningBlock(SignatureInfo& signInfo, - const HapByteBuffer& subBlock, unsigned int type); - DLL_EXPORT static bool SetUnsignedInt32(HapByteBuffer& buffer, int offset, long long value); + const HapByteBuffer& subBlock, uint32_t type); + DLL_EXPORT static bool SetUnsignedInt32(HapByteBuffer& buffer, int32_t offset, long long value); DLL_EXPORT static bool ComputeDigestsWithOptionalBlock(const DigestParameter& digestParam, const std::vector& optionalBlocks, const HapByteBuffer& chunkDigest, HapByteBuffer& finalDigest); static bool ComputeDigestsForEachChunk(const DigestParameter& digestParam, DataSource* contents[], - int len, HapByteBuffer& result); - static int GetChunkCount(long long inputSize, long long chunkSize); + int32_t len, HapByteBuffer& result); + static int32_t GetChunkCount(long long inputSize, long long chunkSize); static bool InitDigestPrefix(const DigestParameter& digestParam, - unsigned char (&chunkContentPrefix)[ZIP_CHUNK_DIGEST_PRIFIX_LEN], int chunkLen); - DLL_EXPORT static DigestParameter GetDigestParameter(int nId); - DLL_EXPORT static bool GetSumOfChunkDigestLen(DataSource* contents[], int len, int chunkDigestLen, + unsigned char (&chunkContentPrefix)[ZIP_CHUNK_DIGEST_PRIFIX_LEN], int32_t chunkLen); + DLL_EXPORT static DigestParameter GetDigestParameter(int32_t nId); + DLL_EXPORT static bool GetSumOfChunkDigestLen(DataSource* contents[], int32_t len, int32_t chunkDigestLen, int& chunkCount, int& sumOfChunkDigestLen); static bool ParseSignBlockHead(HapSignBlockHead& hapSignBlockHead, HapByteBuffer& hapBlockHead); static bool ParseSubSignBlockHead(HapSubSignBlockHead& subSignBlockHead, HapByteBuffer& hapBlockHead); diff --git a/interfaces/innerkits/appverify/include/util/hap_verify_openssl_utils.h b/interfaces/innerkits/appverify/include/util/hap_verify_openssl_utils.h index 66ffd95f8ab6c7b911be4058412abab62bd1473a..e28e0547cedf774861fefde496e45fca170cac02 100644 --- a/interfaces/innerkits/appverify/include/util/hap_verify_openssl_utils.h +++ b/interfaces/innerkits/appverify/include/util/hap_verify_openssl_utils.h @@ -50,45 +50,45 @@ enum SignatureAlgorithm { class HapVerifyOpensslUtils { public: DLL_EXPORT static bool ParsePkcs7Package(const unsigned char packageData[], - unsigned int packageLen, Pkcs7Context& pkcs7Context); + uint32_t packageLen, Pkcs7Context& pkcs7Context); DLL_EXPORT static bool GetCertChains(PKCS7* p7, Pkcs7Context& pkcs7Context); DLL_EXPORT static bool VerifyPkcs7(Pkcs7Context& pkcs7Context); DLL_EXPORT static bool GetPublickeys(const CertChain& signCertChain, std::vector& SignatureVec); DLL_EXPORT static bool GetSignatures(const CertChain& signCertChain, std::vector& SignatureVec); - static int GetDigest(const HapByteBuffer& chunk, const std::vector& optionalBlocks, + static int32_t GetDigest(const HapByteBuffer& chunk, const std::vector& optionalBlocks, const DigestParameter& digestParameter, unsigned char (&out)[EVP_MAX_MD_SIZE]); static bool DigestInit(const DigestParameter& digestParameter); - static bool DigestUpdate(const DigestParameter& digestParameter, const unsigned char content[], int len); - static int GetDigest(const DigestParameter& digestParameter, unsigned char (&out)[EVP_MAX_MD_SIZE]); - static int GetDigestAlgorithmOutputSizeBytes(int nId); - DLL_EXPORT static int GetDigestAlgorithmId(int signAlgorithm); + static bool DigestUpdate(const DigestParameter& digestParameter, const unsigned char content[], int32_t len); + static int32_t GetDigest(const DigestParameter& digestParameter, unsigned char (&out)[EVP_MAX_MD_SIZE]); + static int32_t GetDigestAlgorithmOutputSizeBytes(int32_t nId); + DLL_EXPORT static int32_t GetDigestAlgorithmId(int32_t signAlgorithm); static void GetOpensslErrorMessage(); private: DLL_EXPORT static bool VerifyPkcs7SignedData(Pkcs7Context& pkcs7Context); DLL_EXPORT static bool VerifySignInfo(STACK_OF(PKCS7_SIGNER_INFO)* signerInfoStack, - BIO* p7Bio, int signInfoNum, Pkcs7Context& pkcs7Context); + BIO* p7Bio, int32_t signInfoNum, Pkcs7Context& pkcs7Context); DLL_EXPORT static bool GetPublickeyFromCertificate(const X509* ptrX509, std::vector& publicKeyVec); DLL_EXPORT static bool GetDerCert(X509* ptrX509, std::vector& SignatureVec); static bool VerifyShaWithRsaPss(const PKCS7_SIGNER_INFO* signInfo, BIO* p7Bio, EVP_PKEY* pkey, bool isPss); DLL_EXPORT static bool VerifyShaWithRsaPss(const PKCS7_SIGNER_INFO* signInfo, EVP_PKEY* pkey, bool isPss, - const unsigned char digest[], unsigned int digestLen); + const unsigned char digest[], uint32_t digestLen); static bool VerifyCertChain(CertChain& certsChain, PKCS7* p7, PKCS7_SIGNER_INFO* signInfo, Pkcs7Context& pkcs7Context, CertSign& certVisitSign); static bool IsEnablePss(const PKCS7_SIGNER_INFO* signInfo); static bool GetContentInfo(const PKCS7* p7ContentInfo, HapByteBuffer& content); static bool CheckPkcs7SignedDataIsValid(const PKCS7* p7); - DLL_EXPORT static bool AsnStringCmp(const ASN1_OCTET_STRING* asnStr, const unsigned char data[], int len); - static bool VerifyPkcs7AuthAttributes(const PKCS7_SIGNER_INFO* signInfo, EVP_MD_CTX* mdCtx, int mdType); - static const EVP_MD_CTX* FindMdCtxInBio(BIO* p7Bio, int mdType); + DLL_EXPORT static bool AsnStringCmp(const ASN1_OCTET_STRING* asnStr, const unsigned char data[], int32_t len); + static bool VerifyPkcs7AuthAttributes(const PKCS7_SIGNER_INFO* signInfo, EVP_MD_CTX* mdCtx, int32_t mdType); + static const EVP_MD_CTX* FindMdCtxInBio(BIO* p7Bio, int32_t mdType); static bool CheckDigestParameter(const DigestParameter& digestParameter); private: - static const int OPENSSL_PKCS7_VERIFY_SUCCESS; - static const int OPENSSL_ERR_MESSAGE_MAX_LEN; - static const int OPENSSL_READ_DATA_MAX_TIME; - static const int OPENSSL_READ_DATA_LEN_EACH_TIME; - static const int MAX_OID_LENGTH; + static const int32_t OPENSSL_PKCS7_VERIFY_SUCCESS; + static const int32_t OPENSSL_ERR_MESSAGE_MAX_LEN; + static const int32_t OPENSSL_READ_DATA_MAX_TIME; + static const int32_t OPENSSL_READ_DATA_LEN_EACH_TIME; + static const int32_t MAX_OID_LENGTH; static const std::string PKCS7_EXT_SHAWITHRSA_PSS; }; } // namespace Verify diff --git a/interfaces/innerkits/appverify/include/util/pkcs7_context.h b/interfaces/innerkits/appverify/include/util/pkcs7_context.h index 8eefc7d2fbda8b405aade108ac84e18c466f9128..ce86b381bef48ae9e039178097079b09e9551eed 100644 --- a/interfaces/innerkits/appverify/include/util/pkcs7_context.h +++ b/interfaces/innerkits/appverify/include/util/pkcs7_context.h @@ -32,7 +32,7 @@ using Pkcs7CertChains = std::vector; struct Pkcs7Context { bool needWriteCrl; - int digestAlgorithm; + int32_t digestAlgorithm; MatchingResult matchResult; std::string certIssuer; PKCS7* p7; diff --git a/interfaces/innerkits/appverify/include/util/signature_info.h b/interfaces/innerkits/appverify/include/util/signature_info.h index 05f13235506f1435c14a326476c07c69c9e5451d..d35de7da6d9d706ec20e38758f21d1b6f492ee6d 100644 --- a/interfaces/innerkits/appverify/include/util/signature_info.h +++ b/interfaces/innerkits/appverify/include/util/signature_info.h @@ -30,7 +30,7 @@ struct SignatureInfo { long long hapEocdOffset; HapByteBuffer hapEocd; std::vector optionBlocks; - int version; + int32_t version; }; } // namespace Verify } // namespace Security diff --git a/interfaces/innerkits/appverify/include/verify/hap_verify_v2.h b/interfaces/innerkits/appverify/include/verify/hap_verify_v2.h index ace49d6648b90b65d4e26cc869ab0b11f6ed2023..74fa3a69586a86759ac3da39d8f5c95f3f7a5ddd 100644 --- a/interfaces/innerkits/appverify/include/verify/hap_verify_v2.h +++ b/interfaces/innerkits/appverify/include/verify/hap_verify_v2.h @@ -28,11 +28,11 @@ namespace Security { namespace Verify { class HapVerifyV2 { public: - int Verify(const std::string& filePath, HapVerifyResult& hapVerifyV1Result); - int ParseHapProfile(const std::string& filePath, HapVerifyResult& hapVerifyV1Result); + int32_t Verify(const std::string& filePath, HapVerifyResult& hapVerifyV1Result); + int32_t ParseHapProfile(const std::string& filePath, HapVerifyResult& hapVerifyV1Result); private: - int Verify(RandomAccessFile& hapFile, HapVerifyResult& hapVerifyV1Result); + int32_t Verify(RandomAccessFile& hapFile, HapVerifyResult& hapVerifyV1Result); bool VerifyAppPkc7AndParseProfile(Pkcs7Context& pkcs7Context, HapByteBuffer& hapProfileBlock, HapVerifyResult& hapVerifyV1Result); bool VerifyAppSourceAndParseProfile(Pkcs7Context& pkcs7Context, const HapByteBuffer& hapProfileBlock, @@ -53,11 +53,11 @@ private: bool VerifyProfileSignature(const Pkcs7Context& pkcs7Context, Pkcs7Context& profileContext); private: - static const int HEX_PRINT_LENGTH; - static const int DIGEST_BLOCK_LEN_OFFSET; - static const int DIGEST_ALGORITHM_OFFSET; - static const int DIGEST_LEN_OFFSET; - static const int DIGEST_OFFSET_IN_CONTENT; + static const int32_t HEX_PRINT_LENGTH; + static const int32_t DIGEST_BLOCK_LEN_OFFSET; + static const int32_t DIGEST_ALGORITHM_OFFSET; + static const int32_t DIGEST_LEN_OFFSET; + static const int32_t DIGEST_OFFSET_IN_CONTENT; static const std::string HAP_APP_PATTERN; static const std::string HQF_APP_PATTERN; static const std::string HSP_APP_PATTERN; diff --git a/interfaces/innerkits/appverify/src/common/hap_byte_buffer.cpp b/interfaces/innerkits/appverify/src/common/hap_byte_buffer.cpp index 67d431ddceba405baa7bb82f8a3291814d7f6e90..9ff07f89a2b6fb992f19b6d0730f0c882eb09f59 100644 --- a/interfaces/innerkits/appverify/src/common/hap_byte_buffer.cpp +++ b/interfaces/innerkits/appverify/src/common/hap_byte_buffer.cpp @@ -127,7 +127,7 @@ bool HapByteBuffer::GetInt64(int32_t index, long long& value) return true; } -int HapByteBuffer::GetCapacity() const +int32_t HapByteBuffer::GetCapacity() const { return capacity; } diff --git a/interfaces/innerkits/appverify/src/common/hap_byte_buffer_data_source.cpp b/interfaces/innerkits/appverify/src/common/hap_byte_buffer_data_source.cpp index b94d337dbe7f781f6a8027d5bba081146e18f034..4505efddb632ef4462937211f7593c9789f9627b 100644 --- a/interfaces/innerkits/appverify/src/common/hap_byte_buffer_data_source.cpp +++ b/interfaces/innerkits/appverify/src/common/hap_byte_buffer_data_source.cpp @@ -43,7 +43,7 @@ void HapByteBufferDataSource::Reset() hapByteBuffer.Clear(); } -bool HapByteBufferDataSource::ReadDataAndDigestUpdate(const DigestParameter& digestParam, int chunkSize) +bool HapByteBufferDataSource::ReadDataAndDigestUpdate(const DigestParameter& digestParam, int32_t chunkSize) { const unsigned char* chunk = reinterpret_cast(hapByteBuffer.GetBufferPtr() + hapByteBuffer.GetPosition()); diff --git a/interfaces/innerkits/appverify/src/common/hap_file_data_source.cpp b/interfaces/innerkits/appverify/src/common/hap_file_data_source.cpp index 1ab1082e66c1d16ad25ed638afc75617ca1314de..e9d75365b06fe3eb05fbd378bba79396b5e0df8b 100644 --- a/interfaces/innerkits/appverify/src/common/hap_file_data_source.cpp +++ b/interfaces/innerkits/appverify/src/common/hap_file_data_source.cpp @@ -45,7 +45,7 @@ void HapFileDataSource::Reset() sourcePosition = 0; } -bool HapFileDataSource::ReadDataAndDigestUpdate(const DigestParameter& digestParam, int chunkSize) +bool HapFileDataSource::ReadDataAndDigestUpdate(const DigestParameter& digestParam, int32_t chunkSize) { if (!hapFileRandomAccess.ReadFileFromOffsetAndDigestUpdate(digestParam, chunkSize, fileOffset + sourcePosition)) { HAPVERIFY_LOG_ERROR(LABEL, "ReadFileFromOffsetAndDigestUpdate failed"); diff --git a/interfaces/innerkits/appverify/src/common/random_access_file.cpp b/interfaces/innerkits/appverify/src/common/random_access_file.cpp index 49a8434df1d764f5a281e12de909103996d12a15..5f6a3c079d9793df482711747592c7aae86e7527 100644 --- a/interfaces/innerkits/appverify/src/common/random_access_file.cpp +++ b/interfaces/innerkits/appverify/src/common/random_access_file.cpp @@ -28,8 +28,8 @@ namespace OHOS { namespace Security { namespace Verify { -const int RandomAccessFile::FILE_OPEN_FAIL_ERROR_NUM = -1; -int RandomAccessFile::memoryPageSize = sysconf(_SC_PAGESIZE); +const int32_t RandomAccessFile::FILE_OPEN_FAIL_ERROR_NUM = -1; +int32_t RandomAccessFile::memoryPageSize = sysconf(_SC_PAGESIZE); RandomAccessFile::RandomAccessFile() : fd(FILE_OPEN_FAIL_ERROR_NUM), fileLength(0) @@ -71,14 +71,14 @@ long long RandomAccessFile::GetLength() const bool RandomAccessFile::CheckLittleEndian() { union LittleEndian { - int num; + int32_t num; char ch; } t; t.num = 1; return (t.ch == 1); } -long long RandomAccessFile::DoMMap(int bufCapacity, long long offset, MmapInfo& mmapInfo) +long long RandomAccessFile::DoMMap(int32_t bufCapacity, long long offset, MmapInfo& mmapInfo) { if (!CheckLittleEndian()) { HAPVERIFY_LOG_ERROR(LABEL, "CheckLittleEndian: failed"); @@ -103,7 +103,7 @@ long long RandomAccessFile::DoMMap(int bufCapacity, long long offset, MmapInfo& return 0; } -long long RandomAccessFile::ReadFileFullyFromOffset(char buf[], long long offset, int bufCapacity) +long long RandomAccessFile::ReadFileFullyFromOffset(char buf[], long long offset, int32_t bufCapacity) { if (buf == nullptr) { return DEST_BUFFER_IS_NULL; @@ -131,7 +131,7 @@ long long RandomAccessFile::ReadFileFullyFromOffset(HapByteBuffer& buffer, long } MmapInfo mmapInfo; - int bufCapacity = buffer.GetCapacity(); + int32_t bufCapacity = buffer.GetCapacity(); long long ret = DoMMap(bufCapacity, offset, mmapInfo); if (ret < 0) { return ret; @@ -143,7 +143,7 @@ long long RandomAccessFile::ReadFileFullyFromOffset(HapByteBuffer& buffer, long } bool RandomAccessFile::ReadFileFromOffsetAndDigestUpdate(const DigestParameter& digestParam, - int chunkSize, long long offset) + int32_t chunkSize, long long offset) { MmapInfo mmapInfo; long long ret = DoMMap(chunkSize, offset, mmapInfo); diff --git a/interfaces/innerkits/appverify/src/init/hap_crl_manager.cpp b/interfaces/innerkits/appverify/src/init/hap_crl_manager.cpp index 6fc8baa067a6152645ba780ecd3a4ec5d7a14e81..c80f0d0a83dc3b5008e1af7cf99c3150372e9f04 100644 --- a/interfaces/innerkits/appverify/src/init/hap_crl_manager.cpp +++ b/interfaces/innerkits/appverify/src/init/hap_crl_manager.cpp @@ -71,17 +71,17 @@ void HapCrlManager::Init() bool HapCrlManager::ParseCrls(HapByteBuffer& crlsBuffer) { - unsigned int numOfCrl; + uint32_t numOfCrl; if (!crlsBuffer.GetUInt32(0, numOfCrl)) { HAPVERIFY_LOG_ERROR(LABEL, "get numOfCrl failed"); return false; } - int hasUsed = static_cast(sizeof(numOfCrl)); + int32_t hasUsed = static_cast(sizeof(numOfCrl)); crlsBuffer.SetPosition(hasUsed); HAPVERIFY_LOG_DEBUG(LABEL, "total crl num: %{public}u", numOfCrl); while (numOfCrl && hasUsed <= crlsBuffer.GetCapacity()) { - int crlLen; + int32_t crlLen; if (!crlsBuffer.GetInt32(crlLen)) { HAPVERIFY_LOG_ERROR(LABEL, "get crlLen failed"); return false; @@ -140,7 +140,7 @@ void HapCrlManager::WriteCrlsToFile() crlMtx.unlock(); return; } - unsigned int numOfCrl = crlsMap.size(); + uint32_t numOfCrl = crlsMap.size(); crlFile.write(reinterpret_cast(&numOfCrl), sizeof(numOfCrl)); for (auto crlPair : crlsMap) { HapCertVerifyOpensslUtils::WriteX509CrlToStream(crlFile, crlPair.second); diff --git a/interfaces/innerkits/appverify/src/init/trusted_source_manager.cpp b/interfaces/innerkits/appverify/src/init/trusted_source_manager.cpp index 235d43a0ab5b689f533a258f00f50f7ca9057585..5acab9570286cab83aa62a626be825fa6898131e 100644 --- a/interfaces/innerkits/appverify/src/init/trusted_source_manager.cpp +++ b/interfaces/innerkits/appverify/src/init/trusted_source_manager.cpp @@ -192,7 +192,7 @@ std::string TrustedSourceManager::EncapTrustedAppSourceString(const HapAppSource } MatchingResult TrustedSourceManager::IsTrustedSource(const std::string& certSubject, - const std::string& certIssuer, HapBlobType blobType, int certListPath) const + const std::string& certIssuer, HapBlobType blobType, int32_t certListPath) const { MatchingResult ret = MatchTrustedSource(appTrustedSources, certSubject, certIssuer, blobType, certListPath); if (ret.matchState != DO_NOT_MATCH) { @@ -206,7 +206,7 @@ MatchingResult TrustedSourceManager::IsTrustedSource(const std::string& certSubj } MatchingResult TrustedSourceManager::MatchTrustedSource(const SourceInfoVec& trustedAppSources, - const std::string& certSubject, const std::string& certIssuer, HapBlobType blobType, int certListPath) const + const std::string& certSubject, const std::string& certIssuer, HapBlobType blobType, int32_t certListPath) const { MatchingResult ret; ret.matchState = DO_NOT_MATCH; diff --git a/interfaces/innerkits/appverify/src/init/trusted_ticket_manager.cpp b/interfaces/innerkits/appverify/src/init/trusted_ticket_manager.cpp index a3ac64690a52f17e9bb660d822278a5fe515c7ae..97fddc838c745b38920d204ad9bb7e60f8f04287 100644 --- a/interfaces/innerkits/appverify/src/init/trusted_ticket_manager.cpp +++ b/interfaces/innerkits/appverify/src/init/trusted_ticket_manager.cpp @@ -155,7 +155,7 @@ std::string TrustedTicketManager::EncapTrustedTicketSourceString(const HapTicket } MatchingResult TrustedTicketManager::IsTrustedSource(const std::string& certSubject, - const std::string& certIssuer, int certListPath) const + const std::string& certIssuer, int32_t certListPath) const { MatchingResult ret = MatchTrustedSource(TicketTrustedSources, certSubject, certIssuer, certListPath); if (ret.matchState != DO_NOT_MATCH) { @@ -165,7 +165,7 @@ MatchingResult TrustedTicketManager::IsTrustedSource(const std::string& certSubj } MatchingResult TrustedTicketManager::MatchTrustedSource(const TicketSourceInfoVec& trustedTicketSources, - const std::string& certSubject, const std::string& certIssuer, int certListPath) const + const std::string& certSubject, const std::string& certIssuer, int32_t certListPath) const { MatchingResult ret; ret.matchState = DO_NOT_MATCH; diff --git a/interfaces/innerkits/appverify/src/interfaces/hap_verify.cpp b/interfaces/innerkits/appverify/src/interfaces/hap_verify.cpp index e219faa1f1217fee9bb836736a3fbfc85c3137fb..55c9e92f9fd260d685367f4e946fb4b5dc02cf8c 100644 --- a/interfaces/innerkits/appverify/src/interfaces/hap_verify.cpp +++ b/interfaces/innerkits/appverify/src/interfaces/hap_verify.cpp @@ -83,7 +83,7 @@ void SetDevMode(DevMode mode) g_mtx.unlock(); } -int HapVerify(const std::string& filePath, HapVerifyResult& hapVerifyResult) +int32_t HapVerify(const std::string& filePath, HapVerifyResult& hapVerifyResult) { if (!g_isInit && !HapVerifyInit()) { return VERIFY_SOURCE_INIT_FAIL; @@ -92,7 +92,7 @@ int HapVerify(const std::string& filePath, HapVerifyResult& hapVerifyResult) return hapVerifyV2.Verify(filePath, hapVerifyResult); } -int ParseHapProfile(const std::string& filePath, HapVerifyResult& hapVerifyV1Result) +int32_t ParseHapProfile(const std::string& filePath, HapVerifyResult& hapVerifyV1Result) { HapVerifyV2 hapVerifyV2; return hapVerifyV2.ParseHapProfile(filePath, hapVerifyV1Result); diff --git a/interfaces/innerkits/appverify/src/interfaces/hap_verify_result.cpp b/interfaces/innerkits/appverify/src/interfaces/hap_verify_result.cpp index 37608c1303afe6e685a29cb934ce2610383764a6..ae4e9837810a076b7f3a648f8fbc1924dd7ee7a2 100644 --- a/interfaces/innerkits/appverify/src/interfaces/hap_verify_result.cpp +++ b/interfaces/innerkits/appverify/src/interfaces/hap_verify_result.cpp @@ -30,12 +30,12 @@ HapVerifyResult::~HapVerifyResult() { } -int HapVerifyResult::GetVersion() const +int32_t HapVerifyResult::GetVersion() const { return version; } -void HapVerifyResult::SetVersion(int signatureVersion) +void HapVerifyResult::SetVersion(int32_t signatureVersion) { version = signatureVersion; } @@ -75,12 +75,12 @@ void HapVerifyResult::SetSignature(const std::vector& inputSignatur signatures = inputSignatures; } -int HapVerifyResult::GetProperty(std::string& property) const +int32_t HapVerifyResult::GetProperty(std::string& property) const { return GetBlockFromOptionalBlocks(PROPERTY_BLOB, property); } -int HapVerifyResult::GetBlockFromOptionalBlocks(int blockType, std::string& block) const +int32_t HapVerifyResult::GetBlockFromOptionalBlocks(int32_t blockType, std::string& block) const { for (unsigned long i = 0; i < optionalBlocks.size(); i++) { if (optionalBlocks[i].optionalType == blockType) { diff --git a/interfaces/innerkits/appverify/src/provision/provision_verify.cpp b/interfaces/innerkits/appverify/src/provision/provision_verify.cpp index 749c00aa2f4352fc58101d033382c755dbf166db..616196486b05faa78c050097a53995dadfa9c8d3 100644 --- a/interfaces/innerkits/appverify/src/provision/provision_verify.cpp +++ b/interfaces/innerkits/appverify/src/provision/provision_verify.cpp @@ -315,7 +315,7 @@ AppProvisionVerifyResult CheckDeviceID(ProvisionInfo& info) } #else char udid[DEV_UUID_LEN] = {0}; - int ret = GetDevUdid(udid, sizeof(udid)); + int32_t ret = GetDevUdid(udid, sizeof(udid)); if (ret != EC_SUCCESS) { HAPVERIFY_LOG_ERROR(LABEL, "obtaining current device id failed (%{public}d).", static_cast(ret)); return PROVISION_DEVICE_UNAUTHORIZED; diff --git a/interfaces/innerkits/appverify/src/ticket/ticket_verify.cpp b/interfaces/innerkits/appverify/src/ticket/ticket_verify.cpp index b8b3b03803e169eb37c2af4abe0466134f84a6bf..a2302c7c819a0f0fe8af0915612072c2fe6b234c 100644 --- a/interfaces/innerkits/appverify/src/ticket/ticket_verify.cpp +++ b/interfaces/innerkits/appverify/src/ticket/ticket_verify.cpp @@ -36,8 +36,8 @@ #include "util/pkcs7_context.h" namespace { -const int MAXIMUM_DEVICES = 100; -const int TICKET_MAX_SIZE = 18432; +const int32_t MAXIMUM_DEVICES = 100; +const int32_t TICKET_MAX_SIZE = 18432; const std::string TICKET_FILE_PATH = "/data/update/ticket/"; const std::string VALUE_DEVICE_TYPE_UDID = "udid"; } // namespace @@ -103,7 +103,7 @@ AppProvisionVerifyResult CheckDevice(ProvisionInfo& info) } #else char udid[DEV_UUID_LEN] = {0}; - int ret = GetDevUdid(udid, sizeof(udid)); + int32_t ret = GetDevUdid(udid, sizeof(udid)); if (ret != EC_SUCCESS) { HAPVERIFY_LOG_ERROR(LABEL, "obtaining current device id failed (%{public}d).", static_cast(ret)); return PROVISION_DEVICE_UNAUTHORIZED; @@ -121,7 +121,7 @@ AppProvisionVerifyResult CheckDevice(ProvisionInfo& info) return PROVISION_OK; } -int CompareTicketAndProfile(const ProvisionInfo& ticketInfo, const ProvisionInfo& profileInfo) +int32_t CompareTicketAndProfile(const ProvisionInfo& ticketInfo, const ProvisionInfo& profileInfo) { if (ticketInfo.bundleInfo.bundleName != profileInfo.bundleInfo.bundleName) { HAPVERIFY_LOG_ERROR(LABEL, "ticket bundlename doesn't match"); @@ -165,7 +165,7 @@ int CompareTicketAndProfile(const ProvisionInfo& ticketInfo, const ProvisionInfo bool VerifyTicketSignature(HapByteBuffer& ticketBlock, Pkcs7Context& pkcs7Context, std::string& ticket) { const unsigned char* pkcs7Block = reinterpret_cast(ticketBlock.GetBufferPtr()); - unsigned int pkcs7Len = static_cast(ticketBlock.GetCapacity()); + uint32_t pkcs7Len = static_cast(ticketBlock.GetCapacity()); if (!HapVerifyOpensslUtils::ParsePkcs7Package(pkcs7Block, pkcs7Len, pkcs7Context)) { HAPVERIFY_LOG_ERROR(LABEL, "Parse ticket pkcs7 failed"); return false; @@ -201,13 +201,13 @@ bool VerifyTicketSignature(HapByteBuffer& ticketBlock, Pkcs7Context& pkcs7Contex return true; } -int TicketParseAndVerify(const std::string& ticket, ProvisionInfo& ticketInfo, +int32_t TicketParseAndVerify(const std::string& ticket, ProvisionInfo& ticketInfo, const ProvisionInfo& profileInfo) { if (ParseProvision(ticket, ticketInfo) != PROVISION_OK) { return TICKET_PARSE_FAIL; } - int ret = CompareTicketAndProfile(ticketInfo, profileInfo); + int32_t ret = CompareTicketAndProfile(ticketInfo, profileInfo); if (ret != TICKET_OK) { return ret; } @@ -217,7 +217,7 @@ int TicketParseAndVerify(const std::string& ticket, ProvisionInfo& ticketInfo, return TICKET_OK; } -int VerifyTicket(const std::string& filePath, const ProvisionInfo& profileInfo) +int32_t VerifyTicket(const std::string& filePath, const ProvisionInfo& profileInfo) { HAPVERIFY_LOG_DEBUG(LABEL, "Enter Ticket Verify"); RandomAccessFile ticketFile; @@ -230,7 +230,7 @@ int VerifyTicket(const std::string& filePath, const ProvisionInfo& profileInfo) HAPVERIFY_LOG_ERROR(LABEL, "file length %{public}lld is too larger", fileLength); return OPEN_TICKET_FILE_ERROR; } - int fileLen = static_cast(fileLength); + int32_t fileLen = static_cast(fileLength); HapByteBuffer ticketBlock(fileLen); long long ret = ticketFile.ReadFileFullyFromOffset(ticketBlock, 0); if (ret < 0) { @@ -246,7 +246,7 @@ int VerifyTicket(const std::string& filePath, const ProvisionInfo& profileInfo) } ProvisionInfo ticketInfo; - int ticketRet = TicketParseAndVerify(ticket, ticketInfo, profileInfo); + int32_t ticketRet = TicketParseAndVerify(ticket, ticketInfo, profileInfo); if (ticketRet != TICKET_OK) { HAPVERIFY_LOG_ERROR(LABEL, "ticket parse failed, error: %{public}d", static_cast(ticketRet)); return ticketRet; @@ -263,7 +263,7 @@ bool CheckTicketSource(const ProvisionInfo& profileInfo) return false; } - int ret = VerifyTicket(standardFilePath, profileInfo); + int32_t ret = VerifyTicket(standardFilePath, profileInfo); if (ret != TICKET_VERIFY_SUCCESS) { HAPVERIFY_LOG_ERROR(LABEL, "ticket verify failed, result: %{public}d", ret); return false; diff --git a/interfaces/innerkits/appverify/src/util/hap_cert_verify_openssl_utils.cpp b/interfaces/innerkits/appverify/src/util/hap_cert_verify_openssl_utils.cpp index a1f821d2a9725f3aef205847de84c50bb26e0dc7..b62faec78a1484795ea85f02247744a2f1571aa1 100644 --- a/interfaces/innerkits/appverify/src/util/hap_cert_verify_openssl_utils.cpp +++ b/interfaces/innerkits/appverify/src/util/hap_cert_verify_openssl_utils.cpp @@ -30,12 +30,12 @@ namespace OHOS { namespace Security { namespace Verify { -const unsigned int HapCertVerifyOpensslUtils::MIN_CERT_CHAIN_LEN_NEED_VERIFY_CRL = 2; -const int HapCertVerifyOpensslUtils::OPENSSL_READ_CRL_MAX_TIME = 1048576; // 1024 * 1024 -const int HapCertVerifyOpensslUtils::OPENSSL_READ_CRL_LEN_EACH_TIME = 1024; -const int HapCertVerifyOpensslUtils::BASE64_ENCODE_LEN_OF_EACH_GROUP_DATA = 4; -const int HapCertVerifyOpensslUtils::BASE64_ENCODE_PACKET_LEN = 3; -constexpr int BUFF_SIZE = 3; +const uint32_t HapCertVerifyOpensslUtils::MIN_CERT_CHAIN_LEN_NEED_VERIFY_CRL = 2; +const int32_t HapCertVerifyOpensslUtils::OPENSSL_READ_CRL_MAX_TIME = 1048576; // 1024 * 1024 +const int32_t HapCertVerifyOpensslUtils::OPENSSL_READ_CRL_LEN_EACH_TIME = 1024; +const int32_t HapCertVerifyOpensslUtils::BASE64_ENCODE_LEN_OF_EACH_GROUP_DATA = 4; +const int32_t HapCertVerifyOpensslUtils::BASE64_ENCODE_PACKET_LEN = 3; +constexpr int32_t BUFF_SIZE = 3; X509* HapCertVerifyOpensslUtils::GetX509CertFromPemString(const std::string& pemString) { @@ -45,7 +45,7 @@ X509* HapCertVerifyOpensslUtils::GetX509CertFromPemString(const std::string& pem HAPVERIFY_LOG_ERROR(LABEL, "BIO_new failed"); return nullptr; } - int strLen = static_cast(pemString.size()); + int32_t strLen = static_cast(pemString.size()); if (BIO_write(pemBio, pemString.c_str(), strLen) != strLen) { HapVerifyOpensslUtils::GetOpensslErrorMessage(); HAPVERIFY_LOG_ERROR(LABEL, "BIO_write failed"); @@ -62,7 +62,7 @@ X509* HapCertVerifyOpensslUtils::GetX509CertFromBase64String(const std::string& std::unique_ptr decodeBuffer = std::make_unique(base64String.size()); const unsigned char* input = reinterpret_cast(base64String.c_str()); - int len = EVP_DecodeBlock(decodeBuffer.get(), input, base64String.size()); + int32_t len = EVP_DecodeBlock(decodeBuffer.get(), input, base64String.size()); if (len <= 0) { HapVerifyOpensslUtils::GetOpensslErrorMessage(); HAPVERIFY_LOG_ERROR(LABEL, "base64Decode failed, len: %{public}d", len); @@ -100,7 +100,7 @@ bool HapCertVerifyOpensslUtils::GetFingerprintBase64FromPemCert(const std::strin HAPVERIFY_LOG_ERROR(LABEL, "GetX509CertFromPemString failed"); return false; } - int certLen = i2d_X509(cert, nullptr); + int32_t certLen = i2d_X509(cert, nullptr); if (certLen <= 0) { HAPVERIFY_LOG_ERROR(LABEL, "certLen %{public}d, i2d_X509 failed", certLen); HapVerifyOpensslUtils::GetOpensslErrorMessage(); @@ -123,7 +123,7 @@ bool HapCertVerifyOpensslUtils::GetFingerprintBase64FromPemCert(const std::strin unsigned char hash[SHA256_DIGEST_LENGTH]; SHA256_Final(hash, &sha256); char buff[BUFF_SIZE] = {0}; - for (int index = 0; index < SHA256_DIGEST_LENGTH; ++index) { + for (int32_t index = 0; index < SHA256_DIGEST_LENGTH; ++index) { if (sprintf_s(buff, sizeof(buff), "%02X", hash[index]) < 0) { fingerprint.clear(); HAPVERIFY_LOG_ERROR(LABEL, "transforms hash string to hexadecimal string failed"); @@ -146,14 +146,14 @@ bool HapCertVerifyOpensslUtils::GetPublickeyBase64(const X509* cert, std::string return false; } - int keyLen = i2d_PublicKey(pkey, nullptr); + int32_t keyLen = i2d_PublicKey(pkey, nullptr); if (keyLen <= 0) { HAPVERIFY_LOG_ERROR(LABEL, "keyLen %{public}d, i2d_PublicKey failed", keyLen); HapVerifyOpensslUtils::GetOpensslErrorMessage(); return false; } std::unique_ptr derPublicKey = std::make_unique(keyLen); - int base64KeyLen = CalculateLenAfterBase64Encode(keyLen); + int32_t base64KeyLen = CalculateLenAfterBase64Encode(keyLen); std::unique_ptr base64PublicKey = std::make_unique(base64KeyLen); unsigned char* derCertificateBackup = derPublicKey.get(); if (i2d_PublicKey(pkey, &derCertificateBackup) <= 0) { @@ -162,7 +162,7 @@ bool HapCertVerifyOpensslUtils::GetPublickeyBase64(const X509* cert, std::string return false; } - int outLen = EVP_EncodeBlock(base64PublicKey.get(), derPublicKey.get(), keyLen); + int32_t outLen = EVP_EncodeBlock(base64PublicKey.get(), derPublicKey.get(), keyLen); publicKey = std::string(reinterpret_cast(base64PublicKey.get()), outLen); return true; } @@ -172,7 +172,7 @@ bool HapCertVerifyOpensslUtils::GetPublickeyBase64(const X509* cert, std::string * and openssl function will add '\0' to the encoded string. * So len_after_encode = len_before_encode * 4/3 + 1 */ -int HapCertVerifyOpensslUtils::CalculateLenAfterBase64Encode(int len) +int32_t HapCertVerifyOpensslUtils::CalculateLenAfterBase64Encode(int32_t len) { return static_cast(ceil(static_cast(len) / BASE64_ENCODE_PACKET_LEN) * BASE64_ENCODE_LEN_OF_EACH_GROUP_DATA + 1); @@ -195,7 +195,8 @@ bool HapCertVerifyOpensslUtils::CompareX509Cert(const X509* certA, const std::st return ret; } -X509_CRL* HapCertVerifyOpensslUtils::GetX509CrlFromDerBuffer(const HapByteBuffer& crlBuffer, int offset, int len) +X509_CRL* HapCertVerifyOpensslUtils::GetX509CrlFromDerBuffer( + const HapByteBuffer& crlBuffer, int32_t offset, int32_t len) { if (crlBuffer.GetBufferPtr() == nullptr) { HAPVERIFY_LOG_ERROR(LABEL, "invalid input, crlbuffer is null"); @@ -241,12 +242,12 @@ void HapCertVerifyOpensslUtils::WriteX509CrlToStream(std::ofstream& crlFile, X50 return; } - int totalLen = 0; + int32_t totalLen = 0; long long posStart = crlFile.tellp(); crlFile.seekp(posStart + sizeof(totalLen)); char buf[OPENSSL_READ_CRL_LEN_EACH_TIME]; - int readLen = BIO_read(derBio, buf, sizeof(buf)); - int readTime = 0; + int32_t readLen = BIO_read(derBio, buf, sizeof(buf)); + int32_t readTime = 0; while (readLen > 0 && (++readTime < OPENSSL_READ_CRL_MAX_TIME)) { crlFile.write(buf, readLen); totalLen += readLen; @@ -266,7 +267,7 @@ void HapCertVerifyOpensslUtils::GenerateCertSignFromCertStack(STACK_OF(X509)* ce return; } - for (int i = 0; i < sk_X509_num(certs); i++) { + for (int32_t i = 0; i < sk_X509_num(certs); i++) { X509* cert = sk_X509_value(certs, i); if (cert == nullptr) { continue; @@ -359,7 +360,7 @@ bool HapCertVerifyOpensslUtils::VerifyCertChainPeriodOfValidity(CertChain& certs return false; } - for (unsigned int i = 0; i < certsChain.size() - 1; i++) { + for (uint32_t i = 0; i < certsChain.size() - 1; i++) { if (certsChain[i] == nullptr) { HAPVERIFY_LOG_ERROR(LABEL, "%{public}dst cert is nullptr", i); return false; @@ -447,7 +448,7 @@ X509_CRL* HapCertVerifyOpensslUtils::GetCrlBySignedCertIssuer(STACK_OF(X509_CRL) } X509_NAME* certIssuer = X509_get_issuer_name(cert); - for (int i = 0; i < sk_X509_CRL_num(crls); i++) { + for (int32_t i = 0; i < sk_X509_CRL_num(crls); i++) { X509_CRL* crl = sk_X509_CRL_value(crls, i); if (crl == nullptr) { continue; @@ -543,9 +544,9 @@ std::string HapCertVerifyOpensslUtils::GetDnToString(X509_NAME* name) ", CN=" + commonName; } -void HapCertVerifyOpensslUtils::GetTextFromX509Name(X509_NAME* name, int nId, std::string& text) +void HapCertVerifyOpensslUtils::GetTextFromX509Name(X509_NAME* name, int32_t nId, std::string& text) { - int textLen = X509_NAME_get_text_by_NID(name, nId, nullptr, 0); + int32_t textLen = X509_NAME_get_text_by_NID(name, nId, nullptr, 0); if (textLen <= 0) { return; } diff --git a/interfaces/innerkits/appverify/src/util/hap_profile_verify_utils.cpp b/interfaces/innerkits/appverify/src/util/hap_profile_verify_utils.cpp index cb1c4194c98bf45b461fa4cbd6aeb1f98d402c68..129e0107e187f3d4aee6778a890f580ae3398c6e 100644 --- a/interfaces/innerkits/appverify/src/util/hap_profile_verify_utils.cpp +++ b/interfaces/innerkits/appverify/src/util/hap_profile_verify_utils.cpp @@ -35,7 +35,7 @@ bool HapProfileVerifyUtils::ParseProfile(Pkcs7Context& profilePkcs7Context, cons return true; } const unsigned char* pkcs7Block = reinterpret_cast(pkcs7ProfileBlock.GetBufferPtr()); - unsigned int pkcs7Len = static_cast(pkcs7ProfileBlock.GetCapacity()); + uint32_t pkcs7Len = static_cast(pkcs7ProfileBlock.GetCapacity()); if (!HapVerifyOpensslUtils::ParsePkcs7Package(pkcs7Block, pkcs7Len, profilePkcs7Context)) { HAPVERIFY_LOG_ERROR(LABEL, "parse pkcs7 failed"); return false; diff --git a/interfaces/innerkits/appverify/src/util/hap_signing_block_utils.cpp b/interfaces/innerkits/appverify/src/util/hap_signing_block_utils.cpp index d302fefba61fcbec969d163504e0f43fa1f54a29..5bfcd366b138389c158c77d35e0f4818b78e83dd 100644 --- a/interfaces/innerkits/appverify/src/util/hap_signing_block_utils.cpp +++ b/interfaces/innerkits/appverify/src/util/hap_signing_block_utils.cpp @@ -37,15 +37,15 @@ const long long HapSigningBlockUtils::HAP_SIG_BLOCK_MAGIC_HIGH = 449779798307046 /* 1MB = 1024 * 1024 Bytes */ const long long HapSigningBlockUtils::CHUNK_SIZE = 1048576LL; -const int HapSigningBlockUtils::HAP_SIG_BLOCK_MIN_SIZE = 32; -const int HapSigningBlockUtils::ZIP_HEAD_OF_SIGNING_BLOCK_LENGTH = 32; +const int32_t HapSigningBlockUtils::HAP_SIG_BLOCK_MIN_SIZE = 32; +const int32_t HapSigningBlockUtils::ZIP_HEAD_OF_SIGNING_BLOCK_LENGTH = 32; -const int HapSigningBlockUtils::ZIP_EOCD_SEG_MIN_SIZE = 22; -const int HapSigningBlockUtils::ZIP_EOCD_SEGMENT_FLAG = 0x06054b50; -const int HapSigningBlockUtils::ZIP_EOCD_COMMENT_LENGTH_OFFSET = 20; -const int HapSigningBlockUtils::ZIP_CD_OFFSET_IN_EOCD = 16; -const int HapSigningBlockUtils::ZIP_CD_SIZE_OFFSET_IN_EOCD = 12; -const int HapSigningBlockUtils::ZIP_BLOCKS_NUM_NEED_DIGEST = 3; +const int32_t HapSigningBlockUtils::ZIP_EOCD_SEG_MIN_SIZE = 22; +const int32_t HapSigningBlockUtils::ZIP_EOCD_SEGMENT_FLAG = 0x06054b50; +const int32_t HapSigningBlockUtils::ZIP_EOCD_COMMENT_LENGTH_OFFSET = 20; +const int32_t HapSigningBlockUtils::ZIP_CD_OFFSET_IN_EOCD = 16; +const int32_t HapSigningBlockUtils::ZIP_CD_SIZE_OFFSET_IN_EOCD = 12; +const int32_t HapSigningBlockUtils::ZIP_BLOCKS_NUM_NEED_DIGEST = 3; const char HapSigningBlockUtils::ZIP_FIRST_LEVEL_CHUNK_PREFIX = 0x5a; const char HapSigningBlockUtils::ZIP_SECOND_LEVEL_CHUNK_PREFIX = 0xa5; @@ -105,7 +105,7 @@ bool HapSigningBlockUtils::FindEocdInHap(RandomAccessFile& hapFile, unsigned sho return false; } - int searchRange = static_cast(maxCommentSize) + ZIP_EOCD_SEG_MIN_SIZE; + int32_t searchRange = static_cast(maxCommentSize) + ZIP_EOCD_SEG_MIN_SIZE; if (fileLength < static_cast(searchRange)) { searchRange = static_cast(fileLength); } @@ -118,7 +118,7 @@ bool HapSigningBlockUtils::FindEocdInHap(RandomAccessFile& hapFile, unsigned sho return false; } - int eocdOffsetInSearchBuffer = 0; + int32_t eocdOffsetInSearchBuffer = 0; if (!FindEocdInSearchBuffer(searchEocdBuffer, eocdOffsetInSearchBuffer)) { HAPVERIFY_LOG_ERROR(LABEL, "No Eocd is found"); return false; @@ -148,20 +148,20 @@ bool HapSigningBlockUtils::FindEocdInHap(RandomAccessFile& hapFile, unsigned sho */ bool HapSigningBlockUtils::FindEocdInSearchBuffer(HapByteBuffer& searchBuffer, int& offset) { - int searchBufferSize = searchBuffer.GetCapacity(); + int32_t searchBufferSize = searchBuffer.GetCapacity(); if (searchBufferSize < ZIP_EOCD_SEG_MIN_SIZE) { HAPVERIFY_LOG_ERROR(LABEL, "The size of searchBuffer %{public}d is smaller than min size of Eocd", searchBufferSize); return false; } - int currentOffset = searchBufferSize - ZIP_EOCD_SEG_MIN_SIZE; + int32_t currentOffset = searchBufferSize - ZIP_EOCD_SEG_MIN_SIZE; while (currentOffset >= 0) { - int hapEocdSegmentFlag; + int32_t hapEocdSegmentFlag; if (searchBuffer.GetInt32(currentOffset, hapEocdSegmentFlag) && (hapEocdSegmentFlag == ZIP_EOCD_SEGMENT_FLAG)) { unsigned short commentLength; - int expectedCommentLength = searchBufferSize - ZIP_EOCD_SEG_MIN_SIZE - currentOffset; + int32_t expectedCommentLength = searchBufferSize - ZIP_EOCD_SEG_MIN_SIZE - currentOffset; if (searchBuffer.GetUInt16(currentOffset + ZIP_EOCD_COMMENT_LENGTH_OFFSET, commentLength) && static_cast(commentLength) == expectedCommentLength) { offset = currentOffset; @@ -176,8 +176,8 @@ bool HapSigningBlockUtils::FindEocdInSearchBuffer(HapByteBuffer& searchBuffer, i bool HapSigningBlockUtils::GetCentralDirectoryOffset(HapByteBuffer& eocd, long long eocdOffset, long long& centralDirectoryOffset) { - unsigned int offsetValue; - unsigned int sizeValue; + uint32_t offsetValue; + uint32_t sizeValue; if (!eocd.GetUInt32(ZIP_CD_OFFSET_IN_EOCD, offsetValue) || !eocd.GetUInt32(ZIP_CD_SIZE_OFFSET_IN_EOCD, sizeValue)) { HAPVERIFY_LOG_ERROR(LABEL, "GetUInt32 failed"); @@ -200,7 +200,7 @@ bool HapSigningBlockUtils::GetCentralDirectoryOffset(HapByteBuffer& eocd, long l return true; } -bool HapSigningBlockUtils::SetUnsignedInt32(HapByteBuffer& buffer, int offset, long long value) +bool HapSigningBlockUtils::SetUnsignedInt32(HapByteBuffer& buffer, int32_t offset, long long value) { if ((value < 0) || (value > static_cast(UINT_MAX))) { HAPVERIFY_LOG_ERROR(LABEL, "uint32 value of out range: %{public}lld", value); @@ -313,7 +313,7 @@ bool HapSigningBlockUtils::ParseSubSignBlockHead(HapSubSignBlockHead& subSignBlo * This function reads the head of the HapSubSignBlocks, * and then reads the corresponding data of each block according to the offset provided by the head */ -bool HapSigningBlockUtils::FindHapSubSigningBlock(RandomAccessFile& hapFile, int blockCount, +bool HapSigningBlockUtils::FindHapSubSigningBlock(RandomAccessFile& hapFile, int32_t blockCount, long long blockArrayLen, long long hapSignBlockOffset, SignatureInfo& signInfo) { long long offsetMax = hapSignBlockOffset + blockArrayLen; @@ -321,7 +321,7 @@ bool HapSigningBlockUtils::FindHapSubSigningBlock(RandomAccessFile& hapFile, int long long readHeadOffset = hapSignBlockOffset; HAPVERIFY_LOG_DEBUG(LABEL, "hapSignBlockOffset %{public}lld blockArrayLen: %{public}lld blockCount: %{public}d", hapSignBlockOffset, blockArrayLen, blockCount); - for (int i = 0; i < blockCount; i++) { + for (int32_t i = 0; i < blockCount; i++) { HapByteBuffer hapBlockHead(ZIP_CD_SIZE_OFFSET_IN_EOCD); long long ret = hapFile.ReadFileFullyFromOffset(hapBlockHead, readHeadOffset); if (ret < 0) { @@ -379,7 +379,7 @@ bool HapSigningBlockUtils::FindHapSubSigningBlock(RandomAccessFile& hapFile, int } bool HapSigningBlockUtils::ClassifyHapSubSigningBlock(SignatureInfo& signInfo, - const HapByteBuffer& subBlock, unsigned int type) + const HapByteBuffer& subBlock, uint32_t type) { bool ret = false; switch (type) { @@ -408,10 +408,10 @@ bool HapSigningBlockUtils::ClassifyHapSubSigningBlock(SignatureInfo& signInfo, return ret; } -bool HapSigningBlockUtils::GetOptionalBlockIndex(std::vector& optionBlocks, int type, int& index) +bool HapSigningBlockUtils::GetOptionalBlockIndex(std::vector& optionBlocks, int32_t type, int& index) { - int len = static_cast(optionBlocks.size()); - for (int i = 0; i < len; i++) { + int32_t len = static_cast(optionBlocks.size()); + for (int32_t i = 0; i < len; i++) { if (optionBlocks[i].optionalType == type) { index = i; return true; @@ -433,7 +433,7 @@ bool HapSigningBlockUtils::VerifyHapIntegrity( HapFileDataSource centralDir(hapFile, signInfo.hapCentralDirOffset, centralDirSize, 0); HapByteBufferDataSource eocd(signInfo.hapEocd); DataSource* content[ZIP_BLOCKS_NUM_NEED_DIGEST] = { &contentsZip, ¢ralDir, &eocd }; - int nId = HapVerifyOpensslUtils::GetDigestAlgorithmId(digestInfo.digestAlgorithm); + int32_t nId = HapVerifyOpensslUtils::GetDigestAlgorithmId(digestInfo.digestAlgorithm); DigestParameter digestParam = GetDigestParameter(nId); HapByteBuffer chunkDigest; if (!ComputeDigestsForEachChunk(digestParam, content, ZIP_BLOCKS_NUM_NEED_DIGEST, chunkDigest)) { @@ -458,7 +458,7 @@ bool HapSigningBlockUtils::ComputeDigestsWithOptionalBlock(const DigestParameter const std::vector& optionalBlocks, const HapByteBuffer& chunkDigest, HapByteBuffer& finalDigest) { unsigned char out[EVP_MAX_MD_SIZE]; - int digestLen = HapVerifyOpensslUtils::GetDigest(chunkDigest, optionalBlocks, digestParam, out); + int32_t digestLen = HapVerifyOpensslUtils::GetDigest(chunkDigest, optionalBlocks, digestParam, out); if (digestLen != digestParam.digestOutputSizeBytes) { HAPVERIFY_LOG_ERROR(LABEL, "GetDigest failed, outLen is not right, %{public}u, %{public}d", digestLen, digestParam.digestOutputSizeBytes); @@ -470,10 +470,10 @@ bool HapSigningBlockUtils::ComputeDigestsWithOptionalBlock(const DigestParameter return true; } -bool HapSigningBlockUtils::GetSumOfChunkDigestLen(DataSource* contents[], int len, - int chunkDigestLen, int& chunkCount, int& sumOfChunkDigestLen) +bool HapSigningBlockUtils::GetSumOfChunkDigestLen(DataSource* contents[], int32_t len, + int32_t chunkDigestLen, int& chunkCount, int& sumOfChunkDigestLen) { - for (int i = 0; i < len; i++) { + for (int32_t i = 0; i < len; i++) { if (contents[i] == nullptr) { HAPVERIFY_LOG_ERROR(LABEL, "contents[%{public}d] is nullptr", i); return false; @@ -498,10 +498,10 @@ bool HapSigningBlockUtils::GetSumOfChunkDigestLen(DataSource* contents[], int le } bool HapSigningBlockUtils::ComputeDigestsForEachChunk(const DigestParameter& digestParam, - DataSource* contents[], int len, HapByteBuffer& result) + DataSource* contents[], int32_t len, HapByteBuffer& result) { - int chunkCount = 0; - int sumOfChunksLen = 0; + int32_t chunkCount = 0; + int32_t sumOfChunksLen = 0; if (!GetSumOfChunkDigestLen(contents, len, digestParam.digestOutputSizeBytes, chunkCount, sumOfChunksLen)) { HAPVERIFY_LOG_ERROR(LABEL, "GetSumOfChunkDigestLen failed"); return false; @@ -510,13 +510,13 @@ bool HapSigningBlockUtils::ComputeDigestsForEachChunk(const DigestParameter& dig result.PutByte(0, ZIP_FIRST_LEVEL_CHUNK_PREFIX); result.PutInt32(1, chunkCount); - int chunkIndex = 0; + int32_t chunkIndex = 0; unsigned char out[EVP_MAX_MD_SIZE]; unsigned char chunkContentPrefix[ZIP_CHUNK_DIGEST_PRIFIX_LEN] = {ZIP_SECOND_LEVEL_CHUNK_PREFIX, 0, 0, 0, 0}; - int offset = ZIP_CHUNK_DIGEST_PRIFIX_LEN; - for (int i = 0; i < len; i++) { + int32_t offset = ZIP_CHUNK_DIGEST_PRIFIX_LEN; + for (int32_t i = 0; i < len; i++) { while (contents[i]->HasRemaining()) { - int chunkSize = std::min(contents[i]->Remaining(), CHUNK_SIZE); + int32_t chunkSize = std::min(contents[i]->Remaining(), CHUNK_SIZE); if (!InitDigestPrefix(digestParam, chunkContentPrefix, chunkSize)) { HAPVERIFY_LOG_ERROR(LABEL, "InitDigestPrefix failed"); return false; @@ -527,7 +527,7 @@ bool HapSigningBlockUtils::ComputeDigestsForEachChunk(const DigestParameter& dig return false; } - int digestLen = HapVerifyOpensslUtils::GetDigest(digestParam, out); + int32_t digestLen = HapVerifyOpensslUtils::GetDigest(digestParam, out); if (digestLen != digestParam.digestOutputSizeBytes) { HAPVERIFY_LOG_ERROR(LABEL, "GetDigest failed len: %{public}d digestSizeBytes: %{public}d", digestLen, digestParam.digestOutputSizeBytes); @@ -541,7 +541,7 @@ bool HapSigningBlockUtils::ComputeDigestsForEachChunk(const DigestParameter& dig return true; } -DigestParameter HapSigningBlockUtils::GetDigestParameter(int nId) +DigestParameter HapSigningBlockUtils::GetDigestParameter(int32_t nId) { DigestParameter digestParam; digestParam.digestOutputSizeBytes = HapVerifyOpensslUtils::GetDigestAlgorithmOutputSizeBytes(nId); @@ -551,7 +551,7 @@ DigestParameter HapSigningBlockUtils::GetDigestParameter(int nId) return digestParam; } -int HapSigningBlockUtils::GetChunkCount(long long inputSize, long long chunkSize) +int32_t HapSigningBlockUtils::GetChunkCount(long long inputSize, long long chunkSize) { if (chunkSize <= 0 || inputSize > LLONG_MAX - chunkSize) { return 0; @@ -565,7 +565,7 @@ int HapSigningBlockUtils::GetChunkCount(long long inputSize, long long chunkSize } bool HapSigningBlockUtils::InitDigestPrefix(const DigestParameter& digestParam, - unsigned char (&chunkContentPrefix)[ZIP_CHUNK_DIGEST_PRIFIX_LEN], int chunkLen) + unsigned char (&chunkContentPrefix)[ZIP_CHUNK_DIGEST_PRIFIX_LEN], int32_t chunkLen) { if (memcpy_s((chunkContentPrefix + 1), ZIP_CHUNK_DIGEST_PRIFIX_LEN - 1, (&chunkLen), sizeof(chunkLen)) != EOK) { HAPVERIFY_LOG_ERROR(LABEL, "memcpy_s failed"); diff --git a/interfaces/innerkits/appverify/src/util/hap_verify_openssl_utils.cpp b/interfaces/innerkits/appverify/src/util/hap_verify_openssl_utils.cpp index 34762e09a849a4d1159e115125761a5bb8931985..ebed1cc5c755709302a73571b5f1402d4f747143 100644 --- a/interfaces/innerkits/appverify/src/util/hap_verify_openssl_utils.cpp +++ b/interfaces/innerkits/appverify/src/util/hap_verify_openssl_utils.cpp @@ -31,23 +31,23 @@ namespace Verify { using Pkcs7SignerInfoStack = STACK_OF(PKCS7_SIGNER_INFO); using X509AttributeStack = STACK_OF(X509_ATTRIBUTE); -const int HapVerifyOpensslUtils::OPENSSL_PKCS7_VERIFY_SUCCESS = 1; -const int HapVerifyOpensslUtils::OPENSSL_ERR_MESSAGE_MAX_LEN = 1024; +const int32_t HapVerifyOpensslUtils::OPENSSL_PKCS7_VERIFY_SUCCESS = 1; +const int32_t HapVerifyOpensslUtils::OPENSSL_ERR_MESSAGE_MAX_LEN = 1024; /* * OPENSSL_READ_DATA_MAX_TIME * OPENSSL_READ_DATA_LEN_EACH_TIME < 2GBytes. * make the maximum size of data that can be read each time be 1 KBytes, * so the maximum times of read data is 1024 * 1024 * 2 = 2097152; */ -const int HapVerifyOpensslUtils::OPENSSL_READ_DATA_MAX_TIME = 2097152; -const int HapVerifyOpensslUtils::OPENSSL_READ_DATA_LEN_EACH_TIME = 1024; +const int32_t HapVerifyOpensslUtils::OPENSSL_READ_DATA_MAX_TIME = 2097152; +const int32_t HapVerifyOpensslUtils::OPENSSL_READ_DATA_LEN_EACH_TIME = 1024; /* Signature algorithm OID for extended PKCS7 */ const std::string HapVerifyOpensslUtils::PKCS7_EXT_SHAWITHRSA_PSS = "1.2.840.113549.1.1.10"; -const int HapVerifyOpensslUtils::MAX_OID_LENGTH = 128; +const int32_t HapVerifyOpensslUtils::MAX_OID_LENGTH = 128; bool HapVerifyOpensslUtils::ParsePkcs7Package(const unsigned char packageData[], - unsigned int packageLen, Pkcs7Context& pkcs7Context) + uint32_t packageLen, Pkcs7Context& pkcs7Context) { if (packageData == nullptr || packageLen == 0) { HAPVERIFY_LOG_ERROR(LABEL, "invalid input"); @@ -83,13 +83,13 @@ bool HapVerifyOpensslUtils::GetCertChains(PKCS7* p7, Pkcs7Context& pkcs7Context) GetOpensslErrorMessage(); return false; } - int signCount = sk_PKCS7_SIGNER_INFO_num(signerInfoStack); + int32_t signCount = sk_PKCS7_SIGNER_INFO_num(signerInfoStack); if (signCount <= 0) { HAPVERIFY_LOG_ERROR(LABEL, "can not find signinfo"); return false; } - for (int i = 0; i < signCount; i++) { + for (int32_t i = 0; i < signCount; i++) { /* get ith signInfo */ PKCS7_SIGNER_INFO* signInfo = sk_PKCS7_SIGNER_INFO_value(signerInfoStack, i); if (signInfo == nullptr) { @@ -166,8 +166,8 @@ bool HapVerifyOpensslUtils::VerifyPkcs7SignedData(Pkcs7Context& pkcs7Context) return false; } char buf[OPENSSL_READ_DATA_LEN_EACH_TIME] = {0}; - int readLen = BIO_read(p7Bio, buf, sizeof(buf)); - int readTime = 0; + int32_t readLen = BIO_read(p7Bio, buf, sizeof(buf)); + int32_t readTime = 0; while ((readLen > 0) && (++readTime < OPENSSL_READ_DATA_MAX_TIME)) { readLen = BIO_read(p7Bio, buf, sizeof(buf)); } @@ -179,13 +179,13 @@ bool HapVerifyOpensslUtils::VerifyPkcs7SignedData(Pkcs7Context& pkcs7Context) return false; } /* get the num of signInfo */ - int signCount = sk_PKCS7_SIGNER_INFO_num(signerInfoStack); + int32_t signCount = sk_PKCS7_SIGNER_INFO_num(signerInfoStack); if (signCount <= 0) { HAPVERIFY_LOG_ERROR(LABEL, "can not find signinfo"); BIO_free_all(p7Bio); return false; } - for (int i = 0; i < signCount; i++) { + for (int32_t i = 0; i < signCount; i++) { if (!VerifySignInfo(signerInfoStack, p7Bio, i, pkcs7Context)) { HAPVERIFY_LOG_ERROR(LABEL, "Verify %{public}dst signInfo failed", i); BIO_free_all(p7Bio); @@ -197,7 +197,7 @@ bool HapVerifyOpensslUtils::VerifyPkcs7SignedData(Pkcs7Context& pkcs7Context) } bool HapVerifyOpensslUtils::VerifySignInfo(STACK_OF(PKCS7_SIGNER_INFO)* signerInfoStack, - BIO* p7Bio, int signInfoNum, Pkcs7Context& pkcs7Context) { + BIO* p7Bio, int32_t signInfoNum, Pkcs7Context& pkcs7Context) { if (signerInfoStack == nullptr || p7Bio == nullptr) { HAPVERIFY_LOG_ERROR(LABEL, "invalid input"); return false; @@ -239,7 +239,7 @@ bool HapVerifyOpensslUtils::IsEnablePss(const PKCS7_SIGNER_INFO* signInfo) HAPVERIFY_LOG_ERROR(LABEL, "signInfo->digest_enc_alg is nullptr"); return false; } - int len = OBJ_obj2txt(oId, sizeof(oId), signInfo->digest_enc_alg->algorithm, 1); + int32_t len = OBJ_obj2txt(oId, sizeof(oId), signInfo->digest_enc_alg->algorithm, 1); if (len < 0 || len >= MAX_OID_LENGTH) { HAPVERIFY_LOG_ERROR(LABEL, "Get length of oId failed"); return false; @@ -254,7 +254,7 @@ bool HapVerifyOpensslUtils::VerifyShaWithRsaPss(const PKCS7_SIGNER_INFO* signInf HAPVERIFY_LOG_ERROR(LABEL, "signInfo->digest_alg is nullptr"); return false; } - int mdType = OBJ_obj2nid(signInfo->digest_alg->algorithm); + int32_t mdType = OBJ_obj2nid(signInfo->digest_alg->algorithm); const EVP_MD_CTX* mdCtx = FindMdCtxInBio(p7Bio, mdType); EVP_MD_CTX* mdCtxTmp = EVP_MD_CTX_new(); if (mdCtxTmp == nullptr) { @@ -273,7 +273,7 @@ bool HapVerifyOpensslUtils::VerifyShaWithRsaPss(const PKCS7_SIGNER_INFO* signInf } unsigned char digest[EVP_MAX_MD_SIZE]; - unsigned int digestLen; + uint32_t digestLen; if (EVP_DigestFinal_ex(mdCtxTmp, digest, &digestLen) <= 0) { HAPVERIFY_LOG_ERROR(LABEL, "Digest content failed"); GetOpensslErrorMessage(); @@ -290,7 +290,7 @@ bool HapVerifyOpensslUtils::VerifyShaWithRsaPss(const PKCS7_SIGNER_INFO* signInf return true; } -const EVP_MD_CTX* HapVerifyOpensslUtils::FindMdCtxInBio(BIO* p7Bio, int mdType) +const EVP_MD_CTX* HapVerifyOpensslUtils::FindMdCtxInBio(BIO* p7Bio, int32_t mdType) { EVP_MD_CTX* mdCtx = nullptr; while (p7Bio) { @@ -307,12 +307,13 @@ const EVP_MD_CTX* HapVerifyOpensslUtils::FindMdCtxInBio(BIO* p7Bio, int mdType) return mdCtx; } -bool HapVerifyOpensslUtils::VerifyPkcs7AuthAttributes(const PKCS7_SIGNER_INFO* signInfo, EVP_MD_CTX* mdCtx, int mdType) +bool HapVerifyOpensslUtils::VerifyPkcs7AuthAttributes( + const PKCS7_SIGNER_INFO* signInfo, EVP_MD_CTX* mdCtx, int32_t mdType) { X509AttributeStack* authAttributes = signInfo->auth_attr; if ((authAttributes != nullptr) && (sk_X509_ATTRIBUTE_num(authAttributes) != 0)) { unsigned char digest[EVP_MAX_MD_SIZE]; - unsigned int digestLen; + uint32_t digestLen; if (EVP_DigestFinal_ex(mdCtx, digest, &digestLen) <= 0) { HAPVERIFY_LOG_ERROR(LABEL, "Digest content failed"); GetOpensslErrorMessage(); @@ -331,7 +332,7 @@ bool HapVerifyOpensslUtils::VerifyPkcs7AuthAttributes(const PKCS7_SIGNER_INFO* s } unsigned char* attributesData = nullptr; - int attributesLen = ASN1_item_i2d(reinterpret_cast(authAttributes), &attributesData, + int32_t attributesLen = ASN1_item_i2d(reinterpret_cast(authAttributes), &attributesData, ASN1_ITEM_rptr(PKCS7_ATTR_VERIFY)); if (attributesLen <= 0 || attributesData == nullptr) { HAPVERIFY_LOG_ERROR(LABEL, "ASN1_item_i2d failed"); @@ -349,7 +350,7 @@ bool HapVerifyOpensslUtils::VerifyPkcs7AuthAttributes(const PKCS7_SIGNER_INFO* s return true; } -bool HapVerifyOpensslUtils::AsnStringCmp(const ASN1_OCTET_STRING* asnStr, const unsigned char data[], int len) +bool HapVerifyOpensslUtils::AsnStringCmp(const ASN1_OCTET_STRING* asnStr, const unsigned char data[], int32_t len) { if (asnStr == nullptr) { HAPVERIFY_LOG_ERROR(LABEL, "asnStr is nullptr"); @@ -367,7 +368,7 @@ bool HapVerifyOpensslUtils::AsnStringCmp(const ASN1_OCTET_STRING* asnStr, const HAPVERIFY_LOG_ERROR(LABEL, "asnStr->length: %{public}d is not equal to len: %{public}d", asnStr->length, len); return false; } - for (int i = 0; i < len; i++) { + for (int32_t i = 0; i < len; i++) { if (asnStr->data[i] != data[i]) { HAPVERIFY_LOG_ERROR(LABEL, "%{public}dst data is not equal", i); return false; @@ -377,7 +378,7 @@ bool HapVerifyOpensslUtils::AsnStringCmp(const ASN1_OCTET_STRING* asnStr, const } bool HapVerifyOpensslUtils::VerifyShaWithRsaPss(const PKCS7_SIGNER_INFO* signInfo, EVP_PKEY* pkey, bool isPss, - const unsigned char digest[], unsigned int digestLen) + const unsigned char digest[], uint32_t digestLen) { EVP_PKEY_CTX* pkeyCtx = EVP_PKEY_CTX_new(pkey, nullptr); if (pkeyCtx == nullptr) { @@ -396,7 +397,7 @@ bool HapVerifyOpensslUtils::VerifyShaWithRsaPss(const PKCS7_SIGNER_INFO* signInf EVP_PKEY_CTX_free(pkeyCtx); return false; } - int mdType = OBJ_obj2nid(signInfo->digest_alg->algorithm); + int32_t mdType = OBJ_obj2nid(signInfo->digest_alg->algorithm); if ((isPss && EVP_PKEY_CTX_set_rsa_padding(pkeyCtx, RSA_PKCS1_PSS_PADDING) <= 0) || (EVP_PKEY_CTX_set_signature_md(pkeyCtx, EVP_get_digestbynid(mdType)) <= 0)) { HAPVERIFY_LOG_ERROR(LABEL, "set rsa_padding or signature_md failed"); @@ -417,7 +418,7 @@ bool HapVerifyOpensslUtils::VerifyShaWithRsaPss(const PKCS7_SIGNER_INFO* signInf bool HapVerifyOpensslUtils::GetPublickeys(const CertChain& signCertChain, std::vector& SignatureVec) { - for (unsigned int i = 0; i < signCertChain.size(); i++) { + for (uint32_t i = 0; i < signCertChain.size(); i++) { if (!GetPublickeyFromCertificate(signCertChain[i], SignatureVec)) { HAPVERIFY_LOG_ERROR(LABEL, "%{public}ust Get Publickey failed", i); return false; @@ -429,7 +430,7 @@ bool HapVerifyOpensslUtils::GetPublickeys(const CertChain& signCertChain, bool HapVerifyOpensslUtils::GetSignatures(const CertChain& signCertChain, std::vector& SignatureVec) { - for (unsigned int i = 0; i < signCertChain.size(); i++) { + for (uint32_t i = 0; i < signCertChain.size(); i++) { if (!GetDerCert(signCertChain[i], SignatureVec)) { HAPVERIFY_LOG_ERROR(LABEL, "%{public}ust GetDerCert failed", i); return false; @@ -444,14 +445,14 @@ bool HapVerifyOpensslUtils::GetDerCert(X509* ptrX509, std::vector& return false; } - int certLen = i2d_X509(ptrX509, nullptr); + int32_t certLen = i2d_X509(ptrX509, nullptr); if (certLen <= 0) { HAPVERIFY_LOG_ERROR(LABEL, "certLen %{public}d, i2d_X509 failed", certLen); GetOpensslErrorMessage(); return false; } std::unique_ptr derCertificate = std::make_unique(certLen); - int base64CertLen = HapCertVerifyOpensslUtils::CalculateLenAfterBase64Encode(certLen); + int32_t base64CertLen = HapCertVerifyOpensslUtils::CalculateLenAfterBase64Encode(certLen); std::unique_ptr base64Certificate = std::make_unique(base64CertLen); unsigned char* derCertificateBackup = derCertificate.get(); if (i2d_X509(ptrX509, &derCertificateBackup) <= 0) { @@ -461,7 +462,7 @@ bool HapVerifyOpensslUtils::GetDerCert(X509* ptrX509, std::vector& } /* base64 encode */ - int len = EVP_EncodeBlock(base64Certificate.get(), derCertificate.get(), certLen); + int32_t len = EVP_EncodeBlock(base64Certificate.get(), derCertificate.get(), certLen); SignatureVec.emplace_back(std::string(reinterpret_cast(base64Certificate.get()), len)); return true; } @@ -494,7 +495,7 @@ bool HapVerifyOpensslUtils::GetContentInfo(const PKCS7* p7ContentInfo, HapByteBu return false; } - int strContentInfoLen = strContentInfo->length; + int32_t strContentInfoLen = strContentInfo->length; unsigned char* strContentInfoData = strContentInfo->data; if (strContentInfoData == nullptr || strContentInfoLen <= 0) { HAPVERIFY_LOG_ERROR(LABEL, "ASN1_OCTET_STRING is invalid"); @@ -507,7 +508,7 @@ bool HapVerifyOpensslUtils::GetContentInfo(const PKCS7* p7ContentInfo, HapByteBu return true; } -int HapVerifyOpensslUtils::GetDigestAlgorithmOutputSizeBytes(int nId) +int32_t HapVerifyOpensslUtils::GetDigestAlgorithmOutputSizeBytes(int32_t nId) { return EVP_MD_size(EVP_get_digestbynid(nId)); } @@ -540,7 +541,7 @@ bool HapVerifyOpensslUtils::DigestInit(const DigestParameter& digestParameter) /* the caller must ensure that EVP_DigestInit was called before calling this function */ bool HapVerifyOpensslUtils::DigestUpdate(const DigestParameter& digestParameter, - const unsigned char content[], int len) + const unsigned char content[], int32_t len) { if (content == nullptr) { HAPVERIFY_LOG_ERROR(LABEL, "content is nullptr"); @@ -557,9 +558,9 @@ bool HapVerifyOpensslUtils::DigestUpdate(const DigestParameter& digestParameter, return true; } -int HapVerifyOpensslUtils::GetDigest(const DigestParameter& digestParameter, unsigned char (&out)[EVP_MAX_MD_SIZE]) +int32_t HapVerifyOpensslUtils::GetDigest(const DigestParameter& digestParameter, unsigned char (&out)[EVP_MAX_MD_SIZE]) { - unsigned int outLen = 0; + uint32_t outLen = 0; if (!CheckDigestParameter(digestParameter)) { return outLen; } @@ -571,11 +572,11 @@ int HapVerifyOpensslUtils::GetDigest(const DigestParameter& digestParameter, uns return outLen; } -int HapVerifyOpensslUtils::GetDigest(const HapByteBuffer& chunk, const std::vector& optionalBlocks, +int32_t HapVerifyOpensslUtils::GetDigest(const HapByteBuffer& chunk, const std::vector& optionalBlocks, const DigestParameter& digestParameter, unsigned char (&out)[EVP_MAX_MD_SIZE]) { - int chunkLen = chunk.Remaining(); - unsigned int outLen = 0; + int32_t chunkLen = chunk.Remaining(); + uint32_t outLen = 0; if (digestParameter.md == nullptr) { HAPVERIFY_LOG_ERROR(LABEL, "md is nullprt"); return outLen; @@ -596,7 +597,7 @@ int HapVerifyOpensslUtils::GetDigest(const HapByteBuffer& chunk, const std::vect HAPVERIFY_LOG_ERROR(LABEL, "EVP_DigestUpdate chunk failed"); return outLen; } - for (int i = 0; i < static_cast(optionalBlocks.size()); i++) { + for (int32_t i = 0; i < static_cast(optionalBlocks.size()); i++) { chunkLen = optionalBlocks[i].optionalBlockValue.GetCapacity(); if (EVP_DigestUpdate(digestParameter.ptrCtx, optionalBlocks[i].optionalBlockValue.GetBufferPtr(), chunkLen) <= 0) { @@ -624,7 +625,7 @@ void HapVerifyOpensslUtils::GetOpensslErrorMessage() } } -int HapVerifyOpensslUtils::GetDigestAlgorithmId(int signAlgorithm) +int32_t HapVerifyOpensslUtils::GetDigestAlgorithmId(int32_t signAlgorithm) { switch (signAlgorithm) { case ALGORITHM_SHA256_WITH_RSA_PSS: diff --git a/interfaces/innerkits/appverify/src/verify/hap_verify_v2.cpp b/interfaces/innerkits/appverify/src/verify/hap_verify_v2.cpp index 09013f3fcce4ebd74d3873f6b7e794d15e6d6332..6379eb2ca82cfdd0da52f5d4086a42a13d84f9c3 100644 --- a/interfaces/innerkits/appverify/src/verify/hap_verify_v2.cpp +++ b/interfaces/innerkits/appverify/src/verify/hap_verify_v2.cpp @@ -32,16 +32,16 @@ namespace OHOS { namespace Security { namespace Verify { -const int HapVerifyV2::HEX_PRINT_LENGTH = 3; -const int HapVerifyV2::DIGEST_BLOCK_LEN_OFFSET = 8; -const int HapVerifyV2::DIGEST_ALGORITHM_OFFSET = 12; -const int HapVerifyV2::DIGEST_LEN_OFFSET = 16; -const int HapVerifyV2::DIGEST_OFFSET_IN_CONTENT = 20; +const int32_t HapVerifyV2::HEX_PRINT_LENGTH = 3; +const int32_t HapVerifyV2::DIGEST_BLOCK_LEN_OFFSET = 8; +const int32_t HapVerifyV2::DIGEST_ALGORITHM_OFFSET = 12; +const int32_t HapVerifyV2::DIGEST_LEN_OFFSET = 16; +const int32_t HapVerifyV2::DIGEST_OFFSET_IN_CONTENT = 20; const std::string HapVerifyV2::HAP_APP_PATTERN = "[^]*.hap$"; const std::string HapVerifyV2::HQF_APP_PATTERN = "[^]*.hqf$"; const std::string HapVerifyV2::HSP_APP_PATTERN = "[^]*.hsp$"; -int HapVerifyV2::Verify(const std::string& filePath, HapVerifyResult& hapVerifyV1Result) +int32_t HapVerifyV2::Verify(const std::string& filePath, HapVerifyResult& hapVerifyV1Result) { HAPVERIFY_LOG_DEBUG(LABEL, "Start Verify"); std::string standardFilePath; @@ -55,7 +55,7 @@ int HapVerifyV2::Verify(const std::string& filePath, HapVerifyResult& hapVerifyV return OPEN_FILE_ERROR; } - int resultCode = Verify(hapFile, hapVerifyV1Result); + int32_t resultCode = Verify(hapFile, hapVerifyV1Result); return resultCode; } @@ -76,7 +76,7 @@ bool HapVerifyV2::CheckFilePath(const std::string& filePath, std::string& standa return true; } -int HapVerifyV2::Verify(RandomAccessFile& hapFile, HapVerifyResult& hapVerifyV1Result) +int32_t HapVerifyV2::Verify(RandomAccessFile& hapFile, HapVerifyResult& hapVerifyV1Result) { SignatureInfo hapSignInfo; if (!HapSigningBlockUtils::FindHapSignature(hapFile, hapSignInfo)) { @@ -90,7 +90,7 @@ int HapVerifyV2::Verify(RandomAccessFile& hapFile, HapVerifyResult& hapVerifyV1R if (!VerifyAppPkcs7(pkcs7Context, hapSignInfo.hapSignatureBlock)) { return VERIFY_APP_PKCS7_FAIL; } - int profileIndex = 0; + int32_t profileIndex = 0; if (!HapSigningBlockUtils::GetOptionalBlockIndex(hapSignInfo.optionBlocks, PROFILE_BLOB, profileIndex)) { return NO_PROFILE_BLOCK_FAIL; } @@ -127,7 +127,7 @@ int HapVerifyV2::Verify(RandomAccessFile& hapFile, HapVerifyResult& hapVerifyV1R bool HapVerifyV2::VerifyAppPkcs7(Pkcs7Context& pkcs7Context, const HapByteBuffer& hapSignatureBlock) { const unsigned char* pkcs7Block = reinterpret_cast(hapSignatureBlock.GetBufferPtr()); - unsigned int pkcs7Len = static_cast(hapSignatureBlock.GetCapacity()); + uint32_t pkcs7Len = static_cast(hapSignatureBlock.GetCapacity()); if (!HapVerifyOpensslUtils::ParsePkcs7Package(pkcs7Block, pkcs7Len, pkcs7Context)) { HAPVERIFY_LOG_ERROR(LABEL, "parse pkcs7 failed"); return false; @@ -348,7 +348,7 @@ bool HapVerifyV2::GetDigestAndAlgorithm(Pkcs7Context& digest) * byte[]: digest */ /* length of sizeof(digestblock - 4) */ - int digestBlockLen; + int32_t digestBlockLen; if (!digest.content.GetInt32(DIGEST_BLOCK_LEN_OFFSET, digestBlockLen)) { HAPVERIFY_LOG_ERROR(LABEL, "get digestBlockLen failed"); return false; @@ -359,13 +359,13 @@ bool HapVerifyV2::GetDigestAndAlgorithm(Pkcs7Context& digest) return false; } /* length of digest */ - int digestlen; + int32_t digestlen; if (!digest.content.GetInt32(DIGEST_LEN_OFFSET, digestlen)) { HAPVERIFY_LOG_ERROR(LABEL, "get digestlen failed"); return false; } - int sum = sizeof(digestlen) + sizeof(digest.digestAlgorithm) + digestlen; + int32_t sum = sizeof(digestlen) + sizeof(digest.digestAlgorithm) + digestlen; if (sum != digestBlockLen) { HAPVERIFY_LOG_ERROR(LABEL, "digestBlockLen: %{public}d is not equal to sum: %{public}d", digestBlockLen, sum); @@ -379,7 +379,7 @@ bool HapVerifyV2::GetDigestAndAlgorithm(Pkcs7Context& digest) return true; } -int HapVerifyV2::ParseHapProfile(const std::string& filePath, HapVerifyResult& hapVerifyV1Result) +int32_t HapVerifyV2::ParseHapProfile(const std::string& filePath, HapVerifyResult& hapVerifyV1Result) { HAPVERIFY_LOG_INFO(LABEL, "start to ParseHapProfile"); std::string standardFilePath; @@ -398,13 +398,13 @@ int HapVerifyV2::ParseHapProfile(const std::string& filePath, HapVerifyResult& h return SIGNATURE_NOT_FOUND; } - int profileIndex = 0; + int32_t profileIndex = 0; if (!HapSigningBlockUtils::GetOptionalBlockIndex(hapSignInfo.optionBlocks, PROFILE_BLOB, profileIndex)) { return NO_PROFILE_BLOCK_FAIL; } auto pkcs7ProfileBlock = hapSignInfo.optionBlocks[profileIndex].optionalBlockValue; const unsigned char* pkcs7Block = reinterpret_cast(pkcs7ProfileBlock.GetBufferPtr()); - unsigned int pkcs7Len = static_cast(pkcs7ProfileBlock.GetCapacity()); + uint32_t pkcs7Len = static_cast(pkcs7ProfileBlock.GetCapacity()); Pkcs7Context profileContext; if (!HapVerifyOpensslUtils::ParsePkcs7Package(pkcs7Block, pkcs7Len, profileContext)) { HAPVERIFY_LOG_ERROR(LABEL, "parse pkcs7 failed"); diff --git a/interfaces/innerkits/appverify/test/unittest/include/hap_byte_buffer_test.h b/interfaces/innerkits/appverify/test/unittest/include/hap_byte_buffer_test.h index 6dd2747c5cd153952f1abcd19ddf8d46ffd7cd02..a527bf37644f110686cf0c7634e43b6226663a9a 100644 --- a/interfaces/innerkits/appverify/test/unittest/include/hap_byte_buffer_test.h +++ b/interfaces/innerkits/appverify/test/unittest/include/hap_byte_buffer_test.h @@ -15,10 +15,13 @@ #ifndef HAP_BYTE_BUFFER_TEST_H #define HAP_BYTE_BUFFER_TEST_H -int HapByteBuffer001(void); -int GetIntAndPutOperation001(void); -int Slice001(void); -int CopyPartialBuffer001(void); -int IsEqual001(void); -int IsEqual002(void); + +#include + +int32_t HapByteBuffer001(void); +int32_t GetIntAndPutOperation001(void); +int32_t Slice001(void); +int32_t CopyPartialBuffer001(void); +int32_t IsEqual001(void); +int32_t IsEqual002(void); #endif // HAP_BYTE_BUFFER_TEST_H diff --git a/interfaces/innerkits/appverify/test/unittest/include/hap_cert_verify_openssl_utils_test.h b/interfaces/innerkits/appverify/test/unittest/include/hap_cert_verify_openssl_utils_test.h index 06799ae180518785c361945355d0b15c1fed2aa0..e343f0cce6a8c4937386aba00768fbfe186981e5 100644 --- a/interfaces/innerkits/appverify/test/unittest/include/hap_cert_verify_openssl_utils_test.h +++ b/interfaces/innerkits/appverify/test/unittest/include/hap_cert_verify_openssl_utils_test.h @@ -15,6 +15,7 @@ #ifndef HAP_CERT_VERIFY_OPENSSL_UTILS_TEST_H #define HAP_CERT_VERIFY_OPENSSL_UTILS_TEST_H +#include #include #include "common/hap_byte_buffer.h" @@ -28,16 +29,16 @@ bool Base64StringDecode(const std::string& base64String, HapByteBuffer& output); } } } -int GetCertInfo001(void); -int CertVerify001(void); -int Base64NotUrlSafeCertTest001(void); -int GetX509CrlFromDerBufferTest001(void); -int GetCertsChainTest001(void); -int GetIssuerAndSubjectTest001(void); -int GetSerialNumberFromX509Test001(void); -int VerifyCertChainPeriodOfValidityTest001(void); -int VerifyCrlTest001(void); -int CompareX509CertTest001(void); -int WriteX509CrlToStreamTest001(void); -int PrivateFuncInvalidInputTest001(void); +int32_t GetCertInfo001(void); +int32_t CertVerify001(void); +int32_t Base64NotUrlSafeCertTest001(void); +int32_t GetX509CrlFromDerBufferTest001(void); +int32_t GetCertsChainTest001(void); +int32_t GetIssuerAndSubjectTest001(void); +int32_t GetSerialNumberFromX509Test001(void); +int32_t VerifyCertChainPeriodOfValidityTest001(void); +int32_t VerifyCrlTest001(void); +int32_t CompareX509CertTest001(void); +int32_t WriteX509CrlToStreamTest001(void); +int32_t PrivateFuncInvalidInputTest001(void); #endif // HAP_CERT_VERIFY_OPENSSL_UTILS_TEST_H diff --git a/interfaces/innerkits/appverify/test/unittest/include/hap_crl_manager_test.h b/interfaces/innerkits/appverify/test/unittest/include/hap_crl_manager_test.h index 507dbb5c8a6222393c1682a73e1e9261b2fdc45b..4f43dd59d6abcd56c0df1533d0b4a6a4e2de5d20 100644 --- a/interfaces/innerkits/appverify/test/unittest/include/hap_crl_manager_test.h +++ b/interfaces/innerkits/appverify/test/unittest/include/hap_crl_manager_test.h @@ -15,7 +15,9 @@ #ifndef HAP_CRL_MANAGER_TEST_H #define HAP_CRL_MANAGER_TEST_H +#include + #include "test_const.h" -int WriteAndReadCrlsFileTest001(void); +int32_t WriteAndReadCrlsFileTest001(void); #endif // HAP_CRL_MANAGER_TEST_H diff --git a/interfaces/innerkits/appverify/test/unittest/include/hap_signing_block_utils_test.h b/interfaces/innerkits/appverify/test/unittest/include/hap_signing_block_utils_test.h index faabe77fddd66c344f94ff10aec32a5abe10c388..74b60c3fdcebebcd9759fb2d5928d71ea94091de 100644 --- a/interfaces/innerkits/appverify/test/unittest/include/hap_signing_block_utils_test.h +++ b/interfaces/innerkits/appverify/test/unittest/include/hap_signing_block_utils_test.h @@ -16,6 +16,7 @@ #ifndef HAP_SIGNING_BLOCK_UTILS_TEST_H #define HAP_SIGNING_BLOCK_UTILS_TEST_H +#include #include #include "util/signature_info.h" @@ -29,11 +30,11 @@ long long CreatTestZipFile(const std::string& pathFile, SignatureInfo& signInfo) } } } -int FindHapSignatureTest001(void); -int VerifyHapIntegrityTest001(void); -int FindEocdInHapTest001(void); -int GetCentralDirectoryOffsetTest001(void); -int ClassifyHapSubSigningBlock001(void); -int ComputeDigestsWithOptionalBlock001(void); -int GetSumOfChunkDigestLenTest001(void); +int32_t FindHapSignatureTest001(void); +int32_t VerifyHapIntegrityTest001(void); +int32_t FindEocdInHapTest001(void); +int32_t GetCentralDirectoryOffsetTest001(void); +int32_t ClassifyHapSubSigningBlock001(void); +int32_t ComputeDigestsWithOptionalBlock001(void); +int32_t GetSumOfChunkDigestLenTest001(void); #endif // HAP_SIGNING_BLOCK_UTILS_TEST_H diff --git a/interfaces/innerkits/appverify/test/unittest/include/hap_verify_openssl_utils_test.h b/interfaces/innerkits/appverify/test/unittest/include/hap_verify_openssl_utils_test.h index 007b07637837bfc77eba5bf14c7379d13b614381..7b1eeb11421ddb52fff50710f95b752274b3e87b 100644 --- a/interfaces/innerkits/appverify/test/unittest/include/hap_verify_openssl_utils_test.h +++ b/interfaces/innerkits/appverify/test/unittest/include/hap_verify_openssl_utils_test.h @@ -15,8 +15,10 @@ #ifndef HAP_VERIFY_OPENSSL_UTILS_TEST_H #define HAP_VERIFY_OPENSSL_UTILS_TEST_H +#include + #include "test_const.h" -int VerifyPkcs7001(void); -int GetDigestAlgorithmId001(void); +int32_t VerifyPkcs7001(void); +int32_t GetDigestAlgorithmId001(void); #endif // HAP_VERIFY_OPENSSL_UTILS_TEST_H diff --git a/interfaces/innerkits/appverify/test/unittest/include/hap_verify_result_test.h b/interfaces/innerkits/appverify/test/unittest/include/hap_verify_result_test.h index 8a5c9f97e7f863555f09ee7befe7804efcfed829..8d88165c1711c104522927d32c1ac8d307a6c7b7 100644 --- a/interfaces/innerkits/appverify/test/unittest/include/hap_verify_result_test.h +++ b/interfaces/innerkits/appverify/test/unittest/include/hap_verify_result_test.h @@ -15,9 +15,11 @@ #ifndef HAP_VERIFY_RESULT_TEST_H #define HAP_VERIFY_RESULT_TEST_H +#include + #include "test_const.h" -int GetPublicKeyAndSignature001(void); -int GetProfileAndProperty001(void); -int SetVersionAndGetVersion001(void); +int32_t GetPublicKeyAndSignature001(void); +int32_t GetProfileAndProperty001(void); +int32_t SetVersionAndGetVersion001(void); #endif // HAP_VERIFY_RESULT_TEST_H diff --git a/interfaces/innerkits/appverify/test/unittest/include/hap_verify_test.h b/interfaces/innerkits/appverify/test/unittest/include/hap_verify_test.h index e6268aecb33f7941b74f7427b5dc858aa99e367d..1140660e67911c09aacb293e86d6dfaa8b28f9f4 100644 --- a/interfaces/innerkits/appverify/test/unittest/include/hap_verify_test.h +++ b/interfaces/innerkits/appverify/test/unittest/include/hap_verify_test.h @@ -15,8 +15,10 @@ #ifndef HAP_VERIFY_TEST_H #define HAP_VERIFY_TEST_H -int HapVerify001(void); -int HapVerifyEnableDebug001(void); -int HapVerify002(void); -int HapVerifyOsApp001(void); +#include + +int32_t HapVerify001(void); +int32_t HapVerifyEnableDebug001(void); +int32_t HapVerify002(void); +int32_t HapVerifyOsApp001(void); #endif // HAP_VERIFY_TEST_H diff --git a/interfaces/innerkits/appverify/test/unittest/include/hap_verify_v2_test.h b/interfaces/innerkits/appverify/test/unittest/include/hap_verify_v2_test.h index 4805fbb19f9891b99c97f47a938d75b66234dc4d..939a75a1df1dcf583aa7cd8ccb8f401e0e3c4c46 100644 --- a/interfaces/innerkits/appverify/test/unittest/include/hap_verify_v2_test.h +++ b/interfaces/innerkits/appverify/test/unittest/include/hap_verify_v2_test.h @@ -15,11 +15,13 @@ #ifndef HAP_VERIFY_V2_TEST_H #define HAP_VERIFY_V2_TEST_H +#include + #include "test_const.h" -int CheckFilePathTest001(void); -int GenerateAppIdTest001(void); -int VerifyProfileInfoTest001(void); -int ParseAndVerifyProfileIfNeedTest001(void); -int GetDigestAndAlgorithmTest001(void); +int32_t CheckFilePathTest001(void); +int32_t GenerateAppIdTest001(void); +int32_t VerifyProfileInfoTest001(void); +int32_t ParseAndVerifyProfileIfNeedTest001(void); +int32_t GetDigestAndAlgorithmTest001(void); #endif // HAP_VERIFY_V2_TEST_H diff --git a/interfaces/innerkits/appverify/test/unittest/include/provision_verify_test.h b/interfaces/innerkits/appverify/test/unittest/include/provision_verify_test.h index 87be39c1a8d6c112814ba80ebf016fb8f9a97f66..2c39c9df58f1e58e5fef24cfbff8ea67d19cf65d 100644 --- a/interfaces/innerkits/appverify/test/unittest/include/provision_verify_test.h +++ b/interfaces/innerkits/appverify/test/unittest/include/provision_verify_test.h @@ -14,12 +14,15 @@ */ #ifndef PROVISION_VERIFY_TEST_H #define PROVISION_VERIFY_TEST_H -int ProvisionVerify001(void); -int ProvisionVerify002(void); -int ProvisionVerify003(void); -int ProvisionVerify004(void); -int ProvisionVerify005(void); -int ProvisionVerify006(void); -int ProvisionVerify007(void); -int ProvisionVerify008(void); + +#include + +int32_t ProvisionVerify001(void); +int32_t ProvisionVerify002(void); +int32_t ProvisionVerify003(void); +int32_t ProvisionVerify004(void); +int32_t ProvisionVerify005(void); +int32_t ProvisionVerify006(void); +int32_t ProvisionVerify007(void); +int32_t ProvisionVerify008(void); #endif // PROVISION_VERIFY_TEST_H diff --git a/interfaces/innerkits/appverify/test/unittest/include/random_access_file_test.h b/interfaces/innerkits/appverify/test/unittest/include/random_access_file_test.h index 8ba468beca70f415619b617fe0382130ff6f2bd2..0b496aa1a0f1b0424b61f230989ef6fa42e6b5f2 100644 --- a/interfaces/innerkits/appverify/test/unittest/include/random_access_file_test.h +++ b/interfaces/innerkits/appverify/test/unittest/include/random_access_file_test.h @@ -15,5 +15,7 @@ #ifndef RANDOM_ACCESS_FILE_TEST_H #define RANDOM_ACCESS_FILE_TEST_H -int ReadFileFullyFromOffsetTest001(void); +#include + +int32_t ReadFileFullyFromOffsetTest001(void); #endif // RANDOM_ACCESS_FILE_TEST_H diff --git a/interfaces/innerkits/appverify/test/unittest/include/test_const.h b/interfaces/innerkits/appverify/test/unittest/include/test_const.h index 0c93354b0f1cd8a4714abbf0803abcb6f8a3c964..166e41adb258a0d871a31b7bba55c2a75901d032 100644 --- a/interfaces/innerkits/appverify/test/unittest/include/test_const.h +++ b/interfaces/innerkits/appverify/test/unittest/include/test_const.h @@ -15,6 +15,7 @@ #ifndef HAPVERIFY_TEST_CONST_H #define HAPVERIFY_TEST_CONST_H +#include #include namespace OHOS { @@ -25,48 +26,48 @@ namespace Verify { constexpr char TEST_HAPBYTEBUFFER_CHAR_DATA = 0xff; constexpr unsigned short TEST_HAPBYTEBUFFER_UINT16_DATA = 0xffff; -constexpr unsigned int TEST_HAPBYTEBUFFER_UINT32_DATA = 0xffffffff; -constexpr int TEST_HAPBYTEBUFFER_INT32_DATA = 0xffffffff; +constexpr uint32_t TEST_HAPBYTEBUFFER_UINT32_DATA = 0xffffffff; +constexpr int32_t TEST_HAPBYTEBUFFER_INT32_DATA = 0xffffffff; constexpr long long TEST_HAPBYTEBUFFER_INT64_DATA = 0xffffffffffffffff; -constexpr int TEST_HAPBYTEBUFFER_INT32_DATA_2 = 100000; -constexpr int TEST_HAPBYTEBUFFER_INVALID_INDEX = -1; +constexpr int32_t TEST_HAPBYTEBUFFER_INT32_DATA_2 = 100000; +constexpr int32_t TEST_HAPBYTEBUFFER_INVALID_INDEX = -1; -constexpr int TEST_RANDOMREAD_LENGTH = 150000; -constexpr int TEST_HAPBYTEBUFFER_LENGTH = 15; -constexpr int TEST_HAPBYTEBUFFER_LENGTH_2 = 8; -constexpr int TEST_HAPBYTEBUFFER_POSITION = 10; +constexpr int32_t TEST_RANDOMREAD_LENGTH = 150000; +constexpr int32_t TEST_HAPBYTEBUFFER_LENGTH = 15; +constexpr int32_t TEST_HAPBYTEBUFFER_LENGTH_2 = 8; +constexpr int32_t TEST_HAPBYTEBUFFER_POSITION = 10; -constexpr int TEST_HAPBYTEBUFFER_UINT16_LENGTH = 2; -constexpr int TEST_HAPBYTEBUFFER_INT64_LENGTH = 8; +constexpr int32_t TEST_HAPBYTEBUFFER_UINT16_LENGTH = 2; +constexpr int32_t TEST_HAPBYTEBUFFER_INT64_LENGTH = 8; -constexpr int TEST_FILE_BLOCK_LENGTH = 50; -constexpr int TEST_FILE_BLOCK_COUNT = 3; +constexpr int32_t TEST_FILE_BLOCK_LENGTH = 50; +constexpr int32_t TEST_FILE_BLOCK_COUNT = 3; -constexpr int TEST_FILE_CD_OFFSET_POSITION = 6; +constexpr int32_t TEST_FILE_CD_OFFSET_POSITION = 6; -constexpr int TEST_HAP_SIGN_VERSION = 1; +constexpr int32_t TEST_HAP_SIGN_VERSION = 1; -constexpr int TEST_MAX_COMMENT_SIZE = 4; -constexpr int TEST_INVALID_MAX_COMMENT_SIZE = -1; +constexpr int32_t TEST_MAX_COMMENT_SIZE = 4; +constexpr int32_t TEST_INVALID_MAX_COMMENT_SIZE = -1; -constexpr int TEST_ZIP_EOCD_SIZE = 22; -constexpr int TEST_ZIP_ECD_OFFSET_FIELD_OFFSET = 16; -constexpr int TEST_ZIP_ECD_SIZE_FIELD_OFFSET = 12; +constexpr int32_t TEST_ZIP_EOCD_SIZE = 22; +constexpr int32_t TEST_ZIP_ECD_OFFSET_FIELD_OFFSET = 16; +constexpr int32_t TEST_ZIP_ECD_SIZE_FIELD_OFFSET = 12; -constexpr int TEST_NULL_NID = 118; -constexpr int TEST_SHA256_NID = 672; -constexpr int TEST_SHA384_NID = 673; -constexpr int TEST_SHA512_NID = 674; +constexpr int32_t TEST_NULL_NID = 118; +constexpr int32_t TEST_SHA256_NID = 672; +constexpr int32_t TEST_SHA384_NID = 673; +constexpr int32_t TEST_SHA512_NID = 674; -constexpr int TEST_MINI_HAP_FILE_LENGTH = 2619; +constexpr int32_t TEST_MINI_HAP_FILE_LENGTH = 2619; -constexpr int TEST_SIGN_VERSION = 2; -constexpr int TEST_CERT_CHAIN_LEN = 3; +constexpr int32_t TEST_SIGN_VERSION = 2; +constexpr int32_t TEST_CERT_CHAIN_LEN = 3; -constexpr int TEST_FILE_NUM = 2; -constexpr int TEST_PFOFILE_PKCS7_DATA_INDEX = 5110; -constexpr int TEST_APP_PKCS7_DATA_INDEX = 7000; -constexpr int TEST_VERSION_CODE = 1; +constexpr int32_t TEST_FILE_NUM = 2; +constexpr int32_t TEST_PFOFILE_PKCS7_DATA_INDEX = 5110; +constexpr int32_t TEST_APP_PKCS7_DATA_INDEX = 7000; +constexpr int32_t TEST_VERSION_CODE = 1; const std::string TEST_ANS_TIME = "000000000000Z"; const std::string TEST_FINGERPRINT = "7A1B38212FE86369DECE606D901CB66C7199CC1BDC4EFF52A86EFBFFB1B99A19"; diff --git a/interfaces/innerkits/appverify/test/unittest/include/ticket_verify_test.h b/interfaces/innerkits/appverify/test/unittest/include/ticket_verify_test.h index 23580ccc2e48f91b15d70535860c12ddd25ba2a0..d5fc539cba12e1da37c7f36e8602109c3316a0e4 100644 --- a/interfaces/innerkits/appverify/test/unittest/include/ticket_verify_test.h +++ b/interfaces/innerkits/appverify/test/unittest/include/ticket_verify_test.h @@ -15,8 +15,11 @@ #ifndef HAP_BYTE_BUFFER_TEST_H #define HAP_BYTE_BUFFER_TEST_H -int CheckTicketSource001(void); -int CheckTicketSource002(void); -int CheckTicketSource003(void); -int CheckTicketSource004(void); + +#include + +int32_t CheckTicketSource001(void); +int32_t CheckTicketSource002(void); +int32_t CheckTicketSource003(void); +int32_t CheckTicketSource004(void); #endif // HAP_BYTE_BUFFER_TEST_H diff --git a/interfaces/innerkits/appverify/test/unittest/include/trusted_root_ca_test.h b/interfaces/innerkits/appverify/test/unittest/include/trusted_root_ca_test.h index 8114852eee9763924c977b580f70625397c69241..404c78c4a5e2f056735a6ff6c05811c78d0853cf 100644 --- a/interfaces/innerkits/appverify/test/unittest/include/trusted_root_ca_test.h +++ b/interfaces/innerkits/appverify/test/unittest/include/trusted_root_ca_test.h @@ -15,9 +15,11 @@ #ifndef HAP_TRUSTED_ROOT_CA_TEST_H #define HAP_TRUSTED_ROOT_CA_TEST_H +#include + #include "test_const.h" -int CreatTrustedRootCA001(void); -int FindMatchedRootTest001(void); -int GetTrustedRootCAFromJsonTest001(void); +int32_t CreatTrustedRootCA001(void); +int32_t FindMatchedRootTest001(void); +int32_t GetTrustedRootCAFromJsonTest001(void); #endif // HAP_TRUSTED_ROOT_CA_TEST_H diff --git a/interfaces/innerkits/appverify/test/unittest/include/trusted_ticket_test.h b/interfaces/innerkits/appverify/test/unittest/include/trusted_ticket_test.h index d32fe11c1f0e5f5f8cb0adb2ee3ffc3ea031b344..a87109c6fc4c194f7079858b50cf8016fe78467a 100644 --- a/interfaces/innerkits/appverify/test/unittest/include/trusted_ticket_test.h +++ b/interfaces/innerkits/appverify/test/unittest/include/trusted_ticket_test.h @@ -15,9 +15,11 @@ #ifndef HAP_TRUSTED_TICKET_TEST_H #define HAP_TRUSTED_TICKET_TEST_H +#include + #include "test_const.h" -int CreatTrustedTicketCA001(void); -int IsTrustedSourceTest001(void); -int IsTrustedSourceTest002(void); +int32_t CreatTrustedTicketCA001(void); +int32_t IsTrustedSourceTest001(void); +int32_t IsTrustedSourceTest002(void); #endif // HAP_TRUSTED_TICKET_TEST_H diff --git a/interfaces/innerkits/appverify/test/unittest/src/hap_byte_buffer_test.cpp b/interfaces/innerkits/appverify/test/unittest/src/hap_byte_buffer_test.cpp index 6aadf1e446f9f7879e265e004d9fa5d2c02f110d..832b6cdf652a26bc97afcebd888bf6cb7f7ed082 100644 --- a/interfaces/innerkits/appverify/test/unittest/src/hap_byte_buffer_test.cpp +++ b/interfaces/innerkits/appverify/test/unittest/src/hap_byte_buffer_test.cpp @@ -93,7 +93,7 @@ HWTEST_F (HapByteBufferTest, GetIntAndPutOperation001, TestSize.Level1) * @tc.expected: step1. The return result is false. */ HapByteBuffer emptyBuffer; - int dataInt32; + int32_t dataInt32; ASSERT_FALSE(emptyBuffer.GetInt32(dataInt32)); long long dataInt64; ASSERT_FALSE(emptyBuffer.GetInt64(dataInt64)); @@ -106,7 +106,7 @@ HWTEST_F (HapByteBufferTest, GetIntAndPutOperation001, TestSize.Level1) HapByteBuffer testBuffer(1); char testChar = TEST_HAPBYTEBUFFER_CHAR_DATA; testBuffer.PutData(0, &testChar, sizeof(testChar)); - unsigned int dataUInt32; + uint32_t dataUInt32; ASSERT_FALSE(testBuffer.GetUInt32(1, dataUInt32)); ASSERT_FALSE(testBuffer.GetInt32(1, dataInt32)); ASSERT_FALSE(testBuffer.GetInt64(1, dataInt64)); @@ -128,7 +128,7 @@ HWTEST_F (HapByteBufferTest, GetIntAndPutOperation001, TestSize.Level1) sizeof(TEST_HAPBYTEBUFFER_UINT16_DATA)); ASSERT_EQ(err, EOK); testBuffer2.PutData(sizeof(char), testUInt16, sizeof(testUInt16)); - int testInt32 = TEST_HAPBYTEBUFFER_INT32_DATA; + int32_t testInt32 = TEST_HAPBYTEBUFFER_INT32_DATA; testBuffer2.PutInt32(sizeof(char) + sizeof(unsigned short), testInt32); char testInt64[TEST_HAPBYTEBUFFER_INT64_LENGTH]; err = memcpy_s(testInt64, sizeof(testInt64), &TEST_HAPBYTEBUFFER_INT64_DATA, @@ -173,7 +173,7 @@ HWTEST_F (HapByteBufferTest, Slice001, TestSize.Level1) * @tc.steps: step3. Get int32 from buffer1. * @tc.expected: step3. The return result is equal to TEST_HAPBYTEBUFFER_INT32_DATA_2. */ - int testDataInt32; + int32_t testDataInt32; ASSERT_TRUE(buffer1.GetInt32(testDataInt32)); ASSERT_EQ(testDataInt32, TEST_HAPBYTEBUFFER_INT32_DATA_2); /* @@ -208,10 +208,10 @@ HWTEST_F (HapByteBufferTest, CopyPartialBuffer001, TestSize.Level1) */ buffer1.Clear(); buffer2.CopyPartialBuffer(buffer1, TEST_HAPBYTEBUFFER_LENGTH_2); - int target1; + int32_t target1; ASSERT_TRUE(buffer2.GetInt32(target1)); ASSERT_EQ(target1, TEST_HAPBYTEBUFFER_INT32_DATA); - int target2; + int32_t target2; ASSERT_TRUE(buffer2.GetInt32(target2)); ASSERT_EQ(target2, TEST_HAPBYTEBUFFER_INT32_DATA_2); } @@ -277,7 +277,7 @@ HWTEST_F (HapByteBufferTest, IsEqual002, TestSize.Level1) * @tc.steps: step3. Put string to buffer1 and compare. * @tc.expected: step3. The return is true. */ - for (int i = 0; i < static_cast(testStr.size()); i++) { + for (int32_t i = 0; i < static_cast(testStr.size()); i++) { buffer1.PutByte(i, testStr[i]); } ASSERT_TRUE(buffer1.IsEqual(testStr)); diff --git a/interfaces/innerkits/appverify/test/unittest/src/hap_cert_verify_openssl_utils_test.cpp b/interfaces/innerkits/appverify/test/unittest/src/hap_cert_verify_openssl_utils_test.cpp index 59715b511a2f8a97af984ff43ef516f1b5eff248..878b9391ac960d92f0dcd5601dba2af5ae756940 100644 --- a/interfaces/innerkits/appverify/test/unittest/src/hap_cert_verify_openssl_utils_test.cpp +++ b/interfaces/innerkits/appverify/test/unittest/src/hap_cert_verify_openssl_utils_test.cpp @@ -39,7 +39,7 @@ bool Base64StringDecode(const std::string& base64String, HapByteBuffer& output) } const unsigned char* input = reinterpret_cast(base64String.c_str()); - int len = EVP_DecodeBlock(reinterpret_cast(decodeBuffer.get()), input, base64String.size()); + int32_t len = EVP_DecodeBlock(reinterpret_cast(decodeBuffer.get()), input, base64String.size()); if (len <= 0) { return false; } diff --git a/interfaces/innerkits/appverify/test/unittest/src/hap_signing_block_utils_test.cpp b/interfaces/innerkits/appverify/test/unittest/src/hap_signing_block_utils_test.cpp index 556ef1455c97b71b96344414f1341fdf5f33ed68..2efd921d1ad4d9c6e9c7dbb4a2ab3a53ce3d8e75 100644 --- a/interfaces/innerkits/appverify/test/unittest/src/hap_signing_block_utils_test.cpp +++ b/interfaces/innerkits/appverify/test/unittest/src/hap_signing_block_utils_test.cpp @@ -62,10 +62,10 @@ long long CreatTestZipFile(const std::string& pathFile, SignatureInfo& signInfo) hapFile.write(reinterpret_cast(&signBlob), sizeof(signBlob)); hapFile.write(reinterpret_cast(&profileBlob), sizeof(profileBlob)); hapFile.write(reinterpret_cast(&propertyBlob), sizeof(propertyBlob)); - for (int i = 0; i < TEST_FILE_BLOCK_COUNT; i++) { + for (int32_t i = 0; i < TEST_FILE_BLOCK_COUNT; i++) { hapFile.write(block, sizeof(block)); } - int blockCount = TEST_FILE_BLOCK_COUNT; + int32_t blockCount = TEST_FILE_BLOCK_COUNT; hapFile.write(reinterpret_cast(&blockCount), sizeof(blockCount)); long long signBlockSize = (sizeof(HapSubSignBlockHead) + sizeof(block)) * TEST_FILE_BLOCK_COUNT + HapSigningBlockUtils::ZIP_HEAD_OF_SIGNING_BLOCK_LENGTH; @@ -74,17 +74,17 @@ long long CreatTestZipFile(const std::string& pathFile, SignatureInfo& signInfo) hapFile.write(reinterpret_cast(&magic), sizeof(magic)); magic = HapSigningBlockUtils::HAP_SIG_BLOCK_MAGIC_HIGH_OLD; hapFile.write(reinterpret_cast(&magic), sizeof(magic)); - int version = 1; + int32_t version = 1; hapFile.write(reinterpret_cast(&version), sizeof(version)); /* input central direction */ hapFile.write(block, sizeof(block)); /* input end of central direction */ - int zidEocdSign = HapSigningBlockUtils::ZIP_EOCD_SEGMENT_FLAG; + int32_t zidEocdSign = HapSigningBlockUtils::ZIP_EOCD_SEGMENT_FLAG; hapFile.write(reinterpret_cast(&zidEocdSign), sizeof(zidEocdSign)); hapFile.write(reinterpret_cast(&magic), sizeof(magic)); - unsigned int centralDirLen = sizeof(block); + uint32_t centralDirLen = sizeof(block); hapFile.write(reinterpret_cast(¢ralDirLen), sizeof(centralDirLen)); - unsigned int centralDirOffset = TEST_FILE_BLOCK_LENGTH + signBlockSize; + uint32_t centralDirOffset = TEST_FILE_BLOCK_LENGTH + signBlockSize; hapFile.write(reinterpret_cast(¢ralDirOffset), sizeof(centralDirOffset)); short eocdCommentLen = 0; hapFile.write(reinterpret_cast(&eocdCommentLen), sizeof(eocdCommentLen)); @@ -112,10 +112,10 @@ public: void TearDown(); - static const int TEST_ZIP_BLOCKS_NUM_NEED_DIGEST; + static const int32_t TEST_ZIP_BLOCKS_NUM_NEED_DIGEST; }; -const int HapSigningBlockUtilsTest::TEST_ZIP_BLOCKS_NUM_NEED_DIGEST = 3; +const int32_t HapSigningBlockUtilsTest::TEST_ZIP_BLOCKS_NUM_NEED_DIGEST = 3; void HapSigningBlockUtilsTest::SetUpTestCase(void) { @@ -145,7 +145,7 @@ HWTEST_F(HapSigningBlockUtilsTest, FindHapSignatureTest001, TestSize.Level1) */ std::string pathFile = "./test_hapverify.hap"; SignatureInfo signInfo; - int sumLen = CreatTestZipFile(pathFile, signInfo); + int32_t sumLen = CreatTestZipFile(pathFile, signInfo); /* * @tc.steps: step2. test FindHapSignature function * @tc.expected: step2. the return will be true. @@ -164,7 +164,7 @@ HWTEST_F(HapSigningBlockUtilsTest, FindHapSignatureTest001, TestSize.Level1) hapFile.open(pathFile.c_str(), std::ios::binary | std::ios::out); ASSERT_TRUE(hapFile.is_open()); hapFile.seekp(sumLen - TEST_FILE_CD_OFFSET_POSITION, std::ios_base::beg); - unsigned int errorCentralDirOffset = 20; + uint32_t errorCentralDirOffset = 20; hapFile.write(reinterpret_cast(&errorCentralDirOffset), sizeof(errorCentralDirOffset)); hapFile.close(); ASSERT_FALSE(hapSignBlockUtils.FindHapSignature(hapTestFile, hapSignInfo)); @@ -220,7 +220,7 @@ HWTEST_F(HapSigningBlockUtilsTest, FindEocdInHapTest001, TestSize.Level1) std::ofstream hapFile; hapFile.open(pathFile.c_str(), std::ios::binary | std::ios::out | std::ios::trunc); ASSERT_TRUE(hapFile.is_open()); - unsigned int centralDirLen = TEST_FILE_BLOCK_LENGTH; + uint32_t centralDirLen = TEST_FILE_BLOCK_LENGTH; hapFile.write(reinterpret_cast(¢ralDirLen), sizeof(centralDirLen)); hapFile.close(); /* @@ -232,12 +232,12 @@ HWTEST_F(HapSigningBlockUtilsTest, FindEocdInHapTest001, TestSize.Level1) std::pair eocd; HapSigningBlockUtils hapSignBlockUtils; ASSERT_FALSE(hapSignBlockUtils.FindEocdInHap(hapTestFile, eocd)); - int maxCommentSize = TEST_INVALID_MAX_COMMENT_SIZE; + int32_t maxCommentSize = TEST_INVALID_MAX_COMMENT_SIZE; ASSERT_FALSE(hapSignBlockUtils.FindEocdInHap(hapTestFile, maxCommentSize, eocd)); maxCommentSize = TEST_MAX_COMMENT_SIZE; ASSERT_FALSE(hapSignBlockUtils.FindEocdInHap(hapTestFile, maxCommentSize, eocd)); HapByteBuffer testHapBuffer(TEST_HAPBYTEBUFFER_LENGTH); - int offset = 0; + int32_t offset = 0; ASSERT_FALSE(hapSignBlockUtils.FindEocdInSearchBuffer(testHapBuffer, offset)); } @@ -253,9 +253,9 @@ HWTEST_F(HapSigningBlockUtilsTest, GetCentralDirectoryOffsetTest001, TestSize.Le * @tc.steps: step1. create a test eocd with invalid central offset and length. */ HapByteBuffer testEocd(TEST_ZIP_EOCD_SIZE); - int centralDirLen = TEST_FILE_BLOCK_LENGTH; + int32_t centralDirLen = TEST_FILE_BLOCK_LENGTH; testEocd.PutInt32(TEST_ZIP_ECD_SIZE_FIELD_OFFSET, centralDirLen); - int centralDirOffset = TEST_FILE_BLOCK_LENGTH; + int32_t centralDirOffset = TEST_FILE_BLOCK_LENGTH; testEocd.PutInt32(TEST_ZIP_ECD_OFFSET_FIELD_OFFSET, centralDirOffset); HapSigningBlockUtils hapSignBlockUtils; ASSERT_FALSE(hapSignBlockUtils.SetUnsignedInt32(testEocd, 0, TEST_INVALID_MAX_COMMENT_SIZE)); @@ -283,7 +283,7 @@ HWTEST_F(HapSigningBlockUtilsTest, ClassifyHapSubSigningBlock001, TestSize.Level */ SignatureInfo signInfo; HapByteBuffer subBlock; - unsigned int type = PROPERTY_BLOB; + uint32_t type = PROPERTY_BLOB; HapSigningBlockUtils hapSignBlockUtils; hapSignBlockUtils.ClassifyHapSubSigningBlock(signInfo, subBlock, type); ASSERT_FALSE(signInfo.optionBlocks.empty()); @@ -309,9 +309,10 @@ HWTEST_F(HapSigningBlockUtilsTest, ComputeDigestsWithOptionalBlock001, TestSize. HapSigningBlockUtils hapSignBlockUtils; HapByteBuffer chunkDigest(TEST_HAPBYTEBUFFER_LENGTH); HapByteBuffer finalDigest; - int nid = TEST_NULL_NID; + int32_t nid = TEST_NULL_NID; DigestParameter errorParam = hapSignBlockUtils.GetDigestParameter(nid); - int ret = hapSignBlockUtils.ComputeDigestsWithOptionalBlock(errorParam, optionalBlocks, chunkDigest, finalDigest); + int32_t ret = hapSignBlockUtils.ComputeDigestsWithOptionalBlock( + errorParam, optionalBlocks, chunkDigest, finalDigest); ASSERT_FALSE(ret); nid = TEST_SHA256_NID; DigestParameter digestParam = hapSignBlockUtils.GetDigestParameter(nid); @@ -330,8 +331,8 @@ HWTEST_F(HapSigningBlockUtilsTest, GetSumOfChunkDigestLenTest001, TestSize.Level * @tc.steps: step1. input some error input to test GetSumOfChunkDigestLen * @tc.expected: step1. the return will be false. */ - int chunkCount = 0; - int sumOfChunkDigestLen = 0; + int32_t chunkCount = 0; + int32_t sumOfChunkDigestLen = 0; DataSource* contents[TEST_ZIP_BLOCKS_NUM_NEED_DIGEST] = { nullptr, nullptr, nullptr }; bool ret = HapSigningBlockUtils::GetSumOfChunkDigestLen(contents, 0, 0, chunkCount, sumOfChunkDigestLen); ASSERT_FALSE(ret); @@ -340,7 +341,7 @@ HWTEST_F(HapSigningBlockUtilsTest, GetSumOfChunkDigestLenTest001, TestSize.Level ASSERT_FALSE(ret); HapByteBuffer testBuffer(TEST_ZIP_EOCD_SIZE); HapByteBufferDataSource testSource(testBuffer); - for (int i = 0; i < TEST_ZIP_BLOCKS_NUM_NEED_DIGEST; i++) { + for (int32_t i = 0; i < TEST_ZIP_BLOCKS_NUM_NEED_DIGEST; i++) { contents[i] = &testSource; } ret = HapSigningBlockUtils::GetSumOfChunkDigestLen(contents, diff --git a/interfaces/innerkits/appverify/test/unittest/src/hap_verify_openssl_utils_test.cpp b/interfaces/innerkits/appverify/test/unittest/src/hap_verify_openssl_utils_test.cpp index 9dbfed50a980a29e6be07388c128e8df9d252e89..b4792513b8bdafbd5af093ea792f6d011ba17929 100644 --- a/interfaces/innerkits/appverify/test/unittest/src/hap_verify_openssl_utils_test.cpp +++ b/interfaces/innerkits/appverify/test/unittest/src/hap_verify_openssl_utils_test.cpp @@ -83,7 +83,7 @@ HWTEST_F(HapVerifyOpensslUtilsTest, GetDigestAlgorithmId001, TestSize.Level1) * @tc.steps: step1. use different algorithm IDs to run OpensslVerifyPkcs7 * @tc.expected: step1. the return will be nID. */ - int nId = HapVerifyOpensslUtils::GetDigestAlgorithmId(ALGORITHM_SHA512_WITH_RSA_PSS); + int32_t nId = HapVerifyOpensslUtils::GetDigestAlgorithmId(ALGORITHM_SHA512_WITH_RSA_PSS); ASSERT_TRUE(nId == TEST_SHA512_NID); nId = HapVerifyOpensslUtils::GetDigestAlgorithmId(ALGORITHM_SHA384_WITH_RSA_PSS); ASSERT_TRUE(nId == TEST_SHA384_NID); diff --git a/interfaces/innerkits/appverify/test/unittest/src/hap_verify_result_test.cpp b/interfaces/innerkits/appverify/test/unittest/src/hap_verify_result_test.cpp index a489d73a8b31330b44983fc879d13a83b7e93d06..9e767f892b96cd008ac96fc392f4c2d28643995d 100644 --- a/interfaces/innerkits/appverify/test/unittest/src/hap_verify_result_test.cpp +++ b/interfaces/innerkits/appverify/test/unittest/src/hap_verify_result_test.cpp @@ -97,7 +97,7 @@ HWTEST_F(HapVerifyResultTest, GetProfileAndProperty001, TestSize.Level1) */ std::string getProfile; GetOptionalBlockResultCode targetResult = NO_THIS_BLOCK_IN_PACKAGE; - int ret = hapVerifyResult.GetBlockFromOptionalBlocks(PROFILE_BLOB, getProfile); + int32_t ret = hapVerifyResult.GetBlockFromOptionalBlocks(PROFILE_BLOB, getProfile); ASSERT_TRUE(ret == targetResult); /* * @tc.steps: step3. GetProperty. @@ -118,10 +118,10 @@ HWTEST_F(HapVerifyResultTest, SetVersionAndGetVersion001, TestSize.Level1) * @tc.steps: step1. set a target version to HapVerifyResult. * @tc.expected: step1. the return version is the value we set. */ - int targetVersion = TEST_HAP_SIGN_VERSION; + int32_t targetVersion = TEST_HAP_SIGN_VERSION; HapVerifyResult hapVerifyResult; hapVerifyResult.SetVersion(targetVersion); - int version = hapVerifyResult.GetVersion(); + int32_t version = hapVerifyResult.GetVersion(); ASSERT_TRUE(version == targetVersion); } } diff --git a/interfaces/innerkits/appverify/test/unittest/src/hap_verify_test.cpp b/interfaces/innerkits/appverify/test/unittest/src/hap_verify_test.cpp index 42fd0fb1e5ab0355a2d2001d8c466745eb3641b7..e360edacdfcd69c79ebca6f48ac1c04c64e993b1 100644 --- a/interfaces/innerkits/appverify/test/unittest/src/hap_verify_test.cpp +++ b/interfaces/innerkits/appverify/test/unittest/src/hap_verify_test.cpp @@ -81,7 +81,7 @@ HWTEST_F(HapVerifyTest, HapVerify001, TestSize.Level0) */ HapVerifyResult hapVerifyResult; std::string errorFile = "./signed_test.app"; - int resultCode = HapVerify(errorFile, hapVerifyResult); + int32_t resultCode = HapVerify(errorFile, hapVerifyResult); HapVerifyResultCode targetResult = FILE_PATH_INVALID; ASSERT_TRUE(resultCode == targetResult); std::ofstream appFile; @@ -151,7 +151,7 @@ HWTEST_F(HapVerifyTest, HapVerifyOsApp001, TestSize.Level0) hapFile.write(hapInnerApp.GetBufferPtr(), hapInnerApp.GetCapacity()); hapFile.close(); HapVerifyResult hapVerifyResult; - int ret = HapVerify(filePath, hapVerifyResult); + int32_t ret = HapVerify(filePath, hapVerifyResult); ASSERT_EQ(ret, VERIFY_SUCCESS); } @@ -165,7 +165,7 @@ HWTEST_F(HapVerifyTest, HapVerify002, TestSize.Level0) std::string fileContent[TEST_FILE_NUM] = {HAP_FILE_ECC_SIGN_BASE64, HAP_FILE_RSA_SIGN_BASE64}; std::string filePath[TEST_FILE_NUM] = {"./signed_ecc.hap", "./signed_rsa.hap"}; std::string errorfilePath[TEST_FILE_NUM] = {"./signed_ecc_error.hap", "./signed_rsa_error.hap"}; - for (int i = 0; i < TEST_FILE_NUM; i++) { + for (int32_t i = 0; i < TEST_FILE_NUM; i++) { /* * @tc.steps: step1. input a signed file to verify. * @tc.expected: step1. the return will be VERIFY_SUCCESS. diff --git a/interfaces/innerkits/appverify/test/unittest/src/provision_verify_test.cpp b/interfaces/innerkits/appverify/test/unittest/src/provision_verify_test.cpp index 9c1989787f10e89937886a5585bbe46c5ec9f854..0d4af4dd1cadb4df2a3d6ea0f003d5af228a0874 100644 --- a/interfaces/innerkits/appverify/test/unittest/src/provision_verify_test.cpp +++ b/interfaces/innerkits/appverify/test/unittest/src/provision_verify_test.cpp @@ -191,7 +191,7 @@ const std::string DEVICE_UNAUTH_PROVISION = R"( }, "issuer": "App Gallery" })"; -const int MAXIMUM_NUM_DEVICES = 100; +const int32_t MAXIMUM_NUM_DEVICES = 100; class ProvisionVerifyTest : public testing::Test { public: @@ -233,7 +233,7 @@ HWTEST_F(ProvisionVerifyTest, ProvisionVerify001, TestSize.Level1) * @tc.expected: step1. return code will be PROVISION_INVALID. */ ProvisionInfo info; - int ret = ParseAndVerify(INVALID_PROVISION_1, info); + int32_t ret = ParseAndVerify(INVALID_PROVISION_1, info); ASSERT_EQ(ret, AppProvisionVerifyResult::PROVISION_INVALID); ret = ParseAndVerify(INVALID_PROVISION_2, info); ASSERT_EQ(ret, AppProvisionVerifyResult::PROVISION_INVALID); @@ -254,7 +254,7 @@ HWTEST_F(ProvisionVerifyTest, ProvisionVerify002, TestSize.Level1) * @tc.expected: step2. return code will be PROVISION_OK. */ ProvisionInfo info; - int ret = ParseAndVerify(VALID_PROVISION, info); + int32_t ret = ParseAndVerify(VALID_PROVISION, info); ASSERT_EQ(ret, AppProvisionVerifyResult::PROVISION_OK); ASSERT_EQ(info.versionCode, 2); // version code is 2 ASSERT_EQ(info.versionName, "2.0.0"); @@ -277,7 +277,7 @@ HWTEST_F(ProvisionVerifyTest, ProvisionVerify003, TestSize.Level1) * @tc.expected: step3. return code will be PROVISION_OK. */ ProvisionInfo info; - int ret = ParseAndVerify(VALID_PROVISION_PERMISSION, info); + int32_t ret = ParseAndVerify(VALID_PROVISION_PERMISSION, info); ASSERT_EQ(ret, AppProvisionVerifyResult::PROVISION_OK); ASSERT_EQ(info.versionCode, 3); // version code is 3 ASSERT_EQ(info.versionName, "3.0.0"); @@ -303,7 +303,7 @@ HWTEST_F(ProvisionVerifyTest, ProvisionVerify004, TestSize.Level1) * @tc.expected: step4. return code will be PROVISION_DEVICE_UNAUTHORIZED. */ ProvisionInfo info; - int ret = ParseAndVerify(UNAUTHORIZED_DEVICE_EMPTY_DEVICE_LIST_PROVISION, info); + int32_t ret = ParseAndVerify(UNAUTHORIZED_DEVICE_EMPTY_DEVICE_LIST_PROVISION, info); ASSERT_EQ(ret, AppProvisionVerifyResult::PROVISION_DEVICE_UNAUTHORIZED); } @@ -343,13 +343,13 @@ HWTEST_F(ProvisionVerifyTest, ProvisionVerify005, TestSize.Level1) }, "issuer": "App Gallery" })"; - for (int i = 0; i < MAXIMUM_NUM_DEVICES; i++) { + for (int32_t i = 0; i < MAXIMUM_NUM_DEVICES; i++) { prefixNumDeviceExceededProvision += R"("1234ABCD",)"; } prefixNumDeviceExceededProvision += R"("1234ABCD")"; prefixNumDeviceExceededProvision += postfixNumDeviceExceededProvision; ProvisionInfo info; - int ret = ParseAndVerify(prefixNumDeviceExceededProvision, info); + int32_t ret = ParseAndVerify(prefixNumDeviceExceededProvision, info); ASSERT_EQ(ret, AppProvisionVerifyResult::PROVISION_NUM_DEVICE_EXCEEDED); } @@ -366,7 +366,7 @@ HWTEST_F(ProvisionVerifyTest, ProvisionVerify006, TestSize.Level1) * @tc.expected: step6. return code will be PROVISION_UNSUPPORTED_DEVICE_TYPE. */ ProvisionInfo info; - int ret = ParseAndVerify(UNSUPPORTED_DEVICE_TYPE_PROVISION, info); + int32_t ret = ParseAndVerify(UNSUPPORTED_DEVICE_TYPE_PROVISION, info); ASSERT_EQ(ret, AppProvisionVerifyResult::PROVISION_UNSUPPORTED_DEVICE_TYPE); } @@ -383,7 +383,7 @@ HWTEST_F(ProvisionVerifyTest, ProvisionVerify007, TestSize.Level1) * @tc.expected: step7. return code will be PROVISION_DEVICE_UNAUTHORIZED. */ ProvisionInfo info; - int ret = ParseAndVerify(DEVICE_UNAUTH_PROVISION, info); + int32_t ret = ParseAndVerify(DEVICE_UNAUTH_PROVISION, info); ASSERT_EQ(ret, AppProvisionVerifyResult::PROVISION_DEVICE_UNAUTHORIZED); } @@ -429,14 +429,14 @@ HWTEST_F(ProvisionVerifyTest, ProvisionVerify008, TestSize.Level1) OHOS::AccountSA::OhosAccountKits::GetInstance().GetUdid(deviceId); #else char udid[DEV_UUID_LEN] = {0}; - int udidRet = GetDevUdid(udid, sizeof(udid)); + int32_t udidRet = GetDevUdid(udid, sizeof(udid)); ASSERT_EQ(udidRet, EC_SUCCESS); deviceId = std::string(udid, sizeof(udid) - 1); #endif prefixValidDeviceInfoProvision += deviceId; prefixValidDeviceInfoProvision += postfixValidDeviceInfoProvision; ProvisionInfo info; - int ret = ParseAndVerify(prefixValidDeviceInfoProvision, info); + int32_t ret = ParseAndVerify(prefixValidDeviceInfoProvision, info); ASSERT_EQ(ret, AppProvisionVerifyResult::PROVISION_OK); } @@ -478,14 +478,14 @@ HWTEST_F(ProvisionVerifyTest, ProvisionVerify009, TestSize.Level1) OHOS::AccountSA::OhosAccountKits::GetInstance().GetUdid(deviceId); #else char udid[DEV_UUID_LEN] = {0}; - int udidRet = GetDevUdid(udid, sizeof(udid)); + int32_t udidRet = GetDevUdid(udid, sizeof(udid)); ASSERT_EQ(udidRet, EC_SUCCESS); deviceId = std::string(udid, sizeof(udid) - 1); #endif prefixValidDeviceInfoProvision += deviceId; prefixValidDeviceInfoProvision += postfixValidDeviceInfoProvision; ProvisionInfo info; - int ret = ParseAndVerify(prefixValidDeviceInfoProvision, info); + int32_t ret = ParseAndVerify(prefixValidDeviceInfoProvision, info); ASSERT_EQ(ret, AppProvisionVerifyResult::PROVISION_OK); ASSERT_EQ(info.distributionType, AppDistType::CROWDTESTING); ASSERT_EQ(info.type, ProvisionType::DEBUG); @@ -530,14 +530,14 @@ HWTEST_F(ProvisionVerifyTest, ProvisionVerify010, TestSize.Level1) OHOS::AccountSA::OhosAccountKits::GetInstance().GetUdid(deviceId); #else char udid[DEV_UUID_LEN] = {0}; - int udidRet = GetDevUdid(udid, sizeof(udid)); + int32_t udidRet = GetDevUdid(udid, sizeof(udid)); ASSERT_EQ(udidRet, EC_SUCCESS); deviceId = std::string(udid, sizeof(udid) - 1); #endif prefixValidDeviceInfoProvision += deviceId; prefixValidDeviceInfoProvision += postfixValidDeviceInfoProvision; ProvisionInfo info; - int ret = ParseAndVerify(prefixValidDeviceInfoProvision, info); + int32_t ret = ParseAndVerify(prefixValidDeviceInfoProvision, info); ASSERT_EQ(ret, AppProvisionVerifyResult::PROVISION_OK); ASSERT_EQ(info.distributionType, AppDistType::CROWDTESTING); ASSERT_EQ(info.type, ProvisionType::RELEASE); diff --git a/interfaces/innerkits/appverify/test/unittest/src/random_access_file_test.cpp b/interfaces/innerkits/appverify/test/unittest/src/random_access_file_test.cpp index 84bc762a80a7f18484898d7817af85915ed10a64..4d795386e7a0e4fbe43e518f728a619ee51481d6 100644 --- a/interfaces/innerkits/appverify/test/unittest/src/random_access_file_test.cpp +++ b/interfaces/innerkits/appverify/test/unittest/src/random_access_file_test.cpp @@ -70,7 +70,7 @@ HWTEST_F(RandomAccessFileTest, ReadFileFullyFromOffsetTest001, TestSize.Level1) */ std::string filePath = "./test_hapverify.zip"; SignatureInfo si0; - int sumLen = CreatTestZipFile(filePath, si0); + int32_t sumLen = CreatTestZipFile(filePath, si0); RandomAccessFile hapTestFile1; bool initRet = hapTestFile1.Init(filePath); ASSERT_TRUE(initRet); diff --git a/interfaces/innerkits/appverify_lite/include/app_centraldirectory.h b/interfaces/innerkits/appverify_lite/include/app_centraldirectory.h index 648968a62fbe59fab143f46a859c05ef0e691145..1f4eeefb5908ef4d912aacbe25077140e39959f6 100644 --- a/interfaces/innerkits/appverify_lite/include/app_centraldirectory.h +++ b/interfaces/innerkits/appverify_lite/include/app_centraldirectory.h @@ -16,6 +16,8 @@ #ifndef SECURITY_APP_CENTRALDIECTORY_H #define SECURITY_APP_CENTRALDIECTORY_H +#include + #include "mbedtls/pk.h" #include "app_verify_pub.h" #include "app_file.h" @@ -40,29 +42,29 @@ extern "C" { typedef struct { void *buffer; - int len; + int32_t len; } HapBuf; #pragma pack(4) /* hw sign head */ typedef struct { - unsigned int blockNum; + uint32_t blockNum; unsigned long long size; unsigned long long magicLow; unsigned long long magicHigh; - unsigned int version; + uint32_t version; } HwSignHead; #pragma pack() #pragma pack(2) typedef struct { - int magic; + int32_t magic; short diskNum; short startNum; short coreDirNumOnDisk; short coreDirNum; - int coreDirSize; - int coreDirOffset; + int32_t coreDirSize; + int32_t coreDirOffset; short commentLen; } MinEocd; #pragma pack() @@ -74,22 +76,22 @@ typedef struct { typedef struct { HwSignHead *signHead; - int fullSignBlockOffset; - int hapCoreDirOffset; - int hapEocdOffset; - int hapEocdSize; - int fileSize; - int version; - int certType; + int32_t fullSignBlockOffset; + int32_t hapCoreDirOffset; + int32_t hapEocdOffset; + int32_t hapEocdSize; + int32_t fileSize; + int32_t version; + int32_t certType; } SignatureInfo; bool FindSignature(const FileRead *hapFile, SignatureInfo *signInfo); -bool CreateHapBuffer(HapBuf *hapBuffer, int len); -int ReadFileFullyFromOffset(const HapBuf *buffer, int offset, const FileRead *file); -void HapSetInt32(const HapBuf *buffer, int offset, int value); +bool CreateHapBuffer(HapBuf *hapBuffer, int32_t len); +int32_t ReadFileFullyFromOffset(const HapBuf *buffer, int32_t offset, const FileRead *file); +void HapSetInt32(const HapBuf *buffer, int32_t offset, int32_t value); void ClearHapBuffer(HapBuf *hapBuffer); -void HapPutByte(const HapBuf *hapBuffer, int offset, char value); -void HapPutData(const HapBuf *hapBuffer, int offset, const unsigned char *data, int len); +void HapPutByte(const HapBuf *hapBuffer, int32_t offset, char value); +void HapPutData(const HapBuf *hapBuffer, int32_t offset, const unsigned char *data, int32_t len); #ifdef __cplusplus #if __cplusplus diff --git a/interfaces/innerkits/appverify_lite/include/app_common.h b/interfaces/innerkits/appverify_lite/include/app_common.h index a1805bfff786badbb42d3c89dfd71347911a59a9..1d7e1449657f0714ea322a93391c8421d581ae86 100644 --- a/interfaces/innerkits/appverify_lite/include/app_common.h +++ b/interfaces/innerkits/appverify_lite/include/app_common.h @@ -16,6 +16,8 @@ #ifndef SECURITY_APP_COMMON_H #define SECURITY_APP_COMMON_H +#include + #include "app_verify_base.h" #include "app_verify_pub.h" @@ -101,11 +103,11 @@ do { \ } \ } while (0) -long long HapGetInt64(const unsigned char *buf, int len); -int HapGetInt(const unsigned char *buf, int len); -unsigned int HapGetUnsignedInt(const unsigned char *buf, int len); -short HapGetShort(const unsigned char *buf, int len); -void HapPutInt32(unsigned char *buf, int len, int value); +long long HapGetInt64(const unsigned char *buf, int32_t len); +int32_t HapGetInt(const unsigned char *buf, int32_t len); +uint32_t HapGetUnsignedInt(const unsigned char *buf, int32_t len); +short HapGetShort(const unsigned char *buf, int32_t len); +void HapPutInt32(unsigned char *buf, int32_t len, int32_t value); #ifdef __cplusplus #if __cplusplus } diff --git a/interfaces/innerkits/appverify_lite/include/app_file.h b/interfaces/innerkits/appverify_lite/include/app_file.h index f9b24da76ea13363067877e10745a7f43ab04980..6b361152986cb695c67b17df16c138d2fba76398 100644 --- a/interfaces/innerkits/appverify_lite/include/app_file.h +++ b/interfaces/innerkits/appverify_lite/include/app_file.h @@ -16,6 +16,8 @@ #ifndef SECURITY_APP_FILE_H #define SECURITY_APP_FILE_H +#include + #ifdef __cplusplus #if __cplusplus extern "C" { @@ -34,21 +36,21 @@ enum ReadFileErrorCode { }; typedef struct { - int mmapPosition; - int readMoreLen; - int mmapSize; + int32_t mmapPosition; + int32_t readMoreLen; + int32_t mmapSize; char* mapAddr; } MmapInfo; typedef struct { - int fp; - int offset; - int len; + int32_t fp; + int32_t offset; + int32_t len; } FileRead; -int InitVerify(FileRead *file, const char *filePath, int *handle); -int HapMMap(int bufCapacity, int offset, MmapInfo *mmapInfo, const FileRead *file); -void HapMUnMap(char *mapAddr, int mmapSize); +int32_t InitVerify(FileRead *file, const char *filePath, int32_t *handle); +int32_t HapMMap(int32_t bufCapacity, int32_t offset, MmapInfo *mmapInfo, const FileRead *file); +void HapMUnMap(char *mapAddr, int32_t mmapSize); #ifdef __cplusplus #if __cplusplus } diff --git a/interfaces/innerkits/appverify_lite/include/app_provision.h b/interfaces/innerkits/appverify_lite/include/app_provision.h index 8ea7a48ad62f2eaf1622b7cc28c479232d6414ef..b433531c2562368375a94e62fd1e0e8f58af3fc7 100644 --- a/interfaces/innerkits/appverify_lite/include/app_provision.h +++ b/interfaces/innerkits/appverify_lite/include/app_provision.h @@ -16,6 +16,8 @@ #ifndef SECURITY_APP_PROVISION_H #define SECURITY_APP_PROVISION_H +#include + #include "app_verify_pub.h" #ifdef __cplusplus @@ -33,9 +35,9 @@ extern "C" { #define MAX_UDID_NUM 100 #define UDID_VERIFY_BYTES 64 -int ParseProfile(const char *buf, int len, ProfileProf *pf); +int32_t ParseProfile(const char *buf, int32_t len, ProfileProf *pf); void ProfFreeData(ProfileProf *pf); -int VerifyProfileContent(const ProfileProf *pf); +int32_t VerifyProfileContent(const ProfileProf *pf); #ifdef __cplusplus #if __cplusplus diff --git a/interfaces/innerkits/appverify_lite/include/app_verify.h b/interfaces/innerkits/appverify_lite/include/app_verify.h index d58594ee971bceeb55207312c89b8269416edc67..d5ee409150d6ee7f22a92c6920c284374a7bf796 100644 --- a/interfaces/innerkits/appverify_lite/include/app_verify.h +++ b/interfaces/innerkits/appverify_lite/include/app_verify.h @@ -16,6 +16,8 @@ #ifndef SECURITY_APP_VERIFY_H #define SECURITY_APP_VERIFY_H +#include + #include "mbedtls/pk.h" #include "app_centraldirectory.h" #include "app_provision.h" @@ -77,18 +79,18 @@ typedef enum { /* block head */ typedef struct { - unsigned int type; - unsigned int length; - unsigned int offset; + uint32_t type; + uint32_t length; + uint32_t offset; } BlockHead; /* sign content */ typedef struct { - int version; /* version */ - int blockNum; - int size; - int algId; - int length; + int32_t version; /* version */ + int32_t blockNum; + int32_t size; + int32_t algId; + int32_t length; char hash[NORMAL_HASH_SIZE]; } ContentInfo; @@ -100,7 +102,7 @@ typedef struct { /* trusted app list */ typedef struct { - int maxCertPath; + int32_t maxCertPath; char *name; char *appSignCert; char *profileSignCert; @@ -109,19 +111,20 @@ typedef struct { } TrustAppCert; typedef struct { - int issuerLen; + int32_t issuerLen; char *issuer; - int subjectLen; + int32_t subjectLen; char *subject; mbedtls_pk_type_t pkType; - int pkLen; + int32_t pkLen; char *pkBuf; } CertInfo; -int GetAppid(ProfileProf *profile); -int CalculateHash(const unsigned char *input, int len, int hashAlg, unsigned char *output); -int GetHashUnitLen(int hashAlg); -char *GetSignBlockByType(const SignatureInfo *signInfo, int fp, int blockType, int *len, BlockHead *blockHead); +int32_t GetAppid(ProfileProf *profile); +int32_t CalculateHash(const unsigned char *input, int32_t len, int32_t hashAlg, unsigned char *output); +int32_t GetHashUnitLen(int32_t hashAlg); +char *GetSignBlockByType( + const SignatureInfo *signInfo, int32_t fp, int32_t blockType, int32_t *len, BlockHead *blockHead); #ifdef __cplusplus #if __cplusplus diff --git a/interfaces/innerkits/appverify_lite/include/app_verify_hal.h b/interfaces/innerkits/appverify_lite/include/app_verify_hal.h index 4145eec9bf346d9ed31d09e3034b8ecf8771c4e2..6e7d480783f8476d11a0820fc74f0c48cb4817bb 100644 --- a/interfaces/innerkits/appverify_lite/include/app_verify_hal.h +++ b/interfaces/innerkits/appverify_lite/include/app_verify_hal.h @@ -16,6 +16,7 @@ #ifndef SECURITY_APP_VERIFY_HAL_H #define SECURITY_APP_VERIFY_HAL_H +#include #ifdef __cplusplus #if __cplusplus @@ -25,14 +26,14 @@ extern "C" { #define INQUIRY_UDID_OK 0 #define INQUIRY_UDID_ERROR -1 -typedef int (*GetDeviceUdid)(unsigned char *udid, int size); +typedef int32_t (*GetDeviceUdid)(unsigned char *udid, int32_t size); typedef struct { GetDeviceUdid devUdidFunc; } ProductDiff; void RegistHalFunc(); -int InquiryDeviceUdid(unsigned char *udid, int size); +int32_t InquiryDeviceUdid(unsigned char *udid, int32_t size); #ifdef __cplusplus #if __cplusplus diff --git a/interfaces/innerkits/appverify_lite/include/app_verify_hap.h b/interfaces/innerkits/appverify_lite/include/app_verify_hap.h index e2c39d4cabab42884089c24d103d50a796941c2b..0b912858d47d08e81aa3e2a2b47fb555f16262ca 100644 --- a/interfaces/innerkits/appverify_lite/include/app_verify_hap.h +++ b/interfaces/innerkits/appverify_lite/include/app_verify_hap.h @@ -16,6 +16,8 @@ #ifndef SECURITY_APP_VERIFY_HAP_H #define SECURITY_APP_VERIFY_HAP_H +#include + #include "app_centraldirectory.h" #include "app_common.h" #include "app_file.h" @@ -45,8 +47,9 @@ extern "C" { #define HASH_ALG_SHA384 MBEDTLS_MD_SHA384 /* sha384 */ #define HASH_ALG_SHA512 MBEDTLS_MD_SHA512 /* sha512 */ -bool VerifyIntegrityChunk(int digestAlgorithm, int fp, const SignatureInfo *signInfo, const HapBuf *actualDigest); -int GetDigestAlgorithmId(unsigned int signAlgorithm); +bool VerifyIntegrityChunk( + int32_t digestAlgorithm, int32_t fp, const SignatureInfo *signInfo, const HapBuf *actualDigest); +int32_t GetDigestAlgorithmId(uint32_t signAlgorithm); #ifdef __cplusplus #if __cplusplus diff --git a/interfaces/innerkits/appverify_lite/include/app_verify_pub.h b/interfaces/innerkits/appverify_lite/include/app_verify_pub.h index 9cd863a136089f5024d477d32c8379a7ff073819..ded86429f291e96c686506742deeff54d9254740 100644 --- a/interfaces/innerkits/appverify_lite/include/app_verify_pub.h +++ b/interfaces/innerkits/appverify_lite/include/app_verify_pub.h @@ -17,6 +17,7 @@ #define SECURITY_APP_VERIFY_PUB_H #include +#include #ifdef __cplusplus #if __cplusplus @@ -70,8 +71,8 @@ typedef enum { } AppVErrCode; typedef struct { - int notBefore; - int notAfter; + int32_t notBefore; + int32_t notAfter; } ProfValidity; typedef struct { @@ -83,20 +84,20 @@ typedef struct { } ProfBundleInfo; typedef struct { - int restricNum; + int32_t restricNum; char **restricPermission; - int permissionNum; + int32_t permissionNum; char **permission; } ProfPermission; typedef struct { char *devIdType; - int devidNum; + int32_t devidNum; char **deviceId; } ProfDebugInfo; typedef struct { - int versionCode; /* version */ + int32_t versionCode; /* version */ char *versionName; /* version description */ char *uuid; /* uuid */ char *type; /* debug/release */ @@ -111,34 +112,34 @@ typedef struct { typedef struct { char *pk; - int len; + int32_t len; } AppSignPk; struct VfyRst; -typedef int (*GetSignPk)(struct VfyRst *verifyRst, AppSignPk *pk); +typedef int32_t (*GetSignPk)(struct VfyRst *verifyRst, AppSignPk *pk); typedef void (*FreeSignPK)(AppSignPk *pk); -typedef int (*MessageFunc)(unsigned char operationResult, const char *bundleName, unsigned char errCode); +typedef int32_t (*MessageFunc)(unsigned char operationResult, const char *bundleName, unsigned char errCode); typedef struct VfyRst { ProfileProf profile; /* profile */ } VerifyResult; /* verify app integrity, return 0 if OK, otherwise errcode AppVErrCode */ -int APPVERI_AppVerify(const char *filePath, VerifyResult *verifyRst); +int32_t APPVERI_AppVerify(const char *filePath, VerifyResult *verifyRst); /* free the verify result of APPVERI_AppVerify returned */ void APPVERI_FreeVerifyRst(VerifyResult *verifyRst); /* set debugmode */ -int APPVERI_SetDebugMode(bool mode); +int32_t APPVERI_SetDebugMode(bool mode); /* get unsigned file len without verify, return V_ERR if not OK */ -int APPVERI_GetUnsignedFileLength(const char *filePath); +int32_t APPVERI_GetUnsignedFileLength(const char *filePath); /* register msg func */ void APPVERI_RegisterMsgFunc(MessageFunc messageFunc); void APPVERI_SetActsMode(bool mode); -int APPVERI_IsActsMode(void); +int32_t APPVERI_IsActsMode(void); #ifdef __cplusplus #if __cplusplus diff --git a/interfaces/innerkits/appverify_lite/include/mbedtls_pkcs7.h b/interfaces/innerkits/appverify_lite/include/mbedtls_pkcs7.h index 0be69adf56dd55fcc4b91fffb09e353e4f02fd58..02e6b8fd06f8a3a363f4cb3ece1eae543f222a69 100644 --- a/interfaces/innerkits/appverify_lite/include/mbedtls_pkcs7.h +++ b/interfaces/innerkits/appverify_lite/include/mbedtls_pkcs7.h @@ -16,6 +16,7 @@ #ifndef MBEDTLS_PKCS7_H #define MBEDTLS_PKCS7_H #include +#include #include #include #include @@ -59,12 +60,12 @@ typedef enum { typedef struct { char issuer[MAX_SIGNER_NAME_LEN]; char subject[MAX_SIGNER_NAME_LEN]; - int depth; + int32_t depth; } SignerResovledInfo; typedef struct { SignerResovledInfo *signers; - int nrOfSigners; + int32_t nrOfSigners; } SignersResovedInfo; /* @@ -76,7 +77,7 @@ typedef struct { * crt is the certs list header, the lower ca cert is at front */ typedef struct { - int depth; + int32_t depth; mbedtls_x509_crt *crt; } SignerCertPath; @@ -87,7 +88,7 @@ typedef struct { * next is point to the next signer info, as PKCS7 definination, maybe there are multi signer */ typedef struct tagSignerInfo { - int version; + int32_t version; mbedtls_x509_buf serial; mbedtls_x509_name issuer; mbedtls_x509_crt *rootCert; @@ -122,7 +123,7 @@ typedef struct tagDigestAlgId { * PKCS7 signed-data structure */ typedef struct { - int version; + int32_t version; DigestAlgId digestAlgIds; Content content; mbedtls_x509_crt *certs; @@ -155,7 +156,7 @@ typedef struct { * Note : need to call PKCS7_FreeRes to free the resource when success * parse and use, no need to call PKCS7_FreeRes when parse failed *******************************************************************************/ -int PKCS7_ParseSignedData(const unsigned char *buf, size_t bufLen, Pkcs7 *pkcs7); +int32_t PKCS7_ParseSignedData(const unsigned char *buf, size_t bufLen, Pkcs7 *pkcs7); /******************************************************************************* * Function : PKCS7_VerifyCertsChain @@ -163,7 +164,7 @@ int PKCS7_ParseSignedData(const unsigned char *buf, size_t bufLen, Pkcs7 *pkcs7) * Input : pkcs7 -- the pkcs7 signed data header. * Return : 0 on success, others on fail *******************************************************************************/ -int PKCS7_VerifyCertsChain(const Pkcs7 *pkcs7); +int32_t PKCS7_VerifyCertsChain(const Pkcs7 *pkcs7); /******************************************************************************* * Function : PKCS7_FreeRes @@ -187,8 +188,8 @@ void PKCS7_FreeRes(Pkcs7 *pkcs7); * hashLen - the length of calculated digest hash * Return : 0 on success, others on fail *******************************************************************************/ -typedef int (*PKCS7_CalcDigest)(const Pkcs7 *pkcs7, const SignerInfo *signer, - mbedtls_md_type_t algType, unsigned char *hash, size_t *hashLen); +typedef int32_t (*PKCS7_CalcDigest)(const Pkcs7 *pkcs7, const SignerInfo *signer, + mbedtls_md_type_t algType, unsigned char *hash, size_t *hashLen); /******************************************************************************* * Function : PKCS7_GetContentData @@ -199,7 +200,7 @@ typedef int (*PKCS7_CalcDigest)(const Pkcs7 *pkcs7, const SignerInfo *signer, * dataLen - the content data length * Return : 0 on success, others on fail *******************************************************************************/ -int PKCS7_GetContentData(const Pkcs7 *pkcs7, unsigned char **data, size_t *dataLen); +int32_t PKCS7_GetContentData(const Pkcs7 *pkcs7, unsigned char **data, size_t *dataLen); /******************************************************************************* * Function : PKCS7_GetDigestInSignerAuthAttr @@ -210,7 +211,7 @@ int PKCS7_GetContentData(const Pkcs7 *pkcs7, unsigned char **data, size_t *dataL * digLen - digest length * Return : 0 on success, others on fail *******************************************************************************/ -int PKCS7_GetDigestInSignerAuthAttr(const SignerInfo *signer, unsigned char **dig, size_t *digLen); +int32_t PKCS7_GetDigestInSignerAuthAttr(const SignerInfo *signer, unsigned char **dig, size_t *digLen); /******************************************************************************* * Function : PKCS7_GetSignerAuthAttr @@ -223,7 +224,7 @@ int PKCS7_GetDigestInSignerAuthAttr(const SignerInfo *signer, unsigned char **di * dataLen - signer auth attribute data length * Return : 0 on success, others on fail *******************************************************************************/ -int PKCS7_GetSignerAuthAttr(const SignerInfo *signer, unsigned char **data, size_t *dataLen); +int32_t PKCS7_GetSignerAuthAttr(const SignerInfo *signer, unsigned char **data, size_t *dataLen); /******************************************************************************* * Function : PKCS7_VerifySignerSignature @@ -234,7 +235,7 @@ int PKCS7_GetSignerAuthAttr(const SignerInfo *signer, unsigned char **data, size * Output : NA * Return : 0 on success, others on fail *******************************************************************************/ -int PKCS7_VerifySignerSignature(const Pkcs7 *pkcs7, PKCS7_CalcDigest calcDigest); +int32_t PKCS7_VerifySignerSignature(const Pkcs7 *pkcs7, PKCS7_CalcDigest calcDigest); /******************************************************************************* * Function : PKCS7_GetAllSignersResolvedInfo @@ -264,7 +265,7 @@ void PKCS7_FreeAllSignersResolvedInfo(SignersResovedInfo *sri); * Output : NA * Return : 0 on success, others on error *******************************************************************************/ -int PKCS7_EnableDebugMode(bool mode); +int32_t PKCS7_EnableDebugMode(bool mode); #ifdef __cplusplus #if __cplusplus diff --git a/interfaces/innerkits/appverify_lite/products/default/app_verify_default.c b/interfaces/innerkits/appverify_lite/products/default/app_verify_default.c index 2f6cc7acff55e86a4e574dd90c3a0b1a121d82c9..1919095f873842653571af5b772eec6d391d9a1a 100644 --- a/interfaces/innerkits/appverify_lite/products/default/app_verify_default.c +++ b/interfaces/innerkits/appverify_lite/products/default/app_verify_default.c @@ -17,9 +17,9 @@ #include "app_verify_pub.h" #include "parameter.h" -static int GetUdid(unsigned char *udid, int size) +static int32_t GetUdid(unsigned char *udid, int32_t size) { - int ret = GetDevUdid((char *)udid, size); + int32_t ret = GetDevUdid((char *)udid, size); return ret; } diff --git a/interfaces/innerkits/appverify_lite/src/app_centraldirectory.c b/interfaces/innerkits/appverify_lite/src/app_centraldirectory.c index b1b5a3ec350b19ebfa81addc928c2246e1045588..fbd08c9486f5d7e3951a44da198396bf8fd116fc 100644 --- a/interfaces/innerkits/appverify_lite/src/app_centraldirectory.c +++ b/interfaces/innerkits/appverify_lite/src/app_centraldirectory.c @@ -29,7 +29,7 @@ #include "mbedtls_pkcs7.h" #include "securec.h" -void HapPutByte(const HapBuf *hapBuffer, int offset, char value) +void HapPutByte(const HapBuf *hapBuffer, int32_t offset, char value) { if (hapBuffer == NULL || hapBuffer->buffer == NULL) { return; @@ -40,7 +40,7 @@ void HapPutByte(const HapBuf *hapBuffer, int offset, char value) return; } -void HapPutData(const HapBuf *hapBuffer, int offset, const unsigned char *data, int len) +void HapPutData(const HapBuf *hapBuffer, int32_t offset, const unsigned char *data, int32_t len) { if (hapBuffer == NULL || hapBuffer->buffer == NULL) { return; @@ -52,7 +52,7 @@ void HapPutData(const HapBuf *hapBuffer, int offset, const unsigned char *data, } } -void HapSetInt32(const HapBuf *buffer, int offset, int value) +void HapSetInt32(const HapBuf *buffer, int32_t offset, int32_t value) { if (value < 0) { LOG_ERROR("int32 value of out range: %d", value); @@ -67,7 +67,7 @@ void HapSetInt32(const HapBuf *buffer, int offset, int value) return; } -bool CreateHapBuffer(HapBuf *hapBuffer, int len) +bool CreateHapBuffer(HapBuf *hapBuffer, int32_t len) { if (hapBuffer == NULL || len <= 0) { LOG_ERROR("create buf fail, buf is null"); @@ -93,13 +93,13 @@ void ClearHapBuffer(HapBuf *hapBuffer) hapBuffer->len = 0; } -static bool GetEocd(const FileRead *hapFile, HapEocd *hapEocd, int *eocdOffset) +static bool GetEocd(const FileRead *hapFile, HapEocd *hapEocd, int32_t *eocdOffset) { MmapInfo mmapInfo = {0}; if (hapFile->len <= sizeof(MinEocd)) { return false; } - int ret = HapMMap(hapFile->len, 0, &mmapInfo, hapFile); + int32_t ret = HapMMap(hapFile->len, 0, &mmapInfo, hapFile); if (ret != V_OK) { LOG_ERROR("mmap not ok"); return false; @@ -118,11 +118,11 @@ static bool GetEocd(const FileRead *hapFile, HapEocd *hapEocd, int *eocdOffset) return true; } // only a few haps have comment and use this branch - int maxReadLen = ((unsigned int)(hapFile->len - sizeof(MinEocd)) > UINT16_MAX_VALUE) ? + int32_t maxReadLen = ((unsigned int)(hapFile->len - sizeof(MinEocd)) > UINT16_MAX_VALUE) ? UINT16_MAX_VALUE : (hapFile->len - sizeof(MinEocd)); fileStart += hapFile->len - sizeof(MinEocd) - maxReadLen; LOG_INFO("maxReadLen %d", maxReadLen); - for (int i = 0; i < maxReadLen; i++) { + for (int32_t i = 0; i < maxReadLen; i++) { if ((HapGetShort((unsigned char*)fileStart + i + sizeof(MinEocd) - sizeof(short), sizeof(short)) == (maxReadLen - i)) && (HapGetInt((unsigned char*)fileStart + i, sizeof(int)) == HAP_EOCD_MAGIC)) { @@ -148,7 +148,7 @@ bool FindSignature(const FileRead *hapFile, SignatureInfo *signInfo) if (hapFile == NULL || signInfo == NULL) { return false; } - int eocdOffset = 0; + int32_t eocdOffset = 0; HapEocd hapEocd = {0}; if (!GetEocd(hapFile, &hapEocd, &eocdOffset)) { LOG_ERROR("find Eocd fail"); @@ -165,7 +165,7 @@ bool FindSignature(const FileRead *hapFile, SignatureInfo *signInfo) return true; } -int ReadFileFullyFromOffset(const HapBuf *buffer, int offset, const FileRead *file) +int32_t ReadFileFullyFromOffset(const HapBuf *buffer, int32_t offset, const FileRead *file) { if (buffer == NULL || buffer->buffer == NULL || file == NULL) { return DEST_BUFFER_IS_NULL; @@ -174,7 +174,7 @@ int ReadFileFullyFromOffset(const HapBuf *buffer, int offset, const FileRead *fi return READ_OFFSET_OUT_OF_RANGE; } lseek(file->fp, offset, SEEK_SET); - int readLen = read(file->fp, buffer->buffer, buffer->len); + int32_t readLen = read(file->fp, buffer->buffer, buffer->len); if (readLen != buffer->len) { LOG_ERROR("file read error %d --- %d", readLen, buffer->len); return READ_OFFSET_OUT_OF_RANGE; diff --git a/interfaces/innerkits/appverify_lite/src/app_common.c b/interfaces/innerkits/appverify_lite/src/app_common.c index 6777f8e2f1d2ae96c86adf184239a3a27063be24..d1487b072ec1da5e34089ed47c0ade50782cd2a0 100644 --- a/interfaces/innerkits/appverify_lite/src/app_common.c +++ b/interfaces/innerkits/appverify_lite/src/app_common.c @@ -15,7 +15,7 @@ #include "app_common.h" -long long HapGetInt64(const unsigned char *buf, int len) +long long HapGetInt64(const unsigned char *buf, int32_t len) { if (buf == NULL) { return 0; @@ -30,18 +30,18 @@ long long HapGetInt64(const unsigned char *buf, int len) return (long long)value; } -int HapGetInt(const unsigned char *buf, int len) +int32_t HapGetInt(const unsigned char *buf, int32_t len) { - unsigned int value = HapGetUnsignedInt(buf, len); + uint32_t value = HapGetUnsignedInt(buf, len); return (int)value; } -unsigned int HapGetUnsignedInt(const unsigned char *buf, int len) +uint32_t HapGetUnsignedInt(const unsigned char *buf, int32_t len) { if (buf == NULL) { return 0; } - unsigned int value = 0; + uint32_t value = 0; if (len != sizeof(int)) { return 0; } @@ -51,7 +51,7 @@ unsigned int HapGetUnsignedInt(const unsigned char *buf, int len) return value; } -short HapGetShort(const unsigned char *buf, int len) +short HapGetShort(const unsigned char *buf, int32_t len) { if (buf == NULL) { return 0; @@ -66,13 +66,13 @@ short HapGetShort(const unsigned char *buf, int len) return (short)value; } -void HapPutInt32(unsigned char *buf, int len, int value) +void HapPutInt32(unsigned char *buf, int32_t len, int32_t value) { if (buf == NULL || len < sizeof(int)) { return; } - int i; - unsigned int var = (unsigned int)value; + int32_t i; + uint32_t var = (unsigned int)value; for (i = 0; i < sizeof(int); i++) { buf[i] = var; var = var >> (BYTE_BITS); diff --git a/interfaces/innerkits/appverify_lite/src/app_file.c b/interfaces/innerkits/appverify_lite/src/app_file.c index 27620cfa7bf1fa6c15d95316045bc403c0abca8e..e71def56d5b4394c06d23eeb53d93cafe0aba0df 100644 --- a/interfaces/innerkits/appverify_lite/src/app_file.c +++ b/interfaces/innerkits/appverify_lite/src/app_file.c @@ -25,8 +25,8 @@ #include "app_centraldirectory.h" #include "app_verify_hal.h" -static int g_memoryPageSize = 0; -int InitVerify(FileRead *file, const char *filePath, int *handle) +static int32_t g_memoryPageSize = 0; +int32_t InitVerify(FileRead *file, const char *filePath, int32_t *handle) { if (handle == NULL || file == NULL || filePath == NULL) { LOG_ERROR("file open error"); @@ -63,7 +63,7 @@ int InitVerify(FileRead *file, const char *filePath, int *handle) return V_OK; } -int HapMMap(int bufCapacity, int offset, MmapInfo *mmapInfo, const FileRead *file) +int32_t HapMMap(int32_t bufCapacity, int32_t offset, MmapInfo *mmapInfo, const FileRead *file) { if (mmapInfo == NULL || file == NULL || bufCapacity <= 0) { return MMAP_FAILED; @@ -91,7 +91,7 @@ int HapMMap(int bufCapacity, int offset, MmapInfo *mmapInfo, const FileRead *fil return V_OK; } -void HapMUnMap(char *mapAddr, int mmapSize) +void HapMUnMap(char *mapAddr, int32_t mmapSize) { if (mapAddr == NULL || mmapSize <= 0) { return; diff --git a/interfaces/innerkits/appverify_lite/src/app_provision.c b/interfaces/innerkits/appverify_lite/src/app_provision.c index 299b014f22063a0c232f82fda40193bb923792c9..6ea807b2e3b63c106e3bb777665b4969f6f12c1e 100644 --- a/interfaces/innerkits/appverify_lite/src/app_provision.c +++ b/interfaces/innerkits/appverify_lite/src/app_provision.c @@ -44,7 +44,7 @@ static char *GetStringTag(const cJSON *root, const char *tag) LOG_PRINT_STR("failed to get %s", tag); return NULL; } - int objLen = strlen(jsonObj->valuestring); + int32_t objLen = strlen(jsonObj->valuestring); if (objLen < 0) { LOG_PRINT_STR("len error"); return NULL; @@ -63,12 +63,12 @@ static char *GetStringTag(const cJSON *root, const char *tag) return value; } -static void FreeStringAttay(char **array, int num) +static void FreeStringAttay(char **array, int32_t num) { if (array == NULL) { return; } - for (int i = 0; i < num; i++) { + for (int32_t i = 0; i < num; i++) { if (array[i] != NULL) { APPV_FREE(array[i]); } @@ -77,14 +77,14 @@ static void FreeStringAttay(char **array, int num) return; } -static char **GetStringArrayTag(const cJSON *root, const char *tag, int *numReturn) +static char **GetStringArrayTag(const cJSON *root, const char *tag, int32_t *numReturn) { cJSON *jsonObj = cJSON_GetObjectItem(root, tag); if (jsonObj == NULL) { LOG_PRINT_STR("failed to get %s", tag); return NULL; } - int num = cJSON_GetArraySize(jsonObj); + int32_t num = cJSON_GetArraySize(jsonObj); if (num == 0) { LOG_ERROR("array num 0"); *numReturn = 0; @@ -98,14 +98,14 @@ static char **GetStringArrayTag(const cJSON *root, const char *tag, int *numRetu } (void)memset_s(value, sizeof(char *) * num, 0, sizeof(char *) * num); - for (int i = 0; i < num; i++) { + for (int32_t i = 0; i < num; i++) { cJSON *item = cJSON_GetArrayItem(jsonObj, i); P_NULL_GOTO_WTTH_LOG(item); if (item->valuestring == NULL) { LOG_ERROR("valuestring is NULL"); return NULL; } - int len = strlen(item->valuestring); + int32_t len = strlen(item->valuestring); value[i] = APPV_MALLOC(len + 1); P_NULL_GOTO_WTTH_LOG(value[i]); @@ -123,7 +123,7 @@ EXIT: return NULL; } -static int GetProfValidity(const cJSON *root, ProfValidity *profVal) +static int32_t GetProfValidity(const cJSON *root, ProfValidity *profVal) { cJSON *jsonObj = cJSON_GetObjectItem(root, "validity"); if (jsonObj == NULL) { @@ -147,7 +147,7 @@ static int GetProfValidity(const cJSON *root, ProfValidity *profVal) return V_OK; } -static int GetProfBundleInfo(const cJSON *root, ProfBundleInfo *profVal) +static int32_t GetProfBundleInfo(const cJSON *root, ProfBundleInfo *profVal) { cJSON *jsonObj = cJSON_GetObjectItem(root, "bundle-info"); if (jsonObj == NULL) { @@ -183,7 +183,7 @@ static int GetProfBundleInfo(const cJSON *root, ProfBundleInfo *profVal) return V_OK; } -static int GetProfPermission(const cJSON *root, ProfPermission *profVal) +static int32_t GetProfPermission(const cJSON *root, ProfPermission *profVal) { cJSON *jsonObj = cJSON_GetObjectItem(root, "permissions"); if (jsonObj == NULL) { @@ -195,7 +195,7 @@ static int GetProfPermission(const cJSON *root, ProfPermission *profVal) return V_OK; } -static int GetProfDebugInfo(const cJSON *root, ProfDebugInfo *profVal) +static int32_t GetProfDebugInfo(const cJSON *root, ProfDebugInfo *profVal) { cJSON *jsonObj = cJSON_GetObjectItem(root, "debug-info"); if (jsonObj == NULL) { @@ -211,11 +211,11 @@ static int GetProfDebugInfo(const cJSON *root, ProfDebugInfo *profVal) return V_OK; } -static int GetProfIssuerInfo(const cJSON *root, ProfileProf *pf) +static int32_t GetProfIssuerInfo(const cJSON *root, ProfileProf *pf) { pf->issuer = GetStringTag(root, "issuer"); if (pf->issuer == NULL) { - int len = strlen(APP_STORE); + int32_t len = strlen(APP_STORE); pf->issuer = APPV_MALLOC(len + 1); if (pf->issuer == NULL) { return V_ERR; @@ -281,12 +281,12 @@ void ProfFreeData(ProfileProf *pf) } /* parse profile */ -int ParseProfile(const char *buf, int len, ProfileProf *pf) +int32_t ParseProfile(const char *buf, int32_t len, ProfileProf *pf) { P_NULL_RETURN_WTTH_LOG(pf); P_NULL_RETURN_WTTH_LOG(buf); ProfInit(pf); - int ret; + int32_t ret; char *pfStr = strchr(buf, '{'); P_NULL_RETURN_WTTH_LOG(pfStr); @@ -338,7 +338,7 @@ EXIT: return V_ERR; } -static int VerifyAppTypeAndDistribution(const ProfileProf *pf) +static int32_t VerifyAppTypeAndDistribution(const ProfileProf *pf) { if ((strcmp(pf->type, DEBUG_TYPE) != 0) && (strcmp(pf->type, RELEASE_TYPE) != 0)) { LOG_PRINT_STR("invalid app type: %s", pf->type); @@ -355,7 +355,7 @@ static int VerifyAppTypeAndDistribution(const ProfileProf *pf) return V_OK; } -static int VerifyAppBundleInfo(const ProfileProf *pf) +static int32_t VerifyAppBundleInfo(const ProfileProf *pf) { if (strcmp(pf->type, DEBUG_TYPE) == 0) { if (strlen((char *)pf->bundleInfo.devCert) == 0) { @@ -374,9 +374,9 @@ static int VerifyAppBundleInfo(const ProfileProf *pf) return V_OK; } -static int VerifyUdid(const ProfileProf *pf) +static int32_t VerifyUdid(const ProfileProf *pf) { - unsigned int size = UDID_VERIFY_BYTES + 1; + uint32_t size = UDID_VERIFY_BYTES + 1; if (pf->debugInfo.devidNum > MAX_UDID_NUM) { LOG_ERROR("udid num exceed maximum"); return V_ERR; @@ -387,13 +387,13 @@ static int VerifyUdid(const ProfileProf *pf) return V_ERR; } (void)memset_s(udid, size, 0, size); - int result = InquiryDeviceUdid(udid, size); + int32_t result = InquiryDeviceUdid(udid, size); if (result != INQUIRY_UDID_OK) { free(udid); LOG_ERROR("get udid fail, ret: %d", result); return V_ERR; } - for (int i = 0; i < pf->debugInfo.devidNum; i++) { + for (int32_t i = 0; i < pf->debugInfo.devidNum; i++) { if (strcmp((const char *)pf->debugInfo.deviceId[i], (const char *)udid) == 0) { LOG_INFO("find right udid"); free(udid); @@ -407,14 +407,14 @@ static int VerifyUdid(const ProfileProf *pf) return V_ERR; } -static int VerifyDebugInfo(const ProfileProf *pf) +static int32_t VerifyDebugInfo(const ProfileProf *pf) { if (strcmp(pf->type, DEBUG_TYPE) != 0) { LOG_INFO("not debug app, return ok"); return V_OK; } LOG_PRINT_STR("devid type: %s", pf->debugInfo.devIdType); - int ret; + int32_t ret; if (strcmp(pf->debugInfo.devIdType, "udid") == 0) { ret = VerifyUdid(pf); } else { @@ -424,10 +424,10 @@ static int VerifyDebugInfo(const ProfileProf *pf) return ret; } -int VerifyProfileContent(const ProfileProf *pf) +int32_t VerifyProfileContent(const ProfileProf *pf) { P_NULL_RETURN_WTTH_LOG(pf); - int ret = VerifyAppTypeAndDistribution(pf); + int32_t ret = VerifyAppTypeAndDistribution(pf); if (ret != V_OK) { LOG_PRINT_STR("invalid profile distribution type : %s", pf->appDistType); return V_ERR_INVALID_DISP_TYPE; diff --git a/interfaces/innerkits/appverify_lite/src/app_verify.c b/interfaces/innerkits/appverify_lite/src/app_verify.c index 2fabeda0ba69a624dd227063582b0816a13d3f36..3e5ca1870b14b8cc8fb8acf2d57720f64801216d 100644 --- a/interfaces/innerkits/appverify_lite/src/app_verify.c +++ b/interfaces/innerkits/appverify_lite/src/app_verify.c @@ -113,10 +113,10 @@ static void ContentN2H(ContentInfo *content) return; } -static int GetSignHead(const FileRead *file, SignatureInfo *signInfo) +static int32_t GetSignHead(const FileRead *file, SignatureInfo *signInfo) { struct stat fileSt; - int ret = fstat(file->fp, &fileSt); + int32_t ret = fstat(file->fp, &fileSt); if ((ret != 0) || (fileSt.st_size < sizeof(HwSignHead))) { LOG_ERROR("fstat error, %d, filelen: %d", ret, (int)fileSt.st_size); return V_ERR_GET_SIGNHEAD; @@ -136,7 +136,7 @@ static int GetSignHead(const FileRead *file, SignatureInfo *signInfo) } HwSignHead *signHead = APPV_MALLOC(sizeof(HwSignHead)); P_NULL_RETURN_WTTH_LOG(signHead); - int readLen = read(file->fp, signHead, sizeof(HwSignHead)); + int32_t readLen = read(file->fp, signHead, sizeof(HwSignHead)); if (readLen != sizeof(HwSignHead)) { LOG_ERROR("readLen %d, %d", readLen, (int)sizeof(HwSignHead)); APPV_FREE(signHead); @@ -166,22 +166,22 @@ static int GetSignHead(const FileRead *file, SignatureInfo *signInfo) return V_OK; } -static int FindBlockHead(const SignatureInfo *signInfo, int fp, int blockType, BlockHead *block) +static int32_t FindBlockHead(const SignatureInfo *signInfo, int32_t fp, int32_t blockType, BlockHead *block) { HwSignHead *signH = signInfo->signHead; /* find signature block */ lseek(fp, signInfo->fullSignBlockOffset, SEEK_SET); - int num = signH->blockNum; + int32_t num = signH->blockNum; if (num > MAX_BLOCK_NUM) { return V_ERR; } while (num-- > 0) { - int readLen = read(fp, block, sizeof(BlockHead)); + int32_t readLen = read(fp, block, sizeof(BlockHead)); if (readLen != sizeof(BlockHead)) { LOG_ERROR("find block head , read err %d, %d", readLen, (int)sizeof(BlockHead)); return V_ERR; } - int type = HapGetInt((unsigned char *)&block->type, sizeof(block->type)); + int32_t type = HapGetInt((unsigned char *)&block->type, sizeof(block->type)); LOG_ERROR("find block type: %0x", type); if (type == blockType) { BlockHeadN2H(block); @@ -192,12 +192,13 @@ static int FindBlockHead(const SignatureInfo *signInfo, int fp, int blockType, B return V_ERR; } -char *GetSignBlockByType(const SignatureInfo *signInfo, int fp, int blockType, int *len, BlockHead *blockHead) +char *GetSignBlockByType( + const SignatureInfo *signInfo, int32_t fp, int32_t blockType, int32_t *len, BlockHead *blockHead) { if (signInfo == NULL || blockHead == NULL) { return NULL; } - int ret = FindBlockHead(signInfo, fp, blockType, blockHead); + int32_t ret = FindBlockHead(signInfo, fp, blockType, blockHead); if (ret != V_OK) { LOG_ERROR("find block head error"); return NULL; @@ -230,7 +231,7 @@ char *GetSignBlockByType(const SignatureInfo *signInfo, int fp, int blockType, i return NULL; } lseek(fp, signInfo->fullSignBlockOffset + blockHead->offset, SEEK_SET); - int readLen = read(fp, buf, blockHead->length); + int32_t readLen = read(fp, buf, blockHead->length); if (readLen != blockHead->length) { LOG_ERROR("read error: %d, %d", readLen, blockHead->length); APPV_FREE(buf); @@ -241,16 +242,16 @@ char *GetSignBlockByType(const SignatureInfo *signInfo, int fp, int blockType, i return buf; } -int GetHashUnitLen(int hashAlg) +int32_t GetHashUnitLen(int32_t hashAlg) { LOG_INFO("algId: %d", hashAlg); return mbedtls_md_get_size(mbedtls_md_info_from_type((mbedtls_md_type_t)hashAlg)); } -static int CalcCmpContHash(const Pkcs7 *pkcs7, const SignerInfo *signer, +static int32_t CalcCmpContHash(const Pkcs7 *pkcs7, const SignerInfo *signer, mbedtls_md_type_t algType, unsigned char *hash, size_t *hashLen) { - int rc; + int32_t rc; unsigned char *input = NULL; size_t inputLen; @@ -284,10 +285,10 @@ static int CalcCmpContHash(const Pkcs7 *pkcs7, const SignerInfo *signer, return V_OK; } -static int CalcDigest(const Pkcs7 *pkcs7, const SignerInfo *signer, +static int32_t CalcDigest(const Pkcs7 *pkcs7, const SignerInfo *signer, mbedtls_md_type_t algType, unsigned char *hash, size_t *hashLen) { - int rc; + int32_t rc; unsigned char *input = NULL; size_t inputLen; rc = CalcCmpContHash(pkcs7, signer, algType, hash, hashLen); @@ -312,13 +313,13 @@ static int CalcDigest(const Pkcs7 *pkcs7, const SignerInfo *signer, return V_OK; } -static int VerifyRawHash(const SignatureInfo *signInfo, const FileRead *fileRead, const Pkcs7 *pkcs7Handle) +static int32_t VerifyRawHash(const SignatureInfo *signInfo, const FileRead *fileRead, const Pkcs7 *pkcs7Handle) { /* parse content */ unsigned char *input = NULL; size_t inputLen = 0; /* calc orinal context hash */ - int ret = PKCS7_GetContentData((Pkcs7 *)pkcs7Handle, &input, &inputLen); + int32_t ret = PKCS7_GetContentData((Pkcs7 *)pkcs7Handle, &input, &inputLen); if (ret != V_OK) { LOG_ERROR("get content info error: %d", ret); return ret; @@ -342,7 +343,7 @@ static int VerifyRawHash(const SignatureInfo *signInfo, const FileRead *fileRead return V_ERR; } HapBuf actualDigest = {0}; - int rootHashLen = GetHashUnitLen(content->algId); + int32_t rootHashLen = GetHashUnitLen(content->algId); if (!CreateHapBuffer(&actualDigest, rootHashLen)) { LOG_ERROR("create buf fail"); APPV_FREE(content); @@ -365,7 +366,7 @@ static int VerifyRawHash(const SignatureInfo *signInfo, const FileRead *fileRead return V_OK; } -static int GetCertTypeBySourceName(const TrustAppCert *cert) +static int32_t GetCertTypeBySourceName(const TrustAppCert *cert) { if (cert == NULL) { return CERT_TYPE_OTHER; @@ -383,9 +384,9 @@ static int GetCertTypeBySourceName(const TrustAppCert *cert) } static const TrustAppCert *GetProfSourceBySigningCert(const SignerResovledInfo *signer, - const TrustAppCert* trustList, int num) + const TrustAppCert* trustList, int32_t num) { - for (int i = 0; i < num; i++) { + for (int32_t i = 0; i < num; i++) { if (strcmp(trustList[i].issueCA, signer->issuer) == 0) { if (strcmp(trustList[i].profileSignCert, signer->subject) == 0 || strcmp(trustList[i].profileDebugSignCert, signer->subject) == 0) { @@ -397,7 +398,7 @@ static const TrustAppCert *GetProfSourceBySigningCert(const SignerResovledInfo * return NULL; } -static int GetProfileCertTypeBySignInfo(SignerResovledInfo *signer, int *certType) +static int32_t GetProfileCertTypeBySignInfo(SignerResovledInfo *signer, int32_t *certType) { /* only support first signer cert */ const TrustAppCert *trustCert = GetProfSourceBySigningCert(signer, g_trustAppList, @@ -417,9 +418,9 @@ static int GetProfileCertTypeBySignInfo(SignerResovledInfo *signer, int *certTyp static const TrustAppCert *GetAppSourceBySigningCert(const SignerResovledInfo *signer, - const TrustAppCert* trustList, int num) + const TrustAppCert* trustList, int32_t num) { - for (int i = 0; i < num; i++) { + for (int32_t i = 0; i < num; i++) { if (strcmp(trustList[i].appSignCert, signer->subject) == 0 && strcmp(trustList[i].issueCA, signer->issuer) == 0) { return &trustList[i]; @@ -428,7 +429,7 @@ static const TrustAppCert *GetAppSourceBySigningCert(const SignerResovledInfo *s return NULL; } -static int GetAppCertTypeBySignInfo(SignerResovledInfo *signer, int *certType) +static int32_t GetAppCertTypeBySignInfo(SignerResovledInfo *signer, int32_t *certType) { /* only support first signer cert */ const TrustAppCert *trustCert = GetAppSourceBySigningCert(signer, g_trustAppList, @@ -447,7 +448,7 @@ static int GetAppCertTypeBySignInfo(SignerResovledInfo *signer, int *certType) } /* get singer cert type by trust list */ -static int GetAppSingerCertType(Pkcs7 *pkcs7Handle, int *certType) +static int32_t GetAppSingerCertType(Pkcs7 *pkcs7Handle, int32_t *certType) { SignersResovedInfo *sri = PKCS7_GetAllSignersResolvedInfo(pkcs7Handle); if (sri == NULL || sri->nrOfSigners == 0) { @@ -455,7 +456,7 @@ static int GetAppSingerCertType(Pkcs7 *pkcs7Handle, int *certType) LOG_ERROR("Get all signer's resolved info failed"); return V_ERR; } - int ret = GetAppCertTypeBySignInfo(&sri->signers[0], certType); + int32_t ret = GetAppCertTypeBySignInfo(&sri->signers[0], certType); if (ret != V_OK) { LOG_ERROR("get cert type by sign info failed: %d", ret); PKCS7_FreeAllSignersResolvedInfo(sri); @@ -466,14 +467,14 @@ static int GetAppSingerCertType(Pkcs7 *pkcs7Handle, int *certType) } /* get singer cert type by trust list */ -static int GetProfileSingerCertType(Pkcs7 *pkcs7Handle, int *certType) +static int32_t GetProfileSingerCertType(Pkcs7 *pkcs7Handle, int32_t *certType) { SignersResovedInfo *sri = PKCS7_GetAllSignersResolvedInfo(pkcs7Handle); if (sri == NULL) { LOG_ERROR("Get all signer's resolved info failed"); return V_ERR; } - int ret = GetProfileCertTypeBySignInfo(&sri->signers[0], certType); + int32_t ret = GetProfileCertTypeBySignInfo(&sri->signers[0], certType); if (ret != V_OK) { LOG_ERROR("get cert type by sign info failed: %d", ret); PKCS7_FreeAllSignersResolvedInfo(sri); @@ -484,17 +485,17 @@ static int GetProfileSingerCertType(Pkcs7 *pkcs7Handle, int *certType) } /* verfiy profile data integrity with sign */ -static int VerifyProfileSignGetRaw(const char *buf, int len, char **profileContent, int *contentLen) +static int32_t VerifyProfileSignGetRaw(const char *buf, int32_t len, char **profileContent, int32_t *contentLen) { /* verfiy */ char *profileData = NULL; - int certType; + int32_t certType; unsigned char *input = NULL; size_t inputLen; Pkcs7 *pkcs7 = APPV_MALLOC(sizeof(Pkcs7)); P_NULL_RETURN_WTTH_LOG(pkcs7); - int ret = PKCS7_ParseSignedData((unsigned char *)buf, (size_t)len, pkcs7); + int32_t ret = PKCS7_ParseSignedData((unsigned char *)buf, (size_t)len, pkcs7); P_ERR_GOTO_WTTH_LOG(ret); LOG_INFO("pkcs7 parse message success"); @@ -546,21 +547,21 @@ EXIT: APPV_FREE(profileData); return V_ERR; } -static unsigned char *GetRsaPk(const mbedtls_pk_context *pk, int *len) +static unsigned char *GetRsaPk(const mbedtls_pk_context *pk, int32_t *len) { unsigned char *buf = APPV_MALLOC(MAX_PK_BUF); if (buf == NULL) { LOG_ERROR("malloc error"); return NULL; } - int ret = memset_s(buf, MAX_PK_BUF, 0, MAX_PK_BUF); + int32_t ret = memset_s(buf, MAX_PK_BUF, 0, MAX_PK_BUF); if (ret != EOK) { LOG_ERROR("memset error"); APPV_FREE(buf); return NULL; } unsigned char *c = buf + MAX_PK_BUF; - int pkLen = mbedtls_pk_write_pubkey(&c, buf, pk); + int32_t pkLen = mbedtls_pk_write_pubkey(&c, buf, pk); LOG_INFO("GetRsaPk pkLen %d", pkLen); if (pkLen < 0 || pkLen > MAX_PK_BUF) { LOG_ERROR("get pk buf error"); @@ -589,7 +590,7 @@ static unsigned char *GetRsaPk(const mbedtls_pk_context *pk, int *len) return pkBuf; } -static unsigned char *GetEcPk(const mbedtls_pk_context *pk, int *len) +static unsigned char *GetEcPk(const mbedtls_pk_context *pk, int32_t *len) { mbedtls_ecp_keypair *ecCtx = mbedtls_pk_ec(*pk); if (ecCtx == NULL) { @@ -601,7 +602,7 @@ static unsigned char *GetEcPk(const mbedtls_pk_context *pk, int *len) LOG_ERROR("malloc error"); return NULL; } - int ret = memset_s(buf, MBEDTLS_ECP_MAX_PT_LEN, 0, MBEDTLS_ECP_MAX_PT_LEN); + int32_t ret = memset_s(buf, MBEDTLS_ECP_MAX_PT_LEN, 0, MBEDTLS_ECP_MAX_PT_LEN); if (ret != EOK) { LOG_ERROR("memset error"); APPV_FREE(buf); @@ -639,7 +640,7 @@ static unsigned char *GetEcPk(const mbedtls_pk_context *pk, int *len) return pkBuf; } -static unsigned char *GetPkBuf(const mbedtls_pk_context *pk, int *len) +static unsigned char *GetPkBuf(const mbedtls_pk_context *pk, int32_t *len) { unsigned char *bufA = NULL; if (mbedtls_pk_get_type(pk) == MBEDTLS_PK_RSA || mbedtls_pk_get_type(pk) == MBEDTLS_PK_RSASSA_PSS) { @@ -650,19 +651,19 @@ static unsigned char *GetPkBuf(const mbedtls_pk_context *pk, int *len) return bufA; } -static int ParseCertGetPk(const char *certEncoded, AppSignPk *pk) +static int32_t ParseCertGetPk(const char *certEncoded, AppSignPk *pk) { mbedtls_x509_crt *cert = APPV_MALLOC(sizeof(mbedtls_x509_crt)); P_NULL_RETURN_WTTH_LOG(cert); mbedtls_x509_crt_init(cert); - int ret = mbedtls_x509_crt_parse(cert, (unsigned char *)certEncoded, strlen(certEncoded) + 1); + int32_t ret = mbedtls_x509_crt_parse(cert, (unsigned char *)certEncoded, strlen(certEncoded) + 1); if (ret != V_OK) { LOG_ERROR("load cert failed, ret: %d", ret); APPV_FREE(cert); return V_ERR; } - int len = 0; + int32_t len = 0; unsigned char *pkBuf = GetPkBuf(&cert->pk, &len); if (pkBuf == NULL) { LOG_ERROR("get pk error"); @@ -677,9 +678,9 @@ static int ParseCertGetPk(const char *certEncoded, AppSignPk *pk) return V_OK; } -static int GetAppSignPublicKey(const ProfileProf *profile, AppSignPk *pk) +static int32_t GetAppSignPublicKey(const ProfileProf *profile, AppSignPk *pk) { - int ret; + int32_t ret; /* release cert */ if (profile->bundleInfo.releaseCert && strlen((char *)profile->bundleInfo.releaseCert) != 0) { @@ -702,11 +703,11 @@ static void FreeAppSignPublicKey(AppSignPk *pk) return; } -int GetAppid(ProfileProf *profile) +int32_t GetAppid(ProfileProf *profile) { P_NULL_RETURN_RET_WTTH_LOG(profile, V_ERR); AppSignPk pk = {0}; - int ret = GetAppSignPublicKey(profile, &pk); + int32_t ret = GetAppSignPublicKey(profile, &pk); if (ret != V_OK) { LOG_ERROR("get sign pk failed"); return ret; @@ -714,8 +715,8 @@ int GetAppid(ProfileProf *profile) /* base64 */ size_t useLen = 0; mbedtls_base64_encode(NULL, 0, &useLen, (unsigned char *)pk.pk, pk.len); - int bundleNameLen = strlen(profile->bundleInfo.bundleName); - int appidLen = bundleNameLen + useLen + 1 + 1; + int32_t bundleNameLen = strlen(profile->bundleInfo.bundleName); + int32_t appidLen = bundleNameLen + useLen + 1 + 1; LOG_INFO("GetAppid %d", appidLen); if (useLen > MAX_KEY_PAIR_SIZE) { @@ -750,13 +751,13 @@ int GetAppid(ProfileProf *profile) return V_OK; } -static int VerifyProfGetContent(int fp, const SignatureInfo *signInfo, int certType, ProfileProf *pf) +static int32_t VerifyProfGetContent(int32_t fp, const SignatureInfo *signInfo, int32_t certType, ProfileProf *pf) { char *profBuf = NULL; - int len = 0; + int32_t len = 0; BlockHead blockHead = {0}; - int ret; - int rawLen = 0; + int32_t ret; + int32_t rawLen = 0; char *rawBuf = GetSignBlockByType(signInfo, fp, PROFILE_BLOCK_WITHSIGN_TYPE, &rawLen, &blockHead); P_NULL_RETURN_RET_WTTH_LOG(rawBuf, V_ERR_GET_PROFILE_DATA); LOG_INFO("certType %d", certType); @@ -791,7 +792,7 @@ EXIT: return ret; } -static int CmpCert(const mbedtls_x509_crt *certA, const CertInfo *binSignCert) +static int32_t CmpCert(const mbedtls_x509_crt *certA, const CertInfo *binSignCert) { P_NULL_RETURN_RET_WTTH_LOG(certA, V_ERR); P_NULL_RETURN_RET_WTTH_LOG(binSignCert, V_ERR); @@ -813,7 +814,7 @@ static int CmpCert(const mbedtls_x509_crt *certA, const CertInfo *binSignCert) LOG_ERROR("pk type diff"); return V_ERR; } - int lenA = 0; + int32_t lenA = 0; unsigned char *bufA = GetPkBuf(&certA->pk, &lenA); P_NULL_RETURN_RET_WTTH_LOG(bufA, V_ERR); @@ -833,14 +834,14 @@ static int CmpCert(const mbedtls_x509_crt *certA, const CertInfo *binSignCert) return V_OK; } -int LoadCertAndCmpDest(const unsigned char *certBase64, const CertInfo *binSignCert) +int32_t LoadCertAndCmpDest(const unsigned char *certBase64, const CertInfo *binSignCert) { if (certBase64 == NULL || binSignCert == NULL) { return V_ERR; } mbedtls_x509_crt cert; mbedtls_x509_crt_init(&cert); - int ret = mbedtls_x509_crt_parse(&cert, certBase64, strlen((char *)certBase64) + 1); + int32_t ret = mbedtls_x509_crt_parse(&cert, certBase64, strlen((char *)certBase64) + 1); if (ret != V_OK) { LOG_ERROR("load release cert failed"); LOG_PRINT_STR("%s", certBase64); @@ -857,7 +858,7 @@ int LoadCertAndCmpDest(const unsigned char *certBase64, const CertInfo *binSignC return V_ERR; } -static int CheckReleaseAppSign(const CertInfo *binSignCert, const ProfileProf *pf) +static int32_t CheckReleaseAppSign(const CertInfo *binSignCert, const ProfileProf *pf) { /* if distribution type is app_gallery, return error */ if (strcmp(pf->appDistType, "app_gallery") == 0) { @@ -869,7 +870,7 @@ static int CheckReleaseAppSign(const CertInfo *binSignCert, const ProfileProf *p LOG_ERROR("release app, release Cert null"); return V_ERR; } - int ret = LoadCertAndCmpDest(pf->bundleInfo.releaseCert, binSignCert); + int32_t ret = LoadCertAndCmpDest(pf->bundleInfo.releaseCert, binSignCert); if (ret == V_OK) { LOG_INFO("dev cert consistent"); return V_OK; @@ -878,13 +879,13 @@ static int CheckReleaseAppSign(const CertInfo *binSignCert, const ProfileProf *p return V_ERR; } -static int CheckDebugAppSign(CertInfo *binSignCert, const ProfileProf *pf) +static int32_t CheckDebugAppSign(CertInfo *binSignCert, const ProfileProf *pf) { if (strlen((char *)pf->bundleInfo.devCert) == 0) { LOG_ERROR("debug app, devCert null"); return V_ERR; } - int ret = LoadCertAndCmpDest(pf->bundleInfo.devCert, binSignCert); + int32_t ret = LoadCertAndCmpDest(pf->bundleInfo.devCert, binSignCert); if (ret == V_OK) { LOG_INFO("dev cert consistent"); return V_OK; @@ -900,7 +901,7 @@ static int CheckDebugAppSign(CertInfo *binSignCert, const ProfileProf *pf) return V_ERR; } -static int CheckAppSignCertWithProfile(int appCertType, CertInfo *binSignCert, ProfileProf *pf) +static int32_t CheckAppSignCertWithProfile(int32_t appCertType, CertInfo *binSignCert, ProfileProf *pf) { /* cert type appgallary or system, not check */ if (appCertType == CERT_TYPE_APPGALLARY || appCertType == CERT_TYPE_SYETEM) { @@ -908,7 +909,7 @@ static int CheckAppSignCertWithProfile(int appCertType, CertInfo *binSignCert, P return V_OK; } - int ret = V_ERR; + int32_t ret = V_ERR; /* debug app, app cert consistent with profile dev or release cert */ if (strcmp(DEBUG_TYPE, (char *)pf->type) == 0) { ret = CheckDebugAppSign(binSignCert, pf); @@ -920,9 +921,9 @@ static int CheckAppSignCertWithProfile(int appCertType, CertInfo *binSignCert, P return ret; } -static int CertInfoInit(CertInfo *certInfo) +static int32_t CertInfoInit(CertInfo *certInfo) { - int ret = memset_s(certInfo, sizeof(CertInfo), 0, sizeof(CertInfo)); + int32_t ret = memset_s(certInfo, sizeof(CertInfo), 0, sizeof(CertInfo)); if (ret != EOK) { LOG_ERROR("memset error"); } @@ -951,12 +952,12 @@ void FreeCertInfo(CertInfo *certInfo) return; } -static int GetCertInfo(const mbedtls_x509_crt *ctr, CertInfo **binSignCert) +static int32_t GetCertInfo(const mbedtls_x509_crt *ctr, CertInfo **binSignCert) { CertInfo *certInfo = APPV_MALLOC(sizeof(CertInfo)); P_NULL_RETURN_RET_WTTH_LOG(certInfo, V_ERR_MALLOC); - int ret = CertInfoInit(certInfo); + int32_t ret = CertInfoInit(certInfo); if (ret != V_OK) { LOG_ERROR("cert info init"); ret = V_ERR_MEMSET; @@ -1006,10 +1007,10 @@ EXIT: return ret; } -static int VerfiyAppSourceGetProfile(int fp, const SignatureInfo *signInfo, - int certType, CertInfo *binSignCert, ProfileProf *pf) +static int32_t VerfiyAppSourceGetProfile(int32_t fp, const SignatureInfo *signInfo, + int32_t certType, CertInfo *binSignCert, ProfileProf *pf) { - int ret = VerifyProfGetContent(fp, signInfo, certType, pf); + int32_t ret = VerifyProfGetContent(fp, signInfo, certType, pf); if (ret != V_OK) { LOG_ERROR("VerifyProfGetContent error: %d", ret); return ret; @@ -1032,10 +1033,10 @@ static int VerfiyAppSourceGetProfile(int fp, const SignatureInfo *signInfo, return V_OK; } -static int VerifyAppSignPkcsData(const FileRead *fileRead, const SignatureInfo *signInfo, const Pkcs7 *pkcs7Handle) +static int32_t VerifyAppSignPkcsData(const FileRead *fileRead, const SignatureInfo *signInfo, const Pkcs7 *pkcs7Handle) { /* verify sign, rawdata */ - int ret = PKCS7_VerifyCertsChain(pkcs7Handle); + int32_t ret = PKCS7_VerifyCertsChain(pkcs7Handle); if (ret != V_OK) { LOG_ERROR("Verify certs failed, ret: %d", ret); return V_ERR_VERIFY_CERT_CHAIN; @@ -1058,14 +1059,14 @@ static int VerifyAppSignPkcsData(const FileRead *fileRead, const SignatureInfo * return V_OK; } -static Pkcs7 *GetBinSignPkcs(const char *signBuf, int len) +static Pkcs7 *GetBinSignPkcs(const char *signBuf, int32_t len) { Pkcs7 *pkcs7 = APPV_MALLOC(sizeof(Pkcs7)); if (pkcs7 == NULL) { LOG_ERROR("malloc error"); return NULL; } - int ret = PKCS7_ParseSignedData((unsigned char *)signBuf, (size_t)len, pkcs7); + int32_t ret = PKCS7_ParseSignedData((unsigned char *)signBuf, (size_t)len, pkcs7); if (ret != V_OK) { LOG_ERROR("pkcs7parse message failed, ret: %d", ret); PKCS7_FreeRes(pkcs7); @@ -1075,7 +1076,7 @@ static Pkcs7 *GetBinSignPkcs(const char *signBuf, int len) return pkcs7; } -static FileRead *GetFileRead(int fp, int offset, int size) +static FileRead *GetFileRead(int32_t fp, int32_t offset, int32_t size) { /* raw buf len = sign block head offset */ FileRead *fileRead = APPV_MALLOC(sizeof(FileRead)); @@ -1088,12 +1089,12 @@ static FileRead *GetFileRead(int fp, int offset, int size) fileRead->len = size; return fileRead; } -static int VerifyBinSign(SignatureInfo *signInfo, int fp, CertInfo **signCert, int *certType) +static int32_t VerifyBinSign(SignatureInfo *signInfo, int32_t fp, CertInfo **signCert, int32_t *certType) { - int blockLen; + int32_t blockLen; BlockHead blockHead = {0}; FileRead *fileRead = NULL; - int ret; + int32_t ret; char *signBuf = GetSignBlockByType(signInfo, fp, SIGNATURE_BLOCK_TYPE, &blockLen, &blockHead); P_NULL_RETURN_RET_WTTH_LOG(signBuf, V_ERR_GET_SIGN_BLOCK); @@ -1147,12 +1148,12 @@ EXIT: return ret; } -static int VerifyIntegrity(SignatureInfo *signInfo, int fp, ProfileProf *pf) +static int32_t VerifyIntegrity(SignatureInfo *signInfo, int32_t fp, ProfileProf *pf) { CertInfo *binSignCert = NULL; - int certType = 0; + int32_t certType = 0; - int ret = VerifyBinSign(signInfo, fp, &binSignCert, &certType); + int32_t ret = VerifyBinSign(signInfo, fp, &binSignCert, &certType); if (ret != V_OK) { LOG_ERROR("verify bin sign error"); return ret; @@ -1170,19 +1171,19 @@ static int VerifyIntegrity(SignatureInfo *signInfo, int fp, ProfileProf *pf) return V_OK; } -int APPVERI_AppVerify(const char *filePath, VerifyResult *verifyRst) +int32_t APPVERI_AppVerify(const char *filePath, VerifyResult *verifyRst) { if (filePath == NULL || verifyRst == NULL) { return V_ERR_FILE_OPEN; } - int handle = 0; + int32_t handle = 0; FileRead file = {0}; if (InitVerify(&file, filePath, &handle) != V_OK) { close(handle); return V_ERR_FILE_OPEN; } SignatureInfo signInfo = {0}; - int ret = GetSignHead(&file, &signInfo); + int32_t ret = GetSignHead(&file, &signInfo); if (ret != V_OK) { LOG_ERROR("get sign head error"); close(handle); @@ -1221,13 +1222,13 @@ int APPVERI_AppVerify(const char *filePath, VerifyResult *verifyRst) } /* set debug mode */ -int APPVERI_SetDebugMode(bool mode) +int32_t APPVERI_SetDebugMode(bool mode) { LOG_INFO("set debug mode: %d", mode); if (g_isDebugMode == mode) { return V_OK; } - int ret = PKCS7_EnableDebugMode(mode); + int32_t ret = PKCS7_EnableDebugMode(mode); if (ret != V_OK) { LOG_ERROR("enable pcks7 debug mode failed"); return ret; @@ -1242,7 +1243,7 @@ void APPVERI_SetActsMode(bool mode) g_isActsMode = mode; } -int APPVERI_IsActsMode(void) +int32_t APPVERI_IsActsMode(void) { return g_isActsMode; } diff --git a/interfaces/innerkits/appverify_lite/src/app_verify_hal.c b/interfaces/innerkits/appverify_lite/src/app_verify_hal.c index f57836e1bd25284260b7a59f71572359575725cd..8254e00658b618933905f85104112aed7c52abda 100644 --- a/interfaces/innerkits/appverify_lite/src/app_verify_hal.c +++ b/interfaces/innerkits/appverify_lite/src/app_verify_hal.c @@ -25,7 +25,7 @@ void RegistHalFunc() RegistProductFunc(&g_productDiffFunc); } -int InquiryDeviceUdid(unsigned char *udid, int size) +int32_t InquiryDeviceUdid(unsigned char *udid, int32_t size) { if (g_productDiffFunc.devUdidFunc == NULL) { return INQUIRY_UDID_ERROR; diff --git a/interfaces/innerkits/appverify_lite/src/app_verify_hap.c b/interfaces/innerkits/appverify_lite/src/app_verify_hap.c index 7fef765fa145fd05d50a4aa8ac8262201297526e..8c85400ff0d5732b0e85ce28c128351e989060c2 100644 --- a/interfaces/innerkits/appverify_lite/src/app_verify_hap.c +++ b/interfaces/innerkits/appverify_lite/src/app_verify_hap.c @@ -22,7 +22,7 @@ #include "app_verify.h" #include "securec.h" -int GetDigestAlgorithmId(unsigned int signAlgorithm) +int32_t GetDigestAlgorithmId(uint32_t signAlgorithm) { switch (signAlgorithm & ALGORITHM_MASK) { case ALGORITHM_SHA256: @@ -40,12 +40,12 @@ int GetDigestAlgorithmId(unsigned int signAlgorithm) } } -static int ComputeBlockHash(const char *block, int blockLen, int alg, const HapBuf *result, int *offset) +static int32_t ComputeBlockHash(const char *block, int32_t blockLen, int32_t alg, const HapBuf *result, int32_t *offset) { - int ret, readLen, rawBufLen; + int32_t ret, readLen, rawBufLen; const mbedtls_md_info_t *mdInfo = mbedtls_md_info_from_type((mbedtls_md_type_t)alg); P_NULL_RETURN_WTTH_LOG(mdInfo); - int pos = 0; + int32_t pos = 0; rawBufLen = blockLen; mbedtls_md_context_t *mdCtx = APPV_MALLOC(sizeof(mbedtls_md_context_t)); P_NULL_RETURN_WTTH_LOG(mdCtx); @@ -91,14 +91,14 @@ EXIT: return V_ERR; } -static int GetChunkSumCount(int fileSize, int coreDirectorySize, int eocdSize, int rootHashLen) +static int32_t GetChunkSumCount(int32_t fileSize, int32_t coreDirectorySize, int32_t eocdSize, int32_t rootHashLen) { - int chunkSize = HASH_BLOB_LEN; - int maxSize = INT_MAX - chunkSize; + int32_t chunkSize = HASH_BLOB_LEN; + int32_t maxSize = INT_MAX - chunkSize; if (fileSize > maxSize || coreDirectorySize > maxSize || eocdSize > maxSize) { return 0; } - int count = ((fileSize - 1 + chunkSize) / chunkSize) + ((coreDirectorySize - 1 + chunkSize) / chunkSize) + + int32_t count = ((fileSize - 1 + chunkSize) / chunkSize) + ((coreDirectorySize - 1 + chunkSize) / chunkSize) + ((eocdSize - 1 + chunkSize) / chunkSize); if (rootHashLen < 0 || (((INT_MAX - HAP_DIGEST_PRIFIX_LEN) / count) < rootHashLen)) { LOG_ERROR("overflow count: %d, chunkDigestLen: %d", count, rootHashLen); @@ -108,14 +108,14 @@ static int GetChunkSumCount(int fileSize, int coreDirectorySize, int eocdSize, i return count; } -static int ComputeDigestsWithOptionalBlock(const int digestAlgorithm, int fp, const SignatureInfo *signInfo, +static int32_t ComputeDigestsWithOptionalBlock(const int32_t digestAlgorithm, int32_t fp, const SignatureInfo *signInfo, const HapBuf *chunkDigest, const HapBuf *fianlDigest) { - int ret, readLen; - int rst = V_ERR; + int32_t ret, readLen; + int32_t rst = V_ERR; char *rawBuf = NULL; unsigned char* outbuf = NULL; - int rootHashLen = GetHashUnitLen(digestAlgorithm); + int32_t rootHashLen = GetHashUnitLen(digestAlgorithm); LOG_INFO("rootHashLen %d", rootHashLen); if (rootHashLen <= 0 || rootHashLen > MAX_HASH_SIZE) { return rst; @@ -126,7 +126,7 @@ static int ComputeDigestsWithOptionalBlock(const int digestAlgorithm, int fp, co P_NULL_RETURN_WTTH_LOG(mdCtx); mbedtls_md_init(mdCtx); ret = mbedtls_md_setup(mdCtx, mdInfo, 0); - int rawLen = 0; + int32_t rawLen = 0; BlockHead blockHead = {0}; P_ERR_GOTO_WTTH_LOG(ret); @@ -158,11 +158,12 @@ EXIT: return rst; } -static int HapUpdateDigistHead(int digestAlgorithm, mbedtls_md_context_t *mdCtx, const mbedtls_md_info_t *mdInfo, - int readLen, size_t *hlen) +static int32_t HapUpdateDigistHead( + int32_t digestAlgorithm, mbedtls_md_context_t *mdCtx, + const mbedtls_md_info_t *mdInfo, int32_t readLen, size_t *hlen) { mbedtls_md_init(mdCtx); - int ret = mbedtls_md_setup(mdCtx, mdInfo, 0); + int32_t ret = mbedtls_md_setup(mdCtx, mdInfo, 0); if (ret != 0) { return V_ERR; } @@ -185,20 +186,20 @@ static int HapUpdateDigistHead(int digestAlgorithm, mbedtls_md_context_t *mdCtx, return V_OK; } -static int UpdateSmallBlock(int readLen, const int fp, mbedtls_md_context_t *mdCtx) +static int32_t UpdateSmallBlock(int32_t readLen, const int32_t fp, mbedtls_md_context_t *mdCtx) { - int readLenLeft = readLen; + int32_t readLenLeft = readLen; while (readLenLeft > 0) { - int onceRead = (readLenLeft > ONCE_READ_LEN) ? ONCE_READ_LEN : readLenLeft; + int32_t onceRead = (readLenLeft > ONCE_READ_LEN) ? ONCE_READ_LEN : readLenLeft; unsigned char *onceBuf = APPV_MALLOC(onceRead); P_NULL_RETURN_WTTH_LOG(onceBuf); - int len = read(fp, onceBuf, sizeof(char) * onceRead); + int32_t len = read(fp, onceBuf, sizeof(char) * onceRead); if (len != onceRead) { LOG_ERROR("fread err: %d, %d", len, onceRead); APPV_FREE(onceBuf); return V_ERR; } - int ret = mbedtls_md_update(mdCtx, onceBuf, onceRead); + int32_t ret = mbedtls_md_update(mdCtx, onceBuf, onceRead); APPV_FREE(onceBuf); P_ERR_RETURN_WTTH_LOG(ret); readLenLeft -= onceRead; @@ -206,23 +207,23 @@ static int UpdateSmallBlock(int readLen, const int fp, mbedtls_md_context_t *mdC return V_OK; } -static int ComputerFileHash(const SignatureInfo *signInfo, int digestAlgorithm, const int fp, - const HapBuf *chunkDigest, int *offset) +static int32_t ComputerFileHash(const SignatureInfo *signInfo, int32_t digestAlgorithm, const int32_t fp, + const HapBuf *chunkDigest, int32_t *offset) { mbedtls_md_context_t *mdCtx = APPV_MALLOC(sizeof(mbedtls_md_context_t)); P_NULL_RETURN_WTTH_LOG(mdCtx); lseek(fp, 0, SEEK_SET); - int pos = 0; - int rawBufLen = signInfo->fullSignBlockOffset; + int32_t pos = 0; + int32_t rawBufLen = signInfo->fullSignBlockOffset; while (rawBufLen > 0) { size_t hlen = 0; - int readLen = (rawBufLen > HASH_BLOB_LEN) ? HASH_BLOB_LEN : rawBufLen; + int32_t readLen = (rawBufLen > HASH_BLOB_LEN) ? HASH_BLOB_LEN : rawBufLen; const mbedtls_md_info_t *mdInfo = mbedtls_md_info_from_type((mbedtls_md_type_t)digestAlgorithm); if (mdInfo == NULL) { APPV_FREE(mdCtx); return V_ERR; } - int ret = HapUpdateDigistHead(digestAlgorithm, mdCtx, mdInfo, readLen, &hlen); + int32_t ret = HapUpdateDigistHead(digestAlgorithm, mdCtx, mdInfo, readLen, &hlen); P_ERR_GOTO_WTTH_LOG(ret); LOG_INFO("content: %d, %d", rawBufLen, pos); ret = UpdateSmallBlock(readLen, fp, mdCtx); @@ -247,31 +248,31 @@ EXIT: return V_ERR; } -static int ComputerCoreDirHash(const SignatureInfo *signInfo, int digestAlgorithm, const int fp, - const HapBuf *chunkDigest, int *offset) +static int32_t ComputerCoreDirHash(const SignatureInfo *signInfo, int32_t digestAlgorithm, const int32_t fp, + const HapBuf *chunkDigest, int32_t *offset) { - int centralDirSize = signInfo->hapEocdOffset - signInfo->hapCoreDirOffset; + int32_t centralDirSize = signInfo->hapEocdOffset - signInfo->hapCoreDirOffset; if (centralDirSize <= 0) { return V_ERR; } char *dirBuf = APPV_MALLOC(centralDirSize); P_NULL_RETURN_WTTH_LOG(dirBuf); lseek(fp, signInfo->hapCoreDirOffset, SEEK_SET); - int len = read(fp, dirBuf, sizeof(char) * centralDirSize); + int32_t len = read(fp, dirBuf, sizeof(char) * centralDirSize); if (len != centralDirSize) { LOG_ERROR("fread err: %d, %d", len, centralDirSize); APPV_FREE(dirBuf); return V_ERR; } - int ret = ComputeBlockHash(dirBuf, centralDirSize, digestAlgorithm, chunkDigest, offset); + int32_t ret = ComputeBlockHash(dirBuf, centralDirSize, digestAlgorithm, chunkDigest, offset); (void)memset_s(dirBuf, centralDirSize, 0, centralDirSize); APPV_FREE(dirBuf); P_ERR_RETURN_WTTH_LOG(ret); return V_OK; } -static int ComputerEocdHash(const SignatureInfo *signInfo, int digestAlgorithm, const int fp, - const HapBuf *chunkDigest, int *offset) +static int32_t ComputerEocdHash(const SignatureInfo *signInfo, int32_t digestAlgorithm, const int32_t fp, + const HapBuf *chunkDigest, int32_t *offset) { if (signInfo->hapEocdSize <= 0) { return V_ERR; @@ -279,38 +280,39 @@ static int ComputerEocdHash(const SignatureInfo *signInfo, int digestAlgorithm, HapEocd *eocdBuf = APPV_MALLOC(signInfo->hapEocdSize); P_NULL_RETURN_WTTH_LOG(eocdBuf); lseek(fp, signInfo->hapEocdOffset, SEEK_SET); - int len = read(fp, eocdBuf, signInfo->hapEocdSize); + int32_t len = read(fp, eocdBuf, signInfo->hapEocdSize); if (len != signInfo->hapEocdSize) { LOG_ERROR("fread err: %d, %d", len, signInfo->hapEocdSize); APPV_FREE(eocdBuf); return V_ERR; } HapPutInt32((unsigned char*)(&(eocdBuf->eocdHead.coreDirOffset)), sizeof(int), signInfo->fullSignBlockOffset); - int ret = ComputeBlockHash((char *)(eocdBuf), len, digestAlgorithm, chunkDigest, offset); + int32_t ret = ComputeBlockHash((char *)(eocdBuf), len, digestAlgorithm, chunkDigest, offset); (void)memset_s(eocdBuf, signInfo->hapEocdSize, 0, signInfo->hapEocdSize); APPV_FREE(eocdBuf); P_ERR_RETURN_WTTH_LOG(ret); return V_OK; } -bool VerifyIntegrityChunk(int digestAlgorithm, const int fp, +bool VerifyIntegrityChunk(int32_t digestAlgorithm, const int32_t fp, const SignatureInfo *signInfo, const HapBuf *actualDigest) { if (signInfo == NULL || actualDigest == NULL || actualDigest->buffer == NULL) { return false; } - int centralDirSize = signInfo->hapEocdOffset - signInfo->hapCoreDirOffset; - int rootHashLen = GetHashUnitLen(digestAlgorithm); + int32_t centralDirSize = signInfo->hapEocdOffset - signInfo->hapCoreDirOffset; + int32_t rootHashLen = GetHashUnitLen(digestAlgorithm); if (rootHashLen < 0) { LOG_ERROR("alg error"); return false; } - int sumCount = GetChunkSumCount(signInfo->fullSignBlockOffset, centralDirSize, signInfo->hapEocdSize, rootHashLen); + int32_t sumCount = GetChunkSumCount( + signInfo->fullSignBlockOffset, centralDirSize, signInfo->hapEocdSize, rootHashLen); if (sumCount == 0) { LOG_ERROR("sum count error"); return false; } - int sumOfChunksLen = HAP_DIGEST_PRIFIX_LEN + sumCount * rootHashLen; + int32_t sumOfChunksLen = HAP_DIGEST_PRIFIX_LEN + sumCount * rootHashLen; HapBuf chunkDigest = {0}; if (!CreateHapBuffer(&chunkDigest, sumOfChunksLen)) { return false; @@ -318,8 +320,8 @@ bool VerifyIntegrityChunk(int digestAlgorithm, const int fp, LOG_INFO("alg: %d", digestAlgorithm); HapPutByte(&chunkDigest, 0, HAP_FIRST_LEVEL_CHUNK_PREFIX); HapSetInt32(&chunkDigest, 1, sumCount); - int offset = HAP_DIGEST_PRIFIX_LEN; - int ret; + int32_t offset = HAP_DIGEST_PRIFIX_LEN; + int32_t ret; ret = ComputerFileHash(signInfo, digestAlgorithm, fp, &chunkDigest, &offset); P_ERR_GOTO_WTTH_LOG(ret); ret = ComputerCoreDirHash(signInfo, digestAlgorithm, fp, &chunkDigest, &offset); diff --git a/interfaces/innerkits/appverify_lite/src/mbedtls_pkcs7.c b/interfaces/innerkits/appverify_lite/src/mbedtls_pkcs7.c index 3632f701138ea9219314863289c5b23ab7fc799d..ecf38b62d0fc826fc069d98c4ce1e60c23fde5ba 100644 --- a/interfaces/innerkits/appverify_lite/src/mbedtls_pkcs7.c +++ b/interfaces/innerkits/appverify_lite/src/mbedtls_pkcs7.c @@ -114,12 +114,12 @@ static bool InvalidDigestAlg(const mbedtls_asn1_buf *alg) MBEDTLS_OID_CMP(MBEDTLS_OID_DIGEST_ALG_SHA512, alg); } -static int GetContentInfoType(unsigned char **p, const unsigned char *end, +static int32_t GetContentInfoType(unsigned char **p, const unsigned char *end, mbedtls_asn1_buf *contentType, bool *hasContent) { size_t seqLen = 0; size_t len = 0; - int rc; + int32_t rc; rc = mbedtls_asn1_get_tag(p, end, &seqLen, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE); if (rc) { @@ -140,19 +140,19 @@ static int GetContentInfoType(unsigned char **p, const unsigned char *end, return PKCS7_SUCC; } -static int GetContentLenOfContentInfo(unsigned char **p, const unsigned char *end, size_t *len) +static int32_t GetContentLenOfContentInfo(unsigned char **p, const unsigned char *end, size_t *len) { return mbedtls_asn1_get_tag(p, end, len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_CONTEXT_SPECIFIC); } -static int ParseSignerVersion(unsigned char **p, const unsigned char *end, SignerInfo *signer) +static int32_t ParseSignerVersion(unsigned char **p, const unsigned char *end, SignerInfo *signer) { return mbedtls_asn1_get_int(p, end, &signer->version); } -static int ParseSignerIssuerAndSerialNum(unsigned char **p, const unsigned char *end, SignerInfo *signer) +static int32_t ParseSignerIssuerAndSerialNum(unsigned char **p, const unsigned char *end, SignerInfo *signer) { - int rc; + int32_t rc; size_t len; rc = mbedtls_asn1_get_tag(p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE); @@ -177,9 +177,9 @@ static int ParseSignerIssuerAndSerialNum(unsigned char **p, const unsigned char return rc; } -static int ParseSignerDigestAlg(unsigned char **p, const unsigned char *end, SignerInfo *signer) +static int32_t ParseSignerDigestAlg(unsigned char **p, const unsigned char *end, SignerInfo *signer) { - int rc = mbedtls_asn1_get_alg_null(p, end, &signer->digestAlgId); + int32_t rc = mbedtls_asn1_get_alg_null(p, end, &signer->digestAlgId); if (rc) { return rc; } @@ -189,9 +189,9 @@ static int ParseSignerDigestAlg(unsigned char **p, const unsigned char *end, Sig return PKCS7_SUCC; } -static int ParseSignerAuthAttr(unsigned char **p, const unsigned char *end, SignerInfo *signer) +static int32_t ParseSignerAuthAttr(unsigned char **p, const unsigned char *end, SignerInfo *signer) { - int rc; + int32_t rc; size_t len = 0; unsigned char *raw = *p; @@ -224,9 +224,9 @@ static bool InvalidDigestEncAlg(const mbedtls_x509_buf *alg) MBEDTLS_OID_CMP(MBEDTLS_OID_RSASSA_PSS, alg); } -static int ParseSignerEncAlg(unsigned char **p, const unsigned char *end, SignerInfo *signer) +static int32_t ParseSignerEncAlg(unsigned char **p, const unsigned char *end, SignerInfo *signer) { - int rc; + int32_t rc; mbedtls_asn1_buf params = {0}; /* params not be used now */ rc = mbedtls_asn1_get_alg(p, end, &signer->digestEncAlgId, ¶ms); @@ -243,9 +243,9 @@ static int ParseSignerEncAlg(unsigned char **p, const unsigned char *end, Signer * encryptedDigest EncryptedDigest, * EncryptedDigest ::= OCTET STRING */ -static int ParseSignerSignature(unsigned char **p, const unsigned char *end, SignerInfo *signer) +static int32_t ParseSignerSignature(unsigned char **p, const unsigned char *end, SignerInfo *signer) { - int rc; + int32_t rc; size_t len = 0; rc = mbedtls_asn1_get_tag(p, end, &len, MBEDTLS_ASN1_OCTET_STRING); @@ -259,7 +259,7 @@ static int ParseSignerSignature(unsigned char **p, const unsigned char *end, Sig return PKCS7_SUCC; } -static int GetSignerSignature(const SignerInfo *signer, unsigned char **sig, size_t *sigLen) +static int32_t GetSignerSignature(const SignerInfo *signer, unsigned char **sig, size_t *sigLen) { size_t len = signer->signature.len; unsigned char *buf = signer->signature.p; @@ -268,9 +268,9 @@ static int GetSignerSignature(const SignerInfo *signer, unsigned char **sig, siz return PKCS7_SUCC; } -static int ParseSignerUnAuthAttr(unsigned char **p, const unsigned char *end, SignerInfo *signer) +static int32_t ParseSignerUnAuthAttr(unsigned char **p, const unsigned char *end, SignerInfo *signer) { - int rc; + int32_t rc; size_t len = 0; /* the optional unauth attr is not exist */ @@ -288,7 +288,7 @@ static int ParseSignerUnAuthAttr(unsigned char **p, const unsigned char *end, Si return PKCS7_SUCC; } -static int SerialCmp(const mbedtls_x509_buf *a, const mbedtls_x509_buf *b) +static int32_t SerialCmp(const mbedtls_x509_buf *a, const mbedtls_x509_buf *b) { if (a->len == b->len && memcmp(a->p, b->p, a->len) == 0) { return 0; @@ -297,7 +297,7 @@ static int SerialCmp(const mbedtls_x509_buf *a, const mbedtls_x509_buf *b) } #define DIFF_NUM 32 -static bool IsLegitString(int tag) +static bool IsLegitString(int32_t tag) { if (tag == MBEDTLS_ASN1_UTF8_STRING || tag == MBEDTLS_ASN1_PRINTABLE_STRING) { return true; @@ -305,10 +305,10 @@ static bool IsLegitString(int tag) return false; } -static int CompareX509String(const mbedtls_x509_buf *first, const mbedtls_x509_buf *second) +static int32_t CompareX509String(const mbedtls_x509_buf *first, const mbedtls_x509_buf *second) { if (IsLegitString(first->tag) && IsLegitString(second->tag)) { - for (int i = 0; i < first->len; i++) { + for (int32_t i = 0; i < first->len; i++) { if (first->p[i] == second->p[i] || ((islower(first->p[i]) != 0) && (first->p[i] - DIFF_NUM == second->p[i])) || ((isupper(first->p[i]) != 0) && (first->p[i] + DIFF_NUM == second->p[i]))) { @@ -321,9 +321,9 @@ static int CompareX509String(const mbedtls_x509_buf *first, const mbedtls_x509_b return -1; } -static int GetDeps(const mbedtls_x509_name *nameList) +static int32_t GetDeps(const mbedtls_x509_name *nameList) { - int deps = 0; + int32_t deps = 0; while (nameList != NULL) { nameList = nameList->next; deps++; @@ -331,17 +331,17 @@ static int GetDeps(const mbedtls_x509_name *nameList) return deps; } -static int CompareX509NameList(const mbedtls_x509_name *first, const mbedtls_x509_name *second) +static int32_t CompareX509NameList(const mbedtls_x509_name *first, const mbedtls_x509_name *second) { if (first == NULL || second == NULL) { return -1; } - int firstDeps = GetDeps(first); - int secondDeps = GetDeps(second); + int32_t firstDeps = GetDeps(first); + int32_t secondDeps = GetDeps(second); if (firstDeps != secondDeps) { return -1; } - for (int i = 0; i < firstDeps; i++) { + for (int32_t i = 0; i < firstDeps; i++) { if (first->oid.tag != second->oid.tag || first->oid.len != second->oid.len || memcmp(first->oid.p, second->oid.p, second->oid.len) != 0 || @@ -368,9 +368,9 @@ static void Pkcs7Free(void *ptr) free(ptr); } -static int ParseSignedDataSignerInfos(unsigned char **p, const unsigned char *end, SignerInfo *signers) +static int32_t ParseSignedDataSignerInfos(unsigned char **p, const unsigned char *end, SignerInfo *signers) { - int rc; + int32_t rc; size_t len = 0; rc = mbedtls_asn1_get_tag(p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SET); @@ -427,9 +427,9 @@ static int ParseSignedDataSignerInfos(unsigned char **p, const unsigned char *en return rc; } -static int ParseSignedDataVersion(unsigned char **p, const unsigned char *end, int *ver) +static int32_t ParseSignedDataVersion(unsigned char **p, const unsigned char *end, int32_t *ver) { - int rc = mbedtls_asn1_get_int(p, end, ver); + int32_t rc = mbedtls_asn1_get_int(p, end, ver); if (rc) { return rc; } @@ -442,9 +442,9 @@ static int ParseSignedDataVersion(unsigned char **p, const unsigned char *end, i return PKCS7_SUCC; } -static int ParseSignedDataDigestAlgs(unsigned char **p, const unsigned char *end, DigestAlgId *algIds) +static int32_t ParseSignedDataDigestAlgs(unsigned char **p, const unsigned char *end, DigestAlgId *algIds) { - int rc; + int32_t rc; size_t len = 0; /* parse SET OF header */ @@ -480,7 +480,7 @@ static int ParseSignedDataDigestAlgs(unsigned char **p, const unsigned char *end static void DlogContentInfo(const Content *content) { - int len = content->data.len; + int32_t len = content->data.len; if (len <= 0) { return; } @@ -495,9 +495,9 @@ static void DlogContentInfo(const Content *content) Pkcs7Free(info); } -static int ParseSignedDataContentInfo(unsigned char **p, const unsigned char *end, Content *content) +static int32_t ParseSignedDataContentInfo(unsigned char **p, const unsigned char *end, Content *content) { - int rc; + int32_t rc; size_t len = 0; bool hasContent = false; @@ -522,9 +522,9 @@ static int ParseSignedDataContentInfo(unsigned char **p, const unsigned char *en return PKCS7_SUCC; } -static int ParseSignedDataCerts(unsigned char **p, const unsigned char *end, mbedtls_x509_crt **certs) +static int32_t ParseSignedDataCerts(unsigned char **p, const unsigned char *end, mbedtls_x509_crt **certs) { - int rc; + int32_t rc; size_t len = 0; rc = mbedtls_asn1_get_tag(p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_CONTEXT_SPECIFIC); @@ -539,7 +539,7 @@ static int ParseSignedDataCerts(unsigned char **p, const unsigned char *end, mbe mbedtls_x509_crt_init(*certs); unsigned char *certsEnd = *p + len; - int cnt = 0; + int32_t cnt = 0; while (*p < certsEnd) { /* scan every cert */ size_t oneCertLen; @@ -562,9 +562,9 @@ static int ParseSignedDataCerts(unsigned char **p, const unsigned char *end, mbe return rc; } -static int ParseSignedDataCrl(unsigned char **p, const unsigned char *end, mbedtls_x509_crl *crl) +static int32_t ParseSignedDataCrl(unsigned char **p, const unsigned char *end, mbedtls_x509_crl *crl) { - int rc; + int32_t rc; size_t len = 0; rc = mbedtls_asn1_get_tag(p, end, &len, (MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_CONTEXT_SPECIFIC) + 1); @@ -578,12 +578,12 @@ static int ParseSignedDataCrl(unsigned char **p, const unsigned char *end, mbedt return rc; } -static int ParseSignedData(unsigned char *buf, size_t bufLen, SignedData *signedData) +static int32_t ParseSignedData(unsigned char *buf, size_t bufLen, SignedData *signedData) { unsigned char *p = buf; unsigned char *end = buf + bufLen; size_t len = 0; - int rc; + int32_t rc; /* parse SignedData sequence header */ rc = mbedtls_asn1_get_tag(&p, end, &len, MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE); @@ -702,9 +702,9 @@ static void FreeSignedDataCrl(Pkcs7 *pkcs7) return; } -static int GetCertsNumOfSignedData(const mbedtls_x509_crt *crts) +static int32_t GetCertsNumOfSignedData(const mbedtls_x509_crt *crts) { - int cnt = 0; + int32_t cnt = 0; while (crts != NULL) { crts = crts->next; cnt++; @@ -763,10 +763,10 @@ static void AddCertToSignerCertPath(SignerInfo *signer, mbedtls_x509_crt *crt) signer->certPath.depth++; } -static int BuildSignerCertPath(SignerInfo *signer, mbedtls_x509_crt *lowerCrt, SignedData *signeData) +static int32_t BuildSignerCertPath(SignerInfo *signer, mbedtls_x509_crt *lowerCrt, SignedData *signeData) { - int scanCnt = 0; - int rc = PKCS7_SUCC; + int32_t scanCnt = 0; + int32_t rc = PKCS7_SUCC; if (!g_rootCertLoaded) { return PKCS7_ROOT_CA_NOT_VALID; } @@ -777,7 +777,7 @@ static int BuildSignerCertPath(SignerInfo *signer, mbedtls_x509_crt *lowerCrt, S * find the next level ca cert */ mbedtls_x509_crt *cur = lowerCrt; mbedtls_x509_crt *next = NULL; - int certsCnt = GetCertsNumOfSignedData(certs); + int32_t certsCnt = GetCertsNumOfSignedData(certs); DelCertOfSignedData(signeData, cur); AddCertToSignerCertPath(signer, cur); while (true) { @@ -798,7 +798,7 @@ static int BuildSignerCertPath(SignerInfo *signer, mbedtls_x509_crt *lowerCrt, S return rc; } -static int ConstructSignerCerts(SignedData *signedData) +static int32_t ConstructSignerCerts(SignedData *signedData) { /* scan all of the signers , and filter the signer's certs by serial and name */ SignerInfo *signer = &signedData->signers; @@ -819,7 +819,7 @@ static int ConstructSignerCerts(SignedData *signedData) LOG_ERROR("Could not found signer's lowest cert"); return PKCS7_INVALID_VALUE; } - int rc = BuildSignerCertPath(signer, cert, signedData); + int32_t rc = BuildSignerCertPath(signer, cert, signedData); if (rc != 0) { return rc; } @@ -829,7 +829,7 @@ static int ConstructSignerCerts(SignedData *signedData) } /* get signer digest alg */ -static int GetSignerDigestAlg(const SignerInfo *signer, mbedtls_md_type_t *algType) +static int32_t GetSignerDigestAlg(const SignerInfo *signer, mbedtls_md_type_t *algType) { const mbedtls_x509_buf *alg = &signer->digestAlgId; if (!MBEDTLS_OID_CMP(MBEDTLS_OID_DIGEST_ALG_SHA256, alg)) { @@ -848,7 +848,7 @@ static int GetSignerDigestAlg(const SignerInfo *signer, mbedtls_md_type_t *algTy } /* get signer pubkey of sign from signer cert */ -static int GetSignerPubKeyOfSignature(const SignerInfo *signer, mbedtls_pk_context **pk) +static int32_t GetSignerPubKeyOfSignature(const SignerInfo *signer, mbedtls_pk_context **pk) { /* signer cert_path first cert is the lowest cert. yet is the signature cert */ if (signer == NULL || pk == NULL) { @@ -861,9 +861,9 @@ static int GetSignerPubKeyOfSignature(const SignerInfo *signer, mbedtls_pk_conte return PKCS7_INVALID_VALUE; } -int PKCS7_VerifySignerSignature(const Pkcs7 *pkcs7, PKCS7_CalcDigest calcDigest) +int32_t PKCS7_VerifySignerSignature(const Pkcs7 *pkcs7, PKCS7_CalcDigest calcDigest) { - int rc; + int32_t rc; if (pkcs7 == NULL || calcDigest == NULL) { return PKCS7_INVALID_PARAM; } @@ -912,9 +912,9 @@ int PKCS7_VerifySignerSignature(const Pkcs7 *pkcs7, PKCS7_CalcDigest calcDigest) return rc; } -static int LoadRootCert(void) +static int32_t LoadRootCert(void) { - int rc = 0; + int32_t rc = 0; if (!g_rootCertLoaded) { mbedtls_x509_crt_init(&g_rootCaG2Cert); rc = mbedtls_x509_crt_parse(&g_rootCaG2Cert, ROOT_CA_G2_CERT_IN_PEM, sizeof(ROOT_CA_G2_CERT_IN_PEM)); @@ -937,10 +937,10 @@ static void UnLoadRootCert(void) } } -static int LoadDebugModeRootCert(void) +static int32_t LoadDebugModeRootCert(void) { mbedtls_x509_crt_init(&g_debugModeRootCert); - int rc = mbedtls_x509_crt_parse(&g_debugModeRootCert, DEBUG_MODE_ROOT_CERT_IN_PEM, + int32_t rc = mbedtls_x509_crt_parse(&g_debugModeRootCert, DEBUG_MODE_ROOT_CERT_IN_PEM, sizeof(DEBUG_MODE_ROOT_CERT_IN_PEM)); if (rc) { LOG_ERROR("load debug mode root ca failed %d", rc); @@ -950,16 +950,16 @@ static int LoadDebugModeRootCert(void) } return rc; } -static int UnLoadDebugModeRootCert(void) +static int32_t UnLoadDebugModeRootCert(void) { mbedtls_x509_crt_free(&g_debugModeRootCert); return PKCS7_SUCC; } -static int LoadSelfSignedCert(void) +static int32_t LoadSelfSignedCert(void) { mbedtls_x509_crt_init(&g_ohosRootCert); - int rc = mbedtls_x509_crt_parse(&g_ohosRootCert, OHOS_ROOT_CERT_IN_PEM, sizeof(OHOS_ROOT_CERT_IN_PEM)); + int32_t rc = mbedtls_x509_crt_parse(&g_ohosRootCert, OHOS_ROOT_CERT_IN_PEM, sizeof(OHOS_ROOT_CERT_IN_PEM)); if (rc) { LOG_ERROR("load self signed ca failed %d", rc); return rc; @@ -973,7 +973,7 @@ static void UnLoadSelfSignedCert(void) { mbedtls_x509_crt_free(&g_ohosRootCert); } -static void DLogCrtVerifyInfo(unsigned int flags) +static void DLogCrtVerifyInfo(uint32_t flags) { char vrfyBuf[VERIFY_BUF_LEN]; (void)memset_s(vrfyBuf, VERIFY_BUF_LEN, 0, VERIFY_BUF_LEN); @@ -981,7 +981,7 @@ static void DLogCrtVerifyInfo(unsigned int flags) LOG_DEBUG("%s", vrfyBuf); } -static int IsRevoked(const mbedtls_x509_crt *crt, const mbedtls_x509_crl *crl) +static int32_t IsRevoked(const mbedtls_x509_crt *crt, const mbedtls_x509_crl *crl) { mbedtls_x509_crl_entry *cur = (mbedtls_x509_crl_entry *)(&crl->entry); while (cur != NULL) { @@ -1000,7 +1000,7 @@ static int IsRevoked(const mbedtls_x509_crt *crt, const mbedtls_x509_crl *crl) return PKCS7_SUCC; } -static int VerifyCrl(const mbedtls_x509_crt *crt, const mbedtls_x509_crl *crl) +static int32_t VerifyCrl(const mbedtls_x509_crt *crt, const mbedtls_x509_crl *crl) { const mbedtls_x509_crl *crlList = crl; while (crlList != NULL) { @@ -1018,10 +1018,10 @@ static int VerifyCrl(const mbedtls_x509_crt *crt, const mbedtls_x509_crl *crl) return PKCS7_SUCC; } -static int VerifyClicert(mbedtls_x509_crt *clicert, mbedtls_x509_crt *rootCert, const Pkcs7 *pkcs7) +static int32_t VerifyClicert(mbedtls_x509_crt *clicert, mbedtls_x509_crt *rootCert, const Pkcs7 *pkcs7) { - unsigned int flags; - int rc = mbedtls_x509_crt_verify(clicert, rootCert, + uint32_t flags; + int32_t rc = mbedtls_x509_crt_verify(clicert, rootCert, (mbedtls_x509_crl *)&pkcs7->signedData.crl, NULL, &flags, NULL, NULL); if (rc) { DLogCrtVerifyInfo(flags); @@ -1036,12 +1036,12 @@ static int VerifyClicert(mbedtls_x509_crt *clicert, mbedtls_x509_crt *rootCert, return rc; } -int PKCS7_VerifyCertsChain(const Pkcs7 *pkcs7) +int32_t PKCS7_VerifyCertsChain(const Pkcs7 *pkcs7) { if (pkcs7 == NULL) { return PKCS7_INVALID_PARAM; } - int cnt = 0; + int32_t cnt = 0; const SignerInfo *signer = &pkcs7->signedData.signers; while (signer != NULL) { mbedtls_x509_crt *clicert = signer->certPath.crt; @@ -1049,7 +1049,7 @@ int PKCS7_VerifyCertsChain(const Pkcs7 *pkcs7) LOG_ERROR("Signer has no certs"); return PKCS7_HAS_NO_SIGNER_CRT; } - int rc; + int32_t rc; cnt++; LOG_INFO("signer : %d", cnt); if (g_debugModeEnabled) { @@ -1085,9 +1085,9 @@ int PKCS7_VerifyCertsChain(const Pkcs7 *pkcs7) return PKCS7_SUCC; } -int PKCS7_GetSignerSignningCertSubject(const SignerInfo *signer, char *subject, size_t subjectLen) +int32_t PKCS7_GetSignerSignningCertSubject(const SignerInfo *signer, char *subject, size_t subjectLen) { - int rc; + int32_t rc; if (signer == NULL || subject == NULL) { return PKCS7_INVALID_PARAM; } @@ -1099,9 +1099,9 @@ int PKCS7_GetSignerSignningCertSubject(const SignerInfo *signer, char *subject, return PKCS7_SUCC; } -int PKCS7_GetSignerSignningCertIssuer(const SignerInfo *signer, char *issuer, size_t issuerLen) +int32_t PKCS7_GetSignerSignningCertIssuer(const SignerInfo *signer, char *issuer, size_t issuerLen) { - int rc; + int32_t rc; if (signer == NULL || issuer == NULL) { return PKCS7_INVALID_PARAM; } @@ -1127,7 +1127,7 @@ static bool IsIncludeRoot(const SignerInfo *signer) { mbedtls_x509_crt *pre = signer->certPath.crt; mbedtls_x509_crt *cur = pre; - int i = 0; + int32_t i = 0; while (i < signer->certPath.depth && cur != NULL) { pre = cur; cur = cur->next; @@ -1147,7 +1147,7 @@ static bool IsIncludeRoot(const SignerInfo *signer) return false; } -static int GetSignerSignningCertDepth(const SignerInfo *signer) +static int32_t GetSignerSignningCertDepth(const SignerInfo *signer) { if (IsIncludeRoot(signer)) { return signer->certPath.depth; @@ -1189,9 +1189,9 @@ SignersResovedInfo *PKCS7_GetAllSignersResolvedInfo(const Pkcs7 *pkcs7) Pkcs7Free(sri); return NULL; } - int rc; + int32_t rc; const SignerInfo *signer = &pkcs7->signedData.signers; - int idx = 0; + int32_t idx = 0; while (signer != NULL && idx < signersCnt) { rc = PKCS7_GetSignerSignningCertSubject(signer, sri->signers[idx].subject, sizeof(sri->signers[idx].subject)); if (rc) { @@ -1212,7 +1212,7 @@ OUT: return NULL; } -int PKCS7_GetDigestInSignerAuthAttr(const SignerInfo *signer, unsigned char **dig, size_t *digLen) +int32_t PKCS7_GetDigestInSignerAuthAttr(const SignerInfo *signer, unsigned char **dig, size_t *digLen) { if (signer == NULL || dig == NULL || digLen == NULL) { return PKCS7_INVALID_VALUE; @@ -1228,7 +1228,7 @@ int PKCS7_GetDigestInSignerAuthAttr(const SignerInfo *signer, unsigned char **di while (p < end) { size_t seqLen; unsigned char *seqEnd = NULL; - int rc = mbedtls_asn1_get_tag(&p, end, &seqLen, MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED); + int32_t rc = mbedtls_asn1_get_tag(&p, end, &seqLen, MBEDTLS_ASN1_SEQUENCE | MBEDTLS_ASN1_CONSTRUCTED); if (rc) { return rc; } @@ -1261,7 +1261,7 @@ int PKCS7_GetDigestInSignerAuthAttr(const SignerInfo *signer, unsigned char **di return PKCS7_INVALID_VALUE; } -int PKCS7_GetSignerAuthAttr(const SignerInfo *signer, unsigned char **data, size_t *dataLen) +int32_t PKCS7_GetSignerAuthAttr(const SignerInfo *signer, unsigned char **data, size_t *dataLen) { if (signer == NULL || signer->authAttrRaw.p == NULL || data == NULL || dataLen == NULL) { return PKCS7_INVALID_VALUE; @@ -1272,7 +1272,7 @@ int PKCS7_GetSignerAuthAttr(const SignerInfo *signer, unsigned char **data, size return PKCS7_SUCC; } -int PKCS7_GetContentData(const Pkcs7 *pkcs7, unsigned char **data, size_t *dataLen) +int32_t PKCS7_GetContentData(const Pkcs7 *pkcs7, unsigned char **data, size_t *dataLen) { if (pkcs7 == NULL || data == NULL || dataLen == NULL) { return PKCS7_INVALID_PARAM; @@ -1282,7 +1282,7 @@ int PKCS7_GetContentData(const Pkcs7 *pkcs7, unsigned char **data, size_t *dataL size_t len = pkcs7->signedData.content.data.len; unsigned char *end = p + len; size_t octetLen; - int rc = mbedtls_asn1_get_tag(&p, end, &octetLen, MBEDTLS_ASN1_OCTET_STRING); + int32_t rc = mbedtls_asn1_get_tag(&p, end, &octetLen, MBEDTLS_ASN1_OCTET_STRING); if (rc != 0) { return rc; } @@ -1291,12 +1291,12 @@ int PKCS7_GetContentData(const Pkcs7 *pkcs7, unsigned char **data, size_t *dataL return PKCS7_SUCC; } -int PKCS7_EnableDebugMode(bool mode) +int32_t PKCS7_EnableDebugMode(bool mode) { if (g_debugModeEnabled == mode) { return PKCS7_SUCC; } - int rc = ((mode == true) ? LoadDebugModeRootCert() : UnLoadDebugModeRootCert()); + int32_t rc = ((mode == true) ? LoadDebugModeRootCert() : UnLoadDebugModeRootCert()); if (rc) { return rc; } @@ -1305,10 +1305,10 @@ int PKCS7_EnableDebugMode(bool mode) } #ifdef PARSE_PEM_FORMAT_SIGNED_DATA -static int ParsePemFormatSignedData(const unsigned char *buf, size_t bufLen, mbedtls_pem_context *pem, char *format) +static int32_t ParsePemFormatSignedData(const unsigned char *buf, size_t bufLen, mbedtls_pem_context *pem, char *format) { if (bufLen != 0 && strstr((const char *)buf, "-----BEGIN PKCS7-----") != NULL) { - int ret; + int32_t ret; size_t useLen = 0; mbedtls_pem_init(pem); ret = mbedtls_pem_read_buffer(pem, "-----BEGIN PKCS7-----", "-----END PKCS7-----", @@ -1326,9 +1326,9 @@ static int ParsePemFormatSignedData(const unsigned char *buf, size_t bufLen, mbe } #endif -int PKCS7_ParseSignedData(const unsigned char *buf, size_t bufLen, Pkcs7 *pkcs7) +int32_t PKCS7_ParseSignedData(const unsigned char *buf, size_t bufLen, Pkcs7 *pkcs7) { - int rc; + int32_t rc; size_t len = 0; bool hasContent = false; unsigned char *start = NULL; diff --git a/interfaces/innerkits/appverify_lite/unittest/src/hap_verify_test.cpp b/interfaces/innerkits/appverify_lite/unittest/src/hap_verify_test.cpp index 96370dcc95fba11ed80c068bdb9b23ae2b3077a5..b7491021514a6a1da8591d4b424b7f623ba30a30 100644 --- a/interfaces/innerkits/appverify_lite/unittest/src/hap_verify_test.cpp +++ b/interfaces/innerkits/appverify_lite/unittest/src/hap_verify_test.cpp @@ -22,7 +22,7 @@ using namespace std; using namespace testing::ext; namespace { -const int DELAY_TIME = 4; +const int32_t DELAY_TIME = 4; class HapVerifyTest : public testing::Test { public: diff --git a/interfaces/innerkits/appverify_lite/unittest/src/write_file.cpp b/interfaces/innerkits/appverify_lite/unittest/src/write_file.cpp index 96978b01289d01eec4b730027147c9817afe4358..19ca979746c8644dcc05e89d31b9a1328eba268d 100644 --- a/interfaces/innerkits/appverify_lite/unittest/src/write_file.cpp +++ b/interfaces/innerkits/appverify_lite/unittest/src/write_file.cpp @@ -28,34 +28,34 @@ #include "securec.h" namespace { - const int MAX_FILE_LEN = 1000000; - const int ONCE_WRITE = 2000; + const int32_t MAX_FILE_LEN = 1000000; + const int32_t ONCE_WRITE = 2000; } -int CopyFile(const char *org, const char *dest) +int32_t CopyFile(const char *org, const char *dest) { - int ret = 0; + int32_t ret = 0; if (org == nullptr || dest == nullptr) { return -1; } - int in = open(dest, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); + int32_t in = open(dest, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); if (in < 0) { return -1; } - int wholeLen = strlen(org); + int32_t wholeLen = strlen(org); if (wholeLen == 0 || wholeLen > MAX_FILE_LEN) { close(in); return -1; } std::unique_ptr buffer = std::make_unique(wholeLen); (void)memset_s(buffer.get(), wholeLen, 0, wholeLen); - int len = 0; + int32_t len = 0; mbedtls_base64_decode(reinterpret_cast(buffer.get()), static_cast(wholeLen), reinterpret_cast(&len), reinterpret_cast(org), static_cast(wholeLen)); - int num = 0; + int32_t num = 0; while (num < len) { - int trueLen = ((len - num) >= ONCE_WRITE) ? ONCE_WRITE : (len - num); + int32_t trueLen = ((len - num) >= ONCE_WRITE) ? ONCE_WRITE : (len - num); char *temp = buffer.get() + num; num += trueLen; ret = write(in, temp, trueLen); diff --git a/interfaces/innerkits/appverify_lite/unittest/src/write_file.h b/interfaces/innerkits/appverify_lite/unittest/src/write_file.h index a7c0015a48b4760fde6cb9c05c1e95d6a9355633..7e4c8e4548ce9cae234e38d85294d937b0decf0a 100644 --- a/interfaces/innerkits/appverify_lite/unittest/src/write_file.h +++ b/interfaces/innerkits/appverify_lite/unittest/src/write_file.h @@ -15,10 +15,11 @@ #ifndef APPSECURITY_WRITE_FILE_H #define APPSECURITY_WRITE_FILE_H +#include #include #include void DeleteFile(const char *path); -int CopyFile(const char *org, const char *dest); +int32_t CopyFile(const char *org, const char *dest); const char* GetWrongLiceseHap(void); const char* GetUnsignedHap(void); const char* GetWrongUdidHap(void);