2 // Mono.Security.Protocol.Ntlm.MessageBase
3 // abstract class for all NTLM messages
6 // Sebastien Pouliot <sebastien@ximian.com>
8 // Copyright (C) 2003 Motus Technologies Inc. (http://www.motus.com)
9 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
12 // a. NTLM Authentication Scheme for HTTP, Ronald Tschalär
13 // http://www.innovation.ch/java/ntlm.html
14 // b. The NTLM Authentication Protocol, Copyright © 2003 Eric Glass
15 // http://davenport.sourceforge.net/ntlm.html
17 // Permission is hereby granted, free of charge, to any person obtaining
18 // a copy of this software and associated documentation files (the
19 // "Software"), to deal in the Software without restriction, including
20 // without limitation the rights to use, copy, modify, merge, publish,
21 // distribute, sublicense, and/or sell copies of the Software, and to
22 // permit persons to whom the Software is furnished to do so, subject to
23 // the following conditions:
25 // The above copyright notice and this permission notice shall be
26 // included in all copies or substantial portions of the Software.
28 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 using System
.Globalization
;
40 namespace Mono
.Security
.Protocol
.Ntlm
{
42 public abstract class MessageBase
{
44 static private byte[] header
= { 0x4e, 0x54, 0x4c, 0x4d, 0x53, 0x53, 0x50, 0x00 }
;
47 private NtlmFlags _flags
;
49 protected MessageBase (int messageType
)
54 public NtlmFlags Flags
{
55 get { return _flags; }
56 set { _flags = value; }
63 protected byte[] PrepareMessage (int messageSize
)
65 byte[] message
= new byte [messageSize
];
66 Buffer
.BlockCopy (header
, 0, message
, 0, 8);
68 message
[ 8] = (byte) _type
;
69 message
[ 9] = (byte)(_type
>> 8);
70 message
[10] = (byte)(_type
>> 16);
71 message
[11] = (byte)(_type
>> 24);
76 protected virtual void Decode (byte[] message
)
79 throw new ArgumentNullException ("message");
81 if (message
.Length
< 12) {
82 string msg
= Locale
.GetText ("Minimum message length is 12 bytes.");
83 throw new ArgumentOutOfRangeException ("message", message
.Length
, msg
);
86 if (!CheckHeader (message
)) {
87 string msg
= String
.Format (Locale
.GetText ("Invalid Type{0} message."), _type
);
88 throw new ArgumentException (msg
, "message");
93 protected bool CheckHeader (byte[] message
)
95 for (int i
=0; i
< header
.Length
; i
++) {
96 if (message
[i
] != header
[i
])
99 return (BitConverterLE
.ToUInt32 (message
, 8) == _type
);
102 public abstract byte[] GetBytes ();