提交 0bde254d 编写于 作者: W weijun

6813340: X509Factory should not depend on is.available()==0

Reviewed-by: xuelei
上级 d876c863
...@@ -977,46 +977,35 @@ public final class KeyTool { ...@@ -977,46 +977,35 @@ public final class KeyTool {
if (filename != null) { if (filename != null) {
inStream = new FileInputStream(filename); inStream = new FileInputStream(filename);
} }
// Read the full stream before feeding to X509Factory, String importAlias = (alias!=null)?alias:keyAlias;
// otherwise, keytool -gencert | keytool -importcert
// might not work properly, since -gencert is slow
// and there's no data in the pipe at the beginning.
ByteArrayOutputStream bout = new ByteArrayOutputStream();
try { try {
byte[] b = new byte[4096]; if (keyStore.entryInstanceOf(
while (true) { importAlias, KeyStore.PrivateKeyEntry.class)) {
int len = inStream.read(b); kssave = installReply(importAlias, inStream);
if (len < 0) break; if (kssave) {
bout.write(b, 0, len); System.err.println(rb.getString
("Certificate reply was installed in keystore"));
} else {
System.err.println(rb.getString
("Certificate reply was not installed in keystore"));
}
} else if (!keyStore.containsAlias(importAlias) ||
keyStore.entryInstanceOf(importAlias,
KeyStore.TrustedCertificateEntry.class)) {
kssave = addTrustedCert(importAlias, inStream);
if (kssave) {
System.err.println(rb.getString
("Certificate was added to keystore"));
} else {
System.err.println(rb.getString
("Certificate was not added to keystore"));
}
} }
} finally { } finally {
if (inStream != System.in) { if (inStream != System.in) {
inStream.close(); inStream.close();
} }
} }
inStream = new ByteArrayInputStream(bout.toByteArray());
String importAlias = (alias!=null)?alias:keyAlias;
if (keyStore.entryInstanceOf(importAlias, KeyStore.PrivateKeyEntry.class)) {
kssave = installReply(importAlias, inStream);
if (kssave) {
System.err.println(rb.getString
("Certificate reply was installed in keystore"));
} else {
System.err.println(rb.getString
("Certificate reply was not installed in keystore"));
}
} else if (!keyStore.containsAlias(importAlias) ||
keyStore.entryInstanceOf(importAlias,
KeyStore.TrustedCertificateEntry.class)) {
kssave = addTrustedCert(importAlias, inStream);
if (kssave) {
System.err.println(rb.getString
("Certificate was added to keystore"));
} else {
System.err.println(rb.getString
("Certificate was not added to keystore"));
}
}
} else if (command == IMPORTKEYSTORE) { } else if (command == IMPORTKEYSTORE) {
doImportKeyStore(); doImportKeyStore();
kssave = true; kssave = true;
...@@ -2149,18 +2138,7 @@ public final class KeyTool { ...@@ -2149,18 +2138,7 @@ public final class KeyTool {
inStream = new FileInputStream(filename); inStream = new FileInputStream(filename);
} }
try { try {
// Read the full stream before feeding to X509Factory, printCertFromStream(inStream, out);
// otherwise, keytool -gencert | keytool -printcert
// might not work properly, since -gencert is slow
// and there's no data in the pipe at the beginning.
ByteArrayOutputStream bout = new ByteArrayOutputStream();
byte[] b = new byte[4096];
while (true) {
int len = inStream.read(b);
if (len < 0) break;
bout.write(b, 0, len);
}
printCertFromStream(new ByteArrayInputStream(bout.toByteArray()), out);
} finally { } finally {
if (inStream != System.in) { if (inStream != System.in) {
inStream.close(); inStream.close();
......
/*
* Copyright 2010 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
/*
* @test
* @bug 6813340
* @summary X509Factory should not depend on is.available()==0
*/
import java.io.*;
import java.security.cert.*;
/**
* Tests ol'Mac style file, end witha single '\r'
*/
public class ReturnStream {
public static void main(String[] args) throws Exception {
FileInputStream fin = new FileInputStream(new File(new File(
System.getProperty("test.src", "."), "openssl"), "pem"));
byte[] buffer = new byte[4096];
int size = 0;
while (true) {
int len = fin.read(buffer, size, 4096-size);
if (len < 0) break;
size += len;
}
fin.close();
// Make a copy
System.arraycopy(buffer, 0, buffer, size, size);
size += size;
// Create a ol'Mac style file.
for (int i=0; i<size; i++) {
if (buffer[i] == '\n') buffer[i] = '\r';
}
CertificateFactory factory = CertificateFactory.getInstance("X.509");
if (factory.generateCertificates(
new ByteArrayInputStream(buffer, 0, size)).size() != 2) {
throw new Exception("Cert not OK");
}
}
}
/*
* Copyright 2010 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*/
import java.io.*;
import java.security.cert.*;
class SlowStreamReader {
public static void main(String[] args) throws Exception {
CertificateFactory factory = CertificateFactory.getInstance("X.509");
if (factory.generateCertificates(System.in).size() != 5) {
throw new Exception("Not all certs read");
}
}
}
class SlowStreamWriter {
public static void main(String[] args) throws Exception {
for (int i=0; i<5; i++) {
FileInputStream fin = new FileInputStream(new File(new File(
System.getProperty("test.src", "."), "openssl"), "pem"));
byte[] buffer = new byte[4096];
while (true) {
int len = fin.read(buffer);
if (len < 0) break;
System.out.write(buffer, 0, len);
}
Thread.sleep(2000);
}
}
}
#
# Copyright 2010 Sun Microsystems, Inc. All Rights Reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 2 only, as
# published by the Free Software Foundation.
#
# This code is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# version 2 for more details (a copy is included in the LICENSE file that
# accompanied this code).
#
# You should have received a copy of the GNU General Public License version
# 2 along with this work; if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# have any questions.
#
# @test
# @bug 6813340
# @summary X509Factory should not depend on is.available()==0
if [ "${TESTSRC}" = "" ] ; then
TESTSRC="."
fi
if [ "${TESTJAVA}" = "" ] ; then
echo "TESTJAVA not set. Test cannot execute."
echo "FAILED!!!"
exit 1
fi
# set platform-dependent variables
OS=`uname -s`
case "$OS" in
Windows_* )
FS="\\"
;;
* )
FS="/"
;;
esac
${TESTJAVA}${FS}bin${FS}javac -d . ${TESTSRC}${FS}SlowStream.java
${TESTJAVA}${FS}bin${FS}java -Dtest.src=${TESTSRC} SlowStreamWriter | \
${TESTJAVA}${FS}bin${FS}java SlowStreamReader
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册