Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 20 additions & 20 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,31 +86,31 @@ prependPathIfDirExists $LOGR_SUPPORT_DIR/java/$LOGR_HOST_ARCH/bin
prependPathIfDirExists $LOGR_SUPPORT_DIR/ant/bin
prependPathIfDirExists $LOGR_SUPPORT_DIR/netbeans/currentNetbeans/bin
prependPathIfDirExists $LOGR_ROOT_DIR/bin
prependPathIfDirExists $LOGR_SUPPORT_DIR/anaconda/$LOGR_HOST_ARCH/bin
#prependPathIfDirExists $LOGR_SUPPORT_DIR/anaconda/$LOGR_HOST_ARCH/bin
prependPathIfDirExists $LOGR_SUPPORT_DIR/netbeans/currentNetbeans/java/maven/bin
prependPathIfDirExists $LOGR_ROOT_DIR/tools/developer_tools/portal_testing/PythonSeleniumTest/support_bin

mysqlPath=$LOGR_SUPPORT_DIR/mysql/$LOGR_HOST_ARCH
if [ -d $mysqlPath ]; then
cd $mysqlPath
pythonDir=`pwd`
export PATH=`pwd`/bin:$PATH
export LD_LIBRARY_PATH=`pwd`/lib:$LD_LIBRARY_PATH
fi
#mysqlPath=$LOGR_SUPPORT_DIR/mysql/$LOGR_HOST_ARCH
#if [ -d $mysqlPath ]; then
# cd $mysqlPath
# pythonDir=`pwd`
# export PATH=`pwd`/bin:$PATH
# export LD_LIBRARY_PATH=`pwd`/lib:$LD_LIBRARY_PATH
#fi

# Check if we have local python
if [ -z $LOGR_PYTHON_DIR ]; then
pythonDir=$LOGR_SUPPORT_DIR/python/$LOGR_HOST_ARCH
else
pythonDir=$LOGR_PYTHON_DIR
fi
if [ -d $pythonDir ]; then
cd $pythonDir
pythonDir=`pwd`
export PATH=`pwd`/bin:$PATH
export LD_LIBRARY_PATH=`pwd`/lib:$LD_LIBRARY_PATH
export LOGR_PYTHON_DIR=$pythonDir
fi
#if [ -z $LOGR_PYTHON_DIR ]; then
# pythonDir=$LOGR_SUPPORT_DIR/python/$LOGR_HOST_ARCH
#else
# pythonDir=$LOGR_PYTHON_DIR
#fi
#if [ -d $pythonDir ]; then
# cd $pythonDir
# pythonDir=`pwd`
# export PATH=`pwd`/bin:$PATH
# export LD_LIBRARY_PATH=`pwd`/lib:$LD_LIBRARY_PATH
# export LOGR_PYTHON_DIR=$pythonDir
#fi

if [ -z $PYTHONPATH ]; then
PYTHONPATH=$LOGR_ROOT_DIR/src/python
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* See LICENSE file.
*/
package gov.anl.aps.logr.common.utilities;

import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.spec.InvalidKeySpecException;
Expand All @@ -13,16 +12,17 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.Base64;
import java.util.Arrays;

/**
* Utility class for encrypting and verifying passwords.
*/
public class CryptUtility {
public class CryptUtility{

private static final String SecretKeyFactoryType = "PBKDF2WithHmacSHA1";
private static final int Pbkdf2Iterations = 1003;
private static final int Pbkdf2KeyLengthInBits = 192;
private static final int SaltLengthInBytes = 4;
private static final String SecretKeyFactoryType = "PBKDF2WithHmacSHA512";
private static final int Pbkdf2Iterations = 25000;
private static final int Pbkdf2KeyLengthInBits = 512;
private static final int SaltLengthInBytes = 16;
private static final char[] SaltCharset = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".toCharArray();
private static final String SaltDelimiter = "$";

Expand Down Expand Up @@ -88,14 +88,75 @@ public static String saltAndCryptPasswordWithPbkdf2(String password, String salt
key = SecretKeyFactory.getInstance(SecretKeyFactoryType);
byte[] hashedPassword = key.generateSecret(spec).getEncoded();
String encodedPassword = Base64.getEncoder().encodeToString(hashedPassword);
return salt + SaltDelimiter + encodedPassword;
String encodedSalt = Base64.getEncoder().encodeToString(saltBytes);
return SaltDelimiter+"pbkdf2-sha512"+SaltDelimiter+"25000"+SaltDelimiter+encodedSalt + SaltDelimiter + encodedPassword;
} catch (NoSuchAlgorithmException | InvalidKeySpecException ex) {
// Should not happen
logger.error("Password cannot be crypted: " + ex);
}
return null;
}

/**
* Apply salt string and encrypt password using PBKDF2 standard.
*
* @param password input password
* @param salt salt string
* @return encrypted password
*/
public static String OnlyCryptPasswordWithPbkdf2(String password, String salt) {
char[] passwordChars = password.toCharArray();
byte[] saltBytes = (Base64.getDecoder().decode(salt));
// byte[] saltBytes = salt.getBytes();
// logger.error("calling OnlyCryp...: " + password + "."+salt);
PBEKeySpec spec = new PBEKeySpec(
passwordChars,
saltBytes,
Pbkdf2Iterations,
Pbkdf2KeyLengthInBits
);
SecretKeyFactory key;
try {
key = SecretKeyFactory.getInstance(SecretKeyFactoryType);
byte[] hashedPassword = key.generateSecret(spec).getEncoded();
String encodedPassword = Base64.getEncoder().encodeToString(hashedPassword);
return encodedPassword;
} catch (NoSuchAlgorithmException | InvalidKeySpecException ex) {
// Should not happen
logger.error("Password cannot be crypted: " + ex);
}
return null;
}

public static String OnlyCryptPasswordWithSHA1(String password, String salt) {
char[] passwordChars = password.toCharArray();
byte[] saltBytes = salt.getBytes();
String SecretKeyFactoryType1 = "PBKDF2WithHmacSHA1";
int Pbkdf2Iterations1 = 1003;
int Pbkdf2KeyLengthInBits1 = 192;
int SaltLengthInBytes1 = 4;
// logger.error("calling OnlyCryp..SHA1.: " + password + "."+salt);

PBEKeySpec spec = new PBEKeySpec(
passwordChars,
saltBytes,
Pbkdf2Iterations1,
Pbkdf2KeyLengthInBits1
);
SecretKeyFactory key;
try {
key = SecretKeyFactory.getInstance(SecretKeyFactoryType1);
byte[] hashedPassword = key.generateSecret(spec).getEncoded();
String encodedPassword = Base64.getEncoder().encodeToString(hashedPassword);
return encodedPassword;
} catch (NoSuchAlgorithmException | InvalidKeySpecException ex) {
// Should not happen
logger.error("Password cannot be crypted: " + ex);
}
return null;
}


/**
* Verify encrypted password.
*
Expand All @@ -104,9 +165,33 @@ public static String saltAndCryptPasswordWithPbkdf2(String password, String salt
* @return true if passwords match, false otherwise
*/
public static boolean verifyPasswordWithPbkdf2(String password, String cryptedPassword) {
int saltEnd = cryptedPassword.indexOf(SaltDelimiter);
String salt = cryptedPassword.substring(0, saltEnd);
return cryptedPassword.equals(saltAndCryptPasswordWithPbkdf2(password, salt));
int saltBegin, saltEnd,i;
// added to make it compatible with old stored password
saltBegin=cryptedPassword.indexOf(SaltDelimiter);
String salt, pw, epw;
// logger.error("calling verify..:"+saltBegin );
if( saltBegin!=0 ) //Old password
{
salt=cryptedPassword.substring(0,saltBegin);
pw=cryptedPassword.substring(saltBegin+1);
epw=OnlyCryptPasswordWithSHA1(password,salt);
// logger.error("salt1:"+salt + " hash$" + pw + "new: " + epw );
}
//
else {
saltBegin=1;
for (i=0;i<2;i++)
saltBegin = cryptedPassword.indexOf(SaltDelimiter,saltBegin) + 1;
saltEnd = cryptedPassword.indexOf(SaltDelimiter,saltBegin);

// logger.error("password:"+cryptedPassword + " begin/end:" + saltBegin + "/ " +saltEnd);
salt = cryptedPassword.substring(saltBegin, saltEnd);
pw=cryptedPassword.substring(saltEnd+1);
// logger.error("saltend:"+,saltEnd+ "T",saltBegin + pw)
epw=OnlyCryptPasswordWithPbkdf2(password, salt);
// logger.error("salt2:"+salt + " hash$" + pw + "new: " + epw );
}
return pw.equals(epw);
}

/*
Expand All @@ -115,10 +200,11 @@ public static boolean verifyPasswordWithPbkdf2(String password, String cryptedPa
* @param args main arguments
*/
public static void main(String[] args) {
String password = "cdb";
String password = args[0];
System.out.println("Original password: " + password);
String cryptedPassword = cryptPasswordWithPbkdf2(password);
System.out.println("Crypted password: " + cryptedPassword);
System.out.println("Verified: " + verifyPasswordWithPbkdf2(password, cryptedPassword));

}
}
2 changes: 1 addition & 1 deletion src/python/cdb/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "3.5.0.DEV (2018.07.16)"
__version__ = "4.0.0.DEV (2026.08.19)"
12 changes: 6 additions & 6 deletions src/python/cdb/cdb_web_service/api/fileSystemRestApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ def getDirectoryList(self, path):
url = '%s/directories/%s?parentDirectory=%s' % (self.getContextRoot(), directoryName, parentDirectory)
responseDict = self.sendRequest(url=url, method='GET')
return responseDict
except CdbException, ex:
except CdbException as ex:
raise
except Exception, ex:
except Exception as ex:
self.getLogger().exception('%s' % ex)
raise CdbException(exception=ex)

Expand All @@ -40,9 +40,9 @@ def writeFile(self, path, content):
url = '%s/files/%s?parentDirectory=%s&encodedFileContent=%s' % (self.getContextRoot(), fileName, parentDirectory, encodedFileContent)
responseDict = self.sendSessionRequest(url=url, method='POST')
return responseDict
except CdbException, ex:
except CdbException as ex:
raise
except Exception, ex:
except Exception as ex:
self.getLogger().exception('%s' % ex)
raise CdbException(exception=ex)

Expand All @@ -52,8 +52,8 @@ def writeFile(self, path, content):
if __name__ == '__main__':
#api = FileSystemRestApi('sveseli', 'sveseli', 'zagreb.svdev.net', 10232, 'https')
api = FileSystemRestApi('sveseli', 'sveseli', 'zagreb.svdev.net', 10232, 'http')
print api.getDirectoryList('/home/sveseli')
print api.writeFile('/tmp/xyz', 'Hi there, qweqweqsad \dsdd')
print( api.getDirectoryList('/home/sveseli'))
print( api.writeFile('/tmp/xyz', 'Hi there, qweqweqsad \dsdd'))



2 changes: 1 addition & 1 deletion src/python/cdb/cdb_web_service/api/userRestApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def getUserGroupByName(self, groupName):
api = UserRestApi('sveseli', 'sveseli', 'zagreb.svdev.net', 10232, 'http')
userGroups = api.getUserGroups()
for userGroup in userGroups:
print userGroup.getDisplayString()
print( userGroup.getDisplayString())



Expand Down
2 changes: 1 addition & 1 deletion src/python/cdb/cdb_web_service/cli/addItemLogEntryCli.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def runCommand(self):
else:
log = api.addLogEntryToItemWithQrId(self.getQrId(), self.getLogEntry(), self.getAttachment())

print log.getDisplayString(self.getDisplayKeys(), self.getDisplayFormat())
print( log.getDisplayString(self.getDisplayKeys(), self.getDisplayFormat()))

#######################################################################
# Run command.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def runCommand(self):

propertyValue = api.addPropertyValueToItemWithId(self.getItemId(), self.getPropertyTypeName(), value=self.getValue(), displayValue=self.getDisplayValue())

print propertyValue.getDisplayString(self.getDisplayKeys(), self.getDisplayFormat())
print( propertyValue.getDisplayString(self.getDisplayKeys(), self.getDisplayFormat()))

#######################################################################
# Run command.
Expand Down
2 changes: 1 addition & 1 deletion src/python/cdb/cdb_web_service/cli/addLogAttachmentCli.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def runCommand(self):

logAttachment = api.addLogAttachment(self.getLogId(), self.getAttachment(), self.getAttachmentDescription())

print logAttachment.getDisplayString(self.getDisplayKeys(), self.getDisplayFormat())
print( logAttachment.getDisplayString(self.getDisplayKeys(), self.getDisplayFormat()))

#######################################################################
# Run command.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ def runCommand(self):

if isinstance(propertyMetadata, list):
for metadata in propertyMetadata:
print metadata.getDisplayString(self.getDisplayKeys(), self.getDisplayFormat())
print( metadata.getDisplayString(self.getDisplayKeys(), self.getDisplayFormat()))
else:
print propertyMetadata.getDisplayString(self.getDisplayKeys(), self.getDisplayFormat())
print( propertyMetadata.getDisplayString(self.getDisplayKeys(), self.getDisplayFormat()))

#######################################################################
# Run command.
Expand Down
2 changes: 1 addition & 1 deletion src/python/cdb/cdb_web_service/cli/deleteLogCli.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def runCommand(self):

cdbObject = api.deleteLogEntry(self.getLogId())

print cdbObject.getDisplayString(self.getDisplayKeys(), self.getDisplayFormat())
print( cdbObject.getDisplayString(self.getDisplayKeys(), self.getDisplayFormat()))

#######################################################################
# Run command.
Expand Down
2 changes: 1 addition & 1 deletion src/python/cdb/cdb_web_service/cli/getDirectoryListCli.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def runCommand(self):
""")
self.checkPath()
api = FileSystemRestApi(self.getUsername(), self.getPassword(), self.getServiceHost(), self.getServicePort(), self.getServiceProtocol())
print api.getDirectoryList(self.getPath())
print( api.getDirectoryList(self.getPath()))

#######################################################################
# Run command.
Expand Down
2 changes: 1 addition & 1 deletion src/python/cdb/cdb_web_service/cli/getItemLogsCli.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def runCommand(self):

logs = api.getLogEntriesForItemWithQrId(self.getQrId())
for log in logs:
print log.getDisplayString(self.getDisplayKeys(), self.getDisplayFormat())
print( log.getDisplayString(self.getDisplayKeys(), self.getDisplayFormat()))

#######################################################################
# Run command.
Expand Down
2 changes: 1 addition & 1 deletion src/python/cdb/cdb_web_service/cli/getUserCli.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def runCommand(self):
userInfo = api.getUserById(self.getId())
else:
userInfo = api.getUserByUsername(self.getUsername())
print userInfo.getDisplayString(self.getDisplayKeys(), self.getDisplayFormat())
print( userInfo.getDisplayString(self.getDisplayKeys(), self.getDisplayFormat()))

#######################################################################
# Run command.
Expand Down
2 changes: 1 addition & 1 deletion src/python/cdb/cdb_web_service/cli/getUserGroupsCli.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def runCommand(self):
api = UserRestApi(self.getUsername(), self.getPassword(), self.getServiceHost(), self.getServicePort(), self.getServiceProtocol())
userGroups = api.getUserGroups()
for userGroup in userGroups:
print userGroup.getDisplayString(self.getDisplayKeys(), self.getDisplayFormat())
print( userGroup.getDisplayString(self.getDisplayKeys(), self.getDisplayFormat()))


#######################################################################
Expand Down
2 changes: 1 addition & 1 deletion src/python/cdb/cdb_web_service/cli/getUsersCli.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def runCommand(self):
api = UserRestApi(self.getUsername(), self.getPassword(), self.getServiceHost(), self.getServicePort(), self.getServiceProtocol())
users = api.getUsers()
for user in users:
print user.getDisplayString(self.getDisplayKeys(), self.getDisplayFormat())
print( user.getDisplayString(self.getDisplayKeys(), self.getDisplayFormat()))


#######################################################################
Expand Down
2 changes: 1 addition & 1 deletion src/python/cdb/cdb_web_service/cli/loadLatticeDesignCli.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def runCommand(self):
api = DesignRestApi(self.getUsername(), self.getPassword(), self.getServiceHost(), self.getServicePort(), self.getServiceProtocol())
designElementList = self.loadLatticeCsvFile(self.getCsvFile())
design = api.loadDesign(self.getName(), self.getOwnerUserId(), self.getOwnerGroupId(), self.getIsGroupWriteable(), self.getDescription(), designElementList)
print design.getDisplayString(self.getDisplayKeys(), self.getDisplayFormat())
print( design.getDisplayString(self.getDisplayKeys(), self.getDisplayFormat()))

# Utility methojd to load csv file and prepare list of design
# element dictionaries.
Expand Down
2 changes: 1 addition & 1 deletion src/python/cdb/cdb_web_service/cli/updateLogCli.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def runCommand(self):

log = api.updateLogEntry(self.getLogId(), self.getLogText(), self.getEffectiveFromDate(), self.getEffectiveToDate(), self.getLogTopicName())

print log.getDisplayString(self.getDisplayKeys(), self.getDisplayFormat())
print( log.getDisplayString(self.getDisplayKeys(), self.getDisplayFormat()))

#######################################################################
# Run command.
Expand Down
2 changes: 1 addition & 1 deletion src/python/cdb/cdb_web_service/cli/writeFileCli.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def runCommand(self):
""")
self.checkPath()
api = FileSystemRestApi(self.getUsername(), self.getPassword(), self.getServiceHost(), self.getServicePort(), self.getServiceProtocol())
print api.writeFile(self.getPath(), self.getContent())
print( api.writeFile(self.getPath(), self.getContent()))

#######################################################################
# Run command.
Expand Down
12 changes: 6 additions & 6 deletions src/python/cdb/cdb_web_service/java_api/itemRestApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ def getItemByQrId(self, itemQrId):
if __name__ == "__main__":
itemApi = ItemRestApi(username='cdb', password='cdb', host='localhost', port=8080, protocol='http')

print itemApi.getItemById(500)['name']
print itemApi.getItemById(1233)['name']
print itemApi.getItemById(51)['name']
print itemApi.getItemById(5)['name']
print itemApi.getItemById(3000)['name']
print( itemApi.getItemById(500)['name'])
print( itemApi.getItemById(1233)['name'])
print( itemApi.getItemById(51)['name'])
print( itemApi.getItemById(5)['name'])
print( itemApi.getItemById(3000)['name'])

print itemApi.getItemByQrId(240)['name']
print( itemApi.getItemByQrId(240)['name'])

"""

Expand Down
Loading