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

Can not delete a payload file after running XMLSignature.validate

XMLWordPrintable

      If XMLSignatureInput is constructed by using the FileInputStream as octets source then the octet payload file can't be deleted on Windows platforms after usage.
      Following test case illustrates this case:
      import com.sun.org.apache.xml.internal.security.signature.XMLSignatureInput;
      import java.io.ByteArrayOutputStream;
      import java.io.File;
      import java.io.FileInputStream;
      import java.nio.file.Files;
      import java.nio.file.Path;
      import java.nio.file.Paths;

      public class DeletePayloadFile {
          private static final String filename = "XmlSigInput_payload.txt";
          private static final String content = "123456";

          public static void main(String [] args) throws Exception {
              //Create payload file inside scratch
              Path payload = Paths.get(System.getProperty("user.dir", "."))
                      .resolve(filename);
              Files.write(payload, content.getBytes());

              File pf = payload.toFile();
              FileInputStream fis = new FileInputStream(pf);
              ByteArrayOutputStream baos = new ByteArrayOutputStream();
              XMLSignatureInput sigInput = new XMLSignatureInput(fis);
              sigInput.updateOutputStream(baos);
              System.out.println("baos="+baos.toString()+" result="+baos.toString().equals(content));
              if (!pf.delete()) {
                  throw new RuntimeException("Can't delete XMLSignatureInput payload file:"+filename);
              }

          }
      }

            aefimov Aleksej Efimov
            shadowbug Shadow Bug
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: