src/main/java/org/edgegallery/appstore/infrastructure/util/AppUtil.java
public boolean checkPackageValid(String fileParent) {
        File mfFile = getFile(fileParent, MF_EXTENSION);
        File sourceFile = mfFile.getParentFile();
        File parentFile = new File(fileParent);
        if (!sourceFile.getPath().equals(parentFile.getPath())) {
            LOGGER.info("the package has checked, no need check more.");
            return true;
        }

        IAppdFile fileHandlerMf = AppdFileHandlerFactory.createFileHandler(AppdFileHandlerFactory.MF_FILE);
        if (fileHandlerMf == null) {
            return true;
        }
        fileHandlerMf.load(mfFile);
        Map<String, String> file2hash = getFileHash(fileHandlerMf);
        Set<Map.Entry<String, String>> entries = file2hash.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            String sourceFilePath = fileParent + File.separator + entry.getKey();
            if (!entry.getValue().equals(getHashValue(sourceFilePath))) {
                LOGGER.error("the sourceFile {} hash value is incorrect", entry.getKey());
                return false;
            }
        }
        try {
            String signStr = getSignedData(fileHandlerMf);
            if (!StringUtils.isEmpty(signStr)) {
                return Signature.signedDataVerify(signStr.getBytes(StandardCharsets.UTF_8));
            }
        } catch (CMSException e) {
            LOGGER.error("signedDataVerify catch exception: {}", e.getMessage());
        }
        return false;
    }
/**
     * check package valid.
     *
     * @param fileParent package file parent.
     * @return boolean
     */
check package valid.
@param fileParent package file parent.
@return boolean
check package valid . @param fileParent package file parent . @return boolean
public boolean checkPackageValid(String fileParent) {
        File mfFile = getFile(fileParent, MF_EXTENSION);
        File sourceFile = mfFile.getParentFile();
        File parentFile = new File(fileParent);
        if (!sourceFile.getPath().equals(parentFile.getPath())) {
            LOGGER.info("the package has checked, no need check more.");
            return true;
        }
        IAppdFile fileHandlerMf = AppdFileHandlerFactory.createFileHandler(AppdFileHandlerFactory.MF_FILE);
        if (fileHandlerMf == null) {
            return true;
        }
        fileHandlerMf.load(mfFile);
        Map<String, String> file2hash = getFileHash(fileHandlerMf);
        Set<Map.Entry<String, String>> entries = file2hash.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            String sourceFilePath = fileParent + File.separator + entry.getKey();
            if (!entry.getValue().equals(getHashValue(sourceFilePath))) {
                LOGGER.error("the sourceFile {} hash value is incorrect", entry.getKey());
                return false;
            }
        }
        try {
            String signStr = getSignedData(fileHandlerMf);
            if (!StringUtils.isEmpty(signStr)) {
                return Signature.signedDataVerify(signStr.getBytes(StandardCharsets.UTF_8));
            }
        } catch (CMSException e) {
            LOGGER.error("signedDataVerify catch exception: {}", e.getMessage());
        }
        return false;
    }
public boolean checkPackageValid ( String fileParent ) { File mfFile = getFile ( fileParent , MF_EXTENSION ) ; File sourceFile = mfFile . getParentFile ( ) ; File parentFile = new File ( fileParent ) ; if ( ! sourceFile . getPath ( ) . equals ( parentFile . getPath ( ) ) ) { LOGGER . info ( "the package has checked, no need check more." ) ; return true ; } IAppdFile fileHandlerMf = AppdFileHandlerFactory . createFileHandler ( AppdFileHandlerFactory . MF_FILE ) ; if ( fileHandlerMf == null ) { return true ; } fileHandlerMf . load ( mfFile ) ; Map < String , String > file2hash = getFileHash ( fileHandlerMf ) ; Set < Map . Entry < String , String > > entries = file2hash . entrySet ( ) ; for ( Map . Entry < String , String > entry : entries ) { String sourceFilePath = fileParent + File . separator + entry . getKey ( ) ; if ( ! entry . getValue ( ) . equals ( getHashValue ( sourceFilePath ) ) ) { LOGGER . error ( "the sourceFile {} hash value is incorrect" , entry . getKey ( ) ) ; return false ; } } try { String signStr = getSignedData ( fileHandlerMf ) ; if ( ! StringUtils . isEmpty ( signStr ) ) { return Signature . signedDataVerify ( signStr . getBytes ( StandardCharsets . UTF_8 ) ) ; } } catch ( CMSException e ) { LOGGER . error ( "signedDataVerify catch exception: {}" , e . getMessage ( ) ) ; } return false ; }
check package valid.
check package valid .