bug-classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug classpath/25144] New: javax.crypto.EncryptedPrivateKeyInfo fails wh


From: berrange at redhat dot com
Subject: [Bug classpath/25144] New: javax.crypto.EncryptedPrivateKeyInfo fails when encoding an java.security.AlgorithmParameters instance
Date: 28 Nov 2005 18:18:41 -0000

When encoding a private key, with a non-NULL instance of 
java.security.AlgorithmParameters, the returned byte array of encoded data is 
always zero length. If the AlgorithmParameters instance is NULL, however, then 
the encoding works correctly.

The only bit of javax.crypto.EncryptedPrivateKeyInfo which changes when
AlgorithmParameters is supplied is in this method:

  private void encode() throws IOException
  {
    List algId = new ArrayList(2);
    algId.add(new DERValue(DER.OBJECT_IDENTIFIER, algOid));
    getAlgParameters();
    if (params != null)
      {
        algId.add(DERReader.read(params.getEncoded()));
      }
    List epki = new ArrayList(2);
    epki.add(new DERValue(DER.CONSTRUCTED|DER.SEQUENCE, algId));
    epki.add(new DERValue(DER.OCTET_STRING, encryptedData));
    encoded = new DERValue(DER.CONSTRUCTED|DER.SEQUENCE, epki).getEncoded();
  }


Tracing the code execution, the only place in the code where a zero-length
byte array is constructed is the 'getEncoded()' method on DERValue:

  public byte[] getEncoded()
  {
    if (encoded == null)
      {
        try
          {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            length = DERWriter.write(out, this);
            encoded = out.toByteArray();
          }
        catch (IOException ioe)
          {
            encoded = new byte[0];
          }
      }
    return (byte[]) encoded.clone();
  }

Debuging further shows that when a non-NULL instance of AlgorithmParamters 
is passed to EncryptedPrivateKey info, DERWriter.write() will throw an 
exception trying to encode an instance of 'java.lang.Object', which in turn
results in the zero-length array.

Finally, the place where the 'java.lang.Object' instance was created, turned
out to be in the DERReader.read method - when it was running this logic from
the very first code snippet above:

    if (params != null)
      {
        algId.add(DERReader.read(params.getEncoded()));
      }

So, DERWriter.write() method needs to be fixed to be able to deal to encode 
the java.lang.Object instances created by DERReader.read(). With such a patch
I believe EncryptedPrivateKeyInfo class will operate correctly when passed
an AlgorithmParamters instance.


-- 
           Summary: javax.crypto.EncryptedPrivateKeyInfo fails when encoding
                    an java.security.AlgorithmParameters instance
           Product: classpath
           Version: 0.19
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: classpath
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: berrange at redhat dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25144





reply via email to

[Prev in Thread] Current Thread [Next in Thread]