예제 #1
0
 public void Initialize()
 {
     RunAsSync(async() =>
     {
         bucketName = await UtilityMethods.CreateBucketAsync(Client);
     });
 }
예제 #2
0
        public EncryptionTests()
        {
            using (var kmsClient = new AmazonKeyManagementServiceClient())
            {
                var response = CallAsyncTask(
                    kmsClient.CreateKeyAsync(new CreateKeyRequest
                {
                    Description = "Key for .NET integration tests.",
                    Origin      = OriginType.AWS_KMS,
                    KeyUsage    = KeyUsageType.ENCRYPT_DECRYPT
                }));
                kmsKeyID = response.KeyMetadata.KeyId;
            }

            var encryptionMaterials    = new EncryptionMaterials(RSA.Create());
            var kmsEncryptionMaterials = new EncryptionMaterials(kmsKeyID);

            AmazonS3CryptoConfiguration config = new AmazonS3CryptoConfiguration()
            {
                StorageMode = CryptoStorageMode.InstructionFile
            };

            s3EncryptionClientMetadataMode    = new AmazonS3EncryptionClient(encryptionMaterials);
            s3EncryptionClientFileMode        = new AmazonS3EncryptionClient(config, encryptionMaterials);
            s3EncryptionClientMetadataModeKMS = new AmazonS3EncryptionClient(kmsEncryptionMaterials);
            s3EncryptionClientFileModeKMS     = new AmazonS3EncryptionClient(config, kmsEncryptionMaterials);

            using (StreamWriter writer = File.CreateText(filePath))
            {
                writer.Write(sampleContent);
            }
            bucketName = CallAsyncTask(UtilityMethods.CreateBucketAsync(s3EncryptionClientFileMode, GetType().Name));
        }
예제 #3
0
        public TransferUtilityTests()
        {
            testBucketName = UtilityMethods.CreateBucketAsync(Client, "TransferUtilityTests").Result;

            basePath = Path.Combine(Path.GetTempPath(), "test", "transferutility");
            Directory.CreateDirectory(basePath);

            testFilePath = Path.Combine(basePath, TEST_FILENAME);
            File.WriteAllText(testFilePath, TEST_CONTENT);
        }
예제 #4
0
 public void Initialize()
 {
     Console.WriteLine("Initializing PutObjectTest");
     RunAsSync(async() =>
     {
         IFile file = await this.BaseFolder.CreateFileAsync
                          ("PutObjectFile.txt", CreationCollisionOption.ReplaceExisting);
         await file.WriteAllTextAsync("This is some sample text.!!");
         bucketName = await UtilityMethods.CreateBucketAsync(Client);
         filePath   = file.Path;
     });
     Console.WriteLine("Done initializing PutObjectTest");
 }
예제 #5
0
        public EncryptionTestsV1InteropV2(KmsKeyIdProvider kmsKeyIdProvider) : base(kmsKeyIdProvider)
        {
            kmsKeyID = _kmsKeyIdProvider.GetKmsIdAsync().GetAwaiter().GetResult();

            var rsa = RSA.Create();
            var aes = Aes.Create();

            var asymmetricEncryptionMaterialsV1 = new Amazon.S3.Encryption.EncryptionMaterials(rsa);
            var asymmetricEncryptionMaterialsV2 = new EncryptionMaterialsV2(rsa, AsymmetricAlgorithmType.RsaOaepSha1);

            var symmetricEncryptionMaterialsV1 = new Amazon.S3.Encryption.EncryptionMaterials(aes);
            var symmetricEncryptionMaterialsV2 = new EncryptionMaterialsV2(aes, SymmetricAlgorithmType.AesGcm);

            var kmsEncryptionMaterialsV1 = new Amazon.S3.Encryption.EncryptionMaterials(kmsKeyID);
            var kmsEncryptionMaterialsV2 = new EncryptionMaterialsV2(kmsKeyID, KmsType.KmsContext, new Dictionary <string, string>());

            var configV1 = new Amazon.S3.Encryption.AmazonS3CryptoConfiguration
            {
                StorageMode = Amazon.S3.Encryption.CryptoStorageMode.InstructionFile
            };

            fileConfigV2 = new AmazonS3CryptoConfigurationV2(SecurityProfile.V2AndLegacy)
            {
                StorageMode = CryptoStorageMode.InstructionFile,
            };

            metadataConfigV2 = new AmazonS3CryptoConfigurationV2(SecurityProfile.V2AndLegacy)
            {
                StorageMode = CryptoStorageMode.ObjectMetadata
            };

            s3EncryptionClientMetadataModeAsymmetricWrapV1 = new Amazon.S3.Encryption.AmazonS3EncryptionClient(asymmetricEncryptionMaterialsV1);
            s3EncryptionClientFileModeAsymmetricWrapV1     = new Amazon.S3.Encryption.AmazonS3EncryptionClient(configV1, asymmetricEncryptionMaterialsV1);
            s3EncryptionClientMetadataModeSymmetricWrapV1  = new Amazon.S3.Encryption.AmazonS3EncryptionClient(symmetricEncryptionMaterialsV1);
            s3EncryptionClientFileModeSymmetricWrapV1      = new Amazon.S3.Encryption.AmazonS3EncryptionClient(configV1, symmetricEncryptionMaterialsV1);
            s3EncryptionClientMetadataModeKMSV1            = new Amazon.S3.Encryption.AmazonS3EncryptionClient(kmsEncryptionMaterialsV1);
            s3EncryptionClientFileModeKMSV1 = new Amazon.S3.Encryption.AmazonS3EncryptionClient(configV1, kmsEncryptionMaterialsV1);

            s3EncryptionClientMetadataModeAsymmetricWrapV2 = new AmazonS3EncryptionClientV2(metadataConfigV2, asymmetricEncryptionMaterialsV2);
            s3EncryptionClientFileModeAsymmetricWrapV2     = new AmazonS3EncryptionClientV2(fileConfigV2, asymmetricEncryptionMaterialsV2);
            s3EncryptionClientMetadataModeSymmetricWrapV2  = new AmazonS3EncryptionClientV2(metadataConfigV2, symmetricEncryptionMaterialsV2);
            s3EncryptionClientFileModeSymmetricWrapV2      = new AmazonS3EncryptionClientV2(fileConfigV2, symmetricEncryptionMaterialsV2);
            s3EncryptionClientMetadataModeKMSV2            = new AmazonS3EncryptionClientV2(metadataConfigV2, kmsEncryptionMaterialsV2);
            s3EncryptionClientFileModeKMSV2 = new AmazonS3EncryptionClientV2(fileConfigV2, kmsEncryptionMaterialsV2);

            using (var writer = File.CreateText(filePath))
            {
                writer.Write(SampleContent);
            }
            bucketName = EncryptionTestsUtils.CallAsyncTask(UtilityMethods.CreateBucketAsync(s3EncryptionClientFileModeAsymmetricWrapV1, GetType().Name));
        }
#pragma warning restore 0618

        public EncryptionTestsV1InteropV1N(KmsKeyIdProvider kmsKeyIdProvider) : base(kmsKeyIdProvider)
        {
            kmsKeyID = _kmsKeyIdProvider.GetKmsIdAsync().GetAwaiter().GetResult();

            var rsa = RSA.Create();
            var aes = Aes.Create();

            var asymmetricEncryptionMaterialsV1  = new Amazon.S3.Encryption.EncryptionMaterials(rsa);
            var asymmetricEncryptionMaterialsV1N = new EncryptionMaterials(rsa);

            var symmetricEncryptionMaterialsV1  = new Amazon.S3.Encryption.EncryptionMaterials(aes);
            var symmetricEncryptionMaterialsV1N = new EncryptionMaterials(aes);

            var kmsEncryptionMaterialsV1  = new Amazon.S3.Encryption.EncryptionMaterials(kmsKeyID);
            var kmsEncryptionMaterialsV1N = new EncryptionMaterials(kmsKeyID);

            var configV1 = new Amazon.S3.Encryption.AmazonS3CryptoConfiguration()
            {
                StorageMode = Amazon.S3.Encryption.CryptoStorageMode.InstructionFile
            };
            var configV1N = new AmazonS3CryptoConfiguration()
            {
                StorageMode = CryptoStorageMode.InstructionFile
            };

            s3EncryptionClientMetadataModeAsymmetricWrapV1 = new Amazon.S3.Encryption.AmazonS3EncryptionClient(asymmetricEncryptionMaterialsV1);
            s3EncryptionClientFileModeAsymmetricWrapV1     = new Amazon.S3.Encryption.AmazonS3EncryptionClient(configV1, asymmetricEncryptionMaterialsV1);
            s3EncryptionClientMetadataModeSymmetricWrapV1  = new Amazon.S3.Encryption.AmazonS3EncryptionClient(symmetricEncryptionMaterialsV1);
            s3EncryptionClientFileModeSymmetricWrapV1      = new Amazon.S3.Encryption.AmazonS3EncryptionClient(configV1, symmetricEncryptionMaterialsV1);
            s3EncryptionClientMetadataModeKMSV1            = new Amazon.S3.Encryption.AmazonS3EncryptionClient(kmsEncryptionMaterialsV1);
            s3EncryptionClientFileModeKMSV1 = new Amazon.S3.Encryption.AmazonS3EncryptionClient(configV1, kmsEncryptionMaterialsV1);

#pragma warning disable 0618
            s3EncryptionClientMetadataModeAsymmetricWrapV1N = new AmazonS3EncryptionClient(asymmetricEncryptionMaterialsV1N);
            s3EncryptionClientFileModeAsymmetricWrapV1N     = new AmazonS3EncryptionClient(configV1N, asymmetricEncryptionMaterialsV1N);
            s3EncryptionClientMetadataModeSymmetricWrapV1N  = new AmazonS3EncryptionClient(symmetricEncryptionMaterialsV1N);
            s3EncryptionClientFileModeSymmetricWrapV1N      = new AmazonS3EncryptionClient(configV1N, symmetricEncryptionMaterialsV1N);
            s3EncryptionClientMetadataModeKMSV1N            = new AmazonS3EncryptionClient(kmsEncryptionMaterialsV1N);
            s3EncryptionClientFileModeKMSV1N = new AmazonS3EncryptionClient(configV1N, kmsEncryptionMaterialsV1N);
#pragma warning restore 0618

            using (var writer = File.CreateText(filePath))
            {
                writer.Write(SampleContent);
            }
            bucketName = EncryptionTestsUtils.CallAsyncTask(UtilityMethods.CreateBucketAsync(s3EncryptionClientFileModeAsymmetricWrapV1));
        }
예제 #7
0
        public EncryptionTestsV2(KmsKeyIdProvider kmsKeyIdProvider) : base(kmsKeyIdProvider)
        {
            kmsKeyID = _kmsKeyIdProvider.GetKmsIdAsync().GetAwaiter().GetResult();

            var rsa = RSA.Create();
            var aes = Aes.Create();

            var asymmetricEncryptionMaterials = new EncryptionMaterialsV2(rsa, AsymmetricAlgorithmType.RsaOaepSha1);
            var symmetricEncryptionMaterials  = new EncryptionMaterialsV2(aes, SymmetricAlgorithmType.AesGcm);
            var kmsEncryptionMaterials        =
                new EncryptionMaterialsV2(kmsKeyID, KmsType.KmsContext, new Dictionary <string, string>());

            var fileConfig = new AmazonS3CryptoConfigurationV2(SecurityProfile.V2)
            {
                StorageMode = CryptoStorageMode.InstructionFile
            };


            var metadataConfig = new AmazonS3CryptoConfigurationV2(SecurityProfile.V2)
            {
                StorageMode = CryptoStorageMode.ObjectMetadata
            };

            s3EncryptionClientMetadataModeAsymmetricWrap =
                new AmazonS3EncryptionClientV2(metadataConfig, asymmetricEncryptionMaterials);
            s3EncryptionClientFileModeAsymmetricWrap =
                new AmazonS3EncryptionClientV2(fileConfig, asymmetricEncryptionMaterials);
            s3EncryptionClientMetadataModeSymmetricWrap =
                new AmazonS3EncryptionClientV2(metadataConfig, symmetricEncryptionMaterials);
            s3EncryptionClientFileModeSymmetricWrap =
                new AmazonS3EncryptionClientV2(fileConfig, symmetricEncryptionMaterials);
            s3EncryptionClientMetadataModeKMS = new AmazonS3EncryptionClientV2(metadataConfig, kmsEncryptionMaterials);
            s3EncryptionClientFileModeKMS     = new AmazonS3EncryptionClientV2(fileConfig, kmsEncryptionMaterials);

            s3Client = new AmazonS3Client();

            using (var writer = new StreamWriter(File.OpenWrite(filePath)))
            {
                writer.Write(sampleContent);
                writer.Flush();
            }

            bucketName =
                EncryptionTestsUtils.CallAsyncTask(
                    UtilityMethods.CreateBucketAsync(s3EncryptionClientFileModeAsymmetricWrap));
        }
예제 #8
0
 public void Initialize()
 {
     RunAsSync(async() =>
     {
         try
         {
             IFile file = await this.BaseFolder.CreateFileAsync
                              (testFile, CreationCollisionOption.ReplaceExisting);
             await file.WriteAllTextAsync(testContent);
             fullPath   = file.Path;
             bucketName = await UtilityMethods.CreateBucketAsync(Client);
         }
         catch (Exception e)
         {
             Console.WriteError("Error with init: {0}", e.ToString());
         }
     });
 }
 public void Initialize()
 {
     RunAsSync(async() =>
     {
         try
         {
             IFile file = await this.BaseFolder.CreateFileAsync
                              (testFile, CreationCollisionOption.ReplaceExisting);
             await file.WriteAllTextAsync(testContent);
             fullPath   = file.Path;
             bucketName = await UtilityMethods.CreateBucketAsync(Client);
             var folder = PCLStorage.FileSystem.Current.GetFileFromPathAsync(fullPath).Result;
             Console.WriteLine($"{folder.Path}");
         }
         catch (Exception e)
         {
             Console.WriteError("Error with init: {0}", e.ToString());
         }
     });
 }
예제 #10
0
        public EncryptionTests()
        {
            s3EncryptionClientMetadataMode = new AmazonS3EncryptionClient(encryptionMaterials);

            AmazonS3CryptoConfiguration config = new AmazonS3CryptoConfiguration()
            {
                StorageMode = CryptoStorageMode.InstructionFile
            };

            s3EncryptionClientFileMode = new AmazonS3EncryptionClient(config, encryptionMaterials);


            filePath = Path.Combine(Path.GetTempPath(), "EncryptionPutObjectFile.txt");
            using (StreamWriter writer = File.CreateText(filePath))
            {
                writer.Write(sampleContent);
            }
            _filesToDelete.Add(filePath);

            bucketName = UtilityMethods.CreateBucketAsync(s3EncryptionClientFileMode, "EncryptionTests").Result;
        }
예제 #11
0
 public TransferUtilityTests()
 {
     bucketName = UtilityMethods.CreateBucketAsync(Client, "TransferUtilityTests").Result;
     fullPath   = Path.GetFullPath(testFile);
     File.WriteAllText(fullPath, testContent);
 }
예제 #12
0
        public void TestPipelineOperations()
        {
            var inputBucket  = UtilityMethods.CreateBucketAsync(s3Client).Result;
            var outputBucket = UtilityMethods.CreateBucketAsync(s3Client).Result;
            var pipelineName = "sdktest-pipeline" + DateTime.Now.Ticks;
            var roleName     = "sdktest-ets-role" + DateTime.Now.Ticks;
            var policyName   = "Access_Policy";

            try
            {
                // Create a role with trust policy
                var role = iamClient.CreateRoleAsync(new CreateRoleRequest
                {
                    RoleName = roleName,
                    AssumeRolePolicyDocument = TrustPolicy
                }).Result.Role;
                // Set access policy
                iamClient.PutRolePolicyAsync(new PutRolePolicyRequest
                {
                    RoleName       = roleName,
                    PolicyDocument = AccessPolicy,
                    PolicyName     = policyName
                }).Wait();

                Client.ListPipelinesAsync().Wait();

                // Create Pipeline
                var pipeline = Client.CreatePipelineAsync(
                    new CreatePipelineRequest
                {
                    Name          = pipelineName,
                    InputBucket   = inputBucket,
                    OutputBucket  = outputBucket,
                    Notifications = new Notifications
                    {
                        Completed   = string.Empty,
                        Error       = string.Empty,
                        Progressing = string.Empty,
                        Warning     = string.Empty
                    },
                    Role         = role.Arn,
                    AwsKmsKeyArn = kmsKeyArn
                }).Result.Pipeline;
                Assert.IsNotNull(pipeline);
                Assert.AreEqual(pipeline.Name, pipelineName);
                UtilityMethods.Sleep(System.TimeSpan.FromSeconds(5));

                // List Pipelines
                var pipelines = Client.ListPipelinesAsync().Result.Pipelines;
                Assert.IsTrue(pipelines.Count > 0);
                pipelines.Contains(pipeline);

                // Get Pipeline
                var readPipelineResult = Client.ReadPipelineAsync(
                    new ReadPipelineRequest()
                {
                    Id = pipeline.Id
                }).Result;
                Assert.AreEqual(readPipelineResult.Pipeline.Id, pipeline.Id);

                // Update pipeline
                Client.UpdatePipelineStatusAsync(
                    new UpdatePipelineStatusRequest
                {
                    Id     = pipeline.Id,
                    Status = "Paused"
                }).Wait();

                // Get pipeline
                readPipelineResult = Client.ReadPipelineAsync(
                    new ReadPipelineRequest {
                    Id = pipeline.Id
                }).Result;
                Assert.AreEqual("Paused".ToLower(), readPipelineResult.Pipeline.Status.ToLower());

                // List jobs
                var jobs = Client.ListJobsByPipelineAsync(
                    new ListJobsByPipelineRequest
                {
                    PipelineId = pipeline.Id,
                    Ascending  = "true"
                }).Result.Jobs;

                // Remove pipeline
                Client.DeletePipelineAsync(
                    new DeletePipelineRequest {
                    Id = pipeline.Id
                }).Wait();

                AssertExtensions.ExpectExceptionAsync <Amazon.ElasticTranscoder.Model.ResourceNotFoundException>(Client.ReadPipelineAsync(
                                                                                                                     new ReadPipelineRequest()
                {
                    Id = pipeline.Id
                })).Wait();
            }
            finally
            {
                s3Client.DeleteBucketAsync(new DeleteBucketRequest {
                    BucketName = inputBucket
                }).Wait();
                s3Client.DeleteBucketAsync(new DeleteBucketRequest {
                    BucketName = outputBucket
                }).Wait();

                iamClient.DeleteRolePolicyAsync(new DeleteRolePolicyRequest
                {
                    RoleName   = roleName,
                    PolicyName = policyName
                }).Wait();

                iamClient.DeleteRoleAsync(new DeleteRoleRequest
                {
                    RoleName = roleName
                }).Wait();
            }
        }
예제 #13
0
 public PutObjectTest()
 {
     filePath = Path.Combine(Path.GetTempPath(), "PutObjectFile.txt");
     File.WriteAllText(filePath, "This is some sample text.!!");
     bucketName = UtilityMethods.CreateBucketAsync(Client, "PutObjectTest").Result;
 }
예제 #14
0
 public S3ServiceClientTests()
 {
     bucketName = UtilityMethods.CreateBucketAsync(Client, "s3serviceclienttest").Result;
 }