8186098: sun/security/pkcs11/KeyStore/SecretKeysBasic.sh failed due to libnss3 version cannot be parsed
Improves the approach on parsing lib version Reviewed-by: weijun, xuelei
This commit is contained in:
parent
6d4be03205
commit
7e5577a6c1
@ -31,6 +31,7 @@ import java.io.FileInputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.AlgorithmParameters;
|
import java.security.AlgorithmParameters;
|
||||||
import java.security.InvalidAlgorithmParameterException;
|
import java.security.InvalidAlgorithmParameterException;
|
||||||
import java.security.KeyPairGenerator;
|
import java.security.KeyPairGenerator;
|
||||||
@ -387,6 +388,11 @@ public abstract class PKCS11Test {
|
|||||||
getNSSInfo(nss_library);
|
getNSSInfo(nss_library);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try to parse the version for the specified library.
|
||||||
|
// Assuming the library contains either of the following patterns:
|
||||||
|
// $Header: NSS <version>
|
||||||
|
// Version: NSS <version>
|
||||||
|
// Here, <version> stands for NSS version.
|
||||||
static double getNSSInfo(String library) {
|
static double getNSSInfo(String library) {
|
||||||
// look for two types of headers in NSS libraries
|
// look for two types of headers in NSS libraries
|
||||||
String nssHeader1 = "$Header: NSS";
|
String nssHeader1 = "$Header: NSS";
|
||||||
@ -417,7 +423,7 @@ public abstract class PKCS11Test {
|
|||||||
read = 100 + is.read(data, 100, 900);
|
read = 100 + is.read(data, 100, 900);
|
||||||
}
|
}
|
||||||
|
|
||||||
s = new String(data, 0, read);
|
s = new String(data, 0, read, StandardCharsets.US_ASCII);
|
||||||
i = s.indexOf(nssHeader1);
|
i = s.indexOf(nssHeader1);
|
||||||
if (i > 0 || (i = s.indexOf(nssHeader2)) > 0) {
|
if (i > 0 || (i = s.indexOf(nssHeader2)) > 0) {
|
||||||
found = true;
|
found = true;
|
||||||
@ -443,18 +449,13 @@ public abstract class PKCS11Test {
|
|||||||
|
|
||||||
// the index after whitespace after nssHeader
|
// the index after whitespace after nssHeader
|
||||||
int afterheader = s.indexOf("NSS", i) + 4;
|
int afterheader = s.indexOf("NSS", i) + 4;
|
||||||
int nextSpaceIndex = s.indexOf(' ', afterheader);
|
String version = String.valueOf(s.charAt(afterheader));
|
||||||
|
for (char c = s.charAt(++afterheader);
|
||||||
// If the next space is not found,
|
c == '.' || (c >= '0' && c <= '9');
|
||||||
// it has to print the content for further investigation.
|
c = s.charAt(++afterheader)) {
|
||||||
if (nextSpaceIndex == -1) {
|
version += c;
|
||||||
System.out.println("===== Content start =====");
|
|
||||||
System.out.println(s);
|
|
||||||
System.out.println("===== Content end =====");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String version = s.substring(afterheader, nextSpaceIndex);
|
|
||||||
|
|
||||||
// If a "dot dot" release, strip the extra dots for double parsing
|
// If a "dot dot" release, strip the extra dots for double parsing
|
||||||
String[] dot = version.split("\\.");
|
String[] dot = version.split("\\.");
|
||||||
if (dot.length > 2) {
|
if (dot.length > 2) {
|
||||||
@ -468,6 +469,9 @@ public abstract class PKCS11Test {
|
|||||||
try {
|
try {
|
||||||
nss_version = Double.parseDouble(version);
|
nss_version = Double.parseDouble(version);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
|
System.out.println("===== Content start =====");
|
||||||
|
System.out.println(s);
|
||||||
|
System.out.println("===== Content end =====");
|
||||||
System.out.println("Failed to parse lib" + library +
|
System.out.println("Failed to parse lib" + library +
|
||||||
" version. Set to 0.0");
|
" version. Set to 0.0");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user