Exemplo n.º 1
0
		// Example from http://www.innovation.ch/java/ntlm.html
		public void Encode1 () 
		{
			Type2Message msg = new Type2Message ();
			Assert.AreEqual (2, msg.Type, "Type");
			msg.Nonce = nonce;
			Assert.AreEqual ("4E-54-4C-4D-53-53-50-00-02-00-00-00-00-00-00-00-28-00-00-00-01-82-00-00-53-72-76-4E-6F-6E-63-65-00-00-00-00-00-00-00-00", BitConverter.ToString (msg.GetBytes ()), "GetBytes");
		}
Exemplo n.º 2
0
		public byte [] ProcessMessageType2 ()
		{
			byte [] bytes = new byte [8];
			RandomNumberGenerator.Create ().GetNonZeroBytes (bytes);
			Challenge = bytes [0] << 24 + bytes [1] << 16 + bytes [2] << 8 + bytes [3];
			Context = 0; // FIXME
			ServerOSVersion = 0x0F00000A28010500; // FIXME
			TargetName = Environment.MachineName;
			ServerName = Environment.MachineName;
			// FIXME
			DomainName = ServerName;// IPGlobalProperties.GetIPGlobalProperties ().DomainName;
			DnsHostName = Dns.GetHostName ();
			DnsDomainName = DnsHostName; // FIXME

			type2 = new Type2Message (NtlmVersion.Version3);
			type2.Flags = (NtlmFlags) (unchecked ((int) 0xE21882B7));
			type2.TargetName = TargetName;
			type2.Target.ServerName = ServerName;
			type2.Target.DomainName = DomainName;
			type2.Target.DnsHostName = DnsHostName;
			type2.Target.DnsDomainName = DnsDomainName;
			return type2.GetBytes ();
		}
Exemplo n.º 3
0
    public override void Negotiate(byte[] clientResponse, out byte[] serverChallenge)
    {
#if MONO_SECURITY_DLL
      var type1 = new Type1Message(clientResponse);
      var type2 = new Type2Message();

      if ((int)(type1.Flags & NtlmFlags.NegotiateUnicode) != 0)
        type2.Flags |= NtlmFlags.NegotiateUnicode;
      else if ((int)(type1.Flags & NtlmFlags.NegotiateOem) != 0)
        type2.Flags |= NtlmFlags.NegotiateOem;

      type2.Nonce = Nonce.Create(8, false);

      serverChallenge = type2.GetBytes();
#else
      var type1 = Activator.CreateInstance(typeOfType1Message, clientResponse);
      var type2 = Activator.CreateInstance(typeOfType2Message);
      var type1Flags = (int)typeOfType1Message.GetProperty("Flags").GetValue(type1, null);
      var type2Flags = 0x00000200; // NegotiateNtlm

      if ((type1Flags & 0x00000001) != 0) // NegotiateUnicode
        type2Flags |= 0x00000001;
      else if ((type1Flags & 0x00000002) != 0) // NegotiateOem
        type2Flags |= 0x00000002;

      typeOfType2Message.GetProperty("Flags").SetValue(type2, type2Flags, null);
      typeOfType2Message.GetProperty("Nonce").SetValue(type2, Nonce.Generate(8, false), null);

      serverChallenge = (byte[])typeOfType2Message.GetMethod("GetBytes").Invoke(type2, null);
#endif
    }