src/java.base/share/classes/com/sun/security/ntlm/NTLM.java

Print this page


   1 /*
   2  * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  39 import javax.crypto.IllegalBlockSizeException;
  40 import javax.crypto.Mac;
  41 import javax.crypto.NoSuchPaddingException;
  42 import javax.crypto.SecretKey;
  43 import javax.crypto.SecretKeyFactory;
  44 import javax.crypto.spec.DESKeySpec;
  45 import javax.crypto.spec.SecretKeySpec;
  46 
  47 /**
  48  * NTLM authentication implemented according to MS-NLMP, version 12.1
  49  * @since 1.7
  50  */
  51 class NTLM {
  52 
  53     private final SecretKeyFactory fac;
  54     private final Cipher cipher;
  55     private final MessageDigest md4;
  56     private final Mac hmac;
  57     private final MessageDigest md5;
  58     private static final boolean DEBUG =
  59             System.getProperty("ntlm.debug") != null;


  60 
  61     final Version v;
  62 
  63     final boolean writeLM;
  64     final boolean writeNTLM;
  65 
  66     protected NTLM(String version) throws NTLMException {
  67         if (version == null) version = "LMv2/NTLMv2";
  68         switch (version) {
  69             case "LM": v = NTLM; writeLM = true; writeNTLM = false; break;
  70             case "NTLM": v = NTLM; writeLM = false; writeNTLM = true; break;
  71             case "LM/NTLM": v = NTLM; writeLM = writeNTLM = true; break;
  72             case "NTLM2": v = NTLM2; writeLM = writeNTLM = true; break;
  73             case "LMv2": v = NTLMv2; writeLM = true; writeNTLM = false; break;
  74             case "NTLMv2": v = NTLMv2; writeLM = false; writeNTLM = true; break;
  75             case "LMv2/NTLMv2": v = NTLMv2; writeLM = writeNTLM = true; break;
  76             default: throw new NTLMException(NTLMException.BAD_VERSION,
  77                     "Unknown version " + version);
  78         }
  79         try {


   1 /*
   2  * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  39 import javax.crypto.IllegalBlockSizeException;
  40 import javax.crypto.Mac;
  41 import javax.crypto.NoSuchPaddingException;
  42 import javax.crypto.SecretKey;
  43 import javax.crypto.SecretKeyFactory;
  44 import javax.crypto.spec.DESKeySpec;
  45 import javax.crypto.spec.SecretKeySpec;
  46 
  47 /**
  48  * NTLM authentication implemented according to MS-NLMP, version 12.1
  49  * @since 1.7
  50  */
  51 class NTLM {
  52 
  53     private final SecretKeyFactory fac;
  54     private final Cipher cipher;
  55     private final MessageDigest md4;
  56     private final Mac hmac;
  57     private final MessageDigest md5;
  58     private static final boolean DEBUG =
  59             java.security.AccessController.doPrivileged(
  60                     new sun.security.action.GetBooleanAction("ntlm.debug"))
  61                         .booleanValue();
  62 
  63     final Version v;
  64 
  65     final boolean writeLM;
  66     final boolean writeNTLM;
  67 
  68     protected NTLM(String version) throws NTLMException {
  69         if (version == null) version = "LMv2/NTLMv2";
  70         switch (version) {
  71             case "LM": v = NTLM; writeLM = true; writeNTLM = false; break;
  72             case "NTLM": v = NTLM; writeLM = false; writeNTLM = true; break;
  73             case "LM/NTLM": v = NTLM; writeLM = writeNTLM = true; break;
  74             case "NTLM2": v = NTLM2; writeLM = writeNTLM = true; break;
  75             case "LMv2": v = NTLMv2; writeLM = true; writeNTLM = false; break;
  76             case "NTLMv2": v = NTLMv2; writeLM = false; writeNTLM = true; break;
  77             case "LMv2/NTLMv2": v = NTLMv2; writeLM = writeNTLM = true; break;
  78             default: throw new NTLMException(NTLMException.BAD_VERSION,
  79                     "Unknown version " + version);
  80         }
  81         try {