com.sun.mail.auth.Ntlm类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(10.6k)|赞(0)|评价(0)|浏览(147)

本文整理了Java中com.sun.mail.auth.Ntlm类的一些代码示例,展示了Ntlm类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Ntlm类的具体详情如下:
包路径:com.sun.mail.auth.Ntlm
类名称:Ntlm

Ntlm介绍

[英]NTLMAuthentication:
[中]NTLM身份验证:

代码示例

代码示例来源:origin: com.sun.mail/javax.mail

String domain = props.getProperty(
  "mail." + name + ".auth.ntlm.domain", "");
Ntlm ntlm = new Ntlm(domain, getLocalHost(), u, p, logger);
    s = ntlm.generateType1Msg(flags);
    first = false;
    } else {
    s = ntlm.generateType3Msg(r.getRest());

代码示例来源:origin: com.sun.mail/javax.mail

copybytes(type3, l, ntdomain, "UnicodeLittleUnmarked");
  type3[32] = (byte) (l % 256);
  type3[33] = (byte) (l / 256);
  l += dlen;
  copybytes(type3, l, username, "UnicodeLittleUnmarked");
  type3[40] = (byte) (l % 256);
  type3[41] = (byte) (l / 256);
  l += ulen;
  copybytes(type3, l, hostname, "UnicodeLittleUnmarked");
  type3[48] = (byte) (l % 256);
  type3[49] = (byte) (l / 256);
  l += hlen;
  byte[] lmhash = calcLMHash();
  byte[] lmresponse = calcResponse(lmhash, nonce);
  byte[] nthash = calcNTHash();
  byte[] ntresponse = calcResponse(nthash, nonce);
  System.arraycopy(lmresponse, 0, type3, l, 24);
  type3[16] = (byte) (l % 256);
  System.arraycopy(type3, 0, msg, 0, l);
if (logger.isLoggable(Level.FINE))
  logger.fine("type 3 message: " + toHex(msg));

代码示例来源:origin: camunda/camunda-bpm-platform

this.password = password;
this.logger = logger.getLogger(this.getClass(), "DEBUG NTLM");
  init0();

代码示例来源:origin: camunda/camunda-bpm-platform

public String generateType1Msg(int flags) {
// XXX - should set "flags" in generated message
  int dlen = ntdomain.length();
  type1[16]= (byte) (dlen % 256);
  type1[17]= (byte) (dlen / 256);
  type1[18] = type1[16];
  type1[19] = type1[17];
if (dlen == 0)
  type1[13] &= ~0x10;
  int hlen = hostname.length();
  type1[24]= (byte) (hlen % 256);
  type1[25]= (byte) (hlen / 256);
  type1[26] = type1[24];
  type1[27] = type1[25];
  copybytes(type1, 32, hostname, "iso-8859-1");
  copybytes(type1, hlen+32, ntdomain, "iso-8859-1");
  type1[20] = (byte) ((hlen+32) % 256);
  type1[21] = (byte) ((hlen+32) / 256);
  byte[] msg = new byte[32 + hlen + dlen];
  System.arraycopy(type1, 0, msg, 0, 32 + hlen + dlen);
if (logger.isLoggable(Level.FINE))
  logger.fine("type 1 message: " + toHex(msg));
  String result = null;
try {
  result = new String(BASE64EncoderStream.encode(msg), "iso-8859-1");
  } catch (UnsupportedEncodingException e) {
    assert false;
  }
  return result;
}

代码示例来源:origin: com.sun.mail/javax.mail

@Override
String getInitialResponse(String host, String authzid, String user,
  String passwd) throws MessagingException, IOException {
  ntlm = new Ntlm(getNTLMDomain(), getLocalHost(),
      user, passwd, logger);
  flags = PropUtil.getIntProperty(
    session.getProperties(),
    "mail." + name + ".auth.ntlm.flags", 0);
  String type1 = ntlm.generateType1Msg(flags);
  return type1;
}

代码示例来源:origin: camunda/camunda-bpm-platform

private byte[] calcResponse(byte[] key, byte[] text)
      throws GeneralSecurityException {
  assert key.length == 21;
  DESKeySpec dks1 = new DESKeySpec(makeDesKey(key, 0));
  DESKeySpec dks2 = new DESKeySpec(makeDesKey(key, 7));
  DESKeySpec dks3 = new DESKeySpec(makeDesKey(key, 14));
  SecretKey key1 = fac.generateSecret(dks1);
  SecretKey key2 = fac.generateSecret(dks2);
  SecretKey key3 = fac.generateSecret(dks3);
  cipher.init(Cipher.ENCRYPT_MODE, key1);
  byte[] out1 = cipher.doFinal(text, 0, 8);
  cipher.init(Cipher.ENCRYPT_MODE, key2);
  byte[] out2 = cipher.doFinal(text, 0, 8);
  cipher.init(Cipher.ENCRYPT_MODE, key3);
  byte[] out3 = cipher.doFinal(text, 0, 8);
  byte[] result = new byte[24];
  System.arraycopy(out1, 0, result, 0, 8);
  System.arraycopy(out2, 0, result, 8, 8);
  System.arraycopy(out3, 0, result, 16, 8);
  return result;
}

代码示例来源:origin: camunda/camunda-bpm-platform

void doAuth(String host, String authzid, String user, String passwd)
  throws MessagingException, IOException {
  assert ntlm != null;
  String type3 = ntlm.generateType3Msg(
    getLastServerResponse().substring(4).trim());
  resp = simpleCommand(type3);
}
}

代码示例来源:origin: camunda/camunda-bpm-platform

String getInitialResponse(String host, String authzid, String user,
  String passwd) throws MessagingException, IOException {
  ntlm = new Ntlm(getNTLMDomain(), getLocalHost(),
      user, passwd, logger);
  flags = PropUtil.getIntProperty(
    session.getProperties(),
    "mail." + name + ".auth.ntlm.flags", 0);
  String type1 = ntlm.generateType1Msg(flags);
  return type1;
}

代码示例来源:origin: com.sun.mail/javax.mail

public String generateType1Msg(int flags) {
// XXX - should set "flags" in generated message
  int dlen = ntdomain.length();
  type1[16]= (byte) (dlen % 256);
  type1[17]= (byte) (dlen / 256);
  type1[18] = type1[16];
  type1[19] = type1[17];
if (dlen == 0)
  type1[13] &= ~0x10;
  int hlen = hostname.length();
  type1[24]= (byte) (hlen % 256);
  type1[25]= (byte) (hlen / 256);
  type1[26] = type1[24];
  type1[27] = type1[25];
  copybytes(type1, 32, hostname, "iso-8859-1");
  copybytes(type1, hlen+32, ntdomain, "iso-8859-1");
  type1[20] = (byte) ((hlen+32) % 256);
  type1[21] = (byte) ((hlen+32) / 256);
  byte[] msg = new byte[32 + hlen + dlen];
  System.arraycopy(type1, 0, msg, 0, 32 + hlen + dlen);
if (logger.isLoggable(Level.FINE))
  logger.fine("type 1 message: " + toHex(msg));
  String result = null;
try {
  result = new String(BASE64EncoderStream.encode(msg), "iso-8859-1");
  } catch (UnsupportedEncodingException e) {
    assert false;
  }
  return result;
}

代码示例来源:origin: com.sun.mail/javax.mail

private byte[] calcResponse(byte[] key, byte[] text)
      throws GeneralSecurityException {
  assert key.length == 21;
  DESKeySpec dks1 = new DESKeySpec(makeDesKey(key, 0));
  DESKeySpec dks2 = new DESKeySpec(makeDesKey(key, 7));
  DESKeySpec dks3 = new DESKeySpec(makeDesKey(key, 14));
  SecretKey key1 = fac.generateSecret(dks1);
  SecretKey key2 = fac.generateSecret(dks2);
  SecretKey key3 = fac.generateSecret(dks3);
  cipher.init(Cipher.ENCRYPT_MODE, key1);
  byte[] out1 = cipher.doFinal(text, 0, 8);
  cipher.init(Cipher.ENCRYPT_MODE, key2);
  byte[] out2 = cipher.doFinal(text, 0, 8);
  cipher.init(Cipher.ENCRYPT_MODE, key3);
  byte[] out3 = cipher.doFinal(text, 0, 8);
  byte[] result = new byte[24];
  System.arraycopy(out1, 0, result, 0, 8);
  System.arraycopy(out2, 0, result, 8, 8);
  System.arraycopy(out3, 0, result, 16, 8);
  return result;
}

代码示例来源:origin: com.sun.mail/javax.mail

@Override
void doAuth(String host, String authzid, String user, String passwd)
  throws MessagingException, IOException {
  assert ntlm != null;
  String type3 = ntlm.generateType3Msg(
    getLastServerResponse().substring(4).trim());
  resp = simpleCommand(type3);
}
}

代码示例来源:origin: camunda/camunda-bpm-platform

copybytes(type3, l, ntdomain, "UnicodeLittleUnmarked");
  type3[32] = (byte) (l % 256);
  type3[33] = (byte) (l / 256);
  l += dlen;
  copybytes(type3, l, username, "UnicodeLittleUnmarked");
  type3[40] = (byte) (l % 256);
  type3[41] = (byte) (l / 256);
  l += ulen;
  copybytes(type3, l, hostname, "UnicodeLittleUnmarked");
  type3[48] = (byte) (l % 256);
  type3[49] = (byte) (l / 256);
  l += hlen;
  byte[] lmhash = calcLMHash();
  byte[] lmresponse = calcResponse(lmhash, nonce);
  byte[] nthash = calcNTHash();
  byte[] ntresponse = calcResponse(nthash, nonce);
  System.arraycopy(lmresponse, 0, type3, l, 24);
  type3[16] = (byte) (l % 256);
  System.arraycopy(type3, 0, msg, 0, l);
if (logger.isLoggable(Level.FINE))
  logger.fine("type 3 message: " + toHex(msg));

代码示例来源:origin: camunda/camunda-bpm-platform

String domain = props.getProperty(
  "mail." + name + ".auth.ntlm.domain", "");
Ntlm ntlm = new Ntlm(domain, getLocalHost(), u, p, logger);
    s = ntlm.generateType1Msg(flags);
    first = false;
    } else {
    s = ntlm.generateType3Msg(r.getRest());

代码示例来源:origin: javax.mail/com.springsource.javax.mail

String getInitialResponse(String host, String authzid, String user,
  String passwd) throws MessagingException, IOException {
  ntlm = new Ntlm(getNTLMDomain(), getLocalHost(),
      user, passwd, debug ? out : null);
  flags = PropUtil.getIntProperty(
    session.getProperties(),
    "mail." + name + ".auth.ntlm.flags", 0);
  String type1 = ntlm.generateType1Msg(flags);
  return type1;
}

代码示例来源:origin: javax.mail/com.springsource.javax.mail

public String generateType1Msg(int flags) {
// XXX - should set "flags" in generated message
  int dlen = ntdomain.length();
  type1[16]= (byte) (dlen % 256);
  type1[17]= (byte) (dlen / 256);
  type1[18] = type1[16];
  type1[19] = type1[17];
if (dlen == 0)
  type1[13] &= ~0x10;
  int hlen = hostname.length();
  type1[24]= (byte) (hlen % 256);
  type1[25]= (byte) (hlen / 256);
  type1[26] = type1[24];
  type1[27] = type1[25];
  copybytes(type1, 32, hostname, "iso-8859-1");
  copybytes(type1, hlen+32, ntdomain, "iso-8859-1");
  type1[20] = (byte) ((hlen+32) % 256);
  type1[21] = (byte) ((hlen+32) / 256);
  byte[] msg = new byte[32 + hlen + dlen];
  System.arraycopy(type1, 0, msg, 0, 32 + hlen + dlen);
if (debugout != null)
  debugout.println("DEBUG NTLM: type 1 message: " + toHex(msg));
  String result = null;
try {
  result = new String(BASE64EncoderStream.encode(msg), "iso-8859-1");
  } catch (UnsupportedEncodingException e) {
    assert false;
  }
  return result;
}

代码示例来源:origin: com.sun.mail/javax.mail

private byte[] calcLMHash() throws GeneralSecurityException {
  byte[] magic = {0x4b, 0x47, 0x53, 0x21, 0x40, 0x23, 0x24, 0x25};
  byte[] pwb = null;
try {
  pwb = password.toUpperCase(Locale.ENGLISH).getBytes("iso-8859-1");
} catch (UnsupportedEncodingException ex) {
  // should never happen
  assert false;
}
  byte[] pwb1 = new byte[14];
  int len = password.length();
  if (len > 14)
    len = 14;
  System.arraycopy(pwb, 0, pwb1, 0, len); /* Zero padded */
  DESKeySpec dks1 = new DESKeySpec(makeDesKey(pwb1, 0));
  DESKeySpec dks2 = new DESKeySpec(makeDesKey(pwb1, 7));
  SecretKey key1 = fac.generateSecret(dks1);
  SecretKey key2 = fac.generateSecret(dks2);
  cipher.init(Cipher.ENCRYPT_MODE, key1);
  byte[] out1 = cipher.doFinal(magic, 0, 8);
  cipher.init(Cipher.ENCRYPT_MODE, key2);
  byte[] out2 = cipher.doFinal(magic, 0, 8);
  byte[] result = new byte [21];
  System.arraycopy(out1, 0, result, 0, 8);
  System.arraycopy(out2, 0, result, 8, 8);
  return result;
}

代码示例来源:origin: org.glassfish.metro/webservices-extra

@Override
void doAuth(String host, String authzid, String user, String passwd)
  throws MessagingException, IOException {
  assert ntlm != null;
  String type3 = ntlm.generateType3Msg(
    getLastServerResponse().substring(4).trim());
  resp = simpleCommand(type3);
}
}

代码示例来源:origin: com.sun.mail/javax.mail

this.password = password;
this.logger = logger.getLogger(this.getClass(), "DEBUG NTLM");
  init0();

代码示例来源:origin: javax.mail/com.springsource.javax.mail

copybytes(type3, l, ntdomain, "UnicodeLittleUnmarked");
  type3[32] = (byte) (l % 256);
  type3[33] = (byte) (l / 256);
  l += dlen;
  copybytes(type3, l, username, "UnicodeLittleUnmarked");
  type3[40] = (byte) (l % 256);
  type3[41] = (byte) (l / 256);
  l += ulen;
  copybytes(type3, l, hostname, "UnicodeLittleUnmarked");
  type3[48] = (byte) (l % 256);
  type3[49] = (byte) (l / 256);
  l += hlen;
  byte[] lmhash = calcLMHash();
  byte[] lmresponse = calcResponse(lmhash, nonce);
  byte[] nthash = calcNTHash();
  byte[] ntresponse = calcResponse(nthash, nonce);
  System.arraycopy(lmresponse, 0, type3, l, 24);
  type3[16] = (byte) (l % 256);
  System.arraycopy(type3, 0, msg, 0, l);
if (debugout != null)
  debugout.println("DEBUG NTLM: type 3 message: " + toHex(msg));

代码示例来源:origin: javax.mail/com.springsource.javax.mail

String domain = props.getProperty(
  "mail." + name + ".auth.ntlm.domain", "");
Ntlm ntlm = new Ntlm(domain, getLocalHost(), u, p, debug ? out : null);
    s = ntlm.generateType1Msg(flags);
    first = false;
    } else {
    s = ntlm.generateType3Msg(r.getRest());

相关文章