1 19 20 package com.knowgate.jcifs.ntlmssp; 21 22 import com.knowgate.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 = 38 Config.getProperty("jcifs.encoding", 39 System.getProperty("file.encoding")); 40 41 private int flags; 42 43 49 public int getFlags() { 50 return flags; 51 } 52 53 58 public void setFlags(int flags) { 59 this.flags = flags; 60 } 61 62 68 public boolean getFlag(int flag) { 69 return (getFlags() & flag) != 0; 70 } 71 72 80 public void setFlag(int flag, boolean value) { 81 setFlags(value ? (getFlags() | flag) : 82 (getFlags() & (0xffffffff ^ flag))); 83 } 84 85 static int readULong(byte[] src, int index) { 86 return (src[index] & 0xff) | 87 ((src[index + 1] & 0xff) << 8) | 88 ((src[index + 2] & 0xff) << 16) | 89 ((src[index + 3] & 0xff) << 24); 90 } 91 92 static int readUShort(byte[] src, int index) { 93 return (src[index] & 0xff) | ((src[index + 1] & 0xff) << 8); 94 } 95 96 static byte[] readSecurityBuffer(byte[] src, int index) { 97 int length = readUShort(src, index); 98 int offset = readULong(src, index + 4); 99 byte[] buffer = new byte[length]; 100 System.arraycopy(src, offset, buffer, 0, length); 101 return buffer; 102 } 103 104 static void writeULong(byte[] dest, int offset, int ulong) { 105 dest[offset] = (byte) (ulong & 0xff); 106 dest[offset + 1] = (byte) (ulong >> 8 & 0xff); 107 dest[offset + 2] = (byte) (ulong >> 16 & 0xff); 108 dest[offset + 3] = (byte) (ulong >> 24 & 0xff); 109 } 110 111 static void writeUShort(byte[] dest, int offset, int ushort) { 112 dest[offset] = (byte) (ushort & 0xff); 113 dest[offset + 1] = (byte) (ushort >> 8 & 0xff); 114 } 115 116 static void writeSecurityBuffer(byte[] dest, int offset, int bodyOffset, 117 byte[] src) { 118 int length = (src != null) ? src.length : 0; 119 if (length == 0) return; 120 writeUShort(dest, offset, length); 121 writeUShort(dest, offset + 2, length); 122 writeULong(dest, offset + 4, bodyOffset); 123 System.arraycopy(src, 0, dest, bodyOffset, length); 124 } 125 126 static String getOEMEncoding() { 127 return OEM_ENCODING; 128 } 129 130 135 public abstract byte[] toByteArray(); 136 137 } 138 | Popular Tags |