Blame SOURCES/pr2974-rh1337583-add_systemlineendings_option_to_keytool_and_use_line_separator_instead_of_crlf_in_pkcs10.patch

2d54fe
# HG changeset patch
2d54fe
# User andrew
2d54fe
# Date 1464316115 -3600
2d54fe
#      Fri May 27 03:28:35 2016 +0100
2d54fe
# Node ID 794541fbbdc323f7da8a5cee75611f977eee66ee
2d54fe
# Parent  0be28a33e12dfc9ae1e4be381530643f691d351a
2d54fe
PR2974: PKCS#10 certificate requests now use CRLF line endings rather than system line endings
2d54fe
Summary: Add -systemlineendings option to keytool to allow system line endings to be used again.
2d54fe
2d54fe
diff --git a/src/share/classes/sun/security/pkcs10/PKCS10.java b/src/share/classes/sun/security/pkcs10/PKCS10.java
2d54fe
--- openjdk/jdk/src/share/classes/sun/security/pkcs10/PKCS10.java
2d54fe
+++ openjdk/jdk/src/share/classes/sun/security/pkcs10/PKCS10.java
2d54fe
@@ -30,6 +30,7 @@
2d54fe
 import java.io.IOException;
2d54fe
 import java.math.BigInteger;
2d54fe
 
2d54fe
+import java.security.AccessController;
2d54fe
 import java.security.cert.CertificateException;
2d54fe
 import java.security.NoSuchAlgorithmException;
2d54fe
 import java.security.InvalidKeyException;
2d54fe
@@ -39,6 +40,7 @@
2d54fe
 
2d54fe
 import java.util.Base64;
2d54fe
 
2d54fe
+import sun.security.action.GetPropertyAction;
2d54fe
 import sun.security.util.*;
2d54fe
 import sun.security.x509.AlgorithmId;
2d54fe
 import sun.security.x509.X509Key;
2d54fe
@@ -76,6 +78,14 @@
2d54fe
  * @author Hemma Prafullchandra
2d54fe
  */
2d54fe
 public class PKCS10 {
2d54fe
+
2d54fe
+    private static final byte[] sysLineEndings;
2d54fe
+
2d54fe
+    static {
2d54fe
+        sysLineEndings =
2d54fe
+	    AccessController.doPrivileged(new GetPropertyAction("line.separator")).getBytes();
2d54fe
+    }
2d54fe
+
2d54fe
     /**
2d54fe
      * Constructs an unsigned PKCS #10 certificate request.  Before this
2d54fe
      * request may be used, it must be encoded and signed.  Then it
2d54fe
@@ -293,13 +303,39 @@
2d54fe
      */
2d54fe
     public void print(PrintStream out)
2d54fe
     throws IOException, SignatureException {
2d54fe
+        print(out, false);
2d54fe
+    }
2d54fe
+
2d54fe
+    /**
2d54fe
+     * Prints an E-Mailable version of the certificate request on the print
2d54fe
+     * stream passed.  The format is a common base64 encoded one, supported
2d54fe
+     * by most Certificate Authorities because Netscape web servers have
2d54fe
+     * used this for some time.  Some certificate authorities expect some
2d54fe
+     * more information, in particular contact information for the web
2d54fe
+     * server administrator.
2d54fe
+     *
2d54fe
+     * @param out the print stream where the certificate request
2d54fe
+     *  will be printed.
2d54fe
+     * @param systemLineEndings true if the request should be terminated
2d54fe
+     *  using the system line endings.
2d54fe
+     * @exception IOException when an output operation failed
2d54fe
+     * @exception SignatureException when the certificate request was
2d54fe
+     *  not yet signed.
2d54fe
+     */
2d54fe
+    public void print(PrintStream out, boolean systemLineEndings)
2d54fe
+    throws IOException, SignatureException {
2d54fe
+        byte[] lineEndings;
2d54fe
+
2d54fe
         if (encoded == null)
2d54fe
             throw new SignatureException("Cert request was not signed");
2d54fe
 
2d54fe
+        if (systemLineEndings)
2d54fe
+            lineEndings = sysLineEndings;
2d54fe
+        else
2d54fe
+            lineEndings = new byte[] {'\r', '\n'}; // CRLF
2d54fe
 
2d54fe
-        byte[] CRLF = new byte[] {'\r', '\n'};
2d54fe
         out.println("-----BEGIN NEW CERTIFICATE REQUEST-----");
2d54fe
-        out.println(Base64.getMimeEncoder(64, CRLF).encodeToString(encoded));
2d54fe
+        out.println(Base64.getMimeEncoder(64, lineEndings).encodeToString(encoded));
2d54fe
         out.println("-----END NEW CERTIFICATE REQUEST-----");
2d54fe
     }
2d54fe
 
2d54fe
diff --git a/src/share/classes/sun/security/tools/keytool/Main.java b/src/share/classes/sun/security/tools/keytool/Main.java
2d54fe
--- openjdk/jdk/src/share/classes/sun/security/tools/keytool/Main.java
2d54fe
+++ openjdk/jdk/src/share/classes/sun/security/tools/keytool/Main.java
2d54fe
@@ -124,6 +124,7 @@
2d54fe
     private String infilename = null;
2d54fe
     private String outfilename = null;
2d54fe
     private String srcksfname = null;
2d54fe
+    private boolean systemLineEndings = false;
2d54fe
 
2d54fe
     // User-specified providers are added before any command is called.
2d54fe
     // However, they are not removed before the end of the main() method.
2d54fe
@@ -186,7 +187,7 @@
2d54fe
         CERTREQ("Generates.a.certificate.request",
2d54fe
             ALIAS, SIGALG, FILEOUT, KEYPASS, KEYSTORE, DNAME,
2d54fe
             STOREPASS, STORETYPE, PROVIDERNAME, PROVIDERCLASS,
2d54fe
-            PROVIDERARG, PROVIDERPATH, V, PROTECTED),
2d54fe
+            PROVIDERARG, PROVIDERPATH, SYSTEMLINEENDINGS, V, PROTECTED),
2d54fe
         CHANGEALIAS("Changes.an.entry.s.alias",
2d54fe
             ALIAS, DESTALIAS, KEYPASS, KEYSTORE, STOREPASS,
2d54fe
             STORETYPE, PROVIDERNAME, PROVIDERCLASS, PROVIDERARG,
2d54fe
@@ -319,6 +320,7 @@
2d54fe
         STARTDATE("startdate", "<startdate>", "certificate.validity.start.date.time"),
2d54fe
         STOREPASS("storepass", "<arg>", "keystore.password"),
2d54fe
         STORETYPE("storetype", "<storetype>", "keystore.type"),
2d54fe
+        SYSTEMLINEENDINGS("systemlineendings", null, "system.line.endings"),
2d54fe
         TRUSTCACERTS("trustcacerts", null, "trust.certificates.from.cacerts"),
2d54fe
         V("v", null, "verbose.output"),
2d54fe
         VALIDITY("validity", "<valDays>", "validity.number.of.days");
2d54fe
@@ -559,6 +561,8 @@
2d54fe
                 protectedPath = true;
2d54fe
             } else if (collator.compare(flags, "-srcprotected") == 0) {
2d54fe
                 srcprotectedPath = true;
2d54fe
+            } else if (collator.compare(flags, "-systemlineendings") == 0) {
2d54fe
+                systemLineEndings = true;
2d54fe
             } else  {
2d54fe
                 System.err.println(rb.getString("Illegal.option.") + flags);
2d54fe
                 tinyHelp();
2d54fe
@@ -1463,7 +1467,7 @@
2d54fe
 
2d54fe
         // Sign the request and base-64 encode it
2d54fe
         request.encodeAndSign(subject, signature);
2d54fe
-        request.print(out);
2d54fe
+        request.print(out, systemLineEndings);
2d54fe
 
2d54fe
         checkWeak(rb.getString("the.generated.certificate.request"), request);
2d54fe
     }
2d54fe
@@ -4540,4 +4544,3 @@
2d54fe
         return new Pair<>(a,b);
2d54fe
     }
2d54fe
 }
2d54fe
-
2d54fe
diff --git a/src/share/classes/sun/security/tools/keytool/Resources.java b/src/share/classes/sun/security/tools/keytool/Resources.java
2d54fe
--- openjdk/jdk/src/share/classes/sun/security/tools/keytool/Resources.java
2d54fe
+++ openjdk/jdk/src/share/classes/sun/security/tools/keytool/Resources.java
2d54fe
@@ -168,6 +168,8 @@
2d54fe
                 "keystore password"}, //-storepass
2d54fe
         {"keystore.type",
2d54fe
                 "keystore type"}, //-storetype
2d54fe
+	{"system.line.endings",
2d54fe
+	        "use system line endings rather than CRLF to terminate output"}, //-systemlineendings
2d54fe
         {"trust.certificates.from.cacerts",
2d54fe
                 "trust certificates from cacerts"}, //-trustcacerts
2d54fe
         {"verbose.output",