Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'mcs/class/Mono.Security/Mono.Security.Protocol.Ntlm/Type2Message.cs')
-rwxr-xr-xmcs/class/Mono.Security/Mono.Security.Protocol.Ntlm/Type2Message.cs93
1 files changed, 93 insertions, 0 deletions
diff --git a/mcs/class/Mono.Security/Mono.Security.Protocol.Ntlm/Type2Message.cs b/mcs/class/Mono.Security/Mono.Security.Protocol.Ntlm/Type2Message.cs
new file mode 100755
index 00000000000..7e1a513523c
--- /dev/null
+++ b/mcs/class/Mono.Security/Mono.Security.Protocol.Ntlm/Type2Message.cs
@@ -0,0 +1,93 @@
+//
+// Mono.Security.Protocol.Ntlm.Type2Message - Challenge
+//
+// Author:
+// Sebastien Pouliot (spouliot@motus.com)
+//
+// Copyright (C) 2003 Motus Technologies Inc. (http://www.motus.com)
+//
+// References
+// a. NTLM Authentication Scheme for HTTP, Ronald Tschalär
+// http://www.innovation.ch/java/ntlm.html
+// b. The NTLM Authentication Protocol, Copyright © 2003 Eric Glass
+// http://davenport.sourceforge.net/ntlm.html
+//
+
+using System;
+using System.Security.Cryptography;
+
+namespace Mono.Security.Protocol.Ntlm {
+
+ public class Type2Message : MessageBase {
+
+ private byte[] _nonce;
+ private int _options;
+
+ public Type2Message () : base (2)
+ {
+ _nonce = new byte [8];
+ RandomNumberGenerator rng = RandomNumberGenerator.Create ();
+ rng.GetBytes (_nonce);
+ // default values
+ Flags = (NtlmFlags) 0x8201;
+ }
+
+ public Type2Message (byte[] message) : base (2)
+ {
+ _nonce = new byte [8];
+ Decode (message);
+ }
+
+ ~Type2Message ()
+ {
+ if (_nonce != null)
+ Array.Clear (_nonce, 0, _nonce.Length);
+ }
+
+ // properties
+
+ public byte[] Nonce {
+ get { return (byte[]) _nonce.Clone (); }
+ set {
+ if (value == null)
+ throw new ArgumentNullException ("Nonce");
+ if (value.Length != 8)
+ throw new ArgumentException ("Invalid Nonce Length");
+ _nonce = (byte[]) value.Clone ();
+ }
+ }
+
+ // methods
+
+ private void Decode (byte[] message)
+ {
+ if (message == null)
+ throw new ArgumentNullException ("message");
+
+ if (!CheckHeader (message))
+ throw new ArgumentException ("Invalid Type2 message");
+
+ Flags = (NtlmFlags) BitConverter.ToUInt32 (message, 20);
+
+ Buffer.BlockCopy (message, 24, _nonce, 0, 8);
+ }
+
+ public override byte[] GetBytes ()
+ {
+ byte[] data = PrepareMessage (40);
+
+ // message length
+ short msg_len = (short)data.Length;
+ data [16] = (byte) msg_len;
+ data [17] = (byte)(msg_len >> 8);
+
+ // flags
+ uint f = (uint) Flags;
+ data [20] = (byte) f;
+ data [21] = (byte)(f >> 8);
+
+ Buffer.BlockCopy (_nonce, 0, data, 24, _nonce.Length);
+ return data;
+ }
+ }
+}