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