Exemplo n.º 1
0
        internal bool ValidateAndEncryptStorageCred(string name, string key, string endpoint, out string encryptedKey, out string thumbprint)
        {
            StorSimpleCryptoManager storSimpleCryptoManager = new StorSimpleCryptoManager(StorSimpleClient);

            thumbprint   = storSimpleCryptoManager.GetSecretsEncryptionThumbprint();
            encryptedKey = null;
            if (!string.IsNullOrEmpty(key))
            {
                //validate storage account credentials
                if (!ValidStorageAccountCred(name, key, endpoint))
                {
                    throw new ArgumentException(Resources.StorageCredentialVerificationFailureMessage);
                }
                WriteVerbose(Resources.StorageCredentialVerificationSuccessMessage);
                WriteVerbose(Resources.EncryptionInProgressMessage);
                storSimpleCryptoManager.EncryptSecretWithRakPub(key, out encryptedKey);
            }
            return(true);
        }
        public override void ExecuteCmdlet()
        {
            try
            {
                ValidateParams();

                // Make sure we have a device for supplied name and get its device id.
                var deviceId = StorSimpleClient.GetDeviceId(DeviceName);
                if (deviceId == null)
                {
                    throw new ArgumentException(string.Format(Resources.NoDeviceFoundWithGivenNameInResourceMessage, StorSimpleContext.ResourceName, DeviceName));
                }

                // Get the current device details. ( If we found id from the name, this call is bound to succeed)
                var deviceDetails = StorSimpleClient.GetDeviceDetails(deviceId);

                // The cik also needs to be sent to the service.
                string cik = EncryptionCmdLetHelper.RetrieveCIK(this, StorSimpleContext.ResourceId);

                // Update device details.
                var cryptoManager = new StorSimpleCryptoManager(StorSimpleClient);
                StorSimpleClient.UpdateVirtualDeviceDetails(deviceDetails, TimeZone, SecretKey, AdministratorPassword, SnapshotManagerPassword, cik, cryptoManager);

                // Make request with updated data
                WriteVerbose(string.Format(Resources.BeginningDeviceConfiguration, deviceDetails.DeviceProperties.FriendlyName));
                var taskStatusInfo = StorSimpleClient.UpdateDeviceDetails(deviceDetails);
                HandleSyncTaskResponse(taskStatusInfo, "Setup");
                if (taskStatusInfo.AsyncTaskAggregatedResult == AsyncTaskAggregatedResult.Succeeded)
                {
                    var updatedDetails = StorSimpleClient.GetDeviceDetails(deviceId);
                    WriteObject(updatedDetails);
                    WriteVerbose(string.Format(Resources.StorSimpleDeviceUpdatedSuccessfully, updatedDetails.DeviceProperties.FriendlyName, updatedDetails.DeviceProperties.DeviceId));
                }
            }
            catch (Exception exception)
            {
                this.HandleException(exception);
            }
        }
Exemplo n.º 3
0
        public override void ExecuteCmdlet()
        {
            try
            {
                string deviceid = StorSimpleClient.GetDeviceId(DeviceName);
                if (deviceid == null)
                {
                    WriteVerbose(string.Format(Resources.NoDeviceFoundWithGivenNameInResourceMessage, StorSimpleContext.ResourceName, DeviceName));
                    WriteObject(null);
                    return;
                }

                if (EncryptionEnabled == true && string.IsNullOrEmpty(EncryptionKey))
                {
                    throw new ArgumentNullException("EncryptionKey");
                }

                string encryptedKey = null;
                StorSimpleCryptoManager storSimpleCryptoManager = new StorSimpleCryptoManager(StorSimpleClient);
                if (EncryptionEnabled == true)
                {
                    WriteVerbose(Resources.EncryptionInProgressMessage);
                    storSimpleCryptoManager.EncryptSecretWithRakPub(EncryptionKey, out encryptedKey);
                }

                if (string.IsNullOrEmpty(PrimaryStorageAccountCredential.InstanceId))
                {
                    //The SAC needs to be created inline
                    WriteVerbose(Resources.InlineSacCreationMessage);

                    var sac = PrimaryStorageAccountCredential;

                    //validate storage account credentials
                    bool   storageAccountPresent;
                    string encryptedPassword;
                    string thumbprint;
                    string endpoint = GetEndpointFromHostname(sac.Hostname);
                    string location = GetStorageAccountLocation(sac.Name, out storageAccountPresent);
                    if (!storageAccountPresent ||
                        !ValidateAndEncryptStorageCred(sac.Name, sac.Password, endpoint, out encryptedPassword, out thumbprint))
                    {
                        return;
                    }

                    sac.Password = encryptedPassword;
                    sac.PasswordEncryptionCertThumbprint = thumbprint;
                    sac.Location = location;
                }

                var dc = new DataContainerRequest
                {
                    IsDefault                       = false,
                    Name                            = VolumeContainerName,
                    BandwidthRate                   = BandWidthRateInMbps,
                    IsEncryptionEnabled             = EncryptionEnabled ?? false,
                    EncryptionKey                   = encryptedKey,
                    VolumeCount                     = 0,
                    PrimaryStorageAccountCredential = PrimaryStorageAccountCredential,
                    SecretsEncryptionThumbprint     = storSimpleCryptoManager.GetSecretsEncryptionThumbprint()
                };

                if (WaitForComplete.IsPresent)
                {
                    var taskStatus = StorSimpleClient.CreateDataContainer(deviceid, dc);
                    HandleSyncTaskResponse(taskStatus, "create");
                    if (taskStatus.AsyncTaskAggregatedResult == AsyncTaskAggregatedResult.Succeeded)
                    {
                        var createdDataContainer = StorSimpleClient.GetDataContainer(deviceid, VolumeContainerName);
                        WriteObject(createdDataContainer.DataContainerInfo);
                    }
                }

                else
                {
                    var taskstatus = StorSimpleClient.CreateDataContainerAsync(deviceid, dc);
                    HandleAsyncTaskResponse(taskstatus, "create");
                }
            }
            catch (Exception exception)
            {
                this.HandleException(exception);
            }
        }
Exemplo n.º 4
0
        public void UpdateVirtualDeviceDetails(DeviceDetails details, TimeZoneInfo timeZone, string sek, string adminPasswd, string snapshotPasswd, string cik, StorSimpleCryptoManager cryptoManager)
        {
            if (timeZone != null)
            {
                details.TimeServer.TimeZone = timeZone.StandardName;
            }
            // encrypt supplied secret with the device public key
            var encryptedSecretKey = this.EncryptWithDevicePublicKey(details.DeviceProperties.DeviceId, sek);

            details.VirtualApplianceProperties.EncodedServiceEncryptionKey = encryptedSecretKey;

            // Also set the CIK before making the request - service needs it.
            var encryptedCik = this.EncryptWithDevicePublicKey(details.DeviceProperties.DeviceId, cik);

            details.VirtualApplianceProperties.EncodedChannelIntegrityKey = encryptedCik;

            // Set the admin password
            string encryptedAdminPasswd = null;

            cryptoManager.EncryptSecretWithRakPub(adminPasswd, out encryptedAdminPasswd);
            details.RemoteMinishellSecretInfo.MinishellSecret = encryptedAdminPasswd;

            // Set the snapshot manager password
            string encryptedSnapshotManagerPasswd = null;

            cryptoManager.EncryptSecretWithRakPub(snapshotPasswd, out encryptedSnapshotManagerPasswd);
            details.Snapshot.SnapshotSecret = encryptedSnapshotManagerPasswd;

            // Set the cert thumbprint for the key used.
            details.SecretEncryptionCertThumbprint = cryptoManager.GetSecretsEncryptionThumbprint();

            // mark everything that we dont intend to modify as null - indicating
            // to the service that there has been no change
            details.AlertNotification = null;
            details.Chap                   = null;
            details.DnsServer              = null;
            details.NetInterfaceList       = null;
            details.RemoteMgmtSettingsInfo = null;
            details.WebProxy               = null;
        }
 /// <summary>
 /// Constructs the encryptor to encrypt the secrets like password/key before sharing with service
 /// </summary>
 /// <param name="client"></param>
 public ServiceSecretEncryptor(StorSimpleClient client)
 {
     this.storSimpleCryptoManager = new StorSimpleCryptoManager(client);
 }