private ObjectMetadata getObjectMetadata(Path path) { ObjectMetadata ret = new ObjectMetadata(); long lastModified = path.toFile().lastModified(); if (lastModified != 0) { ret.addUserMetadata("local-modification-time", Long.toString(lastModified)); } long fileSize = path.toFile().length(); if (fileSize != 0) { ret.addUserMetadata("local-size", Long.toString(fileSize)); } return ret; }
/** * Returns the metadata in backward compatibility (old) format, so it can be * read by older version of the AWS SDK. */ private ObjectMetadata toObjectMetadataEO(ObjectMetadata metadata) { // If we generated a symmetric key to encrypt the data, store it in the // object metadata. byte[] encryptedCEK = getEncryptedCEK(); metadata.addUserMetadata(Headers.CRYPTO_KEY, Base64.encodeAsString(encryptedCEK)); // Put the cipher initialization vector (IV) into the object metadata byte[] iv = cipherLite.getIV(); metadata.addUserMetadata(Headers.CRYPTO_IV, Base64.encodeAsString(iv)); // Put the materials description into the object metadata as JSON metadata.addUserMetadata(Headers.MATERIALS_DESCRIPTION, kekMaterialDescAsJson()); return metadata; }
metadata.addUserMetadata(Headers.CRYPTO_KEY_V2, Base64.encodeAsString(encryptedCEK)); metadata.addUserMetadata(Headers.CRYPTO_IV, Base64.encodeAsString(iv)); metadata.addUserMetadata(Headers.MATERIALS_DESCRIPTION, kekMaterialDescAsJson()); metadata.addUserMetadata(Headers.CRYPTO_CEK_ALGORITHM, scheme.getCipherAlgorithm()); int tagLen = scheme.getTagLengthInBits(); if (tagLen > 0) metadata.addUserMetadata(Headers.CRYPTO_TAG_LENGTH, String.valueOf(tagLen)); String keyWrapAlgo = getKeyWrappingAlgorithm(); if (keyWrapAlgo != null) metadata.addUserMetadata(Headers.CRYPTO_KEYWRAP_ALGORITHM, keyWrapAlgo); return metadata;
if (StringUtils.beginsWithIgnoreCase(key, Headers.S3_USER_METADATA_PREFIX)) { key = key.substring(Headers.S3_USER_METADATA_PREFIX.length()); metadata.addUserMetadata(key, header.getValue()); } else if (ignoredHeaders.contains(key)) {
protected final PutObjectRequest createInstructionPutRequest( String bucketName, String key, ContentCryptoMaterial cekMaterial) { byte[] bytes = cekMaterial.toJsonString(cryptoConfig.getCryptoMode()) .getBytes(UTF8); InputStream is = new ByteArrayInputStream(bytes); ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(bytes.length); metadata.addUserMetadata(Headers.CRYPTO_INSTRUCTION_FILE, ""); InstructionFileId ifileId = new S3ObjectId(bucketName, key) .instructionFileId(); return new PutObjectRequest(ifileId.getBucket(), ifileId.getKey(), is, metadata); }
/** * Updates put request to store the specified instruction object in S3. * * @param req * The put-instruction-file request for the instruction file to * be stored in S3. * @param cekMaterial * The instruction object to be stored in S3. * @return A put request to store the specified instruction object in S3. */ protected final PutObjectRequest updateInstructionPutRequest( PutObjectRequest req, ContentCryptoMaterial cekMaterial) { byte[] bytes = cekMaterial.toJsonString(cryptoConfig.getCryptoMode()) .getBytes(UTF8); ObjectMetadata metadata = req.getMetadata(); if (metadata == null) { metadata = new ObjectMetadata(); req.setMetadata(metadata); } // Set the content-length of the upload metadata.setContentLength(bytes.length); // Set the crypto instruction file header metadata.addUserMetadata(Headers.CRYPTO_INSTRUCTION_FILE, ""); // Update the instruction request req.setMetadata(metadata); req.setInputStream(new ByteArrayInputStream(bytes)); // the file attribute in the request is always null before calling this // routine return req; }
metadata.addUserMetadata(Headers.UNENCRYPTED_CONTENT_MD5, metadata.getContentMD5()); metadata.addUserMetadata(Headers.UNENCRYPTED_CONTENT_LENGTH, Long.toString(plaintextLength));
private static void updateMetadata(ObjectMetadata metadata, byte[] keyBytesToStoreInMetadata, Cipher symmetricCipher, Map<String, String> materialsDescription) { // If we generated a symmetric key to encrypt the data, store it in the // object metadata. if (keyBytesToStoreInMetadata != null) { metadata.addUserMetadata(Headers.CRYPTO_KEY, Base64.encodeAsString(keyBytesToStoreInMetadata)); } // Put the cipher initialization vector (IV) into the object metadata metadata.addUserMetadata(Headers.CRYPTO_IV, Base64.encodeAsString(symmetricCipher.getIV())); // Put the materials description into the object metadata as JSON String description = JsonUtils.mapToString(materialsDescription); metadata.addUserMetadata(Headers.MATERIALS_DESCRIPTION, description); }
/** * Returns the metadata in backward compatibility (old) format, so it can be * read by older version of the AWS SDK. */ @SuppressWarnings("checkstyle:hiddenfield") private ObjectMetadata toObjectMetadataEO(ObjectMetadata metadata) { // If we generated a symmetric key to encrypt the data, store it in the // object metadata. final byte[] encryptedCEK = getEncryptedCEK(); metadata.addUserMetadata(Headers.CRYPTO_KEY, Base64.encodeAsString(encryptedCEK)); // Put the cipher initialization vector (IV) into the object metadata final byte[] iv = cipherLite.getIV(); metadata.addUserMetadata(Headers.CRYPTO_IV, Base64.encodeAsString(iv)); // Put the materials description into the object metadata as JSON metadata.addUserMetadata(Headers.MATERIALS_DESCRIPTION, kekMaterialDescAsJson()); return metadata; }
metadata.addUserMetadata(Headers.CRYPTO_KEY_V2, Base64.encodeAsString(encryptedCEK)); metadata.addUserMetadata(Headers.CRYPTO_IV, Base64.encodeAsString(iv)); metadata.addUserMetadata(Headers.MATERIALS_DESCRIPTION, kekMaterialDescAsJson()); metadata.addUserMetadata(Headers.CRYPTO_CEK_ALGORITHM, scheme.getCipherAlgorithm()); final int tagLen = scheme.getTagLengthInBits(); if (tagLen > 0) { metadata.addUserMetadata(Headers.CRYPTO_TAG_LENGTH, String.valueOf(tagLen)); metadata.addUserMetadata(Headers.CRYPTO_KEYWRAP_ALGORITHM, keyWrapAlgo);
/** * Creates the Instruction PutObjectRequest. * @param bucketName the name of the bucket. * @param key the key. * @param instruction the instruction. * @return the PutObjectRequest. */ public static PutObjectRequest createInstructionPutRequest(String bucketName, String key, EncryptionInstruction instruction) { Map<String, String> instructionJSON = convertInstructionToJSONObject(instruction); byte[] instructionBytes = JsonUtils.mapToString(instructionJSON).getBytes(StringUtils.UTF8); InputStream instructionInputStream = new ByteArrayInputStream(instructionBytes); ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(instructionBytes.length); metadata.addUserMetadata(Headers.CRYPTO_INSTRUCTION_FILE, ""); return new PutObjectRequest(bucketName, key + INSTRUCTION_SUFFIX, instructionInputStream, metadata); }
if (key.startsWith(Headers.S3_USER_METADATA_PREFIX)) { key = key.substring(Headers.S3_USER_METADATA_PREFIX.length()); metadata.addUserMetadata(key, header.getValue()); } else if (IGNORED_HEADERS.contains(key)) { log.debug(String.format("%s is ignored.", key));
protected final PutObjectRequest createInstructionPutRequest( String bucketName, String key, ContentCryptoMaterial cekMaterial) { final byte[] bytes = cekMaterial.toJsonString(cryptoConfig.getCryptoMode()) .getBytes(UTF8); final InputStream is = new ByteArrayInputStream(bytes); final ObjectMetadata metadata = new ObjectMetadata(); metadata.setContentLength(bytes.length); metadata.addUserMetadata(Headers.CRYPTO_INSTRUCTION_FILE, ""); final InstructionFileId ifileId = new S3ObjectId(bucketName, key) .instructionFileId(); return new PutObjectRequest(ifileId.getBucket(), ifileId.getKey(), is, metadata); }
objectMetadata.addUserMetadata(SingularityS3Log.LOG_START_S3_ATTR, fileAttributes.getStartTime().get().toString()); LOG.debug("Added extra metadata for object ({}:{})", SingularityS3Log.LOG_START_S3_ATTR, fileAttributes.getStartTime().get()); objectMetadata.addUserMetadata(SingularityS3Log.LOG_END_S3_ATTR, fileAttributes.getEndTime().get().toString()); LOG.debug("Added extra metadata for object ({}:{})", SingularityS3Log.LOG_END_S3_ATTR, fileAttributes.getEndTime().get());
/** * Creates a put request to store the specified instruction object in S3. * * @param request The put request for the original object to be stored in * S3. * @param instruction The instruction object to be stored in S3. * @return A put request to store the specified instruction object in S3. */ public static PutObjectRequest createInstructionPutRequest(PutObjectRequest request, EncryptionInstruction instruction) { Map<String, String> instructionJSON = convertInstructionToJSONObject(instruction); byte[] instructionBytes = JsonUtils.mapToString(instructionJSON).getBytes(StringUtils.UTF8); InputStream instructionInputStream = new ByteArrayInputStream(instructionBytes); ObjectMetadata metadata = request.getMetadata(); // Set the content-length of the upload metadata.setContentLength(instructionBytes.length); // Set the crypto instruction file header metadata.addUserMetadata(Headers.CRYPTO_INSTRUCTION_FILE, ""); // Update the instruction request request.setKey(request.getKey() + INSTRUCTION_SUFFIX); request.setMetadata(metadata); request.setInputStream(instructionInputStream); return request; }
/** * Updates put request to store the specified instruction object in S3. * * @param req * The put-instruction-file request for the instruction file to * be stored in S3. * @param cekMaterial * The instruction object to be stored in S3. * @return A put request to store the specified instruction object in S3. */ protected final PutObjectRequest updateInstructionPutRequest( PutObjectRequest req, ContentCryptoMaterial cekMaterial) { final byte[] bytes = cekMaterial.toJsonString(cryptoConfig.getCryptoMode()) .getBytes(UTF8); ObjectMetadata metadata = req.getMetadata(); if (metadata == null) { metadata = new ObjectMetadata(); req.setMetadata(metadata); } // Set the content-length of the upload metadata.setContentLength(bytes.length); // Set the crypto instruction file header metadata.addUserMetadata(Headers.CRYPTO_INSTRUCTION_FILE, ""); // Update the instruction request req.setMetadata(metadata); req.setInputStream(new ByteArrayInputStream(bytes)); // the file attribute in the request is always null before calling this // routine return req; }
metadata.addUserMetadata(Headers.UNENCRYPTED_CONTENT_MD5, metadata.getContentMD5()); metadata.addUserMetadata(Headers.UNENCRYPTED_CONTENT_LENGTH, Long.toString(plaintextLength));
metadata.addUserMetadata(Headers.UNENCRYPTED_CONTENT_MD5, metadata.getContentMD5()); metadata.addUserMetadata(Headers.UNENCRYPTED_CONTENT_LENGTH, Long.toString(plaintextLength));
metadata.addUserMetadata("um_k1", "um_v1"); metadata.addUserMetadata("um_k2", "um_v2"); final SSECustomerKey sseKey = new SSECustomerKey(new byte[32]);
@Test public void testGetStoredMimeType() throws BinaryStoreException { ObjectMetadata objMeta = new ObjectMetadata(); objMeta.setContentType(TEST_MIME); objMeta.addUserMetadata(S3BinaryStore.USER_MIME_TYPE_KEY, String.valueOf(true)); expect(s3Client.getObjectMetadata(BUCKET, TEST_KEY)).andReturn(objMeta); replayAll(); BinaryValue binaryValue = createBinaryValue(TEST_KEY, TEST_CONTENT); String mimeType = s3BinaryStore.getStoredMimeType(binaryValue); assertEquals(TEST_MIME, mimeType); }