mirror of https://github.com/apache/cloudstack.git
CS-15151: Cluster_details table stores Vcenter Cluster credentials in clear text
Description: Encrypting password values before they're written out to the cluster_details db, and decrypting them when reading in the values from the db.
This commit is contained in:
parent
b09e43f977
commit
9e3330374f
|
|
@ -18,6 +18,7 @@ import java.util.Map;
|
|||
|
||||
import javax.ejb.Local;
|
||||
|
||||
import com.cloud.utils.crypt.DBEncryptionUtil;
|
||||
import com.cloud.utils.db.GenericDaoBase;
|
||||
import com.cloud.utils.db.SearchBuilder;
|
||||
import com.cloud.utils.db.SearchCriteria;
|
||||
|
|
@ -27,12 +28,12 @@ import com.cloud.utils.db.Transaction;
|
|||
public class ClusterDetailsDaoImpl extends GenericDaoBase<ClusterDetailsVO, Long> implements ClusterDetailsDao {
|
||||
protected final SearchBuilder<ClusterDetailsVO> ClusterSearch;
|
||||
protected final SearchBuilder<ClusterDetailsVO> DetailSearch;
|
||||
|
||||
|
||||
protected ClusterDetailsDaoImpl() {
|
||||
ClusterSearch = createSearchBuilder();
|
||||
ClusterSearch.and("clusterId", ClusterSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
|
||||
ClusterSearch.done();
|
||||
|
||||
|
||||
DetailSearch = createSearchBuilder();
|
||||
DetailSearch.and("clusterId", DetailSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
|
||||
DetailSearch.and("name", DetailSearch.entity().getName(), SearchCriteria.Op.EQ);
|
||||
|
|
@ -44,32 +45,40 @@ public class ClusterDetailsDaoImpl extends GenericDaoBase<ClusterDetailsVO, Long
|
|||
SearchCriteria<ClusterDetailsVO> sc = DetailSearch.create();
|
||||
sc.setParameters("clusterId", clusterId);
|
||||
sc.setParameters("name", name);
|
||||
|
||||
return findOneIncludingRemovedBy(sc);
|
||||
|
||||
ClusterDetailsVO detail = findOneIncludingRemovedBy(sc);
|
||||
if("password".equals(name) && detail != null){
|
||||
detail.setValue(DBEncryptionUtil.decrypt(detail.getValue()));
|
||||
}
|
||||
return detail;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public Map<String, String> findDetails(long clusterId) {
|
||||
SearchCriteria<ClusterDetailsVO> sc = ClusterSearch.create();
|
||||
sc.setParameters("clusterId", clusterId);
|
||||
|
||||
|
||||
List<ClusterDetailsVO> results = search(sc, null);
|
||||
Map<String, String> details = new HashMap<String, String>(results.size());
|
||||
for (ClusterDetailsVO result : results) {
|
||||
details.put(result.getName(), result.getValue());
|
||||
if("password".equals(result.getName())){
|
||||
details.put(result.getName(), DBEncryptionUtil.decrypt(result.getValue()));
|
||||
} else {
|
||||
details.put(result.getName(), result.getValue());
|
||||
}
|
||||
}
|
||||
return details;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deleteDetails(long clusterId) {
|
||||
SearchCriteria sc = ClusterSearch.create();
|
||||
sc.setParameters("clusterId", clusterId);
|
||||
|
||||
|
||||
List<ClusterDetailsVO> results = search(sc, null);
|
||||
for (ClusterDetailsVO result : results) {
|
||||
remove(result.getId());
|
||||
remove(result.getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -80,9 +89,13 @@ public class ClusterDetailsDaoImpl extends GenericDaoBase<ClusterDetailsVO, Long
|
|||
SearchCriteria<ClusterDetailsVO> sc = ClusterSearch.create();
|
||||
sc.setParameters("clusterId", clusterId);
|
||||
expunge(sc);
|
||||
|
||||
|
||||
for (Map.Entry<String, String> detail : details.entrySet()) {
|
||||
ClusterDetailsVO vo = new ClusterDetailsVO(clusterId, detail.getKey(), detail.getValue());
|
||||
String value = detail.getValue();
|
||||
if("password".equals(detail.getKey())){
|
||||
value = DBEncryptionUtil.encrypt(value);
|
||||
}
|
||||
ClusterDetailsVO vo = new ClusterDetailsVO(clusterId, detail.getKey(), value);
|
||||
persist(vo);
|
||||
}
|
||||
txn.commit();
|
||||
|
|
@ -96,10 +109,10 @@ public class ClusterDetailsDaoImpl extends GenericDaoBase<ClusterDetailsVO, Long
|
|||
sc.setParameters("clusterId", clusterId);
|
||||
sc.setParameters("name", name);
|
||||
expunge(sc);
|
||||
|
||||
|
||||
ClusterDetailsVO vo = new ClusterDetailsVO(clusterId, name, value);
|
||||
persist(vo);
|
||||
txn.commit();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue