public KeyConfigurationViewModel(Models.Configuration.KeyMaterialConfiguration config)
 {
     this.Keys = new KeyConfigurationInputModel(config);
     if (config.SigningCertificate != null)
     {
         SigningCertificateThumbprint = config.SigningCertificate.Thumbprint;
     }
 }
        public KeyConfigurationInputModel(Models.Configuration.KeyMaterialConfiguration keysConfig)
        {
            if (keysConfig.SigningCertificate != null)
            {
                SigningCertificate = keysConfig.SigningCertificate.Subject;
            }
            if (keysConfig.DecryptionCertificate != null)
            {
                DecryptionCertificate = keysConfig.DecryptionCertificate.Subject;
            }

            SymmetricSigningKey = keysConfig.SymmetricSigningKey;
        }
예제 #3
0
        public static Models.Configuration.KeyMaterialConfiguration ToDomainModel(this Entities.Configuration.KeyMaterialConfiguration entity)
        {
            var model = new Models.Configuration.KeyMaterialConfiguration();

            if (entity == null)
            {
                return(model);
            }

            if (!string.IsNullOrWhiteSpace(entity.SigningCertificateName))
            {
                //var cert = X509.LocalMachine.My.SubjectDistinguishedName.Find(entity.SigningCertificateName, false).FirstOrDefault();
                var cert = X509.CurrentUser.My.SubjectDistinguishedName.Find(entity.SigningCertificateName, false).FirstOrDefault();

                if (cert == null)
                {
                    throw new InvalidOperationException(string.Format(Core.Repositories.Resources.Mappings.SigningCertificateNotFoundException, entity.SigningCertificateName));
                }

                model.SigningCertificate = cert;
            }

            if (!string.IsNullOrWhiteSpace(entity.DecryptionCertificateName))
            {
                //var cert = X509.LocalMachine.My.SubjectDistinguishedName.Find(entity.DecryptionCertificateName, false).FirstOrDefault();
                var cert = X509.CurrentUser.My.SubjectDistinguishedName.Find(entity.DecryptionCertificateName, false).FirstOrDefault();

                if (cert == null)
                {
                    throw new InvalidOperationException(string.Format(Core.Repositories.Resources.Mappings.DecryptionCertificateNotFoundException, entity.DecryptionCertificateName));
                }

                model.DecryptionCertificate = cert;
            }
            else
            {
                model.DecryptionCertificate = null;
            }

            model.SymmetricSigningKey = entity.SymmetricSigningKey;

            return(model);
        }
예제 #4
0
        public static Models.Configuration.KeyMaterialConfiguration ToDomainModel(this Entities.Configuration.KeyMaterialConfiguration entity)
        {
            var model = new Models.Configuration.KeyMaterialConfiguration();

            if (entity == null)
            {
                return(model);
            }

            if (!string.IsNullOrWhiteSpace(entity.SigningCertificateName))
            {
                var cert = X509.LocalMachine.My.SubjectDistinguishedName.Find(entity.SigningCertificateName, false).FirstOrDefault();

                if (cert == null)
                {
                    throw new InvalidOperationException("Signing certificate not found: " + entity.SigningCertificateName);
                }

                model.SigningCertificate = cert;
            }

            if (!string.IsNullOrWhiteSpace(entity.DecryptionCertificateName))
            {
                var cert = X509.LocalMachine.My.SubjectDistinguishedName.Find(entity.DecryptionCertificateName, false).FirstOrDefault();

                if (cert == null)
                {
                    throw new InvalidOperationException("Decryption certificate not found: " + entity.DecryptionCertificateName);
                }

                model.DecryptionCertificate = cert;
            }
            else
            {
                model.DecryptionCertificate = null;
            }

            model.SymmetricSigningKey = entity.SymmetricSigningKey;

            return(model);
        }
예제 #5
0
        public static Entities.Configuration.KeyMaterialConfiguration ToEntity(this Models.Configuration.KeyMaterialConfiguration model)
        {
            var entity = new Entities.Configuration.KeyMaterialConfiguration();

            if (model.SigningCertificate != null)
            {
                entity.SigningCertificateName = model.SigningCertificate.Subject;
            }

            if (model.DecryptionCertificate != null)
            {
                entity.DecryptionCertificateName = model.DecryptionCertificate.Subject;
            }
            else
            {
                entity.DecryptionCertificateName = null;
            }

            entity.SymmetricSigningKey = model.SymmetricSigningKey;

            return(entity);
        }
        public static Models.Configuration.KeyMaterialConfiguration ToDomainModel(this Entities.Configuration.KeyMaterialConfiguration entity)
        {
            var model = new Models.Configuration.KeyMaterialConfiguration();
            if (entity == null)
            {
                return model;
            }

            if (!string.IsNullOrWhiteSpace(entity.SigningCertificateName))
            {
                var cert = X509.LocalMachine.My.SubjectDistinguishedName.Find(entity.SigningCertificateName, false).FirstOrDefault();

                if (cert == null)
                {
                    throw new InvalidOperationException("Signing certificate not found: " + entity.SigningCertificateName);
                }

                model.SigningCertificate = cert;
            }

            if (!string.IsNullOrWhiteSpace(entity.DecryptionCertificateName))
            {
                var cert = X509.LocalMachine.My.SubjectDistinguishedName.Find(entity.DecryptionCertificateName, false).FirstOrDefault();

                if (cert == null)
                {
                    throw new InvalidOperationException("Decryption certificate not found: " + entity.DecryptionCertificateName);
                }

                model.DecryptionCertificate = cert;
            }
            else
            {
                model.DecryptionCertificate = null;
            }

            model.SymmetricSigningKey = entity.SymmetricSigningKey;

            return model;
        }
 public KeyConfigurationViewModel(Models.Configuration.KeyMaterialConfiguration config)
 {
     this.Keys = new KeyConfigurationInputModel(config);
 }