FileDocCategorySizeDatePackage
Type1Message.javaAPI DocJCIFS 1.3.17 API8385Tue Oct 18 15:26:24 BST 2011jcifs.ntlmssp

Type1Message

public class Type1Message extends NtlmMessage
Represents an NTLMSSP Type-1 message.

Fields Summary
private static final int
DEFAULT_FLAGS
private static final String
DEFAULT_DOMAIN
private static final String
DEFAULT_WORKSTATION
private String
suppliedDomain
private String
suppliedWorkstation
Constructors Summary
public Type1Message()
Creates a Type-1 message using default values from the current environment.

        DEFAULT_FLAGS = NTLMSSP_NEGOTIATE_NTLM |
                (Config.getBoolean("jcifs.smb.client.useUnicode", true) ?
                        NTLMSSP_NEGOTIATE_UNICODE : NTLMSSP_NEGOTIATE_OEM);
        DEFAULT_DOMAIN = Config.getProperty("jcifs.smb.client.domain", null);
        String defaultWorkstation = null;
        try {
            defaultWorkstation = NbtAddress.getLocalHost().getHostName();
        } catch (UnknownHostException ex) { }
        DEFAULT_WORKSTATION = defaultWorkstation;
    
        this(getDefaultFlags(), getDefaultDomain(), getDefaultWorkstation());
    
public Type1Message(int flags, String suppliedDomain, String suppliedWorkstation)
Creates a Type-1 message with the specified parameters.

param
flags The flags to apply to this message.
param
suppliedDomain The supplied authentication domain.
param
suppliedWorkstation The supplied workstation name.

        setFlags(getDefaultFlags() | flags);
        setSuppliedDomain(suppliedDomain);
        if (suppliedWorkstation == null)
            suppliedWorkstation = getDefaultWorkstation();
        setSuppliedWorkstation(suppliedWorkstation);
    
public Type1Message(byte[] material)
Creates a Type-1 message using the given raw Type-1 material.

param
material The raw Type-1 material used to construct this message.
throws
IOException If an error occurs while parsing the material.

        parse(material);
    
Methods Summary
public static java.lang.StringgetDefaultDomain()
Returns the default domain from the current environment.

return
A String containing the default domain.

        return DEFAULT_DOMAIN;
    
public static intgetDefaultFlags()
Returns the default flags for a generic Type-1 message in the current environment.

return
An int containing the default flags.

        return DEFAULT_FLAGS;
    
public static java.lang.StringgetDefaultWorkstation()
Returns the default workstation from the current environment.

return
A String containing the default workstation.

        return DEFAULT_WORKSTATION;
    
public java.lang.StringgetSuppliedDomain()
Returns the supplied authentication domain.

return
A String containing the supplied domain.

        return suppliedDomain;
    
public java.lang.StringgetSuppliedWorkstation()
Returns the supplied workstation name.

return
A String containing the supplied workstation name.

        return suppliedWorkstation;
    
private voidparse(byte[] material)

        for (int i = 0; i < 8; i++) {
            if (material[i] != NTLMSSP_SIGNATURE[i]) {
                throw new IOException("Not an NTLMSSP message.");
            }
        }
        if (readULong(material, 8) != 1) {
            throw new IOException("Not a Type 1 message.");
        }
        int flags = readULong(material, 12);
        String suppliedDomain = null;
        if ((flags & NTLMSSP_NEGOTIATE_OEM_DOMAIN_SUPPLIED) != 0) {
            byte[] domain = readSecurityBuffer(material, 16);
            suppliedDomain = new String(domain, getOEMEncoding());
        }
        String suppliedWorkstation = null;
        if ((flags & NTLMSSP_NEGOTIATE_OEM_WORKSTATION_SUPPLIED) != 0) {
            byte[] workstation = readSecurityBuffer(material, 24);
            suppliedWorkstation = new String(workstation, getOEMEncoding());
        }
        setFlags(flags);
        setSuppliedDomain(suppliedDomain);
        setSuppliedWorkstation(suppliedWorkstation);
    
public voidsetSuppliedDomain(java.lang.String suppliedDomain)
Sets the supplied authentication domain for this message.

param
suppliedDomain The supplied domain for this message.

        this.suppliedDomain = suppliedDomain;
    
public voidsetSuppliedWorkstation(java.lang.String suppliedWorkstation)
Sets the supplied workstation name for this message.

param
suppliedWorkstation The supplied workstation for this message.

        this.suppliedWorkstation = suppliedWorkstation;
    
public byte[]toByteArray()

        try {
            String suppliedDomain = getSuppliedDomain();
            String suppliedWorkstation = getSuppliedWorkstation();
            int flags = getFlags();
            boolean hostInfo = false;
            byte[] domain = new byte[0];
            if (suppliedDomain != null && suppliedDomain.length() != 0) {
                hostInfo = true;
                flags |= NTLMSSP_NEGOTIATE_OEM_DOMAIN_SUPPLIED;
                domain = suppliedDomain.toUpperCase().getBytes(
                        getOEMEncoding());
            } else {
                flags &= (NTLMSSP_NEGOTIATE_OEM_DOMAIN_SUPPLIED ^ 0xffffffff);
            }
            byte[] workstation = new byte[0];
            if (suppliedWorkstation != null &&
                    suppliedWorkstation.length() != 0) {
                hostInfo = true;
                flags |= NTLMSSP_NEGOTIATE_OEM_WORKSTATION_SUPPLIED;
                workstation =
                        suppliedWorkstation.toUpperCase().getBytes(
                                getOEMEncoding());
            } else {
                flags &= (NTLMSSP_NEGOTIATE_OEM_WORKSTATION_SUPPLIED ^
                        0xffffffff);
            }
            byte[] type1 = new byte[hostInfo ?
                    (32 + domain.length + workstation.length) : 16];
            System.arraycopy(NTLMSSP_SIGNATURE, 0, type1, 0, 8);
            writeULong(type1, 8, 1);
            writeULong(type1, 12, flags);
            if (hostInfo) {
                writeSecurityBuffer(type1, 16, 32, domain);
                writeSecurityBuffer(type1, 24, 32 + domain.length, workstation);
            }
            return type1;
        } catch (IOException ex) {
            throw new IllegalStateException(ex.getMessage());
        }
    
public java.lang.StringtoString()

        String suppliedDomain = getSuppliedDomain();
        String suppliedWorkstation = getSuppliedWorkstation();
        return "Type1Message[suppliedDomain=" + (suppliedDomain == null ? "null" : suppliedDomain) +
                ",suppliedWorkstation=" + (suppliedWorkstation == null ? "null" : suppliedWorkstation) +
                ",flags=0x" + jcifs.util.Hexdump.toHexString(getFlags(), 8) + "]";