Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2013-2015 Amazon.com, Inc. or its affiliates. All Rights Reserved.
   *
   * Licensed under the Apache License, Version 2.0 (the "License").
   * You may not use this file except in compliance with the License.
   * A copy of the License is located at
   *
   *  http://aws.amazon.com/apache2.0
   *
  * or in the "license" file accompanying this file. This file is distributed
  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
  * express or implied. See the License for the specific language governing
  * permissions and limitations under the License.
  */
 package com.amazonaws.services.s3.internal.crypto;
 
 import static com.amazonaws.services.s3.model.CryptoMode.AuthenticatedEncryption;
 import static com.amazonaws.services.s3.model.CryptoMode.EncryptionOnly;
 
 import java.io.File;
 
A proxy cryptographic module used to dispatch method calls to the appropriate underlying cryptographic module depending on the current configuration.
 
     private final CryptoMode defaultCryptoMode;
    
Encryption only (EO) cryptographic module.
 
     private final S3CryptoModuleEO eo;
    
Authenticated encryption (AE) cryptographic module.
 
     private final S3CryptoModuleAE ae;
 
     public CryptoModuleDispatcher(AWSKMSClient kmsS3Direct s3,
             AWSCredentialsProvider credentialsProvider,
             EncryptionMaterialsProvider encryptionMaterialsProvider,
             CryptoConfiguration cryptoConfig) {
         cryptoConfig = cryptoConfig.clone();    // make a clone
         CryptoMode cryptoMode = cryptoConfig.getCryptoMode();
         if (cryptoMode == null) {
             cryptoMode = ;
             cryptoConfig.setCryptoMode(cryptoMode); // defaults to EO
         }
         cryptoConfig = cryptoConfig.readOnly(); // make read-only
         this. = cryptoConfig.getCryptoMode();
         switch(this.) {
             case :
                 this. = new S3CryptoModuleAEStrict(kmss3credentialsProvider,
                         encryptionMaterialsProvider,
                         cryptoConfig);
                 this. = null;
                 break;
             case :
                 this. = new S3CryptoModuleAE(kmss3credentialsProvider,
                         encryptionMaterialsProvider,
                         cryptoConfig);
                 this. = null;
                 break;
             case :
                 this. = new S3CryptoModuleEO(kmss3credentialsProvider,
                         encryptionMaterialsProvider,
                         cryptoConfig);
                 CryptoConfiguration aeConfig = cryptoConfig.clone();
                 try {
                     aeConfig.setCryptoMode();
                 } catch(UnsupportedOperationException ex) {
                     // BC not available during runtime; but EO can still work.
                     // Hence ignoring.
                 }
                 this. = new S3CryptoModuleAE(kmss3credentialsProvider,
                     encryptionMaterialsProvider,
                     aeConfig.readOnly());
                 break;
            default:
                throw new IllegalStateException();
        }
    }
    @Override
    public PutObjectResult putObjectSecurely(PutObjectRequest putObjectRequest) {
        return  == 
             ? .putObjectSecurely(putObjectRequest)
             : .putObjectSecurely(putObjectRequest)
             ;
    }
    @Override
        // AE module can handle S3 objects encrypted in either AE or EO format
        return .getObjectSecurely(req);
    }
    @Override
            File destinationFile) {
        // AE module can handle S3 objects encrypted in either AE or EO format
        return .getObjectSecurely(reqdestinationFile);
    }
    @Override
            CompleteMultipartUploadRequest req)
                    throws AmazonClientExceptionAmazonServiceException {
        return  ==  
             ? .completeMultipartUploadSecurely(req)
             : .completeMultipartUploadSecurely(req)
             ;
    }
    @Override
        if ( == )
            .abortMultipartUploadSecurely(req);
        else
            .abortMultipartUploadSecurely(req);
    }
    @Override
            InitiateMultipartUploadRequest req)
                    throws AmazonClientExceptionAmazonServiceException {
        return  ==  
             ? .initiateMultipartUploadSecurely(req)
             : .initiateMultipartUploadSecurely(req)
             ;
    }

    

NOTE: Because the encryption process requires context from block N-1 in order to encrypt block N, parts uploaded with the AmazonS3EncryptionClient (as opposed to the normal AmazonS3Client) must be uploaded serially, and in order. Otherwise, the previous encryption context isn't available to use when encrypting the current part.

    @Override
        return  == 
             ? .uploadPartSecurely(req)
             : .uploadPartSecurely(req)
             ;
    }
    @Override
        return  ==  
             ? .copyPartSecurely(req)
             : .copyPartSecurely(req)
             ;
    }
    @Override
            PutInstructionFileRequest req) {
        return  == 
            ? .putInstructionFileSecurely(req)
            : .putInstructionFileSecurely(req)
            ;
    }
    @Override
            String uploadIdOutputStream osthrows IOException {
        if ( == )
            .putLocalObjectSecurely(requploadIdos);
        else
            .putLocalObjectSecurely(requploadIdos);
    }
New to GrepCode? Check out our FAQ X