Skip to content

Commit 5af1b31

Browse files
authored
Merge pull request #151 from zzq996/master
Version 3.24.3
2 parents 7c6feb2 + 156503c commit 5af1b31

24 files changed

+432
-120
lines changed

README-Android.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
Version 3.24.3
2+
Resolved issues:
3+
1. Optimized log info of some exception stack
4+
2. Added log when client closed
5+
3. Fixed the issue of hostname verifying
6+
4. Optimized Security of client encryption
7+
5. Optimized the retry logic
8+
6. Fixed issue of setObjectMetadata not working while copyObject
9+
7. Optimized object key coding of temporary url
10+
8. Optimized performance of parsing and generating time string
11+
9. Optimized logic of xml generating
12+
10. Fixed several issues of null pointer
13+
14+
Third-party dependence:
15+
1. Replace okhttp 4.12.0 with okhttp 4.11.0
16+
2. Replace okio 3.6.0 with okio 3.5.0
17+
3. Replace jackson-core 2.15.2 with jackson-core 2.13.3
18+
4. Replace jackson-databind 2.15.2 with jackson-databind 2.13.4.1
19+
5. Replace jackson-annotations 2.15.2 with jackson-annotations 2.13.3
20+
-----------------------------------------------------------------------------------
121
Version 3.23.9.1
222
New features:
323
1. Allow you set custom dns resolver

README-Java.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
Version 3.24.3
2+
Resolved issues:
3+
1. Optimized log info of some exception stack
4+
2. Added log when client closed
5+
3. Fixed the issue of hostname verifying
6+
4. Optimized Security of client encryption
7+
5. Optimized the retry logic
8+
6. Fixed issue of setObjectMetadata not working while copyObject
9+
7. Optimized object key coding of temporary url
10+
8. Optimized performance of parsing and generating time string
11+
9. Optimized logic of xml generating
12+
10. Fixed several issues of null pointer
13+
14+
Third-party dependence:
15+
1. Replace okhttp 4.12.0 with okhttp 4.11.0
16+
2. Replace okio 3.6.0 with okio 3.5.0
17+
3. Replace jackson-core 2.15.2 with jackson-core 2.13.3
18+
4. Replace jackson-databind 2.15.2 with jackson-databind 2.13.4.1
19+
5. Replace jackson-annotations 2.15.2 with jackson-annotations 2.13.3
20+
-----------------------------------------------------------------------------------
121
Version 3.23.9.1
222
New features:
323
1. Allow you set custom dns resolver

README.MD

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
Version 3.24.3
2+
Resolved issues:
3+
1. Optimized log info of some exception stack
4+
2. Added log when client closed
5+
3. Fixed the issue of hostname verifying
6+
4. Optimized Security of client encryption
7+
5. Optimized the retry logic
8+
6. Fixed issue of setObjectMetadata not working while copyObject
9+
7. Optimized object key coding of temporary url
10+
8. Optimized performance of parsing and generating time string
11+
9. Optimized logic of xml generating
12+
10. Fixed several issues of null pointer
13+
14+
Third-party dependence:
15+
1. Replace okhttp 4.12.0 with okhttp 4.11.0
16+
2. Replace okio 3.6.0 with okio 3.5.0
17+
3. Replace jackson-core 2.15.2 with jackson-core 2.13.3
18+
4. Replace jackson-databind 2.15.2 with jackson-databind 2.13.4.1
19+
5. Replace jackson-annotations 2.15.2 with jackson-annotations 2.13.3
20+
-----------------------------------------------------------------------------------
121
Version 3.23.9.1
222
New features:
323
1. Allow you set custom dns resolver

README_CN.MD

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
Version 3.24.3
2+
Resolved issues:
3+
1. 优化某些堆栈的日志打印
4+
2. 增加client close时的日志打印
5+
3. 修复域名校验不正确的问题
6+
4. 客户端加密功能的安全整改
7+
5. 优化重试逻辑
8+
6. 修复拷贝对象时的元数据设置不生效的问题
9+
7. 优化临时url的路径编码逻辑
10+
8. 优化解析、生成时间字符串的性能
11+
9. 优化xml生成逻辑
12+
10. 修复部分空指针问题
13+
14+
Third-party dependence:
15+
1. 使用 okhttp 4.12.0 替代 okhttp 4.11.0
16+
2. 使用 okio 3.6.0 替代 okio 3.5.0
17+
3. 使用 jackson-core 2.15.2 替代 jackson-core 2.13.3
18+
4. 使用 jackson-databind 2.15.2 替代 jackson-databind 2.13.4.1
19+
5. 使用 jackson-annotations 2.15.2 替代 jackson-annotations 2.13.3
20+
-----------------------------------------------------------------------------------
121
Version 3.23.9.1
222
New features:
323
1. 支持设置自定义dns解析器

app/src/main/java/com/obs/log/AbstractLog4jLogger.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@
1515

1616
package com.obs.log;
1717

18-
import java.util.logging.Logger;
19-
2018
import com.obs.services.internal.utils.AccessLoggerUtils;
2119

20+
import java.io.IOException;
21+
import java.io.PrintWriter;
22+
import java.io.StringWriter;
23+
import java.util.logging.Logger;
24+
2225
public abstract class AbstractLog4jLogger {
2326
private static final Logger ILOG = Logger.getLogger(AbstractLog4jLogger.class.getName());
2427

@@ -55,6 +58,7 @@ public void info(Object obj, Throwable e) {
5558
try {
5659
LoggerMethodHolder.info.invoke(this.logger, obj, e);
5760
AccessLoggerUtils.appendLog(obj, "info");
61+
appendLogForThrowable(e,"info");
5862
} catch (Exception ex) {
5963
ILOG.warning(ex.getMessage());
6064
}
@@ -88,6 +92,7 @@ public void warn(Object obj, Throwable e) {
8892
try {
8993
LoggerMethodHolder.warn.invoke(this.logger, obj, e);
9094
AccessLoggerUtils.appendLog(obj, "warn");
95+
appendLogForThrowable(e,"warn");
9196
} catch (Exception ex) {
9297
ILOG.warning(ex.getMessage());
9398
}
@@ -121,6 +126,7 @@ public void error(Object obj, Throwable e) {
121126
try {
122127
LoggerMethodHolder.error.invoke(this.logger, obj, e);
123128
AccessLoggerUtils.appendLog(obj, "error");
129+
appendLogForThrowable(e,"error");
124130
} catch (Exception ex) {
125131
ILOG.warning(ex.getMessage());
126132
}
@@ -154,6 +160,7 @@ public void debug(Object obj, Throwable e) {
154160
try {
155161
LoggerMethodHolder.debug.invoke(this.logger, obj, e);
156162
AccessLoggerUtils.appendLog(obj, "debug");
163+
appendLogForThrowable(e,"debug");
157164
} catch (Exception ex) {
158165
ILOG.warning(ex.getMessage());
159166
}
@@ -187,6 +194,7 @@ public void trace(Object obj, Throwable e) {
187194
try {
188195
LoggerMethodHolder.trace.invoke(this.logger, obj, e);
189196
AccessLoggerUtils.appendLog(obj, "trace");
197+
appendLogForThrowable(e,"trace");
190198
} catch (Exception ex) {
191199
ILOG.warning(ex.getMessage());
192200
}
@@ -202,4 +210,15 @@ public void accessRecord(Object obj) {
202210
}
203211
}
204212
}
213+
214+
protected void appendLogForThrowable(Throwable e, String level) {
215+
AccessLoggerUtils.appendLog("Throwable Message:" + e.getMessage(), level);
216+
try (StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw)) {
217+
e.printStackTrace(pw);
218+
AccessLoggerUtils.appendLog("Throwable printStackTrace:" + sw, level);
219+
} catch (IOException ex)
220+
{
221+
AccessLoggerUtils.appendLog("Throwable printStackTrace failed:" + ex.getMessage(), level);
222+
}
223+
}
205224
}

app/src/main/java/com/obs/services/AbstractClient.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ protected void init(String accessKey, String secretKey, String securityToken, Ob
6868
if (this.isAuthTypeNegotiation()) {
6969
this.getProviderCredentials().setIsAuthTypeNegotiation(true);
7070
}
71-
this.initHttpClient(config.getHttpDispatcher(), config.getCustomizedDnsImpl());
71+
this.initHttpClient(config.getHttpDispatcher(), config.getCustomizedDnsImpl(), config.getHostnameVerifier());
7272
OBSXMLBuilder.setXmlDocumentBuilderFactoryClass(config.getXmlDocumentBuilderFactoryClass());
7373
reqBean.setRespTime(new Date());
7474
reqBean.setResultCode(Constants.RESULTCODE_SUCCESS);
@@ -435,7 +435,11 @@ public void refresh(String accessKey, String secretKey, String securityToken) {
435435
*/
436436
@Override
437437
public void close() throws IOException {
438+
ILOG.warn("client closing");
439+
AccessLoggerUtils.printLog();
438440
this.shutdown();
441+
ILOG.warn("client closed");
442+
AccessLoggerUtils.printLog();
439443
}
440444

441445
public String base64Md5(InputStream is, long length, long offset) throws NoSuchAlgorithmException, IOException {

app/src/main/java/com/obs/services/ObsConfiguration.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
package com.obs.services;
1616

17+
import javax.net.ssl.HostnameVerifier;
1718
import javax.net.ssl.KeyManagerFactory;
1819
import javax.net.ssl.TrustManagerFactory;
1920

@@ -99,6 +100,8 @@ public class ObsConfiguration implements Cloneable {
99100
private Dispatcher httpDispatcher;
100101

101102
private Dns customizedDnsImpl;
103+
104+
private HostnameVerifier hostnameVerifier;
102105

103106
private String xmlDocumentBuilderFactoryClass;
104107

@@ -901,6 +904,17 @@ public Dns getCustomizedDnsImpl() {
901904
public void setCustomizedDnsImpl(Dns customizedDnsImpl) {
902905
this.customizedDnsImpl = customizedDnsImpl;
903906
}
907+
908+
public HostnameVerifier getHostnameVerifier()
909+
{
910+
return hostnameVerifier;
911+
}
912+
913+
public void setHostnameVerifier(HostnameVerifier hostnameVerifier)
914+
{
915+
this.hostnameVerifier = hostnameVerifier;
916+
}
917+
904918
public String getXmlDocumentBuilderFactoryClass() {
905919
return xmlDocumentBuilderFactoryClass;
906920
}

app/src/main/java/com/obs/services/crypto/CTRCipherGenerator.java

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.security.InvalidKeyException;
2828
import java.security.MessageDigest;
2929
import java.security.NoSuchAlgorithmException;
30+
import java.security.NoSuchProviderException;
3031
import java.security.SecureRandom;
3132
import javax.crypto.BadPaddingException;
3233
import javax.crypto.Cipher;
@@ -52,6 +53,16 @@ public class CTRCipherGenerator {
5253

5354
static int sha256BufferLen = 65536;
5455

56+
private static String AesCipherProvider = "";
57+
58+
public static String getAesCipherProvider() {
59+
return AesCipherProvider;
60+
}
61+
62+
public static void setAesCipherProvider(String aesCipherProvider) {
63+
AesCipherProvider = aesCipherProvider;
64+
}
65+
5566
public SecureRandom getSecureRandom() {
5667
return secureRandom;
5768
}
@@ -87,6 +98,7 @@ public byte[] getCryptoKeyBytes() {
8798
public byte[] getRandomCryptoKeyBytes() {
8899
return getRandomBytes(CRYPTO_KEY_BYTES_LEN);
89100
}
101+
90102
public byte[] getRandomBytes(int randomBytesLen) {
91103
byte[] randomBytes;
92104
randomBytes = new byte[randomBytesLen];
@@ -130,23 +142,22 @@ public CTRCipherGenerator(
130142
public CipherInputStream getAES256DecryptedStream(
131143
InputStream ciphertextInput, byte[] object_CryptoIvBytes, byte[] object_CryptoKeyBytes)
132144
throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException,
133-
InvalidKeyException {
145+
InvalidKeyException, NoSuchProviderException {
134146
SecretKeySpec keySpec = new SecretKeySpec(object_CryptoKeyBytes, "AES");
135147
IvParameterSpec ivSpec = new IvParameterSpec(object_CryptoIvBytes);
136-
Cipher cipher = Cipher.getInstance(AES_ALGORITHM);
148+
Cipher cipher = getAesCipher();
137149
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
138150
return new CipherInputStream(ciphertextInput, cipher);
139151
}
140152

141153
public CipherInputStream getAES256EncryptedStream(
142154
InputStream plaintextInput, byte[] object_CryptoIvBytes, byte[] object_CryptoKeyBytes)
143155
throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException,
144-
InvalidKeyException {
156+
InvalidKeyException, NoSuchProviderException {
145157
SecretKeySpec keySpec = new SecretKeySpec(object_CryptoKeyBytes, "AES");
146158
IvParameterSpec ivSpec = new IvParameterSpec(object_CryptoIvBytes);
147-
Cipher cipher = Cipher.getInstance(AES_ALGORITHM);
159+
Cipher cipher = getAesCipher();
148160
cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec);
149-
150161
return new CipherInputStream(plaintextInput, cipher);
151162
}
152163

@@ -161,10 +172,10 @@ public static byte[] getBytesFromBase64(String cryptoInfo) throws UnsupportedEnc
161172
public static byte[] getAESEncryptedBytes(
162173
byte[] plainText, int plainTextOffset, int plainTextLength, byte[] aesKeyBytes, byte[] aesIvBytes)
163174
throws IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException,
164-
InvalidKeyException, NoSuchPaddingException, NoSuchAlgorithmException {
175+
InvalidKeyException, NoSuchPaddingException, NoSuchAlgorithmException, NoSuchProviderException {
165176
SecretKeySpec keySpec = new SecretKeySpec(aesKeyBytes, "AES");
166177
IvParameterSpec ivSpec = new IvParameterSpec(aesIvBytes);
167-
Cipher cipher = Cipher.getInstance(AES_ALGORITHM);
178+
Cipher cipher = getAesCipher();
168179
cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec);
169180
return cipher.doFinal(plainText, plainTextOffset, plainTextLength);
170181
}
@@ -225,6 +236,13 @@ public static byte[] getFileSha256Bytes(String filePath) throws IOException, NoS
225236
return fileSha256Digest.digest();
226237
}
227238

239+
public static Cipher getAesCipher()
240+
throws NoSuchPaddingException, NoSuchAlgorithmException, NoSuchProviderException {
241+
return AesCipherProvider.equals("")
242+
? Cipher.getInstance(AES_ALGORITHM)
243+
: Cipher.getInstance(AES_ALGORITHM, AesCipherProvider);
244+
}
245+
228246
public SHA256Info computeSHA256HashAES(
229247
InputStream plainTextStream,
230248
byte[] object_CryptoIvBytes,
@@ -235,7 +253,7 @@ public SHA256Info computeSHA256HashAES(
235253
try {
236254
SecretKeySpec keySpec = new SecretKeySpec(object_CryptoKeyBytes, "AES");
237255
IvParameterSpec ivSpec = new IvParameterSpec(object_CryptoIvBytes);
238-
Cipher cipher = Cipher.getInstance(AES_ALGORITHM);
256+
Cipher cipher = getAesCipher();
239257
cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec);
240258
bis = new BufferedInputStream(plainTextStream);
241259
MessageDigest plainTextSha256 = MessageDigest.getInstance("SHA-256");

app/src/main/java/com/obs/services/crypto/CryptoObsClient.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import java.security.InvalidAlgorithmParameterException;
5959
import java.security.InvalidKeyException;
6060
import java.security.NoSuchAlgorithmException;
61+
import java.security.NoSuchProviderException;
6162
import java.util.Objects;
6263
import javax.crypto.BadPaddingException;
6364
import javax.crypto.IllegalBlockSizeException;
@@ -257,7 +258,8 @@ protected ObsFSFile putObjectImpl(PutObjectRequest request) throws ServiceExcept
257258
| NoSuchAlgorithmException
258259
| InvalidKeyException
259260
| IllegalBlockSizeException
260-
| BadPaddingException e) {
261+
| BadPaddingException
262+
| NoSuchProviderException e) {
261263
throw new ServiceException(e);
262264
} finally {
263265
if (result != null && result.getBody() != null && request.isAutoClose()) {
@@ -373,7 +375,8 @@ protected ObsObject getObjectImpl(GetObjectRequest request) throws ServiceExcept
373375
| UnsupportedEncodingException
374376
| NoSuchAlgorithmException
375377
| BadPaddingException
376-
| InvalidKeyException e) {
378+
| InvalidKeyException
379+
| NoSuchProviderException e) {
377380
throw new ServiceException(e);
378381
}
379382
}
@@ -389,7 +392,8 @@ protected ObsObject getObjectImpl(GetObjectRequest request) throws ServiceExcept
389392
| InvalidAlgorithmParameterException
390393
| NoSuchPaddingException
391394
| NoSuchAlgorithmException
392-
| InvalidKeyException e) {
395+
| InvalidKeyException
396+
| NoSuchProviderException e) {
393397
throw new ServiceException(e);
394398
}
395399
} else {

0 commit comments

Comments
 (0)