public XmlElement GetTransportTokenAssertion() { var doc = new XmlDocument(); var element = doc.CreateElement( "msf", "WindowsTransportSecurity", PolicyImportHelper.FramingPolicyNS); var protectionLevel = doc.CreateElement( "msf", "ProtectionLevel", PolicyImportHelper.FramingPolicyNS); protectionLevel.InnerText = ProtectionLevel.ToString(); element.AppendChild(protectionLevel); return(element); }
// // Client side starts here, but server also loops through this method. // private void StartSendBlob(byte[] message, LazyAsyncResult lazyResult) { Win32Exception win32exception = null; if (message != s_emptyMessage) { message = GetOutgoingBlob(message, ref win32exception); } if (win32exception != null) { // Signal remote side on a failed attempt. StartSendAuthResetSignal(lazyResult, message, win32exception); return; } if (HandshakeComplete) { if (_context.IsServer && !CheckSpn()) { Exception exception = new AuthenticationException(SR.net_auth_bad_client_creds_or_target_mismatch); int statusCode = ERROR_TRUST_FAILURE; message = new byte[8]; //sizeof(long) for (int i = message.Length - 1; i >= 0; --i) { message[i] = (byte)(statusCode & 0xFF); statusCode = (int)((uint)statusCode >> 8); } StartSendAuthResetSignal(lazyResult, message, exception); return; } if (PrivateImpersonationLevel < _expectedImpersonationLevel) { Exception exception = new AuthenticationException(SR.Format(SR.net_auth_context_expectation, _expectedImpersonationLevel.ToString(), PrivateImpersonationLevel.ToString())); int statusCode = ERROR_TRUST_FAILURE; message = new byte[8]; //sizeof(long) for (int i = message.Length - 1; i >= 0; --i) { message[i] = (byte)(statusCode & 0xFF); statusCode = (int)((uint)statusCode >> 8); } StartSendAuthResetSignal(lazyResult, message, exception); return; } ProtectionLevel result = _context.IsConfidentialityFlag ? ProtectionLevel.EncryptAndSign : _context.IsIntegrityFlag ? ProtectionLevel.Sign : ProtectionLevel.None; if (result < _expectedProtectionLevel) { Exception exception = new AuthenticationException(SR.Format(SR.net_auth_context_expectation, result.ToString(), _expectedProtectionLevel.ToString())); int statusCode = ERROR_TRUST_FAILURE; message = new byte[8]; //sizeof(long) for (int i = message.Length - 1; i >= 0; --i) { message[i] = (byte)(statusCode & 0xFF); statusCode = (int)((uint)statusCode >> 8); } StartSendAuthResetSignal(lazyResult, message, exception); return; } // Signal remote party that we are done _framer.WriteHeader.MessageId = FrameHeader.HandshakeDoneId; if (_context.IsServer) { // Server may complete now because client SSPI would not complain at this point. _remoteOk = true; // However the client will wait for server to send this ACK //Force signaling server OK to the client if (message == null) { message = s_emptyMessage; } } } else if (message == null || message == s_emptyMessage) { throw new InternalException(); } if (message != null) { //even if we are completed, there could be a blob for sending. if (lazyResult == null) { _framer.WriteMessage(message); } else { IAsyncResult ar = _framer.BeginWriteMessage(message, s_writeCallback, lazyResult); if (!ar.CompletedSynchronously) { return; } _framer.EndWriteMessage(ar); } } CheckCompletionBeforeNextReceive(lazyResult); }
public static void Main() { // <Snippet0> Uri baseAddress = new Uri("http://localhost:8001/Simple"); ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), baseAddress); serviceHost.AddServiceEndpoint( typeof(ICalculator), new WSHttpBinding(), "CalculatorServiceObject"); // Enable Mex ServiceMetadataBehavior smb = new ServiceMetadataBehavior(); smb.HttpGetEnabled = true; serviceHost.Description.Behaviors.Add(smb); serviceHost.Open(); // <Snippet1> ContractDescription cd0 = new ContractDescription("ICalculator"); // </Snippet1> // <Snippet2> ContractDescription cd1 = new ContractDescription("ICalculator", "http://www.tempuri.org"); // </Snippet2> // <Snippet13> ContractDescription cd2 = ContractDescription.GetContract(typeof(ICalculator)); // </Snippet13> // <Snippet14> CalculatorService calcSvc = new CalculatorService(); ContractDescription cd3 = ContractDescription.GetContract(typeof(ICalculator), calcSvc); // </Snippet14> // <Snippet15> ContractDescription cd4 = ContractDescription.GetContract(typeof(ICalculator), typeof(CalculatorService)); // </Snippet15> ContractDescription cd = serviceHost.Description.Endpoints[0].Contract; Console.WriteLine("Displaying information for contract: {0}", cd.Name.ToString()); // <Snippet3> KeyedByTypeCollection <IContractBehavior> behaviors = cd.Behaviors; Console.WriteLine("\tDisplay all behaviors:"); foreach (IContractBehavior behavior in behaviors) { Console.WriteLine("\t\t" + behavior.ToString()); } // </Snippet3> // <Snippet4> Type type = cd.CallbackContractType; // </Snippet4> // <Snippet5> string configName = cd.ConfigurationName; Console.WriteLine("\tConfiguration name: {0}", configName); // </Snippet5> // <Snippet6> Type contractType = cd.ContractType; Console.WriteLine("\tContract type: {0}", contractType.ToString()); // </Snippet6> // <Snippet7> bool hasProtectionLevel = cd.HasProtectionLevel; if (hasProtectionLevel) { // <Snippet11> ProtectionLevel protectionLevel = cd.ProtectionLevel; Console.WriteLine("\tProtection Level: {0}", protectionLevel.ToString()); // </Snippet11> } // </Snippet7> // <Snippet8> string name = cd.Name; Console.WriteLine("\tName: {0}", name); // </Snippet8> // <Snippet9> string namespc = cd.Namespace; Console.WriteLine("\tNamespace: {0}", namespc); // </Snippet9> // <Snippet10> OperationDescriptionCollection odc = cd.Operations; Console.WriteLine("\tDisplay Operations:"); foreach (OperationDescription od in odc) { Console.WriteLine("\t\t" + od.Name); } // </Snippet10> // <Snippet12> SessionMode sm = cd.SessionMode; Console.WriteLine("\tSessionMode: {0}", sm.ToString()); // </Snippet12> // <Snippet16> Collection <ContractDescription> inheretedContracts = cd.GetInheritedContracts(); Console.WriteLine("\tInherited Contracts:"); foreach (ContractDescription contractdescription in inheretedContracts) { Console.WriteLine("\t\t" + contractdescription.Name); } // </Snippet16> Console.WriteLine("The service is ready."); Console.WriteLine("Press <ENTER> to terminate service."); Console.WriteLine(); Console.ReadLine(); // Close the ServiceHostBase to shutdown the service. serviceHost.Close(); // </Snippet0> }
private void StartSendBlob(byte[] message, LazyAsyncResult lazyResult) { Win32Exception e = null; if (message != _EmptyMessage) { message = this.GetOutgoingBlob(message, ref e); } if (e != null) { this.StartSendAuthResetSignal(lazyResult, message, e); } else { if (this.HandshakeComplete) { if (this._Context.IsServer && !this.CheckSpn()) { Exception exception = new AuthenticationException(SR.GetString("net_auth_bad_client_creds_or_target_mismatch")); int num = 0x6fe; message = new byte[8]; for (int i = message.Length - 1; i >= 0; i--) { message[i] = (byte)(num & 0xff); num = num >> 8; } this.StartSendAuthResetSignal(lazyResult, message, exception); return; } if (this.PrivateImpersonationLevel < this._ExpectedImpersonationLevel) { Exception exception3 = new AuthenticationException(SR.GetString("net_auth_context_expectation", new object[] { this._ExpectedImpersonationLevel.ToString(), this.PrivateImpersonationLevel.ToString() })); int num3 = 0x6fe; message = new byte[8]; for (int j = message.Length - 1; j >= 0; j--) { message[j] = (byte)(num3 & 0xff); num3 = num3 >> 8; } this.StartSendAuthResetSignal(lazyResult, message, exception3); return; } ProtectionLevel level = this._Context.IsConfidentialityFlag ? ProtectionLevel.EncryptAndSign : (this._Context.IsIntegrityFlag ? ProtectionLevel.Sign : ProtectionLevel.None); if (level < this._ExpectedProtectionLevel) { Exception exception4 = new AuthenticationException(SR.GetString("net_auth_context_expectation", new object[] { level.ToString(), this._ExpectedProtectionLevel.ToString() })); int num5 = 0x6fe; message = new byte[8]; for (int k = message.Length - 1; k >= 0; k--) { message[k] = (byte)(num5 & 0xff); num5 = num5 >> 8; } this.StartSendAuthResetSignal(lazyResult, message, exception4); return; } this._Framer.WriteHeader.MessageId = 20; if (this._Context.IsServer) { this._RemoteOk = true; if (message == null) { message = _EmptyMessage; } } } else if ((message == null) || (message == _EmptyMessage)) { throw new InternalException(); } if (message != null) { if (lazyResult == null) { this._Framer.WriteMessage(message); } else { IAsyncResult asyncResult = this._Framer.BeginWriteMessage(message, _WriteCallback, lazyResult); if (!asyncResult.CompletedSynchronously) { return; } this._Framer.EndWriteMessage(asyncResult); } } this.CheckCompletionBeforeNextReceive(lazyResult); } }
public string GetProtectionLevelName() { return(ProtectionLevel.ToString().ToLower()); }
public string PersonalToString() { return("ProtectionLevel: " + ProtectionLevel.ToString() + " \n" + "Power: " + Power.ToString() + " \n"); }
} // ReceiveCallback // // Properties // public override Object this[Object key] { get { String keyStr = key as String; if (keyStr == null) { return(null); } switch (keyStr.ToLower(CultureInfo.InvariantCulture)) { case UserNameKey: return(_securityUserName); case PasswordKey: return(null); // Intentionally refuse to return password. case DomainKey: return(_securityDomain); case SocketCacheTimeoutKey: return(_socketCacheTimeout); case ReceiveTimeoutKey: return(_receiveTimeout); case SocketCachePolicyKey: return(_socketCachePolicy.ToString()); case RetryCountKey: return(_retryCount); case ConnectionGroupNameKey: return(_connectionGroupName); case ProtectionLevelKey: if (authSet) { return(_protectionLevel.ToString()); } break; } // switch (keyStr.ToLower(CultureInfo.InvariantCulture)) return(null); } set { String keyStr = key as String; if (keyStr == null) { return; } switch (keyStr.ToLower(CultureInfo.InvariantCulture)) { case UserNameKey: _securityUserName = (String)value; break; case PasswordKey: _securityPassword = (String)value; break; case DomainKey: _securityDomain = (String)value; break; case SocketCacheTimeoutKey: int timeout = Convert.ToInt32(value, CultureInfo.InvariantCulture); if (timeout < 0) { throw new RemotingException( CoreChannel.GetResourceString( "Remoting_Tcp_SocketTimeoutNegative")); } _socketCacheTimeout = TimeSpan.FromSeconds(timeout); ClientSocketCache.SocketTimeout = _socketCacheTimeout; break; case ReceiveTimeoutKey: _receiveTimeout = Convert.ToInt32(value, CultureInfo.InvariantCulture); ClientSocketCache.ReceiveTimeout = _receiveTimeout; break; case SocketCachePolicyKey: _socketCachePolicy = (SocketCachePolicy)(value is SocketCachePolicy ? value : Enum.Parse(typeof(SocketCachePolicy), (String)value, true)); ClientSocketCache.CachePolicy = _socketCachePolicy; break; case RetryCountKey: _retryCount = Convert.ToInt32(value, CultureInfo.InvariantCulture); break; case ConnectionGroupNameKey: _connectionGroupName = (String)value; break; case ProtectionLevelKey: _protectionLevel = (ProtectionLevel)(value is ProtectionLevel ? value : Enum.Parse(typeof(ProtectionLevel), (String)value, true)); authSet = true; break; case SPNKey: _spn = (String)value; authSet = true; break; } // switch (keyStr.ToLower(CultureInfo.InvariantCulturey)) } } // this[]