1 19 20 package jcifs.ntlmssp; 21 22 import jcifs.Config; 23 24 27 public abstract class NtlmMessage implements NtlmFlags { 28 29 32 protected static final byte[] NTLMSSP_SIGNATURE = new byte[] { 33 (byte) 'N', (byte) 'T', (byte) 'L', (byte) 'M', 34 (byte) 'S', (byte) 'S', (byte) 'P', (byte) 0 35 }; 36 37 private static final String OEM_ENCODING = Config.getProperty("jcifs.encoding", "Cp850"); 38 39 private int flags; 40 41 47 public int getFlags() { 48 return flags; 49 } 50 51 56 public void setFlags(int flags) { 57 this.flags = flags; 58 } 59 60 66 public boolean getFlag(int flag) { 67 return (getFlags() & flag) != 0; 68 } 69 70 78 public void setFlag(int flag, boolean value) { 79 setFlags(value ? (getFlags() | flag) : 80 (getFlags() & (0xffffffff ^ flag))); 81 } 82 83 static int readULong(byte[] src, int index) { 84 return (src[index] & 0xff) | 85 ((src[index + 1] & 0xff) << 8) | 86 ((src[index + 2] & 0xff) << 16) | 87 ((src[index + 3] & 0xff) << 24); 88 } 89 90 static int readUShort(byte[] src, int index) { 91 return (src[index] & 0xff) | ((src[index + 1] & 0xff) << 8); 92 } 93 94 static byte[] readSecurityBuffer(byte[] src, int index) { 95 int length = readUShort(src, index); 96 int offset = readULong(src, index + 4); 97 byte[] buffer = new byte[length]; 98 System.arraycopy(src, offset, buffer, 0, length); 99 return buffer; 100 } 101 102 static void writeULong(byte[] dest, int offset, int ulong) { 103 dest[offset] = (byte) (ulong & 0xff); 104 dest[offset + 1] = (byte) (ulong >> 8 & 0xff); 105 dest[offset + 2] = (byte) (ulong >> 16 & 0xff); 106 dest[offset + 3] = (byte) (ulong >> 24 & 0xff); 107 } 108 109 static void writeUShort(byte[] dest, int offset, int ushort) { 110 dest[offset] = (byte) (ushort & 0xff); 111 dest[offset + 1] = (byte) (ushort >> 8 & 0xff); 112 } 113 114 static void writeSecurityBuffer(byte[] dest, int offset, int bodyOffset, 115 byte[] src) { 116 int length = (src != null) ? src.length : 0; 117 if (length == 0) return; 118 writeUShort(dest, offset, length); 119 writeUShort(dest, offset + 2, length); 120 writeULong(dest, offset + 4, bodyOffset); 121 System.arraycopy(src, 0, dest, bodyOffset, length); 122 } 123 124 static String getOEMEncoding() { 125 return OEM_ENCODING; 126 } 127 128 133 public abstract byte[] toByteArray(); 134 135 } 136 | Popular Tags |