Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

fix: kms decryption of redis_temp_locker_encryption_key (#2650)

Abhishek Marrivagu5a6601fad4d1
diff --git a/crates/external_services/src/kms.rs b/crates/external_services/src/kms.rs
index 31c82253fe..1f3d1aee90 100644
--- a/crates/external_services/src/kms.rs
+++ b/crates/external_services/src/kms.rs
@@ -120,6 +120,14 @@ pub enum KmsError {
/// The KMS client has not been initialized.
#[error("The KMS client has not been initialized")]
KmsClientNotInitialized,
+
+ /// The KMS client has not been initialized.
+ #[error("Hex decode failed")]
+ HexDecodeFailed,
+
+ /// The KMS client has not been initialized.
+ #[error("Utf8 decode failed")]
+ Utf8DecodeFailed,
}
impl KmsConfig {
@@ -140,7 +148,7 @@ impl KmsConfig {
/// A wrapper around a KMS value that can be decrypted.
#[derive(Clone, Debug, Default, serde::Deserialize, Eq, PartialEq)]
#[serde(transparent)]
-pub struct KmsValue(Secret<String>);
+pub struct KmsValue(pub Secret<String>);
impl common_utils::ext_traits::ConfigExt for KmsValue {
fn is_empty_after_trim(&self) -> bool {
diff --git a/crates/router/src/configs/kms.rs b/crates/router/src/configs/kms.rs
index 317ad0608b..c3dd8ead19 100644
--- a/crates/router/src/configs/kms.rs
+++ b/crates/router/src/configs/kms.rs
@@ -1,5 +1,6 @@
use common_utils::errors::CustomResult;
-use external_services::kms::{decrypt::KmsDecrypt, KmsClient, KmsError};
+use error_stack::{IntoReport, ResultExt};
+use external_services::kms::{decrypt::KmsDecrypt, KmsClient, KmsError, KmsValue};
use masking::ExposeInterface;
use crate::configs::settings;
@@ -41,6 +42,19 @@ impl KmsDecrypt for settings::ActiveKmsSecrets {
kms_client: &KmsClient,
) -> CustomResult<Self::Output, KmsError> {
self.jwekey = self.jwekey.expose().decrypt_inner(kms_client).await?.into();
+ self.redis_temp_locker_encryption_key = hex::decode(
+ KmsValue(
+ String::from_utf8(self.redis_temp_locker_encryption_key.expose())
+ .into_report()
+ .change_context(KmsError::Utf8DecodeFailed)?
+ .into(),
+ )
+ .decrypt_inner(kms_client)
+ .await?,
+ )
+ .into_report()
+ .change_context(KmsError::HexDecodeFailed)?
+ .into();
Ok(self)
}
}
diff --git a/crates/router/src/configs/settings.rs b/crates/router/src/configs/settings.rs
index ec1ea7d77e..56031c1f06 100644
--- a/crates/router/src/configs/settings.rs
+++ b/crates/router/src/configs/settings.rs
@@ -52,7 +52,7 @@ pub enum Subcommand {
#[derive(Clone)]
pub struct ActiveKmsSecrets {
pub jwekey: masking::Secret<Jwekey>,
- pub redis_temp_locker_encryption_key: masking::Secret<String>,
+ pub redis_temp_locker_encryption_key: masking::Secret<Vec<u8>>,
}
#[derive(Debug, Deserialize, Clone, Default)]
diff --git a/crates/router/src/core/payment_methods/vault.rs b/crates/router/src/core/payment_methods/vault.rs
index 945745ef38..dfe72a6cdf 100644
--- a/crates/router/src/core/payment_methods/vault.rs
+++ b/crates/router/src/core/payment_methods/vault.rs
@@ -721,7 +721,6 @@ fn get_redis_temp_locker_encryption_key(state: &routes::AppState) -> RouterResul
.kms_secrets
.redis_temp_locker_encryption_key
.peek()
- .as_bytes()
.to_owned();
#[cfg(not(feature = "kms"))]
diff --git a/crates/router/src/routes/app.rs b/crates/router/src/routes/app.rs
index 3d92957948..863d0e8230 100644
--- a/crates/router/src/routes/app.rs
+++ b/crates/router/src/routes/app.rs
@@ -132,6 +132,7 @@ impl AppState {
.locker
.redis_temp_locker_encryption_key
.clone()
+ .into_bytes()
.into(),
}
.decrypt_inner(kms_client)