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

no KME if identity and certificate public keys conflicts

    XMLWordPrintable

    Details

      Description

      Name: smR10189 Date: 06/28/2004



      The method Identity.addCertificate must throw KeyManagementException
      if there is a conflict between a certificate's public key and
      identity's public key

      According to the JDK 1.5.0 spec."
      public void addCertificate(Certificate certificate)
                          throws KeyManagementException
      .....
      Throws:
      KeyManagementException - if the certificate is not valid, if the
                               public key in the certificate being added
                               conflicts with this identity's public key,"

      The example below reproduces this bug:
      ------------------test.java----------------
      import java.io.*;
      import java.security.*;
      public class test extends Identity {

          public test(String name) { super(name); }

          public static void main(String[] av)
          {
              StubPublicKey key1 = new StubPublicKey("key");
              StubPublicKey key2 = new StubPublicKey("key");
       
              test id;
              try {
                  id = new test("name");
                  id.setPublicKey(key1);
              } catch(Exception e) {
                  System.out.println("Failed: unexpected exception " + e);
                  return;
              }
              
              StubCertificate cert = new StubCertificate(key2);

              System.out.println("Are keys equal: "
                  + id.getPublicKey().equals( cert.getPublicKey() ) );

              try {
                  id.addCertificate( cert );
                  System.out.println("Failed: no KeyManagementException");
              } catch(KeyManagementException e) {
                  System.out.println("Passed");
              }
          }
      }

      class StubPublicKey implements PublicKey {
          private String key;

          public StubPublicKey(String k) { key = k; }
          public String getAlgorithm() { return key; }
          public byte[] getEncoded() { return key.getBytes(); }
          public String getFormat() { return key; }
          public boolean equals(Object object) { return false; }
      }

      class StubCertificate implements Certificate
      {
          private PublicKey key;

          public StubCertificate(PublicKey k) { key = k; }
          
          public void decode(InputStream stream)
                  throws KeyException, IOException {}
          public void encode(OutputStream stream)
                  throws KeyException, IOException {}
          public String getFormat() { return null; }
          public Principal getGuarantor() { return null; }
          public Principal getPrincipal() { return null; }
          public String toString(boolean detailed){ return null; }
          public PublicKey getPublicKey() { return key; }
      }
      ------------------OUTPUT-------------------
      Are keys equal: false
      Failed: no KeyManagementException

      % java -version
      java version "1.5.0-beta3"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta3-b57)
      Java HotSpot(TM) Server VM (build 1.5.0-beta3-b57, mixed mode)

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

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            duke J. Duke (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: