From 56239c32468be2050ed27fb2b2f38e9995acb2ac Mon Sep 17 00:00:00 2001 From: "Bala.FA" Date: Mon, 15 Jul 2019 16:16:21 +0530 Subject: [PATCH] fix: handle SSE in statObject() and have one source code. --- api/src/main/java/io/minio/MinioClient.java | 34 +++++++++++++-------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/api/src/main/java/io/minio/MinioClient.java b/api/src/main/java/io/minio/MinioClient.java index f100be94f..433af7743 100755 --- a/api/src/main/java/io/minio/MinioClient.java +++ b/api/src/main/java/io/minio/MinioClient.java @@ -1286,6 +1286,19 @@ private String getText(XmlPullParser xpp) throws XmlPullParserException { return null; } + private void checkReadRequestSse(ServerSideEncryption sse) throws InvalidArgumentException { + if (sse == null) { + return; + } + + if (sse.getType() != SSE_C) { + throw new InvalidArgumentException("only SSE_C is supported for all read requests."); + } + + if (!this.baseUrl.isHttps()) { + throw new InvalidArgumentException("SSE_C operations must be performed over a secure connection."); + } + } /** * Executes GET method for given request parameters. @@ -1482,12 +1495,7 @@ public ObjectStat statObject(String bucketName, String objectName) throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException, InternalException,InvalidResponseException { - HttpResponse response = executeHead(bucketName, objectName); - ResponseHeader header = response.header(); - Map> httpHeaders = response.httpHeaders(); - ObjectStat objectStat = new ObjectStat(bucketName, objectName, header, httpHeaders); - - return objectStat; + return statObject(bucketName, objectName, null); } /** @@ -1523,14 +1531,14 @@ public ObjectStat statObject(String bucketName, String objectName, ServerSideEnc throws InvalidBucketNameException, NoSuchAlgorithmException, InsufficientDataException, IOException, InvalidKeyException, NoResponseException, XmlPullParserException, ErrorResponseException, InternalException, InvalidArgumentException, InvalidResponseException { - if ((sse.getType() == ServerSideEncryption.Type.SSE_S3) - || (sse.getType() == ServerSideEncryption.Type.SSE_KMS)) { - throw new InvalidArgumentException("Invalid encryption option specified for encryption type " + sse.getType()); - } else if ((sse.getType() == ServerSideEncryption.Type.SSE_C) && (!this.baseUrl.isHttps())) { - throw new InvalidArgumentException("SSE_C operations must be performed over a secure connection."); + checkReadRequestSse(sse); + + Map headers; + if (sse != null) { + headers = new HashMap<>(); + sse.marshal(headers); } - Map headers = new HashMap<>(); - sse.marshal(headers); + HttpResponse response = executeHead(bucketName, objectName, headers); ResponseHeader header = response.header(); Map> httpHeaders = response.httpHeaders();