View Javadoc
1   /**
2    * Waffle (https://github.com/dblock/waffle)
3    *
4    * Copyright (c) 2010 - 2015 Application Security, Inc.
5    *
6    * All rights reserved. This program and the accompanying materials
7    * are made available under the terms of the Eclipse Public License v1.0
8    * which accompanies this distribution, and is available at
9    * http://www.eclipse.org/legal/epl-v10.html
10   *
11   * Contributors:
12   *     Application Security, Inc.
13   */
14  package waffle.util;
15  
16  /**
17   * Rudimentary NTLM message utility.
18   * 
19   * @author dblock[at]dblock[dot]org
20   */
21  public final class NtlmMessage {
22  
23      // NTLM messages start with 0x4e544c4d53535000, NTLMSSP signature
24      /** The Constant NTLM_SSP_SIGNATURE. */
25      private static final byte[] NTLM_SSP_SIGNATURE = { 0x4e, 0x54, 0x4c, 0x4d, 0x53, 0x53, 0x50, 0x00 };
26  
27      /**
28       * Checks if is ntlm message.
29       *
30       * @param message
31       *            the message
32       * @return true, if is ntlm message
33       */
34      public static boolean isNtlmMessage(final byte[] message) {
35          if (message == null || message.length < NtlmMessage.NTLM_SSP_SIGNATURE.length) {
36              return false;
37          }
38  
39          for (int i = 0; i < NtlmMessage.NTLM_SSP_SIGNATURE.length; i++) {
40              if (NtlmMessage.NTLM_SSP_SIGNATURE[i] != message[i]) {
41                  return false;
42              }
43          }
44  
45          return true;
46      }
47  
48      /**
49       * Get NTLM message type.
50       * 
51       * @param message
52       *            Assuming a valid NTLM message.
53       * @return Message type.
54       */
55      public static int getMessageType(final byte[] message) {
56          return message[NtlmMessage.NTLM_SSP_SIGNATURE.length];
57      }
58  
59      /**
60       * Instantiates a new ntlm message.
61       */
62      private NtlmMessage() {
63          // Prevent Instantiation of object
64      }
65  }