Blame SOURCES/pr2974-rh1337583-add_systemlineendings_option_to_keytool_and_use_line_separator_instead_of_crlf_in_pkcs10.patch

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