use of io.hops.hopsworks.persistence.entity.certificates.UserCerts in project hopsworks by logicalclocks.
the class AuthController method resetProjectCertPassword.
private void resetProjectCertPassword(Users p, String oldPass) {
// For every project, change the certificate secret in the database
// Get cert password by decrypting it with old password
List<Project> projects = projectFacade.findAllMemberStudies(p);
try {
for (Project project : projects) {
UserCerts userCert = userCertsFacade.findUserCert(project.getName(), p.getUsername());
String masterEncryptionPassword = certificatesMgmService.getMasterEncryptionPassword();
String certPassword = HopsUtils.decrypt(oldPass, userCert.getUserKeyPwd(), masterEncryptionPassword);
// Encrypt it with new password and store it in the db
String newSecret = HopsUtils.encrypt(p.getPassword(), certPassword, masterEncryptionPassword);
userCert.setUserKeyPwd(newSecret);
userCertsFacade.update(userCert);
}
} catch (Exception ex) {
LOGGER.log(Level.SEVERE, null, ex);
throw new EJBException(ex);
}
}
use of io.hops.hopsworks.persistence.entity.certificates.UserCerts in project hopsworks by logicalclocks.
the class PSUserCertsMasterPasswordHandler method rollback.
@Override
@SuppressWarnings("unchecked")
public void rollback(MasterPasswordChangeResult result) {
Map<String, String> items2rollback = (HashMap<String, String>) result.getRollbackItems();
LOGGER.log(Level.INFO, "Rolling back PSU certificates");
for (Map.Entry<String, String> oldPassword : items2rollback.entrySet()) {
String key = oldPassword.getKey();
String value = oldPassword.getValue();
String[] project__username = key.split(HdfsUsersController.USER_NAME_DELIMITER, 2);
UserCerts userCerts = certsFacade.findUserCert(project__username[0], project__username[1]);
userCerts.setUserKeyPwd(value);
certsFacade.update(userCerts);
}
}
use of io.hops.hopsworks.persistence.entity.certificates.UserCerts in project hopsworks by logicalclocks.
the class CertificateMaterializer method getMaterialFromDatabase.
/*
* Utility methods
*/
private CryptoMaterial getMaterialFromDatabase(MaterialKey key) throws IOException {
UserCerts projectSpecificCerts = certsFacade.findUserCert(key.projectName, key.username);
ByteBuffer keyStore = ByteBuffer.wrap(projectSpecificCerts.getUserKey());
ByteBuffer trustStore = ByteBuffer.wrap(projectSpecificCerts.getUserCert());
char[] password = decryptMaterialPassword(key.getExtendedUsername(), projectSpecificCerts.getUserKeyPwd());
return new CryptoMaterial(keyStore, trustStore, password);
}
use of io.hops.hopsworks.persistence.entity.certificates.UserCerts in project hopsworks by logicalclocks.
the class CertificatesController method generateCertificates.
/**
* Creates x509 certificates for a project specific user and project generic
*
* @param project Associated project
* @param user Hopsworks user
* @return
*/
@Asynchronous
public Future<CertsResult> generateCertificates(Project project, Users user) throws Exception {
String userKeyPwd = HopsUtils.randomString(64);
String encryptedKey = HopsUtils.encrypt(user.getPassword(), userKeyPwd, certificatesMgmService.getMasterEncryptionPassword());
Pair<KeyStore, KeyStore> userKeystores = generateStores(project.getName() + Settings.HOPS_USERNAME_SEPARATOR + user.getUsername(), userKeyPwd, Endpoint.PROJECT);
UserCerts uc = certsFacade.putUserCerts(project.getName(), user.getUsername(), convertKeystoreToByteArray(userKeystores.getValue0(), userKeyPwd), convertKeystoreToByteArray(userKeystores.getValue1(), userKeyPwd), encryptedKey);
// Run custom certificateHandlers
for (CertificateHandler certificateHandler : certificateHandlers) {
certificateHandler.generate(project, user, uc);
}
LOGGER.log(Level.FINE, "Created project generic certificates for project: " + project.getName());
return new AsyncResult<>(new CertsResult(project.getName(), user.getUsername()));
}
use of io.hops.hopsworks.persistence.entity.certificates.UserCerts in project hopsworks by logicalclocks.
the class PSUserCertsMasterPasswordHandler method perform.
@Override
public MasterPasswordChangeResult perform(String oldMasterPassword, String newMasterPassword) {
StringBuilder successLog = new StringBuilder();
successLog.append("Performing change of master password for PSU certificates\n");
Map<String, String> oldPasswords4Rollback = new HashMap<>();
List<UserCerts> allPSCerts = certsFacade.findAllUserCerts();
String mapKey = null, oldPassword, newEncCertPassword;
Users user;
try {
LOGGER.log(Level.INFO, "Updating PSU certs with new Hopsworks master encryption password");
for (UserCerts psCert : allPSCerts) {
mapKey = psCert.getUserCertsPK().getProjectname() + HdfsUsersController.USER_NAME_DELIMITER + psCert.getUserCertsPK().getUsername();
oldPassword = psCert.getUserKeyPwd();
oldPasswords4Rollback.putIfAbsent(mapKey, oldPassword);
user = userFacade.findByUsername(psCert.getUserCertsPK().getUsername());
if (user == null) {
throw new Exception("Could not find Hopsworks user for certificate " + mapKey);
}
newEncCertPassword = getNewUserPassword(user.getPassword(), oldPassword, oldMasterPassword, newMasterPassword);
psCert.setUserKeyPwd(newEncCertPassword);
certsFacade.update(psCert);
successLog.append("Updated certificate: ").append(mapKey).append("\n");
}
return new MasterPasswordChangeResult<>(successLog, oldPasswords4Rollback, null);
} catch (Exception ex) {
String errorMsg = "Something went wrong while updating master encryption password for Project Specific User " + "certificates. PSU certificate provoked the error was: " + mapKey;
LOGGER.log(Level.SEVERE, errorMsg + " rolling back...", ex);
return new MasterPasswordChangeResult<Map<String, String>>(oldPasswords4Rollback, new EncryptionMasterPasswordException(errorMsg));
}
}
Aggregations