Beispiel #1
0
		/// <exception cref="SharpCifs.Smb.SmbException"></exception>
		public SigningDigest(SmbTransport transport, NtlmPasswordAuthentication auth)
		{
			try
			{
				_digest = MessageDigest.GetInstance("MD5");
			}
			catch (NoSuchAlgorithmException ex)
			{
				if (Log.Level > 0)
				{
					Runtime.PrintStackTrace(ex, Log);
				}
				throw new SmbException("MD5", ex);
			}
			try
			{
                switch (SmbConstants.LmCompatibility)
				{
					case 0:
					case 1:
					case 2:
					{
						_macSigningKey = new byte[40];
						auth.GetUserSessionKey(transport.Server.EncryptionKey, _macSigningKey, 0);
						Array.Copy(auth.GetUnicodeHash(transport.Server.EncryptionKey), 0, _macSigningKey
							, 16, 24);
						break;
					}

					case 3:
					case 4:
					case 5:
					{
						_macSigningKey = new byte[16];
						auth.GetUserSessionKey(transport.Server.EncryptionKey, _macSigningKey, 0);
						break;
					}

					default:
					{
						_macSigningKey = new byte[40];
						auth.GetUserSessionKey(transport.Server.EncryptionKey, _macSigningKey, 0);
						Array.Copy(auth.GetUnicodeHash(transport.Server.EncryptionKey), 0, _macSigningKey
							, 16, 24);
					    break;
					}
				}
			}
			catch (Exception ex)
			{
				throw new SmbException(string.Empty, ex);
			}
			if (Log.Level >= 5)
			{
                Log.WriteLine("LM_COMPATIBILITY=" + SmbConstants.LmCompatibility);
				Hexdump.ToHexdump(Log, _macSigningKey, 0, _macSigningKey.Length);
			}
		}
Beispiel #2
0
		/// <summary>Creates an HMACT64 instance which uses the given secret key material.</summary>
		/// <remarks>Creates an HMACT64 instance which uses the given secret key material.</remarks>
		/// <param name="key">The key material to use in hashing.</param>
		public Hmact64(byte[] key) 
		{
			int length = Math.Min(key.Length, BlockLength);
			for (int i = 0; i < length; i++)
			{
				_ipad[i] = unchecked((byte)(key[i] ^ Ipad));
				_opad[i] = unchecked((byte)(key[i] ^ Opad));
			}
			for (int i1 = length; i1 < BlockLength; i1++)
			{
				_ipad[i1] = Ipad;
				_opad[i1] = Opad;
			}
			try
			{
				_md5 = GetInstance("MD5");
			}
			catch (Exception ex)
			{
				throw new InvalidOperationException(ex.Message);
			}
			EngineReset();
		}
Beispiel #3
0
		/// <exception cref="SharpCifs.Smb.SmbException"></exception>
		public SigningDigest(byte[] macSigningKey, bool bypass)
		{
			try
			{
				_digest = MessageDigest.GetInstance("MD5");
			}
			catch (NoSuchAlgorithmException ex)
			{
				if (Log.Level > 0)
				{
					Runtime.PrintStackTrace(ex, Log);
				}
				throw new SmbException("MD5", ex);
			}
			this._macSigningKey = macSigningKey;
			this._bypass = bypass;
			_updates = 0;
			_signSequence = 0;
			if (Log.Level >= 5)
			{
				Log.WriteLine("macSigningKey:");
				Hexdump.ToHexdump(Log, macSigningKey, 0, macSigningKey.Length);
			}
		}