use of com.amazonaws.services.s3.model.MaterialsDescriptionProvider in project aws-sdk-android by aws-amplify.
the class S3CryptoModuleBase method createContentCryptoMaterial.
/**
* Creates and returns a non-null content crypto material for the given
* request.
*
* @throws AmazonClientException if no encryption material can be found.
*/
protected final ContentCryptoMaterial createContentCryptoMaterial(AmazonWebServiceRequest req) {
if (req instanceof EncryptionMaterialsFactory) {
// per request level encryption materials
final EncryptionMaterialsFactory f = (EncryptionMaterialsFactory) req;
final EncryptionMaterials materials = f.getEncryptionMaterials();
if (materials != null) {
return buildContentCryptoMaterial(materials, cryptoConfig.getCryptoProvider(), req);
}
}
if (req instanceof MaterialsDescriptionProvider) {
// per request level material description
final MaterialsDescriptionProvider mdp = (MaterialsDescriptionProvider) req;
final Map<String, String> matdescReq = mdp.getMaterialsDescription();
final ContentCryptoMaterial ccm = newContentCryptoMaterial(kekMaterialsProvider, matdescReq, cryptoConfig.getCryptoProvider(), req);
if (ccm != null) {
return ccm;
}
if (matdescReq != null) {
// check to see if KMS is in use and if so we should fall thru
// to the s3 client level encryption material
final EncryptionMaterials material = kekMaterialsProvider.getEncryptionMaterials();
if (!material.isKMSEnabled()) {
throw new AmazonClientException("No material available from the encryption material provider for description " + matdescReq);
}
}
// if there is no material description, fall thru to use
// the per s3 client level encryption materials
}
// per s3 client level encryption materials
return newContentCryptoMaterial(this.kekMaterialsProvider, cryptoConfig.getCryptoProvider(), req);
}
use of com.amazonaws.services.s3.model.MaterialsDescriptionProvider in project aws-sdk-android by aws-amplify.
the class S3CryptoModuleBase method initiateMultipartUploadSecurely.
@Override
public InitiateMultipartUploadResult initiateMultipartUploadSecurely(InitiateMultipartUploadRequest req) {
appendUserAgent(req, USER_AGENT);
// Generate a one-time use symmetric key and initialize a cipher to
// encrypt object data
final ContentCryptoMaterial cekMaterial = createContentCryptoMaterial(req);
if (cryptoConfig.getStorageMode() == ObjectMetadata) {
ObjectMetadata metadata = req.getObjectMetadata();
if (metadata == null) {
metadata = new ObjectMetadata();
}
// Store encryption info in metadata
req.setObjectMetadata(updateMetadataWithContentCryptoMaterial(metadata, null, cekMaterial));
}
final InitiateMultipartUploadResult result = s3.initiateMultipartUpload(req);
final T uploadContext = newUploadContext(req, cekMaterial);
if (req instanceof MaterialsDescriptionProvider) {
final MaterialsDescriptionProvider p = (MaterialsDescriptionProvider) req;
uploadContext.setMaterialsDescription(p.getMaterialsDescription());
}
multipartUploadContexts.put(result.getUploadId(), uploadContext);
return result;
}
use of com.amazonaws.services.s3.model.MaterialsDescriptionProvider in project aws-sdk-android by aws-amplify.
the class ContentCryptoMaterial method mergeMaterialDescriptions.
static Map<String, String> mergeMaterialDescriptions(EncryptionMaterials materials, AmazonWebServiceRequest req) {
Map<String, String> matdesc = materials.getMaterialsDescription();
if (req instanceof MaterialsDescriptionProvider) {
final MaterialsDescriptionProvider mdp = (MaterialsDescriptionProvider) req;
final Map<String, String> matdescReq = mdp.getMaterialsDescription();
if (matdescReq != null) {
matdesc = new TreeMap<String, String>(matdesc);
// request takes precedence
matdesc.putAll(matdescReq);
}
}
return matdesc;
}
Aggregations