Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw signature exception from signing and signature validation utils #6179

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
Expand Up @@ -1976,23 +1976,20 @@ public static boolean isSCIM2UserMaxItemsPerPageEnabled() {
* @param signature The signature to be verified.
* @param tenantDomain The tenant domain to which the data belongs.
* @return true if the signature is valid, false otherwise.
* @throws IdentityKeyStoreResolverException If an error occurs during the signature validation process.
* @throws SignatureException If an error occurs during the signature validation process.
*/
public static boolean validateSignatureFromTenant(String data, byte[] signature, String tenantDomain)
throws IdentityKeyStoreResolverException {
throws SignatureException {

int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
try {
IdentityTenantUtil.initializeRegistry(tenantId);
PublicKey publicKey = IdentityKeyStoreResolver.getInstance().getCertificate(tenantDomain, null)
.getPublicKey();
return SignatureUtil.validateSignature(data, signature, publicKey);
} catch (IdentityException e) {
throw new IdentityKeyStoreResolverException(
IdentityKeyStoreResolverConstants.ErrorMessages
.ERROR_CODE_ERROR_RETRIEVING_TENANT_PRIVATE_KEY.getCode(),
"Error while loading the private key", e);
throw new SignatureException("Error while validating the signature from tenant: " + tenantDomain, e);
}
PublicKey publicKey = IdentityKeyStoreResolver.getInstance().getCertificate(tenantDomain, null)
.getPublicKey();
return SignatureUtil.validateSignature(data, signature, publicKey);
}

/**
Expand All @@ -2001,9 +1998,9 @@ public static boolean validateSignatureFromTenant(String data, byte[] signature,
* @param data The data to be signed.
* @param tenantDomain The tenant domain to which the data belongs.
* @return The signature of the data.
* @throws IdentityKeyStoreResolverException If an error occurs during the signature generation process.
* @throws SignatureException If an error occurs during the signature generation process.
*/
public static byte[] signWithTenantKey(String data, String tenantDomain) throws IdentityKeyStoreResolverException {
public static byte[] signWithTenantKey(String data, String tenantDomain) throws SignatureException {

int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
KeyStoreManager keyStoreManager = KeyStoreManager.getInstance(tenantId);
Expand All @@ -2013,23 +2010,18 @@ public static byte[] signWithTenantKey(String data, String tenantDomain) throws
try {
privateKey = keyStoreManager.getDefaultPrivateKey();
} catch (Exception e) {
throw new IdentityKeyStoreResolverException(IdentityKeyStoreResolverConstants.ErrorMessages
.ERROR_CODE_ERROR_RETRIEVING_TENANT_PRIVATE_KEY.getCode(),
String.format(IdentityKeyStoreResolverConstants.ErrorMessages
throw new SignatureException(String.format(IdentityKeyStoreResolverConstants.ErrorMessages
.ERROR_CODE_ERROR_RETRIEVING_TENANT_PRIVATE_KEY.getDescription(), tenantDomain),
e);
}
} else {
String tenantKeyStoreName = IdentityKeyStoreResolverUtil.buildTenantKeyStoreName(tenantDomain);
try {
String tenantKeyStoreName = IdentityKeyStoreResolverUtil.buildTenantKeyStoreName(tenantDomain);
IdentityTenantUtil.initializeRegistry(tenantId);
privateKey = (PrivateKey) keyStoreManager.getPrivateKey(tenantKeyStoreName, tenantDomain);
} catch (IdentityException e) {
throw new IdentityKeyStoreResolverException(
IdentityKeyStoreResolverConstants.ErrorMessages
.ERROR_CODE_ERROR_RETRIEVING_TENANT_PRIVATE_KEY.getCode(),
"Error while loading the private key", e);
throw new SignatureException("Error while signing from private key of tenant: " + tenantDomain, e);
}
privateKey = (PrivateKey) keyStoreManager.getPrivateKey(tenantKeyStoreName, tenantDomain);
}
return SignatureUtil.doSignature(data, privateKey);
}
Expand Down
Loading