Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ftn.security.minikms.service;

import ftn.security.minikms.entity.KeyMaterial;
import ftn.security.minikms.enumeration.KeyType;
import ftn.security.minikms.repository.KeyMetadataRepository;
import ftn.security.minikms.repository.WrappedKeyRepository;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -75,7 +76,20 @@ public KeyMaterial getKey(UUID keyId, Integer version) {
var wrappedKey = keyRepository.findByMetadataIdAndVersion(keyId, version)
.orElseThrow(() -> new InvalidParameterException("Key with given id and version does not exist"));

return wrappedKey.getWrappedMaterial();
if (metadata.getKeyType().equals(KeyType.HMAC))
return wrappedKey.getWrappedMaterial();
try {
byte[] unwrappedKey = rootKeyManager.unwrap(
wrappedKey.getWrappedMaterial().getKey(), keyId, version
);

KeyMaterial material = new KeyMaterial();
material.setKey(unwrappedKey);
material.setPublicKey(wrappedKey.getWrappedMaterial().getPublicKey());
return material;
} catch (GeneralSecurityException e) {
throw new RuntimeException("Failed to unwrap key material", e);
}
}

public KeyMaterial getKeySig(UUID keyId, Integer version) {
Expand Down
Loading