Blame SOURCES/pr2974-rh1337583-add_systemlineendings_option_to_keytool_and_use_line_separator_instead_of_crlf_in_pkcs10.patch

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