#356: SmbEncrypt.java
projectforge-business/src/main/java/arlut/csd/crypto/SmbEncrypt.java Java class, projectforge-business/src/main/java/arlut/csd/crypto/SmbEncrypt.java 780 lines · 452 code · 170 comments · 158 blank
Purpose: Source file: arlut/csd/crypto/SmbEncrypt.java. SmbEncrypt.java is part of the ProjectForge open-source project management application.
Source (first 100 lines)
/*
smbencrypt.java
Created: 15 March 2001
Java Port By: Jonathan Abbey, jonabbey@arlut.utexas.edu
-----------------------------------------------------------------------
Based on smbencrypt.c and smbdes.c in Samba
Unix SMB/Netbios implementation.
Version 1.9.
a partial implementation of DES designed for use in the
SMB authentication protocol
Copyright (C) Andrew Tridgell 1998
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA
-----------------------------------------------------------------------
Ganymede Directory Management System
Copyright (C) 1996-2010
The University of Texas at Austin
Contact information
Web site: http://www.arlut.utexas.edu/gash2
Author Email: ganymede_author@arlut.utexas.edu
Email mailing list: ganymede@arlut.utexas.edu
US Mail:
Computer Science Division
Applied Research Laboratories
The University of Texas at Austin
PO Box 8029, Austin TX 78713-8029
Telephone: (512) 835-3200
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package arlut.csd.crypto;
/*------------------------------------------------------------------------------
class
smbencrypt
------------------------------------------------------------------------------*/
import java.util.Arrays;
/**
* <p>This Java class implements the two cryptographic hash methods used
* by SMB clients. In particular, the LANMANHash() and NTUNICODEHash()
* static methods in this class perform the two hashes required for Samba's
* encrypted password entries. As such, this class and the other classes
* in the broadly named arlut.csd.crypto package provide all the support
* functions necessary to allow Ganymede to manage Samba's password file.</p>
*
* <p>The following notes are from the original Samba source code for the
* smbdes.c module, which this module is adapted from.</p>
*
* <p>--------------------------------------------------</p>
*
* <p>Unix SMB/Netbios implementation.<br>
* Version 1.9.</p>
*
* <p>a partial implementation of DES designed for use in the
* SMB authentication protocol</p>
Git History
0050a24d9 String password -> char[] password. Not yet tested: LDAP client/master and change of Wlan-Password.
af35917ac More code cleanup
9ebb88522 Initial commit
0050a24d9
String password -> char[] password. Not yet tested: LDAP client/master and change of Wlan-Password.0050a24d94cf7b08c614508298c43974e84a25ac
diff --git a/projectforge-business/src/main/java/arlut/csd/crypto/SmbEncrypt.java b/projectforge-business/src/main/java/arlut/csd/crypto/SmbEncrypt.java
index c95f653ab..21aba9e57 100644
--- a/projectforge-business/src/main/java/arlut/csd/crypto/SmbEncrypt.java
+++ b/projectforge-business/src/main/java/arlut/csd/crypto/SmbEncrypt.java
@@ -78,6 +78,8 @@ package arlut.csd.crypto;
------------------------------------------------------------------------------*/
+import java.util.Arrays;
+
/**
* <p>This Java class implements the two cryptographic hash methods used
* by SMB clients. In particular, the LANMANHash() and NTUNICODEHash()
@@ -727,17 +729,18 @@ public class SmbEncrypt {
*
* <p>This method hashes the first 128 characters of the password,
* with full Unicode range and case preservation.</p>
+ *
+ * Refactored by Kai Reinhard for handling of char arrays.
+ *
+ * @param c_ary
+ * @return
*/
-
- public static String NTUNICODEHash(String password)
- {
- if (password.length() > 128)
+ public static String NTUNICODEHash(char[] c_ary) {
+ if (c_ary.length > 128)
{
- password = password.substring(0, 128);
+ c_ary = Arrays.copyOfRange(c_ary, 0, 128);
}
- final char c_ary[] = password.toCharArray();
-
// we need to simulate NT's little endian Unicode
// representation before we pass this to md4
@@ -771,7 +774,7 @@ public class SmbEncrypt {
}
System.err.println(LANMANHash(argv[0]));
- System.err.println(NTUNICODEHash(argv[0]));
+ System.err.println(NTUNICODEHash(argv[0].toCharArray()));
System.exit(0);
}
} af35917ac
More code cleanupaf35917ac240dadd71e1121f6e1e15d29e971aa9
diff --git a/projectforge-business/src/main/java/arlut/csd/crypto/SmbEncrypt.java b/projectforge-business/src/main/java/arlut/csd/crypto/SmbEncrypt.java
index ebb4b7f21..c95f653ab 100644
--- a/projectforge-business/src/main/java/arlut/csd/crypto/SmbEncrypt.java
+++ b/projectforge-business/src/main/java/arlut/csd/crypto/SmbEncrypt.java
@@ -277,9 +277,8 @@ public class SmbEncrypt {
out[i] = d[(i+count)%n];
}
- for (int i=0; i<n; i++)
- {
- d[i] = out[i];
+ if (n >= 0) {
+ System.arraycopy(out, 0, d, 0, n);
}
}
9ebb88522