public String[] verify(byte[] type3,byte[] nonce) throws NTLMException {
  if (type3 == null || nonce == null) {
    throw new NTLMException(NTLMException.PROTOCOL,"type1 or nonce cannot be null");
  }
  debug("NTLM Server: Type 3 received\n");
  if (type3 != null)   debug(type3);
  Reader r=new Reader(type3);
  String username=r.readSecurityBuffer(36,true);
  String hostname=r.readSecurityBuffer(44,true);
  String incomingDomain=r.readSecurityBuffer(28,true);
  boolean verified=false;
  char[] password=getPassword(incomingDomain,username);
  if (password == null) {
    throw new NTLMException(NTLMException.USER_UNKNOWN,"Unknown user");
  }
  byte[] incomingLM=r.readSecurityBuffer(12);
  byte[] incomingNTLM=r.readSecurityBuffer(20);
  if (!verified && (allVersion || v == Version.NTLM)) {
    if (incomingLM.length > 0) {
      byte[] pw1=getP1(password);
      byte[] lmhash=calcLMHash(pw1);
      byte[] lmresponse=calcResponse(lmhash,nonce);
      if (Arrays.equals(lmresponse,incomingLM)) {
        verified=true;
      }
    }
    if (incomingNTLM.length > 0) {
      byte[] pw2=getP2(password);
      byte[] nthash=calcNTHash(pw2);
      byte[] ntresponse=calcResponse(nthash,nonce);
      if (Arrays.equals(ntresponse,incomingNTLM)) {
        verified=true;
      }
    }
    debug("NTLM Server: verify using NTLM: " + verified + "\n");
  }
  if (!verified && (allVersion || v == Version.NTLM2)) {
    byte[] pw2=getP2(password);
    byte[] nthash=calcNTHash(pw2);
    byte[] clientNonce=Arrays.copyOf(incomingLM,8);
    byte[] ntlmresponse=ntlm2NTLM(nthash,clientNonce,nonce);
    if (Arrays.equals(incomingNTLM,ntlmresponse)) {
      verified=true;
    }
    debug("NTLM Server: verify using NTLM2: " + verified + "\n");
  }
  if (!verified && (allVersion || v == Version.NTLMv2)) {
    byte[] pw2=getP2(password);
    byte[] nthash=calcNTHash(pw2);
    if (incomingLM.length > 0) {
      byte[] clientNonce=Arrays.copyOfRange(incomingLM,16,incomingLM.length);
      byte[] lmresponse=calcV2(nthash,username.toUpperCase(Locale.US) + incomingDomain,clientNonce,nonce);
      if (Arrays.equals(lmresponse,incomingLM)) {
        verified=true;
      }
    }
    if (incomingNTLM.length > 0) {
      byte[] clientBlob=Arrays.copyOfRange(incomingNTLM,16,incomingNTLM.length);
      byte[] ntlmresponse=calcV2(nthash,username.toUpperCase(Locale.US) + incomingDomain,clientBlob,nonce);
      if (Arrays.equals(ntlmresponse,incomingNTLM)) {
        verified=true;
      }
    }
    debug("NTLM Server: verify using NTLMv2: " + verified + "\n");
  }
  if (!verified) {
    throw new NTLMException(NTLMException.AUTH_FAILED,"None of LM and NTLM verified");
  }
  return new String[]{username,hostname,incomingDomain};
}

public String [ ] verify ( byte [ ] type3 , byte [ ] nonce ) throws NTLMException { if ( type3 == null || nonce == null ) { throw new NTLMException ( NTLMException . PROTOCOL , "type1 or nonce cannot be null" ) ; } debug ( "NTLM Server: Type 3 received\n" ) ; if ( type3 != null ) debug ( type3 ) ; Reader r = new Reader ( type3 ) ; String username = r . readSecurityBuffer ( 36 , true ) ; String hostname = r . readSecurityBuffer ( 44 , true ) ; String incomingDomain = r . readSecurityBuffer ( 28 , true ) ; boolean verified = false ; char [ ] password = getPassword ( incomingDomain , username ) ; if ( password == null ) { throw new NTLMException ( NTLMException . USER_UNKNOWN , "Unknown user" ) ; } byte [ ] incomingLM = r . readSecurityBuffer ( 12 ) ; byte [ ] incomingNTLM = r . readSecurityBuffer ( 20 ) ; if ( ! verified && ( allVersion || v == Version . NTLM ) ) { if ( incomingLM . length > 0 ) { byte [ ] pw1 = getP1 ( password ) ; byte [ ] lmhash = calcLMHash ( pw1 ) ; byte [ ] lmresponse = calcResponse ( lmhash , nonce ) ; if ( Arrays . equals ( lmresponse , incomingLM ) ) { verified = true ; } } if ( incomingNTLM . length > 0 ) { byte [ ] pw2 = getP2 ( password ) ; byte [ ] nthash = calcNTHash ( pw2 ) ; byte [ ] ntresponse = calcResponse ( nthash , nonce ) ; if ( Arrays . equals ( ntresponse , incomingNTLM ) ) { verified = true ; } } debug ( "NTLM Server: verify using NTLM: " + verified + "\n" ) ; } if ( ! verified && ( allVersion || v == Version . NTLM2 ) ) { byte [ ] pw2 = getP2 ( password ) ; byte [ ] nthash = calcNTHash ( pw2 ) ; byte [ ] clientNonce = Arrays . copyOf ( incomingLM , 8 ) ; byte [ ] ntlmresponse = ntlm2NTLM ( nthash , clientNonce , nonce ) ; if ( Arrays . equals ( incomingNTLM , ntlmresponse ) ) { verified = true ; } debug ( "NTLM Server: verify using NTLM2: " + verified + "\n" ) ; } if ( ! verified && ( allVersion || v == Version . NTLMv2 ) ) { byte [ ] pw2 = getP2 ( password ) ; byte [ ] nthash = calcNTHash ( pw2 ) ; if ( incomingLM . length > 0 ) { byte [ ] clientNonce = Arrays . copyOfRange ( incomingLM , 16 , incomingLM . length ) ; byte [ ] lmresponse = calcV2 ( nthash , username . toUpperCase ( Locale . US ) + incomingDomain , clientNonce , nonce ) ; if ( Arrays . equals ( lmresponse , incomingLM ) ) { verified = true ; } } if ( incomingNTLM . length > 0 ) { byte [ ] clientBlob = Arrays . copyOfRange ( incomingNTLM , 16 , incomingNTLM . length ) ; byte [ ] ntlmresponse = calcV2 ( nthash , username . toUpperCase ( Locale . US ) + incomingDomain , clientBlob , nonce ) ; if ( Arrays . equals ( ntlmresponse , incomingNTLM ) ) { verified = true ; } } debug ( "NTLM Server: verify using NTLMv2: " + verified + "\n" ) ; } if ( ! verified ) { throw new NTLMException ( NTLMException . AUTH_FAILED , "None of LM and NTLM verified" ) ; } return new String [ ] { username , hostname , incomingDomain } ; }
verifies the type3 message received from client and returns various negotiated information .
