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

SunJSSE provider throws incorrect exception when signing object with null key

    XMLWordPrintable

    Details

      Description



      Name: akR10050 Date: 08/28/2003


      According to the javadoc specification of SignedObject class,
      InvalidKeyException must be thrown in case the key is invalid. However, when the
      key is null, SunJSSE signature engine throws InvalidParameterException which is
      invalid behaviour.

      This testcase demonstrates the described behaviour:
      ----------------- Test26.java -------------------------
      import java.security.*;

      public class Test26 {
          public static void main(String[] args) {
              Signature sign = null;
              Signature sign1 = null;
              try {
                  sign = Signature.getInstance("MD5andSHA1withRSA", "SunJSSE");
                  sign1 = Signature.getInstance("SHA1withDSA", "SUN");
              } catch (Exception e) {
                  e.printStackTrace(System.err);
              }

              String testObject = "test";

              System.out.print("Trying a SunJSSE signature with null key... ");
              try {
                  new SignedObject(testObject, null, sign);
              } catch (InvalidKeyException ike) {
                  System.out.println("Right: InvalidKeyException");
              } catch (InvalidParameterException ipe) {
                  System.out.println("Wrong: InvalidParameterException");
              } catch (Exception e) {
                  System.out.println("Extremely wrong: " + e);
              }

              System.out.print("Trying a SUN signature with null key... ");
              try {
                  new SignedObject(testObject, null, sign1);
              } catch (InvalidKeyException ike) {
                  System.out.println("Right: InvalidKeyException");
              } catch (InvalidParameterException ipe) {
                  System.out.println("Wrong: InvalidParameterException");
              } catch (Exception e) {
                  System.out.println("Extremely wrong: " + e);
              }

          }
      }

      -------------------------------------------------------

      Here is sample output from the testcase:
      $ java Test26
      Trying a SunJSSE signature with null key... Wrong: InvalidParameterException
      Trying a SUN signature with null key... Right: InvalidKeyException

      ======================================================================

        Attachments

          Activity

            People

            Assignee:
            andreas Andreas Sterbenz
            Reporter:
            kaisunw Kai Kai (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: