Skip to content

Commit 8ce0146

Browse files
jcmfernandesioquatix
authored andcommitted
Fix auth_tag retrieval on JRuby (#32)
1 parent 7727185 commit 8ce0146

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

lib/rack/session/encryptor.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def encrypt(message)
302302
encrypted_data = cipher.update(serialized_payload) << cipher.final
303303

304304
data << cipher_iv
305-
data << cipher.auth_tag(16)
305+
data << auth_tag_from(cipher)
306306
data << encrypted_data
307307

308308
Base64.strict_encode64(data)
@@ -327,6 +327,21 @@ def message_secret_from_salt(salt)
327327
def set_cipher_key(cipher, key)
328328
cipher.key = key
329329
end
330+
331+
if RUBY_ENGINE == 'jruby'
332+
# JRuby's OpenSSL implementation doesn't currently support passing
333+
# an argument to #auth_tag. Here we work around that.
334+
def auth_tag_from(cipher)
335+
tag = cipher.auth_tag
336+
raise Error, 'the auth tag must be 16 bytes long' if tag.bytesize != 16
337+
338+
tag
339+
end
340+
else
341+
def auth_tag_from(cipher)
342+
cipher.auth_tag(16)
343+
end
344+
end
330345
end
331346

332347
def initialize(secret, opts = {})

0 commit comments

Comments
 (0)