Blame pr2974-rh1337583-add_systemlineendings_option_to_keytool_and_use_line_separator_instead_of_crlf_in_pkcs10.patch

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