Jar在解密AES加密的授权令牌方法时崩溃。hs_err_pid文件提到了arrayof_jbyte_fill。

huangapple go评论69阅读模式
英文:

Jar crashes while decrypting AES encrypted Authorization token method in code. hs_err _pid file mentions arrayof_jbyte_fill

问题

这个问题大致每天在生产环境中发生一次。负载约为20TPS,每次请求在服务器上调用AES解密两次。错误不会在所有请求上生成,但每天会崩溃一次。以下是hs_err_pid文件的片段。

Java运行环境检测到了致命错误:

SIGSEGV (0xb),pc=0x00007f26cc5de47e,pid=53978,tid=0x00007f26837f7700
JRE版本:Java(TM) SE Runtime Environment (8.0_241-b31) (构建 1.8.0_241-b31)
Java虚拟机:Java HotSpot(TM) 64位服务器VM (25.241-b31 混合模式 linux-amd64 压缩 oops)
有问题的帧:
v ~StubRoutines::arrayof_jbyte_fill

当前线程 (0x00007f26d0a03800):JavaThread "http-nio-9094-exec-10" 守护线程
[_thread_in_Java,id=54617,stack(0x00007f26836f7000,0x00007f26837f8000)]

堆栈:[0x00007f26836f7000,0x00007f26837f8000],sp=0x00007f26837f44f0,可用空间=1013k
本地帧:(J=编译的Java代码,j=解释的,Vv=VM代码,C=本地代码)
v ~StubRoutines::arrayof_jbyte_fill
J 26458 C2 java.util.Arrays.fill([BB)V (21字节) @ 0x00007f26cc737ca2
[0x00007f26cc737c60+0x42]
j com.sun.crypto.provider.CipherCore.fillOutputBuffer([BI[BII[B)I+73
j com.sun.crypto.provider.CipherCore.doFinal([BII)[B+65
j com.sun.crypto.provider.AESCipher.engineDoFinal([BII)[B+7
j javax.crypto.Cipher.doFinal([B)[B+30
j com.hello.genesys.common.AES.decrypt([BLjava/lang/String;)[B+92

以下是解密方法:

public static byte[] decrypt(byte[] data, String password) throws Exception {
    try {
        log.info("/// Inside the decrypter method of AES class ////");
        if (null == cipher) {
            log.info("The Cipher is null and hence forming a new object of cipher");
            cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING");
        }

        log.info("Key generation method to be called");
        Key k = new SecretKeySpec(password.getBytes(), AES_ENCRYPTION_TYPE);

        log.info("Cipher initialization to be done");
        cipher.init(Cipher.DECRYPT_MODE, k);

        log.info("The byte array value to be returned");

        return cipher.doFinal(data);
    } catch (Throwable e) {
        log.info("Inside the Exception of AES decryption method");
        e.printStackTrace();
    }
    return null;
}

这个方法在不同的类中调用:

byte[] decrypter = AES.decrypt(decodeToken, _env("tokenSalt"));

它不会抛出异常,但会因为与arrayof_jbyte_fill相关的错误而崩溃。请帮我解决这个问题,因为它只在生产环境中发生,而不在低环境中发生。有关更多详细信息,请访问hs_err_pid文件链接:https://drive.google.com/file/d/1WDG4rm7vIw6HDbhZPtXjud7r8TEh4d74/view?usp=sharing

英文:

This issue occurs around once in a day on the production environment. The load is around 20TPS and the AES decryption is called twice for every request on the server. The error is not generated for all requests but It crashes once in a day. Following is the snippet of hs_err_pid file.

A fatal error has been detected by the Java Runtime Environment:

SIGSEGV (0xb) at pc=0x00007f26cc5de47e, pid=53978, tid=0x00007f26837f7700
JRE version: Java(TM) SE Runtime Environment (8.0_241-b31) (build 1.8.0_241-b31)
Java VM: Java HotSpot(TM) 64-Bit Server VM (25.241-b31 mixed mode linux-amd64 compressed oops)
Problematic frame:
v ~StubRoutines::arrayof_jbyte_fill

Current thread (0x00007f26d0a03800):  JavaThread "http-nio-9094-exec-10" daemon 
[_thread_in_Java, id=54617, stack(0x00007f26836f7000,0x00007f26837f8000)]


Stack: [0x00007f26836f7000,0x00007f26837f8000],  sp=0x00007f26837f44f0,  free space=1013k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
v  ~StubRoutines::arrayof_jbyte_fill
J 26458 C2 java.util.Arrays.fill([BB)V (21 bytes) @ 0x00007f26cc737ca2 
[0x00007f26cc737c60+0x42]
j  com.sun.crypto.provider.CipherCore.fillOutputBuffer([BI[BII[B)I+73
j  com.sun.crypto.provider.CipherCore.doFinal([BII)[B+65
j  com.sun.crypto.provider.AESCipher.engineDoFinal([BII)[B+7
j  javax.crypto.Cipher.doFinal([B)[B+30
j  com.hello.genesys.common.AES.decrypt([BLjava/lang/String;)[B+92

Following is the decryption method :

public static byte[] decrypt(byte[] data, String password) throws Exception {
    try {
    	log.info("/// Inside the decrypter method of AES class ////");
        if (null == cipher) {
        	log.info("The Cipher is null and hence forming new object of cipher");
            cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING");
        }

        log.info("Key generation method to be called");
        Key k = new SecretKeySpec(password.getBytes(), AES_ENCRYPTION_TYPE);
        
        log.info("Cipher initialization to be done");
        cipher.init(Cipher.DECRYPT_MODE, k);

        log.info("The byte array value to be returned");
        
        return cipher.doFinal(data);
    } catch (Throwable e) {
    	log.info("Inside Exception of AES decryption method");
        e.printStackTrace();
    }
    return null;
}

This method is called in a different class :

byte[] decrypter = AES.decrypt(decodeToken, _env("tokenSalt"));

It does not throws an exception but crashes with arrayof_jbyte_fill related error. Please help me solve this issue as it occurs only in the production environment but not in a lower environment. Link to the hs_err_pid file for more details: https://drive.google.com/file/d/1WDG4rm7vIw6HDbhZPtXjud7r8TEh4d74/view?usp=sharing

答案1

得分: 0

错误出在密码对象本身。我现在已经创建并初始化了一个本地密码对象,而不是全局对象,在部署后的两周内似乎没有崩溃。因此,由于两个解密过程连续发生,它在第二个解密请求期间崩溃,因为该对象仍然被第一个解密过程使用。所以这是我对这个问题的分析。

英文:

The goof-up was with the cipher object itself. I have now created & initialized a local cipher object instead of the global one and there seems to be no crash for 2 weeks after deployment. So as 2 decryption processes were occurring simultaneously back to back, it was getting crashed during the second decryption request as the object was still being used by the first one. So this is my analysis for this issue

huangapple
  • 本文由 发表于 2020年8月3日 09:52:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/63222761.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定