Improve error handling while verifying VaultConfig
This commit is contained in:
parent
4a20fbf7ab
commit
e34597a716
@ -8,11 +8,14 @@ import java.net.URI
|
|||||||
import java.security.Key
|
import java.security.Key
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import io.jsonwebtoken.Claims
|
import io.jsonwebtoken.Claims
|
||||||
|
import io.jsonwebtoken.IncorrectClaimException
|
||||||
import io.jsonwebtoken.JwsHeader
|
import io.jsonwebtoken.JwsHeader
|
||||||
import io.jsonwebtoken.JwtException
|
import io.jsonwebtoken.JwtException
|
||||||
import io.jsonwebtoken.Jwts
|
import io.jsonwebtoken.Jwts
|
||||||
|
import io.jsonwebtoken.MissingClaimException
|
||||||
import io.jsonwebtoken.SigningKeyResolverAdapter
|
import io.jsonwebtoken.SigningKeyResolverAdapter
|
||||||
import io.jsonwebtoken.security.Keys
|
import io.jsonwebtoken.security.Keys
|
||||||
|
import io.jsonwebtoken.security.SignatureException
|
||||||
import kotlin.properties.Delegates
|
import kotlin.properties.Delegates
|
||||||
|
|
||||||
class VaultConfig private constructor(builder: VaultConfigBuilder) {
|
class VaultConfig private constructor(builder: VaultConfigBuilder) {
|
||||||
@ -35,6 +38,7 @@ class VaultConfig private constructor(builder: VaultConfigBuilder) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class VaultConfigBuilder {
|
class VaultConfigBuilder {
|
||||||
|
|
||||||
internal var id: String = UUID.randomUUID().toString()
|
internal var id: String = UUID.randomUUID().toString()
|
||||||
internal var vaultFormat = CryptoConstants.MAX_VAULT_VERSION;
|
internal var vaultFormat = CryptoConstants.MAX_VAULT_VERSION;
|
||||||
internal var cipherCombo = VaultCipherCombo.SIV_CTRMAC
|
internal var cipherCombo = VaultCipherCombo.SIV_CTRMAC
|
||||||
@ -72,6 +76,7 @@ class VaultConfig private constructor(builder: VaultConfigBuilder) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private const val JSON_KEY_VAULTFORMAT = "format"
|
private const val JSON_KEY_VAULTFORMAT = "format"
|
||||||
private const val JSON_KEY_CIPHERCONFIG = "cipherCombo"
|
private const val JSON_KEY_CIPHERCONFIG = "cipherCombo"
|
||||||
private const val JSON_KEY_MAXFILENAMELEN = "maxFilenameLen"
|
private const val JSON_KEY_MAXFILENAMELEN = "maxFilenameLen"
|
||||||
@ -110,24 +115,24 @@ class VaultConfig private constructor(builder: VaultConfigBuilder) {
|
|||||||
.maxFilenameLength(parser.body[JSON_KEY_MAXFILENAMELEN] as Int)
|
.maxFilenameLength(parser.body[JSON_KEY_MAXFILENAMELEN] as Int)
|
||||||
|
|
||||||
VaultConfig(vaultConfigBuilder)
|
VaultConfig(vaultConfigBuilder)
|
||||||
/*} catch (SignatureVerificationException e) {
|
} catch (e: Exception) {
|
||||||
throw new VaultKeyInvalidException();
|
when (e) {
|
||||||
} catch (InvalidClaimException e) {
|
is MissingClaimException, is IncorrectClaimException -> throw VaultVersionMismatchException("Vault config not for version " + unverifiedVaultConfig.vaultFormat)
|
||||||
throw new VaultVersionMismatchException("Vault config not for version " + expectedVaultFormat);
|
is SignatureException -> throw VaultKeyInvalidException()
|
||||||
} catch (JWTVerificationException e) {
|
is JwtException -> throw VaultConfigLoadException("Failed to verify vault config", e)
|
||||||
throw new VaultConfigLoadException("Failed to verify vault config: " + unverifiedConfig.getToken());
|
else -> throw VaultConfigLoadException(e)
|
||||||
*/
|
}
|
||||||
} catch (e: JwtException) {
|
|
||||||
throw VaultConfigLoadException("Failed to verify vault config", e)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
fun createVaultConfig(): VaultConfigBuilder {
|
fun createVaultConfig(): VaultConfigBuilder {
|
||||||
return VaultConfigBuilder()
|
return VaultConfigBuilder()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class UnverifiedSigningKeyResolver : SigningKeyResolverAdapter() {
|
private class UnverifiedSigningKeyResolver : SigningKeyResolverAdapter() {
|
||||||
|
|
||||||
lateinit var keyId: URI
|
lateinit var keyId: URI
|
||||||
var vaultFormat: Int by Delegates.notNull()
|
var vaultFormat: Int by Delegates.notNull()
|
||||||
|
|
||||||
|
@ -13,4 +13,9 @@ public class VaultConfigLoadException extends BackendException {
|
|||||||
public VaultConfigLoadException(String message, JwtException e) {
|
public VaultConfigLoadException(String message, JwtException e) {
|
||||||
super(message, e);
|
super(message, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public VaultConfigLoadException(Exception e) {
|
||||||
|
super(e);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user