Beispiel #1
0
        public ActionResult Edit(VendorCredentialModel inputModel)
        {
            if (!ModelState.IsValid)
            {
                var resultModel = VendorCredentialModel.ForEdit(dataContextFactory, inputModel.VendorCredentialId.Value);
                resultModel.CredentialName  = inputModel.CredentialName;
                resultModel.CredentialValue = inputModel.CredentialValue;
                return(View("CreateEdit", resultModel));
            }

            using (var dataContext = dataContextFactory.Create())
            {
                var vendorCredential =
                    dataContext.VendorCredentials.Where(x => x.VendorCredentialId == inputModel.VendorCredentialId.Value).Single();

                vendorCredential.CredentialName  = inputModel.CredentialName;
                vendorCredential.CredentialValue =
                    SymmetricEncryption.EncryptForDatabase(Encoding.UTF8.GetBytes(inputModel.CredentialValue));

                dataContext.SaveChanges();
            }

            Flash.Success("VendorCredential was successfully modified.");
            return(RedirectToAction("Details", "Vendor", new { key = inputModel.VendorId }));
        }
Beispiel #2
0
        public ActionResult Create(VendorCredentialModel inputModel)
        {
            if (!ModelState.IsValid)
            {
                var resultModel = VendorCredentialModel.ForCreate(dataContextFactory, inputModel.VendorId);
                resultModel.CredentialName  = inputModel.CredentialName;
                resultModel.CredentialValue = inputModel.CredentialValue;
                return(View("CreateEdit", resultModel));
            }

            using (var dataContext = dataContextFactory.Create())
            {
                var vendor = dataContext.Vendors.Single(v => v.ObjectId == inputModel.VendorId); // ensuring the vendor is authorized

                dataContext.VendorCredentials.Add(new VendorCredential()
                {
                    Vendor          = vendor,
                    CredentialName  = inputModel.CredentialName,
                    CredentialValue = SymmetricEncryption.EncryptForDatabase(Encoding.UTF8.GetBytes(inputModel.CredentialValue))
                });
                dataContext.SaveChanges();
            }

            Flash.Success("VendorCredential was successfully saved.");
            return(RedirectToAction("Details", "Vendor", new { key = inputModel.VendorId }));
        }
Beispiel #3
0
 /// <summary>
 /// Generates keybytes for the private key
 /// </summary>
 public void SetKeyBytes()
 {
     //Generate a new private key
     using (var r = new RSACryptoServiceProvider(2048, new CspParameters()
     {
         Flags = CspProviderFlags.CreateEphemeralKey | CspProviderFlags.NoPrompt
     })){
         try
         {
             var privateKeyBytes = r.ExportCspBlob(true);
             this.KeyBytes = SymmetricEncryption.EncryptForDatabase(privateKeyBytes);
         }
         finally{
             r.PersistKeyInCsp = false;
         }
     }
 }
Beispiel #4
0
        public WithAVendorDBScenario()
        {
            using (var dataContext = new DataContext())
            {
                var country = DatabaseUtil.InsertItem(dataContext, dataContext.Countries, new Country()
                {
                    CountryCode       = "vendor cc",
                    CountryName       = "vendor country.CountryName",
                    NativeCountryName = "vendor country.NativeCountryName"
                });

                var vendor = DatabaseUtil.InsertItem(dataContext, dataContext.Vendors, new Vendor()
                {
                    Name        = VendorName,
                    Street      = "vendor.street",
                    PostalCode  = "vendor.postalcode",
                    City        = "vendor.city",
                    Region      = "vendor.region",
                    CountryCode = country.CountryCode
                });

                VendorId = vendor.ObjectId;

                VendorCredential = "vendorCredential.value";

                DatabaseUtil.InsertItem(dataContext, dataContext.VendorCredentials,
                                        new VendorCredential()
                {
                    CredentialName  = "vendorCredential.name",
                    CredentialValue = SymmetricEncryption.EncryptForDatabase(Encoding.UTF8.GetBytes(VendorCredential)),
                    VendorId        = vendor.ObjectId,
                });

                var privateKey = new PrivateKey()
                {
                    DisplayName = "I am a private key",
                    VendorId    = vendor.ObjectId
                };

                privateKey.SetKeyBytes();

                privateKey = DatabaseUtil.InsertItem(dataContext, dataContext.PrivateKeys, privateKey);

                PublicKeyXml = privateKey.GetPublicKeyXmlString();

                SkuCode = "super sku";

                var sku = DatabaseUtil.InsertItem(dataContext, dataContext.SKUs, new SKU()
                {
                    SkuCode            = SkuCode,
                    PrivateKeyId       = privateKey.PrivateKeyId,
                    VendorId           = vendor.ObjectId,
                    LicenseDuration    = 12,
                    AutoDomainDuration = 12
                });

                SkuId = sku.SkuId;

                var feature = DatabaseUtil.InsertItem(dataContext, dataContext.Features, new Feature()
                {
                    FeatureName = "feature.featureName",
                    VendorId    = vendor.ObjectId
                });

                FeatureCode = feature.FeatureCode;

                DatabaseUtil.InsertItem(dataContext, dataContext.SkuFeatures, new SkuFeature()
                {
                    SkuId     = sku.SkuId,
                    FeatureId = feature.FeatureId,
                });
            }
        }