Blame SOURCES/pr2974-rh1337583-add_systemlineendings_option_to_keytool_and_use_line_separator_instead_of_crlf_in_pkcs10.patch

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