2 // Mono.Security.Protocol.Ntlm.Type1Message - Negotiation
5 // Sebastien Pouliot <sebastien@ximian.com>
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
11 // a. NTLM Authentication Scheme for HTTP, Ronald Tschalär
12 // http://www.innovation.ch/java/ntlm.html
13 // b. The NTLM Authentication Protocol, Copyright © 2003 Eric Glass
14 // http://davenport.sourceforge.net/ntlm.html
16 // Permission is hereby granted, free of charge, to any person obtaining
17 // a copy of this software and associated documentation files (the
18 // "Software"), to deal in the Software without restriction, including
19 // without limitation the rights to use, copy, modify, merge, publish,
20 // distribute, sublicense, and/or sell copies of the Software, and to
21 // permit persons to whom the Software is furnished to do so, subject to
22 // the following conditions:
24 // The above copyright notice and this permission notice shall be
25 // included in all copies or substantial portions of the Software.
27 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
30 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
31 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
32 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
33 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 using System
.Globalization
;
40 namespace Mono
.Security
.Protocol
.Ntlm
{
42 public class Type1Message
: MessageBase
{
45 private string _domain
;
47 public Type1Message () : base (1)
50 _domain
= Environment
.UserDomainName
;
51 _host
= Environment
.MachineName
;
52 Flags
= (NtlmFlags
) 0xb203;
55 public Type1Message (byte[] message
) : base (1)
62 public string Domain
{
63 get { return _domain; }
64 set { _domain = value; }
69 set { _host = value; }
74 protected override void Decode (byte[] message
)
76 base.Decode (message
);
78 Flags
= (NtlmFlags
) BitConverterLE
.ToUInt32 (message
, 12);
80 int dom_len
= BitConverterLE
.ToUInt16 (message
, 16);
81 int dom_off
= BitConverterLE
.ToUInt16 (message
, 20);
82 _domain
= Encoding
.ASCII
.GetString (message
, dom_off
, dom_len
);
84 int host_len
= BitConverterLE
.ToUInt16 (message
, 24);
85 _host
= Encoding
.ASCII
.GetString (message
, 32, host_len
);
88 public override byte[] GetBytes ()
90 short dom_len
= (short) _domain
.Length
;
91 short host_len
= (short) _host
.Length
;
93 byte[] data
= PrepareMessage (32 + dom_len
+ host_len
);
95 data
[12] = (byte) Flags
;
96 data
[13] = (byte)((uint)Flags
>> 8);
97 data
[14] = (byte)((uint)Flags
>> 16);
98 data
[15] = (byte)((uint)Flags
>> 24);
100 short dom_off
= (short)(32 + host_len
);
102 data
[16] = (byte) dom_len
;
103 data
[17] = (byte)(dom_len
>> 8);
104 data
[18] = data
[16];
105 data
[19] = data
[17];
106 data
[20] = (byte) dom_off
;
107 data
[21] = (byte)(dom_off
>> 8);
109 data
[24] = (byte) host_len
;
110 data
[25] = (byte)(host_len
>> 8);
111 data
[26] = data
[24];
112 data
[27] = data
[25];
116 byte[] host
= Encoding
.ASCII
.GetBytes (_host
.ToUpper (CultureInfo
.InvariantCulture
));
117 Buffer
.BlockCopy (host
, 0, data
, 32, host
.Length
);
119 byte[] domain
= Encoding
.ASCII
.GetBytes (_domain
.ToUpper (CultureInfo
.InvariantCulture
));
120 Buffer
.BlockCopy (domain
, 0, data
, dom_off
, domain
.Length
);