mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-26 14:24:46 +02:00
8234147: Avoid looking up standard charsets in core libraries
Reviewed-by: alanb
This commit is contained in:
parent
4e64af81a2
commit
cd589d8469
36 changed files with 200 additions and 237 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. 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
|
||||
|
@ -25,6 +25,8 @@
|
|||
|
||||
package com.sun.java.util.jar.pack;
|
||||
|
||||
import sun.nio.cs.UTF_8;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.File;
|
||||
|
@ -443,7 +445,7 @@ class Driver {
|
|||
// Skip sig4, disks4, entries4, clen4, coff4, cmt2
|
||||
i += 4+4+4+4+4+2;
|
||||
if (i < tail.length)
|
||||
return new String(tail, i, tail.length-i, "UTF8");
|
||||
return new String(tail, i, tail.length-i, UTF_8.INSTANCE);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2010, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2010, 2019, Oracle and/or its affiliates. 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
|
||||
|
@ -29,7 +29,7 @@ import sun.security.action.GetBooleanAction;
|
|||
|
||||
import static com.sun.security.ntlm.Version.*;
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
@ -182,13 +182,9 @@ class NTLM {
|
|||
String readSecurityBuffer(int offset, boolean unicode)
|
||||
throws NTLMException {
|
||||
byte[] raw = readSecurityBuffer(offset);
|
||||
try {
|
||||
return raw == null ? null : new String(
|
||||
raw, unicode ? "UnicodeLittleUnmarked" : "ISO8859_1");
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
throw new NTLMException(NTLMException.PACKET_READ_ERROR,
|
||||
"Invalid input encoding");
|
||||
}
|
||||
return raw == null ? null : new String(
|
||||
raw, unicode ? StandardCharsets.UTF_16LE
|
||||
: StandardCharsets.ISO_8859_1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -247,12 +243,9 @@ class NTLM {
|
|||
}
|
||||
|
||||
void writeSecurityBuffer(int offset, String str, boolean unicode) {
|
||||
try {
|
||||
writeSecurityBuffer(offset, str == null ? null : str.getBytes(
|
||||
unicode ? "UnicodeLittleUnmarked" : "ISO8859_1"));
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
assert false;
|
||||
}
|
||||
writeSecurityBuffer(offset, str == null ? null : str.getBytes(
|
||||
unicode ? StandardCharsets.UTF_16LE
|
||||
: StandardCharsets.ISO_8859_1));
|
||||
}
|
||||
|
||||
byte[] getBytes() {
|
||||
|
@ -380,20 +373,14 @@ class NTLM {
|
|||
}
|
||||
|
||||
byte[] calcV2(byte[] nthash, String text, byte[] blob, byte[] challenge) {
|
||||
try {
|
||||
byte[] ntlmv2hash = hmacMD5(nthash,
|
||||
text.getBytes("UnicodeLittleUnmarked"));
|
||||
byte[] cn = new byte[blob.length+8];
|
||||
System.arraycopy(challenge, 0, cn, 0, 8);
|
||||
System.arraycopy(blob, 0, cn, 8, blob.length);
|
||||
byte[] result = new byte[16+blob.length];
|
||||
System.arraycopy(hmacMD5(ntlmv2hash, cn), 0, result, 0, 16);
|
||||
System.arraycopy(blob, 0, result, 16, blob.length);
|
||||
return result;
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
assert false;
|
||||
}
|
||||
return null;
|
||||
byte[] ntlmv2hash = hmacMD5(nthash, text.getBytes(StandardCharsets.UTF_16LE));
|
||||
byte[] cn = new byte[blob.length+8];
|
||||
System.arraycopy(challenge, 0, cn, 0, 8);
|
||||
System.arraycopy(blob, 0, cn, 8, blob.length);
|
||||
byte[] result = new byte[16+blob.length];
|
||||
System.arraycopy(hmacMD5(ntlmv2hash, cn), 0, result, 0, 16);
|
||||
System.arraycopy(blob, 0, result, 16, blob.length);
|
||||
return result;
|
||||
}
|
||||
|
||||
// NTLM2 LM/NTLM
|
||||
|
@ -412,19 +399,11 @@ class NTLM {
|
|||
// Password in ASCII and UNICODE
|
||||
|
||||
static byte[] getP1(char[] password) {
|
||||
try {
|
||||
return new String(password).toUpperCase(
|
||||
Locale.ENGLISH).getBytes("ISO8859_1");
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
return null;
|
||||
}
|
||||
return new String(password).toUpperCase(Locale.ENGLISH)
|
||||
.getBytes(StandardCharsets.ISO_8859_1);
|
||||
}
|
||||
|
||||
static byte[] getP2(char[] password) {
|
||||
try {
|
||||
return new String(password).getBytes("UnicodeLittleUnmarked");
|
||||
} catch (UnsupportedEncodingException ex) {
|
||||
return null;
|
||||
}
|
||||
return new String(password).getBytes(StandardCharsets.UTF_16LE);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue