Search in sources :

Example 1 with MaterialsDescriptionProvider

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);
}
Also used : MaterialsDescriptionProvider(com.amazonaws.services.s3.model.MaterialsDescriptionProvider) EncryptionMaterialsFactory(com.amazonaws.services.s3.model.EncryptionMaterialsFactory) EncryptionMaterials(com.amazonaws.services.s3.model.EncryptionMaterials) AmazonClientException(com.amazonaws.AmazonClientException)

Example 2 with MaterialsDescriptionProvider

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;
}
Also used : MaterialsDescriptionProvider(com.amazonaws.services.s3.model.MaterialsDescriptionProvider) InitiateMultipartUploadResult(com.amazonaws.services.s3.model.InitiateMultipartUploadResult) DOT(com.amazonaws.services.s3.model.InstructionFileId.DOT) USER_AGENT(com.amazonaws.services.s3.AmazonS3EncryptionClient.USER_AGENT) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) ObjectMetadata(com.amazonaws.services.s3.model.CryptoStorageMode.ObjectMetadata)

Example 3 with MaterialsDescriptionProvider

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;
}
Also used : MaterialsDescriptionProvider(com.amazonaws.services.s3.model.MaterialsDescriptionProvider)

Aggregations

MaterialsDescriptionProvider (com.amazonaws.services.s3.model.MaterialsDescriptionProvider)3 AmazonClientException (com.amazonaws.AmazonClientException)1 USER_AGENT (com.amazonaws.services.s3.AmazonS3EncryptionClient.USER_AGENT)1 ObjectMetadata (com.amazonaws.services.s3.model.CryptoStorageMode.ObjectMetadata)1 EncryptionMaterials (com.amazonaws.services.s3.model.EncryptionMaterials)1 EncryptionMaterialsFactory (com.amazonaws.services.s3.model.EncryptionMaterialsFactory)1 InitiateMultipartUploadResult (com.amazonaws.services.s3.model.InitiateMultipartUploadResult)1 DOT (com.amazonaws.services.s3.model.InstructionFileId.DOT)1 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)1