Esempio n. 1
0
 public IList <EntriesDecrypterResult> Run(DecryptGenericWorkflowOptions options)
 {
     if (!IsBuilt)
     {
         throw new EnvCryptException("workflow cannot be run because it has not been built");
     }
     return(_workflow.Run(options));
 }
Esempio n. 2
0
        private void DecryptPlainText(DecryptGenericWorkflowOptions options, List <PairWithEncyptionAlgo> detailsOfAlgoUsedTakenFromDat, List <EntriesDecrypterResult> ret)
        {
            var plainTextRequests =
                detailsOfAlgoUsedTakenFromDat.Where(d => d.EncryptionAlgo == EnvCryptAlgoEnum.PlainText).ToArray();

            if (plainTextRequests.Any())
            {
                // Case: PlainText
                var workflowOptions = new DecryptPlainTextEntryWorkflowOptions()
                {
                    CategoryEntryPair = plainTextRequests.Select(r => r.Pair).ToList(),
                    DatFilePath       = options.DatFilePath
                };
                var result = _plaintextWorkFlowBuilder.WithDatLoader(_datLoader)
                             .Build()
                             .Run(workflowOptions);
                ret.AddRange(result);
            }
        }
Esempio n. 3
0
        private void DecryptRsa(DecryptGenericWorkflowOptions options, List <PairWithEncyptionAlgo> detailsOfAlgoUsedTakenFromDat, List <EntriesDecrypterResult> ret)
        {
            var rsaRequests =
                detailsOfAlgoUsedTakenFromDat.Where(d => d.EncryptionAlgo == EnvCryptAlgoEnum.Rsa).ToArray();

            if (rsaRequests.Any())
            {
                // Case: RSA
                var workflowOptions = new DecryptEntryWorkflowOptions()
                {
                    CategoryEntryPair            = rsaRequests.Select(r => r.Pair).ToList(),
                    DatFilePath                  = options.DatFilePath,
                    KeyFilePaths                 = new[] { options.KeyFilePath },
                    ThrowIfDecryptingKeyNotFound = false
                };
                var result = _rsaWorkFlowBuilder.WithDatLoader(_datLoader)
                             .Build()
                             .Run(workflowOptions);
                ret.AddRange(result);
            }
        }
Esempio n. 4
0
        public IList <EntriesDecrypterResult> Run(DecryptGenericWorkflowOptions options)
        {
            Contract.Requires <ArgumentNullException>(options != null, "options");
            Contract.Requires <EnvCryptException>(options.CategoryEntryPair.Any(),
                                                  "at least one entry has to be requested");
            //
            var dat = _datLoader.Load(
                new DatFromFileLoaderOptions()
            {
                DatFilePath = options.DatFilePath
            });

            // Get algo used for all requested entries
            var detailsOfAlgoUsedTakenFromDat            = new List <PairWithEncyptionAlgo>(options.CategoryEntryPair.Count);
            EnvCryptAlgoEnum?algorithmThatIsNotPlainText = null;

            for (uint entryI = 0; entryI < options.CategoryEntryPair.Count; entryI++)
            {
                var currentRequestedPair = options.CategoryEntryPair[(int)entryI];

                Entry foundEntry;
                if (!dat.SearchForEntry(currentRequestedPair.Category, currentRequestedPair.Entry, out foundEntry))
                {
                    if (options.ThrowExceptionIfEntryNotFound)
                    {
                        throw new EnvCryptException("cannot find entry  {0}  in category  {1}",
                                                    currentRequestedPair.Category, currentRequestedPair.Entry);
                    }
                    continue;
                }

                // Check that all requested entries use the same encryption algorithm because we are only loading one key
                if (foundEntry.EncryptionAlgorithm != EnvCryptAlgoEnum.PlainText)
                {
                    if (algorithmThatIsNotPlainText.HasValue)
                    {
                        if (foundEntry.EncryptionAlgorithm != algorithmThatIsNotPlainText.Value)
                        {
                            throw new EnvCryptException(
                                      "all requested entries to be decrypted must have the same encryption algorithm.  Since if they are not, one key cannot possibly decrypt for more than one algorithm");
                        }
                    }
                    else
                    {
                        {
                            algorithmThatIsNotPlainText = foundEntry.EncryptionAlgorithm;
                        }
                    }
                }

                detailsOfAlgoUsedTakenFromDat.Add(new PairWithEncyptionAlgo(currentRequestedPair,
                                                                            foundEntry.EncryptionAlgorithm));
            }


            var ret = new List <EntriesDecrypterResult>();

            DecryptPlainText(options, detailsOfAlgoUsedTakenFromDat, ret);

            DecryptRsa(options, detailsOfAlgoUsedTakenFromDat, ret);

            DecryptAes(options, detailsOfAlgoUsedTakenFromDat, ret);


            return(ret);
        }