summaryrefslogtreecommitdiff
path: root/app/models/concerns/token_authenticatable_strategies/encryption_helper.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/models/concerns/token_authenticatable_strategies/encryption_helper.rb')
-rw-r--r--app/models/concerns/token_authenticatable_strategies/encryption_helper.rb12
1 files changed, 8 insertions, 4 deletions
diff --git a/app/models/concerns/token_authenticatable_strategies/encryption_helper.rb b/app/models/concerns/token_authenticatable_strategies/encryption_helper.rb
index 25c050820d6..3be82ed72d3 100644
--- a/app/models/concerns/token_authenticatable_strategies/encryption_helper.rb
+++ b/app/models/concerns/token_authenticatable_strategies/encryption_helper.rb
@@ -5,10 +5,6 @@ module TokenAuthenticatableStrategies
DYNAMIC_NONCE_IDENTIFIER = "|"
NONCE_SIZE = 12
- def self.encrypt_token(plaintext_token)
- Gitlab::CryptoHelper.aes256_gcm_encrypt(plaintext_token)
- end
-
def self.decrypt_token(token)
return unless token
@@ -22,5 +18,13 @@ module TokenAuthenticatableStrategies
Gitlab::CryptoHelper.aes256_gcm_decrypt(token)
end
end
+
+ def self.encrypt_token(plaintext_token)
+ return Gitlab::CryptoHelper.aes256_gcm_encrypt(plaintext_token) unless Feature.enabled?(:dynamic_nonce, type: :ops)
+
+ iv = ::Digest::SHA256.hexdigest(plaintext_token).bytes.take(NONCE_SIZE).pack('c*')
+ token = Gitlab::CryptoHelper.aes256_gcm_encrypt(plaintext_token, nonce: iv)
+ "#{DYNAMIC_NONCE_IDENTIFIER}#{token}#{iv}"
+ end
end
end