Skip to content

Commit 14d0cc2

Browse files
committed
Refactor messages by subclasses
merge SelectObjectContentRequest merge ListVersionsResult Remove unused CompleteMultipartUploadOutput.java merge ListMultipartUploadsResult merge NotificationRecords merge SseConfiguration merge DeleteRequest, DeleteResult merge RestoreRequest merge NotificationConfiguration merge LifecycleConfiguration merge ReplicationConfiguration merge Filter merge ObjectLockConfiguration merge ListAllMyBucketsResult merge Item merge ListObjectsResult Move common fields for ListPartsResult and GetObjectAttributesOutput Signed-off-by: Bala.FA <bala@minio.io>
1 parent 5e7e074 commit 14d0cc2

File tree

234 files changed

+12146
-11714
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

234 files changed

+12146
-11714
lines changed

adminapi/src/main/java/io/minio/admin/Crypto.java

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package io.minio.admin;
1919

20+
import io.minio.errors.MinioException;
2021
import java.io.ByteArrayOutputStream;
2122
import java.io.EOFException;
2223
import java.io.IOException;
@@ -156,22 +157,25 @@ private static byte[] generateKey(byte[] secret, byte[] salt) {
156157
}
157158

158159
private static byte[] generateEncryptDecryptAdditionalData(
159-
boolean encryptFlag, int aeadId, byte[] key, byte[] paddedNonce)
160-
throws InvalidCipherTextException {
161-
AEADCipher cipher = getEncryptCipher(aeadId, key, paddedNonce);
162-
int outputLength = cipher.getMac().length;
163-
byte[] additionalData = new byte[outputLength];
164-
cipher.doFinal(additionalData, 0);
165-
return appendBytes(new byte[] {0}, additionalData);
160+
boolean encryptFlag, int aeadId, byte[] key, byte[] paddedNonce) throws MinioException {
161+
try {
162+
AEADCipher cipher = getEncryptCipher(aeadId, key, paddedNonce);
163+
int outputLength = cipher.getMac().length;
164+
byte[] additionalData = new byte[outputLength];
165+
cipher.doFinal(additionalData, 0);
166+
return appendBytes(new byte[] {0}, additionalData);
167+
} catch (InvalidCipherTextException e) {
168+
throw new MinioException(e);
169+
}
166170
}
167171

168172
private static byte[] generateEncryptAdditionalData(int aeadId, byte[] key, byte[] paddedNonce)
169-
throws InvalidCipherTextException {
173+
throws MinioException {
170174
return generateEncryptDecryptAdditionalData(true, aeadId, key, paddedNonce);
171175
}
172176

173177
private static byte[] generateDecryptAdditionalData(int aeadId, byte[] key, byte[] paddedNonce)
174-
throws InvalidCipherTextException {
178+
throws MinioException {
175179
return generateEncryptDecryptAdditionalData(false, aeadId, key, paddedNonce);
176180
}
177181

@@ -190,7 +194,7 @@ private static byte[] updateNonceId(byte[] nonce, int idx) {
190194
}
191195

192196
/** Encrypt data payload. */
193-
public static byte[] encrypt(byte[] payload, String password) throws InvalidCipherTextException {
197+
public static byte[] encrypt(byte[] payload, String password) throws MinioException {
194198
byte[] nonce = random(NONCE_LENGTH);
195199
byte[] salt = random(SALT_LENGTH);
196200

@@ -219,7 +223,11 @@ public static byte[] encrypt(byte[] payload, String password) throws InvalidCiph
219223
int outputLength = cipher.getOutputSize(chunk.length);
220224
byte[] encryptedData = new byte[outputLength];
221225
int outputOffset = cipher.processBytes(chunk, 0, chunk.length, encryptedData, 0);
222-
cipher.doFinal(encryptedData, outputOffset);
226+
try {
227+
cipher.doFinal(encryptedData, outputOffset);
228+
} catch (InvalidCipherTextException e) {
229+
throw new MinioException(e);
230+
}
223231

224232
result = appendBytes(result, encryptedData);
225233

@@ -243,20 +251,24 @@ public static class DecryptReader {
243251
private byte[] oneByte = null;
244252
private boolean eof = false;
245253

246-
public DecryptReader(InputStream inputStream, byte[] secret)
247-
throws EOFException, IOException, InvalidCipherTextException {
254+
public DecryptReader(InputStream inputStream, byte[] secret) throws MinioException {
248255
this.inputStream = inputStream;
249256
this.secret = secret;
250-
readFully(this.inputStream, this.salt, true);
251-
readFully(this.inputStream, this.aeadId, true);
252-
readFully(this.inputStream, this.nonce, true);
257+
try {
258+
readFully(this.inputStream, this.salt, true);
259+
readFully(this.inputStream, this.aeadId, true);
260+
readFully(this.inputStream, this.nonce, true);
261+
} catch (EOFException e) {
262+
throw new MinioException(e);
263+
} catch (IOException e) {
264+
throw new MinioException(e);
265+
}
253266
this.key = generateKey(this.secret, this.salt);
254267
byte[] paddedNonce = appendBytes(this.nonce, new byte[] {0, 0, 0, 0});
255268
this.additionalData = generateDecryptAdditionalData(this.aeadId[0], this.key, paddedNonce);
256269
}
257270

258-
private byte[] decrypt(byte[] encryptedData, boolean lastChunk)
259-
throws InvalidCipherTextException {
271+
private byte[] decrypt(byte[] encryptedData, boolean lastChunk) throws MinioException {
260272
this.count++;
261273
if (lastChunk) {
262274
this.additionalData = markAsLast(this.additionalData);
@@ -268,12 +280,16 @@ private byte[] decrypt(byte[] encryptedData, boolean lastChunk)
268280
byte[] decryptedData = new byte[outputLength];
269281
int outputOffset =
270282
cipher.processBytes(encryptedData, 0, encryptedData.length, decryptedData, 0);
271-
cipher.doFinal(decryptedData, outputOffset);
283+
try {
284+
cipher.doFinal(decryptedData, outputOffset);
285+
} catch (InvalidCipherTextException e) {
286+
throw new MinioException(e);
287+
}
272288
return decryptedData;
273289
}
274290

275291
/** Read a chunk at least one byte more than chunk size. */
276-
private byte[] readChunk() throws IOException {
292+
private byte[] readChunk() throws EOFException, IOException {
277293
if (this.eof) {
278294
return new byte[] {};
279295
}
@@ -302,19 +318,24 @@ private byte[] readChunk() throws IOException {
302318
return baos.toByteArray();
303319
}
304320

305-
public byte[] readAllBytes() throws IOException, InvalidCipherTextException {
321+
public byte[] readAllBytes() throws MinioException {
306322
ByteArrayOutputStream baos = new ByteArrayOutputStream();
307323
while (!this.eof) {
308-
byte[] payload = this.readChunk();
309-
baos.write(this.decrypt(payload, this.eof));
324+
try {
325+
byte[] payload = this.readChunk();
326+
baos.write(this.decrypt(payload, this.eof));
327+
} catch (EOFException e) {
328+
throw new MinioException(e);
329+
} catch (IOException e) {
330+
throw new MinioException(e);
331+
}
310332
}
311333
return baos.toByteArray();
312334
}
313335
}
314336

315337
/** Decrypt data stream. */
316-
public static byte[] decrypt(InputStream inputStream, String password)
317-
throws EOFException, IOException, InvalidCipherTextException {
338+
public static byte[] decrypt(InputStream inputStream, String password) throws MinioException {
318339
DecryptReader reader =
319340
new DecryptReader(inputStream, password.getBytes(StandardCharsets.UTF_8));
320341
return reader.readAllBytes();

0 commit comments

Comments
 (0)