示例#1
0
        public static CryptoProvider CreateSample(bool addElements = true)
        {
            CryptoProvider cp = new CryptoProvider()
            {
                Key = new CryptoKeyInfo()
                {
                    Uri           = "Filepath to RSA key file; http support in future.",
                    ContainerName = "RSA=supported container name",
                    CspFlags      = CspProviderFlags.NoFlags
                }
            };

            cp.Errors = null;
            if (addElements)
            {
                cp.Elements.Add("Element:IndexedElement[0]:Element");
                cp.Elements.Add("Element:IndexedElement[1]:Element");
            }
            else
            {
                cp.Elements = null;
            }

            return(cp);
        }
        public ParameterInfo GetCryptoValues(CryptoProvider planCrypto = null, bool isEncryptMode = true)
        {
            if (HasCrypto)
            {
                Crypto.InheritSettingsIfRequired(planCrypto);
            }

            switch (Type)
            {
            case SerializationType.Xml:
            {
                XmlDocument values = new XmlDocument();
                values.LoadXml(Values.ToString());
                ParameterInfo pi = XmlHelpers.GetCryptoValues(this, ref values, isEncryptMode);
                pi.Values = XmlHelpers.Serialize <string>(values);
                return(pi);
            }

            case SerializationType.Yaml:
            case SerializationType.Json:
            {
                return(YamlHelpers.GetCryptoValues(this, isEncryptMode));
            }

            case SerializationType.Unspecified:
            default:
            {
                return(this);
            }
            }
        }
示例#3
0
        public void InheritSettingsIfRequired(CryptoProvider provider, CryptoInheritElementAction inheritElementAction = CryptoInheritElementAction.None)
        {
            if (provider?.Key == null)
            {
                return;
            }

            if (Key == null)
            {
                Key = new CryptoKeyInfo();
            }

            if (string.IsNullOrWhiteSpace(Key.Uri) || string.IsNullOrWhiteSpace(Key.ContainerName))
            {
                Key.Uri           = provider.Key.Uri;
                Key.ContainerName = provider.Key.ContainerName;
                Key.CspFlags      = provider.Key.CspFlags;
            }

            if (inheritElementAction != CryptoInheritElementAction.None)
            {
                if (inheritElementAction == CryptoInheritElementAction.Replace || Elements == null)
                {
                    Elements = new List <string>();
                }

                if (provider.Elements != null && provider.Elements.Count > 0)
                {
                    foreach (string el in provider.Elements)
                    {
                        Elements.Add(el);
                    }
                }
            }
        }
 public SecurityContext GetCryptoValues(CryptoProvider planCrypto = null, bool isEncryptMode = true)
 {
     if (HasCrypto)
     {
         Crypto.InheritSettingsIfRequired(planCrypto);
     }
     return(YamlHelpers.GetCryptoValues(this, isEncryptMode));
 }
        public static SecurityContext CreateSample()
        {
            SecurityContext sc = new SecurityContext()
            {
                Domain   = "AD Domain",
                UserName = "******",
                Password = "******",
                Provider = "Reserved for future use: AD, AWS, Azure, etc.",

                Crypto = CryptoProvider.CreateSample()
            };

            return(sc);
        }
        /// <summary>
        /// Serializes Valus to string, decrypting as required.  safeSerializedValues does not include decrypted values.
        /// </summary>
        /// <param name="planCrypto">Plan-level Crypto settings, to be inherited by local Crypto.</param>
        /// <param name="safeSerializedValues">Serialized Values, but with any Encrypted values still shown as encrypted.</param>
        /// <returns>Yaml-/Json-/Xml-serialized values.</returns>
        public string GetSerializedValues(CryptoProvider planCrypto, out string safeSerializedValues)
        {
            ParameterInfo pi = this;

            if (HasCrypto)
            {
                pi = GetCryptoValues(planCrypto, isEncryptMode: false);
            }

            string v = null;

            safeSerializedValues = null;
            switch (Type)
            {
            case SerializationType.Yaml:
            {
                v = Utilities.YamlHelpers.Serialize(pi.Values);
                safeSerializedValues = Utilities.YamlHelpers.Serialize(this.Values);
                break;
            }

            case SerializationType.Json:
            {
                v = Utilities.YamlHelpers.Serialize(pi.Values, serializeAsJson: true);
                safeSerializedValues = Utilities.YamlHelpers.Serialize(this.Values, serializeAsJson: true);
                break;
            }

            case SerializationType.Xml:
            {
                v = Utilities.XmlHelpers.Serialize <object>(pi.Values);
                safeSerializedValues = Utilities.XmlHelpers.Serialize <object>(this.Values);
                break;
            }

            case SerializationType.Unspecified:
            {
                v = pi.Values.ToString();
                safeSerializedValues = this.Values.ToString();
                break;
            }
            }

            return(v);
        }
 public void InheritSettingsIfAllowed(SecurityContext sourceContext)
 {
     if (sourceContext != null && sourceContext.IsInheritable && !this.BlockInheritance)
     {
         Domain   = sourceContext.Domain;
         UserName = sourceContext.UserName;
         Password = sourceContext.Password;
         Provider = sourceContext.Provider;
         Config   = sourceContext.Config?.Clone();
         Crypto   = new CryptoProvider();
         Crypto.InheritSettingsIfRequired(sourceContext.Crypto, CryptoInheritElementAction.Replace);
         IsInheritable = true;
         IsInherited   = true;
     }
     else
     {
         IsInherited = false;  //overwrite any user-declared setting
     }
 }
示例#8
0
        public static Plan CreateSample()
        {
            Plan p = new Plan()
            {
                Name               = "SamplePlan",
                Description        = "Sample Plan, all features shown.",
                UniqueName         = "Human-knowable name for database lookups",
                DefaultHandlerType = "Synapse.Handlers.CommandLine:CommandHandler",
                InstanceId         = 0,
                IsActive           = true,
                Signature          = "RSA Cryptographic signature, applied at runtime.",
                Crypto             = CryptoProvider.CreateSample(addElements: false),
                RunAs              = SecurityContext.CreateSample(),
                Result             = ExecuteResult.CreateSample()
            };

            p.Actions.Add(ActionItem.CreateSample());

            return(p);
        }
        public void Impersonate(CryptoProvider crypto)
        {
            if (!IsValid)
            {
                return;
            }

            if (!IsImpersonating)
            {
                _token = IntPtr.Zero;

                SecurityContext sc = this;
                if (HasCrypto && Crypto.HasElements)
                {
                    sc = GetCryptoValues(crypto, isEncryptMode: false);
                }

                bool ok = LogonUser(sc.UserName, sc.Domain, sc.Password,
                                    LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, ref _token);

                if (HasCrypto)
                {
                    sc = null;
                }

                //try { password.Dispose(); } catch { }

                if (!ok)
                {
                    int error = Marshal.GetLastWin32Error();
                    throw new Win32Exception(error);
                }

                WindowsIdentity identity = new WindowsIdentity(_token);
                _impContext = identity.Impersonate();
            }
        }
        public static ParameterInfo CreateSample()
        {
            ParameterInfo p = new ParameterInfo()
            {
                Name        = "NameSupportsInheritance",
                Type        = SerializationType.Yaml,
                Uri         = "http://host/path",
                InheritFrom = "APrecedingNamedParamInfo",
                Crypto      = CryptoProvider.CreateSample(),
                Values      = "Custom values as defined by Handler/Provider"
            };

            p.Dynamic = new List <DynamicValue>
            {
                DynamicValue.CreateSample()
            };
            p.ParentExitData = new List <ParentExitDataValue>()
            {
                ParentExitDataValue.CreateSample()
            };
            p.ForEach = ForEachInfo.CreateSample();

            return(p);
        }
 /// <summary>
 /// Serializes Valus to string, decrypting as required.
 /// </summary>
 /// <param name="planCrypto">Plan-level Crypto settings, to be inherited by local Crypto.</param>
 /// <returns>Yaml-/Json-/Xml-serialized values.</returns>
 public string GetSerializedValues(CryptoProvider planCrypto = null)
 {
     return(GetSerializedValues(planCrypto, out string safeSerializedValues));
 }