Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8241823

SignedObject throws NullPointerException for null keys with an initialized Signature object



    • Backport
    • Status: Resolved
    • P1
    • Resolution: Fixed
    • 8-pool
    • openjdk8u252
    • security-libs
    • None
    • 11
    • b09
    • generic
    • generic


      This is the backport of a fix for a regression introduced in jdk11 with "JDK-8146293: Add support for RSASSA-PSS Signature algorithm". Manually creating this backport issue is necessary, because the original fix is a closed (i.e. unaccessible) issue in JBS.

      The regression has been fixed in jdk11 by "JDK-8204152: SignedObject throws NullPointerException for null keys with an initialized Signature object".

      This is the original commit: http://hg.openjdk.java.net/jdk/jdk/rev/11c7290b85ff

      Now RSASSA-PSS support has been downported to 8u, but the fix of the regression has not. Unfortunately, because the fix for JDK-8204152 is a closed issue in JBS, we can't say if Oracle already has or plans to downport this fix to their 8u version.

      The regression is that sun.security.rsa.RSAKeyFactory::toRSAKey() now throws NullPointerExceptions for "null" key arguments whereas before it threw InvalidKeyExceptions. These new NullPointerExceptions propagate through standard interfaces like java.security.SignatureSpi::engineInitVerify() or java.security.SignatureSpi::engineInitSign() into user code where they can lead to crashes because of unhandled NullPointerExcpetions.

      Because we've already observed several such crashes in our internal testing and because we expect that other user code will be affected as well we plan to fix this in our distribution, but of course it would be much better if this isse will be fixed in upstream 8u right away.

      JDK-8204152, the original fix for the regression is trivial and applies cleanly to 8u (modulo the usual path shuffling):

      diff -r da301ecaa81d -r 9ccf26c34b3a src/share/classes/sun/security/rsa/RSAKeyFactory.java
      --- a/src/share/classes/sun/security/rsa/RSAKeyFactory.java Fri Mar 27 05:14:30 2020 +0000
      +++ b/src/share/classes/sun/security/rsa/RSAKeyFactory.java Tue Jun 19 23:33:31 2018 +0000
      @@ -115,6 +115,9 @@
            * Used by RSASignature and RSACipher.
           public static RSAKey toRSAKey(Key key) throws InvalidKeyException {
      + if (key == null) {
      + throw new InvalidKeyException("Key must not be null");
      + }
               if ((key instanceof RSAPrivateKeyImpl) ||
                   (key instanceof RSAPrivateCrtKeyImpl) ||
                   (key instanceof RSAPublicKeyImpl)) {

      In the RFR for JDK-8204152 (https://mail.openjdk.java.net/pipermail/security-dev/2018-June/017405.html) the original author mentions:

      "Can someone please help review this fix for addressing JCK test failure?
      Changes are very trivial, just check for null and thrown
      InvalidKeyException instead of letting NPE be thrown later"

      Apparently, the Spec Lead of the JSR337 Maintenance Release 3 has decided to exclude these tests in the lates version of the JCK for 8 MR 3 instead of downporting the corresponding fix, but nevertheless we think this fix is important to prevent regressions in application code.




            simonis Volker Simonis
            simonis Volker Simonis
            0 Vote for this issue
            3 Start watching this issue