List of usage examples for org.apache.http.impl.auth NTLMEngineException NTLMEngineException
public NTLMEngineException(final String message, final Throwable cause)
From source file:ti.ntlm.JCIFSEngine.java
@Override public String generateType3Msg(final String username, final String password, final String domain, final String workstation, final String challenge) throws NTLMEngineException { Type2Message type2Message;/* w w w. j av a2s . c o m*/ try { type2Message = new Type2Message(Base64.decode(challenge)); } catch (final IOException exception) { throw new NTLMEngineException("Invalid NTLM type 2 message", exception); } final int type2Flags = type2Message.getFlags(); final int type3Flags = type2Flags & (0xffffffff ^ (NtlmFlags.NTLMSSP_TARGET_TYPE_DOMAIN | NtlmFlags.NTLMSSP_TARGET_TYPE_SERVER)); final Type3Message type3Message = new Type3Message(type2Message, password, domain, username, workstation, type3Flags); return Base64.encode(type3Message.toByteArray()); }
From source file:org.orbeon.oxf.resources.handler.JCIFSEngine.java
public String generateType3Msg(String username, String password, String domain, String workstation, String challenge) throws NTLMEngineException { Type2Message t2m;/*from ww w. jav a2 s.c o m*/ try { t2m = new Type2Message(Base64.decode(challenge)); } catch (IOException ex) { throw new NTLMEngineException("Invalid Type2 message", ex); } Type3Message t3m = new Type3Message(t2m, password, domain, username, workstation, 0); return Base64.encode(t3m.toByteArray()); }
From source file:io.cloudslang.content.httpclient.build.auth.JCIFSEngine.java
public String generateType3Msg(final String username, final String password, final String domain, final String workstation, final String challenge) throws NTLMEngineException { Type2Message type2Message;/*from ww w . ja v a 2s.c om*/ try { type2Message = new Type2Message(Base64.decode(challenge)); } catch (final IOException exception) { throw new NTLMEngineException("Invalid NTLM type 2 message", exception); } final int type2Flags = type2Message.getFlags(); final int type3Flags = type2Flags & (~(NtlmFlags.NTLMSSP_TARGET_TYPE_DOMAIN | NtlmFlags.NTLMSSP_TARGET_TYPE_SERVER)); final Type3Message type3Message = new Type3Message(type2Message, password, domain, username, workstation, type3Flags); return Base64.encode(type3Message.toByteArray()); }
From source file:com.mobilehelix.appserver.auth.JCIFSHttpClientEngine.java
@Override public String generateType3Msg(final String username, final String password, final String domain, final String workstation, final String challenge) throws NTLMEngineException { Type2Message type2Message;/*from www . j av a 2 s . c o m*/ try { type2Message = new Type2Message(Base64.decode(challenge)); } catch (final IOException exception) { throw new NTLMEngineException("Invalid NTLM type 2 message", exception); } final int type2Flags = type2Message.getFlags(); final int type3Flags = type2Flags & (0xffffffff ^ (NtlmFlags.NTLMSSP_TARGET_TYPE_DOMAIN | NtlmFlags.NTLMSSP_TARGET_TYPE_SERVER)); final Type3Message type3Message = new Type3Message(type2Message, password, domain, username, workstation, type3Flags); return Base64.encode(type3Message.toByteArray()); }
From source file:org.cleverbus.core.common.ws.transport.http.ntlm.JCIFSEngine.java
public String generateType3Msg(final String username, final String password, final String domain, final String workstation, final String challenge) throws NTLMEngineException { Type2Message type2Message;/*from w ww . j a v a2 s . c o m*/ try { type2Message = new Type2Message(Base64.decode(challenge)); } catch (final IOException exception) { throw new NTLMEngineException("Invalid NTLM type 2 message", exception); } final int type2Flags = type2Message.getFlags(); final int type3Flags = type2Flags & (0xffffffff ^ (NtlmFlags.NTLMSSP_TARGET_TYPE_DOMAIN | NtlmFlags.NTLMSSP_TARGET_TYPE_SERVER)); final Type3Message type3Message = new Type3Message(type2Message, password, domain, username, workstation, type3Flags); return Base64.encode(type3Message.toByteArray()); }
From source file:org.jasig.portlet.calendar.adapter.exchange.JCIFSEngine.java
public String generateType3Msg(final String username, final String password, final String domain, final String workstation, final String challenge) throws NTLMEngineException { if (log.isDebugEnabled()) { log.debug("Generating NTLM Type 3 message; username=" + username + ", password.length=" + password.length() + ", domain=" + domain + ", workstation=" + workstation + ", challenge=" + challenge);/*from w w w.j a va 2s .c om*/ } Type2Message type2Message; try { type2Message = new Type2Message(Base64.decode(challenge)); } catch (final IOException exception) { throw new NTLMEngineException("Invalid NTLM type 2 message", exception); } final int type2Flags = type2Message.getFlags(); final int type3Flags = type2Flags & (0xffffffff ^ (NtlmFlags.NTLMSSP_TARGET_TYPE_DOMAIN | NtlmFlags.NTLMSSP_TARGET_TYPE_SERVER)); final Type3Message type3Message = new Type3Message(type2Message, password, domain, username, workstation, type3Flags); return Base64.encode(type3Message.toByteArray()); }
From source file:com.anaplan.client.transport.JCIFSEngine.java
/** {@inheritDoc} */ @Override/*from ww w . ja v a 2 s .co m*/ public String generateType1Msg(String domain, String workstation) throws NTLMEngineException { try { Object type1Message = TYPE_1_MESSAGE.getConstructor(Integer.TYPE, String.class, String.class) .newInstance(TYPE_1_FLAGS, domain, workstation); byte[] byteArray = (byte[]) TYPE_1_MESSAGE.getMethod("toByteArray").invoke(type1Message); return (String) BASE64.getMethod("encode", byteArray.getClass()).invoke(null, byteArray); } catch (Exception thrown) { throw new NTLMEngineException("Failed to generate NTLM type 1 message", thrown); } }
From source file:be.nabu.libs.http.client.ntlm.NTLMEngineImpl.java
/** Calculates RC4 */ static byte[] RC4(final byte[] value, final byte[] key) throws NTLMEngineException { try {/*from w w w. j a v a 2 s . c om*/ final Cipher rc4 = Cipher.getInstance("RC4"); rc4.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(key, "RC4")); return rc4.doFinal(value); } catch (final Exception e) { throw new NTLMEngineException(e.getMessage(), e); } }
From source file:be.nabu.libs.http.client.ntlm.NTLMEngineImpl.java
/** * Calculates the NTLM2 Session Response for the given challenge, using the * specified password and client challenge. * * @return The NTLM2 Session Response. This is placed in the NTLM response * field of the Type 3 message; the LM response field contains the * client challenge, null-padded to 24 bytes. *//*from www .j a v a 2s .c om*/ static byte[] ntlm2SessionResponse(final byte[] ntlmHash, final byte[] challenge, final byte[] clientChallenge) throws NTLMEngineException { try { // Look up MD5 algorithm (was necessary on jdk 1.4.2) // This used to be needed, but java 1.5.0_07 includes the MD5 // algorithm (finally) // Class x = Class.forName("gnu.crypto.hash.MD5"); // Method updateMethod = x.getMethod("update",new // Class[]{byte[].class}); // Method digestMethod = x.getMethod("digest",new Class[0]); // Object mdInstance = x.newInstance(); // updateMethod.invoke(mdInstance,new Object[]{challenge}); // updateMethod.invoke(mdInstance,new Object[]{clientChallenge}); // byte[] digest = (byte[])digestMethod.invoke(mdInstance,new // Object[0]); final MessageDigest md5 = MessageDigest.getInstance("MD5"); md5.update(challenge); md5.update(clientChallenge); final byte[] digest = md5.digest(); final byte[] sessionHash = new byte[8]; System.arraycopy(digest, 0, sessionHash, 0, 8); return lmResponse(ntlmHash, sessionHash); } catch (final Exception e) { if (e instanceof NTLMEngineException) { throw (NTLMEngineException) e; } throw new NTLMEngineException(e.getMessage(), e); } }
From source file:be.nabu.libs.http.client.ntlm.NTLMEngineImpl.java
/** * Creates the LM Hash of the user's password. * * @param password/* www .j a va2s. c o m*/ * The password. * * @return The LM Hash of the given password, used in the calculation of the * LM Response. */ private static byte[] lmHash(final String password) throws NTLMEngineException { try { final byte[] oemPassword = password.toUpperCase(Locale.US).getBytes("US-ASCII"); final int length = Math.min(oemPassword.length, 14); final byte[] keyBytes = new byte[14]; System.arraycopy(oemPassword, 0, keyBytes, 0, length); final Key lowKey = createDESKey(keyBytes, 0); final Key highKey = createDESKey(keyBytes, 7); final byte[] magicConstant = "KGS!@#$%".getBytes("US-ASCII"); final Cipher des = Cipher.getInstance("DES/ECB/NoPadding"); des.init(Cipher.ENCRYPT_MODE, lowKey); final byte[] lowHash = des.doFinal(magicConstant); des.init(Cipher.ENCRYPT_MODE, highKey); final byte[] highHash = des.doFinal(magicConstant); final byte[] lmHash = new byte[16]; System.arraycopy(lowHash, 0, lmHash, 0, 8); System.arraycopy(highHash, 0, lmHash, 8, 8); return lmHash; } catch (final Exception e) { throw new NTLMEngineException(e.getMessage(), e); } }