예제 #1
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="attributes">the attributes for server</param>
 /// <param name="nlmpConfig">
 /// the config for nlmp client, this param maybe null. if null, spng does not support nlmp.
 /// </param>
 /// <param name="kileConfig">
 /// the config for kile client, this param maybe null. if null, spng does not support Kerberos.
 /// </param>
 /// <param name="sspiConfig">
 /// the config for sspi client, this param maybe null. if null, spng does not support sspi.
 /// </param>
 /// <exception cref="ArgumentException">
 /// at least one of nlmpConfig, kileConfig and sspiConfig must not be null
 /// </exception>
 public SpngClientSecurityContext(
     ClientSecurityContextAttribute attributes,
     NlmpClientSecurityConfig nlmpConfig,
     KerberosClientSecurityConfig kileConfig,
     SspiClientSecurityConfig sspiConfig)
 {
     InitializeClientSecurityContext(attributes, nlmpConfig, kileConfig, sspiConfig);
 }
예제 #2
0
        /// <summary>
        /// initialize the client security context.
        /// </summary>
        /// <param name="attributes">the attributes for server</param>
        /// <param name="nlmpConfig">
        /// the config for nlmp client, this param maybe null. if null, spng does not support nlmp.
        /// </param>
        /// <param name="kileConfig">
        /// the config for kile client, this param maybe null. if null, spng does not support Kerberos.
        /// </param>
        /// <param name="sspiConfig">
        /// the config for sspi client, this param maybe null. if null, spng does not support sspi.
        /// </param>
        /// <exception cref="ArgumentException">
        /// at least one of nlmpConfig, kileConfig and sspiConfig must not be null
        /// </exception>
        private void InitializeClientSecurityContext(
            ClientSecurityContextAttribute attributes,
            NlmpClientSecurityConfig nlmpConfig,
            KerberosClientSecurityConfig kileConfig,
            SspiClientSecurityConfig sspiConfig)
        {
            if (nlmpConfig == null && kileConfig == null && sspiConfig == null)
            {
                throw new ArgumentException("at least one of nlmpConfig, kileConfig and sspiConfig must not be null");
            }

            List <SecurityConfig> configList = new List <SecurityConfig>();

            // build the mech types
            List <MechType> mechTypes = new List <MechType>();

            if (kileConfig != null)
            {
                configList.Add(kileConfig);
                mechTypes.Add(new MechType(Consts.KerbOidInt));
            }
            if (nlmpConfig != null)
            {
                configList.Add(nlmpConfig);
                mechTypes.Add(new MechType(Consts.NlmpOidInt));
            }
            if (sspiConfig != null)
            {
                configList.Add(sspiConfig);
                switch (sspiConfig.SecurityType)
                {
                case SecurityPackageType.Ntlm:
                    mechTypes.Add(new MechType(Consts.NlmpOidInt));
                    break;

                case SecurityPackageType.Kerberos:
                    mechTypes.Add(new MechType(Consts.KerbOidInt));
                    break;

                default:
                    mechTypes.Add(new MechType(Consts.UnknownOidInt));
                    break;
                }
            }

            // build a spng config
            SpngClientSecurityConfig spngConfig =
                new SpngClientSecurityConfig(attributes, new MechTypeList(mechTypes.ToArray()));

            // add spng config to config list.
            configList.Insert(0, spngConfig);

            // initialize the spng client
            this.client = new SpngClient(spngConfig);
            this.needContinueProcessing = true;
            this.packageType            = SecurityPackageType.Negotiate;
            this.securityConfigList     = configList.ToArray();
        }