Exemplo n.º 1
0
 /// <summary>
 /// Dispose this instance
 /// </summary>
 /// <param name="disposing"></param>
 protected override void Dispose(bool disposing)
 {
     lock (kmsClientLock)
     {
         if (kmsClient != null)
         {
             kmsClient.Dispose();
             kmsClient = null;
         }
     }
     base.Dispose(disposing);
 }
Exemplo n.º 2
0
 private void EnsureWrappedClientIsInstantiated()
 {
     if (wrappedClient == null)
     {
         lock (wrappedClientLock)
         {
             if (wrappedClient == null)
             {
                 wrappedClient = CreateFromExistingClient(existingClient, feature);
             }
         }
     }
 }
Exemplo n.º 3
0
        /// <summary>
        /// Generates an instruction that will be used to encrypt an object
        /// using materials with the KMSKeyID set.
        /// </summary>
        /// <param name="kmsClient">
        /// Used to call KMS to generate a data key.
        /// </param>
        /// <param name="materials">
        /// The encryption materials to be used to encrypt and decrypt data.
        /// </param>
        /// <returns>
        /// The instruction that will be used to encrypt an object.
        /// </returns>
        internal static EncryptionInstructions GenerateInstructionsForKMSMaterials(ICoreAmazonKMS kmsClient, EncryptionMaterials materials)
        {
            if (materials.KMSKeyID != null)
            {
                var iv = new byte[IVLength];

                // Generate IV, and get both the key and the encrypted key from KMS.
                RandomNumberGenerator.Create().GetBytes(iv);
                var result = kmsClient.GenerateDataKey(materials.KMSKeyID, materials.MaterialsDescription, KMSKeySpec);

                return(new EncryptionInstructions(materials.MaterialsDescription, result.KeyPlaintext, result.KeyCiphertext, iv));
            }
            else
            {
                throw new ArgumentException("Error generating encryption instructions.  EncryptionMaterials must have the KMSKeyID set.");
            }
        }
Exemplo n.º 4
0
        private static ICoreAmazonKMS CreateFromExistingClient(AmazonServiceClient existingClient, string feature)
        {
            ICoreAmazonKMS coreKMSClient = null;

            try
            {
                coreKMSClient = ServiceClientHelpers.CreateServiceFromAssembly <ICoreAmazonKMS>(
                    ServiceClientHelpers.KMS_ASSEMBLY_NAME, ServiceClientHelpers.KMS_SERVICE_CLASS_NAME,
                    existingClient);
            }
            catch (Exception e)
            {
                var msg = string.Format(CultureInfo.CurrentCulture,
                                        "Error instantiating {0} from assembly {1}.  " +
                                        "The assembly and class must be available at runtime in order to use {2}.",
                                        ServiceClientHelpers.KMS_SERVICE_CLASS_NAME, ServiceClientHelpers.KMS_ASSEMBLY_NAME, feature);
                throw new InvalidOperationException(msg, e);
            }

            return(coreKMSClient);
        }
Exemplo n.º 5
0
        protected virtual void Dispose(bool disposing)
        {
            if (disposed)
            {
                return;
            }

            if (disposing)
            {
                lock (wrappedClientLock)
                {
                    if (wrappedClient != null)
                    {
                        wrappedClient.Dispose();
                        wrappedClient = null;
                    }
                }

                disposed = true;
            }
        }