hello all,

the attached patch --already committed-- fixes the above PR.

2006-08-02  Raif S. Naffah  <[EMAIL PROTECTED]>

        PR Classpath/28556
        * gnu/java/security/key/rsa/RSAKeyPairPKCS8Codec.java 
(encodePrivateKey):
        Updated documentation to clarify that RFC-2459 states that the 
parameters
        field of the AlgorithmIdentifier element MUST be NULL if present.
        Amended the code to reflect the specs.
        (decodePrivateKey): Handle case of NULL AlgorithmIdentifier.parameters.


the newly added TestOfPR28556 (in gnu.testlet.gnu.java.security.key.rsa) 
should now pass.


cheers;
rsn
Index: RSAKeyPairPKCS8Codec.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/security/key/rsa/RSAKeyPairPKCS8Codec.java,v
retrieving revision 1.7
diff -u -r1.7 RSAKeyPairPKCS8Codec.java
--- RSAKeyPairPKCS8Codec.java	25 Jun 2006 22:45:27 -0000	1.7
+++ RSAKeyPairPKCS8Codec.java	2 Aug 2006 03:15:29 -0000
@@ -98,6 +98,9 @@
    *   }
    * </pre>
    * <p>
+   * As indicated in RFC-2459: "The parameters field shall have ASN.1 type NULL
+   * for this algorithm identifier.".
+   * <p>
    * The <i>privateKey</i> field, which is an OCTET STRING, contains the
    * DER-encoded form of the RSA private key defined as:
    * <pre>
@@ -140,8 +143,9 @@

     DERValue derOID = new DERValue(DER.OBJECT_IDENTIFIER, RSA_ALG_OID);

-    ArrayList algorithmID = new ArrayList(1);
+    ArrayList algorithmID = new ArrayList(2);
     algorithmID.add(derOID);
+    algorithmID.add(new DERValue(DER.NULL, null));
     DERValue derAlgorithmID = new DERValue(DER.CONSTRUCTED | DER.SEQUENCE,
                                            algorithmID);

@@ -238,9 +242,12 @@
         if (! algOID.equals(RSA_ALG_OID))
           throw new InvalidParameterException("Unexpected OID: " + algOID);

+        // rfc-2459 states that this field is OPTIONAL but NULL if/when present
         DERValue val = der.read();
-        byte[] pkBytes = (byte[]) val.getValue();
+        if (val.getTag() == DER.NULL)
+          val = der.read();

+        byte[] pkBytes = (byte[]) val.getValue();
         der = new DERReader(pkBytes);
         DERValue derRSAPrivateKey = der.read();
         DerUtil.checkIsConstructed(derRSAPrivateKey, "Wrong RSAPrivateKey field");

Reply via email to