Commit b0614f29 authored by michael.simon's avatar michael.simon
Browse files

Add sha256 fingerprint to ssh key page

parent 72c3d4be
......@@ -23,4 +23,6 @@ public interface SshPubKeyDao extends BaseDao<SshPubKeyEntity, Long> {
List<SshPubKeyEntity> findByUserAndKey(Long userId, String encodedKey);
List<SshPubKeyEntity> findByUserAndStatusWithRegs(Long userId, SshPubKeyStatus keyStatus);
}
......@@ -39,6 +39,19 @@ public class JpaSshPubKeyDao extends JpaBaseDao<SshPubKeyEntity, Long> implement
.getResultList();
}
@Override
@SuppressWarnings("unchecked")
public List<SshPubKeyEntity> findByUserAndStatusWithRegs(Long userId, SshPubKeyStatus keyStatus) {
return em.createQuery("select e from SshPubKeyEntity e "
+ "left join fetch e.sshPubKeyRegistries "
// + "left join fetch e.sshPubKeyRegistries.registry "
// + "left join fetch e.sshPubKeyRegistries.registry.service "
+ "where e.user.id = :userId and e.keyStatus = :keyStatus")
.setParameter("userId", userId)
.setParameter("keyStatus", keyStatus)
.getResultList();
}
@Override
@SuppressWarnings("unchecked")
public List<SshPubKeyEntity> findByUserAndKey(Long userId, String encodedKey) {
......
package edu.kit.scc.webreg.entity;
import java.util.Date;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
@Entity(name = "SshPubKeyEntity")
......@@ -18,6 +20,9 @@ public class SshPubKeyEntity extends AbstractBaseEntity {
@ManyToOne(targetEntity = UserEntity.class)
private UserEntity user;
@OneToMany(targetEntity = SshPubKeyRegistryEntity.class, mappedBy = "sshPubKey")
private Set<SshPubKeyRegistryEntity> sshPubKeyRegistries;
@Enumerated(EnumType.STRING)
private SshPubKeyStatus keyStatus;
......@@ -91,4 +96,12 @@ public class SshPubKeyEntity extends AbstractBaseEntity {
public void setExpiresAt(Date expiresAt) {
this.expiresAt = expiresAt;
}
public Set<SshPubKeyRegistryEntity> getSshPubKeyRegistries() {
return sshPubKeyRegistries;
}
public void setSshPubKeyRegistries(Set<SshPubKeyRegistryEntity> sshPubKeyRegistries) {
this.sshPubKeyRegistries = sshPubKeyRegistries;
}
}
......@@ -25,4 +25,6 @@ public interface SshPubKeyService extends BaseService<SshPubKeyEntity, Long> {
SshPubKeyEntity deployKey(Long userId, SshPubKeyEntity entity) throws SshPubKeyBlacklistedException;
List<SshPubKeyEntity> findByUserAndStatusWithRegs(Long userId, SshPubKeyStatus keyStatus);
}
......@@ -39,7 +39,12 @@ public class SshPubKeyServiceImpl extends BaseServiceImpl<SshPubKeyEntity, Long>
public List<SshPubKeyEntity> findByUserAndStatus(Long userId, SshPubKeyStatus keyStatus) {
return dao.findByUserAndStatus(userId, keyStatus);
}
@Override
public List<SshPubKeyEntity> findByUserAndStatusWithRegs(Long userId, SshPubKeyStatus keyStatus) {
return dao.findByUserAndStatusWithRegs(userId, keyStatus);
}
@Override
public SshPubKeyEntity deployKey(Long userId, SshPubKeyEntity entity)
throws SshPubKeyBlacklistedException {
......
......@@ -4,6 +4,7 @@ import java.io.Serializable;
import java.math.BigInteger;
import java.security.AlgorithmParameters;
import java.security.KeyFactory;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.spec.DSAPublicKeySpec;
import java.security.spec.ECGenParameterSpec;
......@@ -46,6 +47,11 @@ public class OpenSshKeyDecoder implements Serializable {
BigInteger m = decodeBigInt(key);
RSAPublicKeySpec spec = new RSAPublicKeySpec(m, e);
key.setPublicKey(KeyFactory.getInstance("RSA").generatePublic(spec));
MessageDigest digest = MessageDigest.getInstance("SHA256");
byte[] result = digest.digest(key.getBytes());
key.setFingerprint(java.util.Base64.getEncoder().encodeToString(result));
} else if (type.equals("ssh-dss")) {
BigInteger p = decodeBigInt(key);
BigInteger q = decodeBigInt(key);
......
......@@ -21,6 +21,8 @@ public class OpenSshPublicKey implements Serializable {
private String decoderResult;
private String fingerprint;
public OpenSshPublicKey() {
super();
decoderPos = 0;
......@@ -77,4 +79,12 @@ public class OpenSshPublicKey implements Serializable {
public void setPubKeyEntity(SshPubKeyEntity pubKeyEntity) {
this.pubKeyEntity = pubKeyEntity;
}
public String getFingerprint() {
return fingerprint;
}
public void setFingerprint(String fingerprint) {
this.fingerprint = fingerprint;
}
}
......@@ -155,6 +155,12 @@ public class SetServiceSshPubKeyBean implements Serializable {
return null;
}
public String delete(SshPubKeyRegistryEntity reg) {
sshPubKeyRegistryService.delete(reg);
sshPubKeyRegistryList.remove(reg);
return null;
}
public Long getId() {
return id;
......
......@@ -72,9 +72,9 @@ public class UserSshKeyManagementBean implements Serializable {
public void preRenderView(ComponentSystemEvent ev) {
if (user == null) {
user = userService.findById(sessionManager.getUserId());
List<SshPubKeyEntity> sshPubKeyList = sshPubKeyService.findByUserAndStatus(user.getId(), SshPubKeyStatus.ACTIVE);
List<SshPubKeyEntity> sshPubKeyList = sshPubKeyService.findByUserAndStatusWithRegs(user.getId(), SshPubKeyStatus.ACTIVE);
keyList = new ArrayList<>();
keyList = new ArrayList<OpenSshPublicKey>();
for (SshPubKeyEntity sshKey : sshPubKeyList) {
try {
keyList.add(keyDecoder.decode(sshKey));
......
......@@ -54,8 +54,9 @@
<h:outputText value="#{regKey.sshPubKey.name}"/>
</p:column>
<p:column>
<p:commandLink action="#{setServiceSshPubKeyBean.delete(regKey)}" update="@form">
<p:commandLink action="#{setServiceSshPubKeyBean.delete(regKey)}" immediate="true" update="@form">
<h:panelGroup styleClass="ui-icon ui-icon-trash" />
<p:confirm header="#{messages.confirm_header}" message="#{messages.confirm}" />
</p:commandLink>
</p:column>
</p:dataTable>
......@@ -80,7 +81,8 @@
</p:dataTable>
<p:dialog header="#{messages.set_ssh_pub_key_for} #{setServiceSshPubKeyBean.serviceEntity.name}"
widgetVar="addKeyDlg" id="addKeyDlgId" modal="true">
widgetVar="addKeyDlg" id="addKeyDlgId" modal="true" closable="false" closeOnEscape="true"
showEffect="fade" hideEffect="fade">
<div class="panel">
<h:outputText value="#{messages.service_ssh_pub_key_help_modal}" />
......@@ -131,6 +133,11 @@
</h:panelGroup>
</p:dialog>
<p:confirmDialog global="true" showEffect="fade" hideEffect="fade" closable="false" closeOnEscape="true">
<p:commandButton value="#{messages.yes}" type="button" styleClass="ui-confirmdialog-yes" />
<p:commandButton value="#{messages.no}" type="button" styleClass="ui-confirmdialog-no" />
</p:confirmDialog>
</p:panel>
</div>
......
......@@ -38,15 +38,23 @@
<h:outputText value="#{key.pubKeyEntity.keyType}"/>
</p:column>
<p:column>
<h:outputText value="#{key.publicKey}" rendered="#{not empty key.publicKey}" />
<h:outputText value="#{key.fingerprint}" rendered="#{not empty key.publicKey}" />
<h:outputText value="#{messages.ssh_key_type_unknown}" rendered="#{empty key.publicKey}" />
</p:column>
<p:column>
<f:facet name="header"><h:outputText value="#{messages.expires}:"/></f:facet>
<h:outputText value="#{of:formatDate(key.pubKeyEntity.expiresAt, 'dd.MM.yyyy HH:mm')}"/>
</p:column>
<p:column>
<f:facet name="header"><h:outputText value="#{messages.services}:"/></f:facet>
<p:repeat var="reg" value="#{key.pubKeyEntity.sshPubKeyRegistries}">
<h:outputText value="#{reg.registry.service.name}"/>
</p:repeat>
</p:column>
<p:column>
<p:commandLink id="delete" action="#{userSshKeyManagementBean.deleteKey(key.pubKeyEntity.name)}" value="#{messages.delete}" immediate="true" update="@form">
<p:column width="5%">
<p:commandLink id="delete" action="#{userSshKeyManagementBean.deleteKey(key.pubKeyEntity.name)}" immediate="true" update="@form">
<h:panelGroup styleClass="ui-icon ui-icon-trash" />
<p:confirm header="#{messages.confirm_header}" message="#{messages.confirm}" />
</p:commandLink>
</p:column>
......@@ -71,7 +79,7 @@
</p:ajaxStatus>
</p:panel>
<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
<p:confirmDialog global="true" showEffect="fade" hideEffect="fade" closable="false" closeOnEscape="true">
<p:commandButton value="#{messages.yes}" type="button" styleClass="ui-confirmdialog-yes" />
<p:commandButton value="#{messages.no}" type="button" styleClass="ui-confirmdialog-no" />
</p:confirmDialog>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment