コード例 #1
0
        public static void PersistCIK(StorSimpleCmdletBase cmdlet, string resourceId, string cik)
        {
            if (string.IsNullOrEmpty(resourceId))
            {
                throw new ArgumentNullException("resourceId", Resources.ResourceIdMissing);
            }

            if (string.IsNullOrEmpty(cik))
            {
                throw new Exception(Resources.CIKInvalid);
            }

            StorSimpleKeyManager mgr = cmdlet.StorSimpleClient.GetResourceContext().StorSimpleKeyManager;
            KeyStoreOperationStatus status = mgr.PersistCIK(cik);

            if (status == KeyStoreOperationStatus.PERSIST_FILE_ALREADY_EXISTS)
            {
                cmdlet.WriteWarning("Key storage operation failed with error that file already exists. Deleting and retrying");
                mgr.CleanupCIK();
                status = mgr.PersistCIK(cik);
            }

            // other error codes are NOT expected - those validations have been done already
            if (status != KeyStoreOperationStatus.PERSIST_SUCCESS)
            {
                throw new Exception(Resources.PersistSecretFailed);
            }
        }
コード例 #2
0
        public static string RetrieveCIK(StorSimpleCmdletBase cmdlet, string resourceId)
        {
            string cik = null;

            StorSimpleKeyManager mgr = cmdlet.StorSimpleClient.GetResourceContext().StorSimpleKeyManager;
            KeyStoreOperationStatus status = mgr.RetrieveCIK(out cik);

            if (status == KeyStoreOperationStatus.RETRIEVE_FILESREAM_EMPTY ||
                status == KeyStoreOperationStatus.RETRIEVE_FILESTREAM_INVALID)
            {
                // CIK was persisted, but has been corrupted
                throw new Exception(Resources.PersistedCIKCorrupted);
            }

            if (status == KeyStoreOperationStatus.RETRIEVE_FILE_DOES_NOT_EXIST)
            {
                // CIK was never persisted
                throw new Exception(Resources.CIKNotPersisted);
            }

            // other error codes are NOT expected - those validations have been done already
            if (status != KeyStoreOperationStatus.RETRIEVE_SUCCESS)
            {
                throw new Exception(Resources.CIKFetchFailed);
            }

            if (string.IsNullOrEmpty(cik))
            {
                // CIK retrieved successfully, but is NULL :(
                throw new Exception(Resources.PersistedCIKIsNull);
            }

            return cik;
        }
コード例 #3
0
        public static string RetrieveCIK(StorSimpleCmdletBase cmdlet, string resourceId)
        {
            string cik = null;

            StorSimpleKeyManager    mgr    = cmdlet.StorSimpleClient.GetResourceContext().StorSimpleKeyManager;
            KeyStoreOperationStatus status = mgr.RetrieveCIK(out cik);

            if (status == KeyStoreOperationStatus.RETRIEVE_FILESREAM_EMPTY ||
                status == KeyStoreOperationStatus.RETRIEVE_FILESTREAM_INVALID)
            {
                // CIK was persisted, but has been corrupted
                throw new Exception(Resources.PersistedCIKCorrupted);
            }

            if (status == KeyStoreOperationStatus.RETRIEVE_FILE_DOES_NOT_EXIST)
            {
                // CIK was never persisted
                throw new Exception(Resources.CIKNotPersisted);
            }

            // other error codes are NOT expected - those validations have been done already
            if (status != KeyStoreOperationStatus.RETRIEVE_SUCCESS)
            {
                throw new Exception(Resources.CIKFetchFailed);
            }

            if (string.IsNullOrEmpty(cik))
            {
                // CIK retrieved successfully, but is NULL :(
                throw new Exception(Resources.PersistedCIKIsNull);
            }

            return(cik);
        }
コード例 #4
0
        public static void PersistCIK(StorSimpleCmdletBase cmdlet, string resourceId, string cik)
        {
            if (string.IsNullOrEmpty(resourceId))
            {
                throw new ArgumentNullException("resourceId", Resources.ResourceIdMissing);
            }

            if (string.IsNullOrEmpty(cik))
            {
                throw new Exception(Resources.CIKInvalid);
            }

            StorSimpleKeyManager    mgr    = cmdlet.StorSimpleClient.GetResourceContext().StorSimpleKeyManager;
            KeyStoreOperationStatus status = mgr.PersistCIK(cik);

            if (status == KeyStoreOperationStatus.PERSIST_FILE_ALREADY_EXISTS)
            {
                cmdlet.WriteWarning("Key storage operation failed with error that file already exists. Deleting and retrying");
                mgr.CleanupCIK();
                status = mgr.PersistCIK(cik);
            }

            // other error codes are NOT expected - those validations have been done already
            if (status != KeyStoreOperationStatus.PERSIST_SUCCESS)
            {
                throw new Exception(Resources.PersistSecretFailed);
            }
        }
コード例 #5
0
        public static void ValidatePersistedCIK(StorSimpleCmdletBase cmdlet, string resourceId)
        {
            string cik = RetrieveCIK(cmdlet, resourceId);

            StorSimpleCryptoManager cryptMgr = new StorSimpleCryptoManager(cmdlet.StorSimpleClient);
            string rakPub = cryptMgr.GetPlainTextRAKPub(cik);

            if (string.IsNullOrEmpty(rakPub))
            {
                throw new Exception(Resources.PersistedCIKValidationFailed);
            }
        }
コード例 #6
0
        public static void ValidatePersistedCIK(StorSimpleCmdletBase cmdlet, string resourceId)
        {
            string cik = RetrieveCIK(cmdlet, resourceId);

            StorSimpleCryptoManager cryptMgr = new StorSimpleCryptoManager(cmdlet.StorSimpleClient);

            string rakPub = null;

            try
            {
                rakPub = cryptMgr.GetPlainTextRAKPub(cik);
            }
            catch (CryptographicException exception)
            {
                // This case is to handle the failures during decrypting the Rak Pub
                cmdlet.WriteVerbose(string.Format(Resources.CIKInvalidWithException, exception.Message));
                throw new Exception(Resources.CIKInvalidWhileDecrypting);
            }

            if (string.IsNullOrEmpty(rakPub))
            {
                throw new Exception(Resources.PersistedCIKValidationFailed);
            }
        }
コード例 #7
0
        public static void ValidatePersistedCIK(StorSimpleCmdletBase cmdlet, string resourceId)
        {
            string cik = RetrieveCIK(cmdlet, resourceId);
            
            StorSimpleCryptoManager cryptMgr = new StorSimpleCryptoManager(cmdlet.StorSimpleClient);

            string rakPub = null;

            try
            {
                rakPub = cryptMgr.GetPlainTextRAKPub(cik);
            }
            catch (CryptographicException exception)
            {
                // This case is to handle the failures during decrypting the Rak Pub
                cmdlet.WriteVerbose(string.Format(Resources.CIKInvalidWithException, exception.Message));
                throw new Exception(Resources.CIKInvalidWhileDecrypting);
            }

            if (string.IsNullOrEmpty(rakPub))
            {
                throw new Exception(Resources.PersistedCIKValidationFailed);
            }
        }
コード例 #8
0
        public static void ValidatePersistedCIK(StorSimpleCmdletBase cmdlet, string resourceId)
        {
            string cik = RetrieveCIK(cmdlet, resourceId);
            
            StorSimpleCryptoManager cryptMgr = new StorSimpleCryptoManager(cmdlet.StorSimpleClient);
            string rakPub = cryptMgr.GetPlainTextRAKPub(cik);

            if (string.IsNullOrEmpty(rakPub))
            {
                throw new Exception(Resources.PersistedCIKValidationFailed);
            }
        }