Skip to content

Commit

Permalink
Merge pull request #151 from zzq996/master
Browse files Browse the repository at this point in the history
Version 3.24.3
  • Loading branch information
zzq996 authored May 6, 2024
2 parents 7c6feb2 + 156503c commit 5af1b31
Show file tree
Hide file tree
Showing 24 changed files with 432 additions and 120 deletions.
20 changes: 20 additions & 0 deletions README-Android.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
Version 3.24.3
Resolved issues:
1. Optimized log info of some exception stack
2. Added log when client closed
3. Fixed the issue of hostname verifying
4. Optimized Security of client encryption
5. Optimized the retry logic
6. Fixed issue of setObjectMetadata not working while copyObject
7. Optimized object key coding of temporary url
8. Optimized performance of parsing and generating time string
9. Optimized logic of xml generating
10. Fixed several issues of null pointer

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

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

Third-party dependence:
1. Replace okhttp 4.12.0 with okhttp 4.11.0
2. Replace okio 3.6.0 with okio 3.5.0
3. Replace jackson-core 2.15.2 with jackson-core 2.13.3
4. Replace jackson-databind 2.15.2 with jackson-databind 2.13.4.1
5. Replace jackson-annotations 2.15.2 with jackson-annotations 2.13.3
-----------------------------------------------------------------------------------
Version 3.23.9.1
New features:
1. Allow you set custom dns resolver
Expand Down
20 changes: 20 additions & 0 deletions README_CN.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
Version 3.24.3
Resolved issues:
1. 优化某些堆栈的日志打印
2. 增加client close时的日志打印
3. 修复域名校验不正确的问题
4. 客户端加密功能的安全整改
5. 优化重试逻辑
6. 修复拷贝对象时的元数据设置不生效的问题
7. 优化临时url的路径编码逻辑
8. 优化解析、生成时间字符串的性能
9. 优化xml生成逻辑
10. 修复部分空指针问题

Third-party dependence:
1. 使用 okhttp 4.12.0 替代 okhttp 4.11.0
2. 使用 okio 3.6.0 替代 okio 3.5.0
3. 使用 jackson-core 2.15.2 替代 jackson-core 2.13.3
4. 使用 jackson-databind 2.15.2 替代 jackson-databind 2.13.4.1
5. 使用 jackson-annotations 2.15.2 替代 jackson-annotations 2.13.3
-----------------------------------------------------------------------------------
Version 3.23.9.1
New features:
1. 支持设置自定义dns解析器
Expand Down
23 changes: 21 additions & 2 deletions app/src/main/java/com/obs/log/AbstractLog4jLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@

package com.obs.log;

import java.util.logging.Logger;

import com.obs.services.internal.utils.AccessLoggerUtils;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.logging.Logger;

public abstract class AbstractLog4jLogger {
private static final Logger ILOG = Logger.getLogger(AbstractLog4jLogger.class.getName());

Expand Down Expand Up @@ -55,6 +58,7 @@ public void info(Object obj, Throwable e) {
try {
LoggerMethodHolder.info.invoke(this.logger, obj, e);
AccessLoggerUtils.appendLog(obj, "info");
appendLogForThrowable(e,"info");
} catch (Exception ex) {
ILOG.warning(ex.getMessage());
}
Expand Down Expand Up @@ -88,6 +92,7 @@ public void warn(Object obj, Throwable e) {
try {
LoggerMethodHolder.warn.invoke(this.logger, obj, e);
AccessLoggerUtils.appendLog(obj, "warn");
appendLogForThrowable(e,"warn");
} catch (Exception ex) {
ILOG.warning(ex.getMessage());
}
Expand Down Expand Up @@ -121,6 +126,7 @@ public void error(Object obj, Throwable e) {
try {
LoggerMethodHolder.error.invoke(this.logger, obj, e);
AccessLoggerUtils.appendLog(obj, "error");
appendLogForThrowable(e,"error");
} catch (Exception ex) {
ILOG.warning(ex.getMessage());
}
Expand Down Expand Up @@ -154,6 +160,7 @@ public void debug(Object obj, Throwable e) {
try {
LoggerMethodHolder.debug.invoke(this.logger, obj, e);
AccessLoggerUtils.appendLog(obj, "debug");
appendLogForThrowable(e,"debug");
} catch (Exception ex) {
ILOG.warning(ex.getMessage());
}
Expand Down Expand Up @@ -187,6 +194,7 @@ public void trace(Object obj, Throwable e) {
try {
LoggerMethodHolder.trace.invoke(this.logger, obj, e);
AccessLoggerUtils.appendLog(obj, "trace");
appendLogForThrowable(e,"trace");
} catch (Exception ex) {
ILOG.warning(ex.getMessage());
}
Expand All @@ -202,4 +210,15 @@ public void accessRecord(Object obj) {
}
}
}

protected void appendLogForThrowable(Throwable e, String level) {
AccessLoggerUtils.appendLog("Throwable Message:" + e.getMessage(), level);
try (StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw)) {
e.printStackTrace(pw);
AccessLoggerUtils.appendLog("Throwable printStackTrace:" + sw, level);
} catch (IOException ex)
{
AccessLoggerUtils.appendLog("Throwable printStackTrace failed:" + ex.getMessage(), level);
}
}
}
6 changes: 5 additions & 1 deletion app/src/main/java/com/obs/services/AbstractClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected void init(String accessKey, String secretKey, String securityToken, Ob
if (this.isAuthTypeNegotiation()) {
this.getProviderCredentials().setIsAuthTypeNegotiation(true);
}
this.initHttpClient(config.getHttpDispatcher(), config.getCustomizedDnsImpl());
this.initHttpClient(config.getHttpDispatcher(), config.getCustomizedDnsImpl(), config.getHostnameVerifier());
OBSXMLBuilder.setXmlDocumentBuilderFactoryClass(config.getXmlDocumentBuilderFactoryClass());
reqBean.setRespTime(new Date());
reqBean.setResultCode(Constants.RESULTCODE_SUCCESS);
Expand Down Expand Up @@ -435,7 +435,11 @@ public void refresh(String accessKey, String secretKey, String securityToken) {
*/
@Override
public void close() throws IOException {
ILOG.warn("client closing");
AccessLoggerUtils.printLog();
this.shutdown();
ILOG.warn("client closed");
AccessLoggerUtils.printLog();
}

public String base64Md5(InputStream is, long length, long offset) throws NoSuchAlgorithmException, IOException {
Expand Down
14 changes: 14 additions & 0 deletions app/src/main/java/com/obs/services/ObsConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.obs.services;

import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.TrustManagerFactory;

Expand Down Expand Up @@ -99,6 +100,8 @@ public class ObsConfiguration implements Cloneable {
private Dispatcher httpDispatcher;

private Dns customizedDnsImpl;

private HostnameVerifier hostnameVerifier;

private String xmlDocumentBuilderFactoryClass;

Expand Down Expand Up @@ -901,6 +904,17 @@ public Dns getCustomizedDnsImpl() {
public void setCustomizedDnsImpl(Dns customizedDnsImpl) {
this.customizedDnsImpl = customizedDnsImpl;
}

public HostnameVerifier getHostnameVerifier()
{
return hostnameVerifier;
}

public void setHostnameVerifier(HostnameVerifier hostnameVerifier)
{
this.hostnameVerifier = hostnameVerifier;
}

public String getXmlDocumentBuilderFactoryClass() {
return xmlDocumentBuilderFactoryClass;
}
Expand Down
34 changes: 26 additions & 8 deletions app/src/main/java/com/obs/services/crypto/CTRCipherGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.security.InvalidKeyException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.SecureRandom;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
Expand All @@ -52,6 +53,16 @@ public class CTRCipherGenerator {

static int sha256BufferLen = 65536;

private static String AesCipherProvider = "";

public static String getAesCipherProvider() {
return AesCipherProvider;
}

public static void setAesCipherProvider(String aesCipherProvider) {
AesCipherProvider = aesCipherProvider;
}

public SecureRandom getSecureRandom() {
return secureRandom;
}
Expand Down Expand Up @@ -87,6 +98,7 @@ public byte[] getCryptoKeyBytes() {
public byte[] getRandomCryptoKeyBytes() {
return getRandomBytes(CRYPTO_KEY_BYTES_LEN);
}

public byte[] getRandomBytes(int randomBytesLen) {
byte[] randomBytes;
randomBytes = new byte[randomBytesLen];
Expand Down Expand Up @@ -130,23 +142,22 @@ public CTRCipherGenerator(
public CipherInputStream getAES256DecryptedStream(
InputStream ciphertextInput, byte[] object_CryptoIvBytes, byte[] object_CryptoKeyBytes)
throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException,
InvalidKeyException {
InvalidKeyException, NoSuchProviderException {
SecretKeySpec keySpec = new SecretKeySpec(object_CryptoKeyBytes, "AES");
IvParameterSpec ivSpec = new IvParameterSpec(object_CryptoIvBytes);
Cipher cipher = Cipher.getInstance(AES_ALGORITHM);
Cipher cipher = getAesCipher();
cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);
return new CipherInputStream(ciphertextInput, cipher);
}

public CipherInputStream getAES256EncryptedStream(
InputStream plaintextInput, byte[] object_CryptoIvBytes, byte[] object_CryptoKeyBytes)
throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException,
InvalidKeyException {
InvalidKeyException, NoSuchProviderException {
SecretKeySpec keySpec = new SecretKeySpec(object_CryptoKeyBytes, "AES");
IvParameterSpec ivSpec = new IvParameterSpec(object_CryptoIvBytes);
Cipher cipher = Cipher.getInstance(AES_ALGORITHM);
Cipher cipher = getAesCipher();
cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec);

return new CipherInputStream(plaintextInput, cipher);
}

Expand All @@ -161,10 +172,10 @@ public static byte[] getBytesFromBase64(String cryptoInfo) throws UnsupportedEnc
public static byte[] getAESEncryptedBytes(
byte[] plainText, int plainTextOffset, int plainTextLength, byte[] aesKeyBytes, byte[] aesIvBytes)
throws IllegalBlockSizeException, BadPaddingException, InvalidAlgorithmParameterException,
InvalidKeyException, NoSuchPaddingException, NoSuchAlgorithmException {
InvalidKeyException, NoSuchPaddingException, NoSuchAlgorithmException, NoSuchProviderException {
SecretKeySpec keySpec = new SecretKeySpec(aesKeyBytes, "AES");
IvParameterSpec ivSpec = new IvParameterSpec(aesIvBytes);
Cipher cipher = Cipher.getInstance(AES_ALGORITHM);
Cipher cipher = getAesCipher();
cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec);
return cipher.doFinal(plainText, plainTextOffset, plainTextLength);
}
Expand Down Expand Up @@ -225,6 +236,13 @@ public static byte[] getFileSha256Bytes(String filePath) throws IOException, NoS
return fileSha256Digest.digest();
}

public static Cipher getAesCipher()
throws NoSuchPaddingException, NoSuchAlgorithmException, NoSuchProviderException {
return AesCipherProvider.equals("")
? Cipher.getInstance(AES_ALGORITHM)
: Cipher.getInstance(AES_ALGORITHM, AesCipherProvider);
}

public SHA256Info computeSHA256HashAES(
InputStream plainTextStream,
byte[] object_CryptoIvBytes,
Expand All @@ -235,7 +253,7 @@ public SHA256Info computeSHA256HashAES(
try {
SecretKeySpec keySpec = new SecretKeySpec(object_CryptoKeyBytes, "AES");
IvParameterSpec ivSpec = new IvParameterSpec(object_CryptoIvBytes);
Cipher cipher = Cipher.getInstance(AES_ALGORITHM);
Cipher cipher = getAesCipher();
cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec);
bis = new BufferedInputStream(plainTextStream);
MessageDigest plainTextSha256 = MessageDigest.getInstance("SHA-256");
Expand Down
10 changes: 7 additions & 3 deletions app/src/main/java/com/obs/services/crypto/CryptoObsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.util.Objects;
import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
Expand Down Expand Up @@ -257,7 +258,8 @@ protected ObsFSFile putObjectImpl(PutObjectRequest request) throws ServiceExcept
| NoSuchAlgorithmException
| InvalidKeyException
| IllegalBlockSizeException
| BadPaddingException e) {
| BadPaddingException
| NoSuchProviderException e) {
throw new ServiceException(e);
} finally {
if (result != null && result.getBody() != null && request.isAutoClose()) {
Expand Down Expand Up @@ -373,7 +375,8 @@ protected ObsObject getObjectImpl(GetObjectRequest request) throws ServiceExcept
| UnsupportedEncodingException
| NoSuchAlgorithmException
| BadPaddingException
| InvalidKeyException e) {
| InvalidKeyException
| NoSuchProviderException e) {
throw new ServiceException(e);
}
}
Expand All @@ -389,7 +392,8 @@ protected ObsObject getObjectImpl(GetObjectRequest request) throws ServiceExcept
| InvalidAlgorithmParameterException
| NoSuchPaddingException
| NoSuchAlgorithmException
| InvalidKeyException e) {
| InvalidKeyException
| NoSuchProviderException e) {
throw new ServiceException(e);
}
} else {
Expand Down
Loading

0 comments on commit 5af1b31

Please sign in to comment.