Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用无盐单向散列,同时修复无完整性检查的代码下载问题_Java_Spring_Security_Password Hash_Checkmarx - Fatal编程技术网

Java 使用无盐单向散列,同时修复无完整性检查的代码下载问题

Java 使用无盐单向散列,同时修复无完整性检查的代码下载问题,java,spring,security,password-hash,checkmarx,Java,Spring,Security,Password Hash,Checkmarx,我正在尝试使用下面的代码加载一些库“.so”/.dll”文件 System.load("some file"); 然后在使用checkmarx工具执行静态应用程序安全测试(SAST)之后 它抱怨下载的代码没有完整性检查问题 然后,我尝试使用校验和修复未进行完整性检查的代码下载问题 我使用sha-512算法生成了一个库文件校验和,并将其保持在字符串常量中 public static final String TRUSTED_SHA512 = "12af30d9ff

我正在尝试使用下面的代码加载一些库“.so”/.dll”文件

System.load("some file");
然后在使用checkmarx工具执行静态应用程序安全测试(SAST)之后 它抱怨下载的代码没有完整性检查问题

然后,我尝试使用校验和修复未进行完整性检查的代码下载问题

我使用sha-512算法生成了一个库文件校验和,并将其保持在字符串常量中

 public static final String TRUSTED_SHA512 = "12af30d9ffc1cdd85d21e73c8c81b7c379a9b4ab2ea5676cd9d232788e2b44fbab876796104f37d0f6a5f7bc5f97eb3663e432785b94039b5320bbfac3d19516";
现在,在加载文件之前,我将使用相同的算法再次计算哈希值,并根据字符串常量TRUSTED_SHA512

 MessageDigest md = MessageDigest.getInstance("SHA-512");
        String sha512ofQrcToolsWrapper = ChecksumHelper.getFileChecksum(md,temp);
        if(sha512ofQrcToolsWrapper.equalsIgnoreCase(ServiceConstants.TRUSTED_SHA512_OF_QRCTOOLSWRAPPER)) {
            System.load(temp.getAbsolutePath());
        }else{
            throw new Exception("failed to load windows dll file : Checksum mismatched");
        }
现在,checkmarx工具又给了一次使用无盐单向散列的机会 然后我用静态salt值更新了消息摘要。这个 使用fix salt值而不是random值的原因是,我们希望在运行时计算相同的哈希值,以检查常量中已经存在的哈希值

 public static String getFileChecksum(MessageDigest digest, File file) throws IOException, NoSuchAlgorithmException {
    //Get file input stream for reading the file content
    FileInputStream fis = new FileInputStream(file);

    //Create byte array to read data in chunks
    byte[] byteArray = new byte[1024];
    int bytesCount = 0;

    //Read file data and update in message digest
    while ((bytesCount = fis.read(byteArray)) != -1) {
        digest.update(byteArray, 0, bytesCount);
    }

    //Static salt value
    digest.update(getSalt());
    
    //close the stream; We don't need it now.
    fis.close();

    //Get the hash's bytes
    byte[] bytes = digest.digest();

    //This bytes[] has bytes in decimal format;
    //Convert it to hexadecimal format
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < bytes.length; i++) {
        sb.append(Integer.toString((bytes[i] & 0xff) + 0x100, 16).substring(1));
    }

    //return complete hash
    return sb.toString();
}
public静态字符串getFileChecksum(MessageDigest digest,File File)抛出IOException、nosuchagorithmexception{
//获取用于读取文件内容的文件输入流
FileInputStream fis=新的FileInputStream(文件);
//创建字节数组以读取数据块
字节[]字节数组=新字节[1024];
int字节数=0;
//读取文件数据并在消息摘要中更新
while((字节数=fis.read(字节数组))!=-1){
更新(字节数组,0,字节计数);
}
//静态盐值
更新(getSalt());
//关闭小溪,我们现在不需要它。
fis.close();
//获取散列的字节数
字节[]字节=摘要。摘要();
//此字节[]具有十进制格式的字节;
//将其转换为十六进制格式
StringBuilder sb=新的StringBuilder();
for(int i=0;i
注意“getSalt()方法返回具有固定值的字节数组”

不过,萨斯特仍在抱怨这两个问题

  • 下载没有完整性检查的代码
  • 使用不含盐的单向散列
  • 请提供解决方案以解决这些问题。如果还有什么需要澄清的,请告诉我


    提前感谢

    您的代码应该已经运行了。我的理论是,Checkmarx无法遍历到您的helper方法ChecksumHelper.getFileChecksum并创建数据流。当然不是很理想,但是试着将helper方法的主体移到主代码中,在主代码中有一个校验和验证。谢谢,@RomanCanlas我试过了,但仍然面临同样的问题,它不起作用