Skip to content

Commit 95dbfe0

Browse files
committed
openssl: import fixes from upstream
Import the following two commits from upstream: commit 72126d6c8b88abd69c3565fc3bbbd5ed1e401611 Author: Kazuki Yamaguchi <k@rhe.jp> Date: Thu Dec 1 22:27:03 2016 +0900 pkey: check existence of EVP_PKEY_get0() EVP_PKEY_get0() did not exist in early OpenSSL 0.9.8 series. So define ourselves if needed. commit 94a1c4e0c5705ad1e9a4ca08cacaa6cba8b1e6f5 Author: Kazuki Yamaguchi <k@rhe.jp> Date: Thu Dec 1 22:13:22 2016 +0900 test/test_cipher: fix test with OpenSSL 1.0.1 before 1.0.1d Set the authentication tag before the AAD when decrypting. Before OpenSSL commit 96f7fafa2431 ("Don't require tag before ciphertext in AESGCM mode", 2012-10-16, at OpenSSL_1_0_1-stable branch, included in OpenSSL 1.0.1d), the authentication tag must be set before any calls of EVP_CipherUpdate(). They should fix build on CentOS 5 and Ubuntu 12.04 respectively. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56953 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent 671c929 commit 95dbfe0

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

ext/openssl/extconf.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
have_func("SSL_SESSION_cmp") # removed
9696
OpenSSL.check_func_or_macro("SSL_set_tlsext_host_name", "openssl/ssl.h")
9797
have_struct_member("CRYPTO_THREADID", "ptr", "openssl/crypto.h")
98+
have_func("EVP_PKEY_get0")
9899

99100
# added in 1.0.1
100101
have_func("SSL_CTX_set_next_proto_select_cb")

ext/openssl/openssl_missing.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ int HMAC_CTX_copy(HMAC_CTX *out, HMAC_CTX *in);
4747
i2d_ASN1_TYPE, V_ASN1_SET, V_ASN1_UNIVERSAL, 0)
4848
#endif
4949

50+
#if !defined(HAVE_EVP_PKEY_GET0)
51+
# define EVP_PKEY_get0(pk) (pk->pkey.ptr)
52+
#endif
53+
5054
/* added in 1.0.2 */
5155
#if !defined(OPENSSL_NO_EC)
5256
#if !defined(HAVE_EC_CURVE_NIST2NID)

test/openssl/test_cipher.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -192,32 +192,32 @@ def test_aes_gcm
192192
cipher = new_encryptor("aes-128-gcm", key: key, iv: iv, auth_data: aad)
193193
assert_equal ct, cipher.update(pt) << cipher.final
194194
assert_equal tag, cipher.auth_tag
195-
cipher = new_decryptor("aes-128-gcm", key: key, iv: iv, auth_data: aad, auth_tag: tag)
195+
cipher = new_decryptor("aes-128-gcm", key: key, iv: iv, auth_tag: tag, auth_data: aad)
196196
assert_equal pt, cipher.update(ct) << cipher.final
197197

198198
# truncated tag is accepted
199199
cipher = new_encryptor("aes-128-gcm", key: key, iv: iv, auth_data: aad)
200200
assert_equal ct, cipher.update(pt) << cipher.final
201201
assert_equal tag[0, 8], cipher.auth_tag(8)
202-
cipher = new_decryptor("aes-128-gcm", key: key, iv: iv, auth_data: aad, auth_tag: tag[0, 8])
202+
cipher = new_decryptor("aes-128-gcm", key: key, iv: iv, auth_tag: tag[0, 8], auth_data: aad)
203203
assert_equal pt, cipher.update(ct) << cipher.final
204204

205205
# wrong tag is rejected
206206
tag2 = tag.dup
207207
tag2.setbyte(-1, (tag2.getbyte(-1) + 1) & 0xff)
208-
cipher = new_decryptor("aes-128-gcm", key: key, iv: iv, auth_data: aad, auth_tag: tag2)
208+
cipher = new_decryptor("aes-128-gcm", key: key, iv: iv, auth_tag: tag2, auth_data: aad)
209209
cipher.update(ct)
210210
assert_raise(OpenSSL::Cipher::CipherError) { cipher.final }
211211

212212
# wrong aad is rejected
213213
aad2 = aad[0..-2] << aad[-1].succ
214-
cipher = new_decryptor("aes-128-gcm", key: key, iv: iv, auth_data: aad2, auth_tag: tag)
214+
cipher = new_decryptor("aes-128-gcm", key: key, iv: iv, auth_tag: tag, auth_data: aad2)
215215
cipher.update(ct)
216216
assert_raise(OpenSSL::Cipher::CipherError) { cipher.final }
217217

218218
# wrong ciphertext is rejected
219219
ct2 = ct[0..-2] << ct[-1].succ
220-
cipher = new_decryptor("aes-128-gcm", key: key, iv: iv, auth_data: aad, auth_tag: tag)
220+
cipher = new_decryptor("aes-128-gcm", key: key, iv: iv, auth_tag: tag, auth_data: aad)
221221
cipher.update(ct2)
222222
assert_raise(OpenSSL::Cipher::CipherError) { cipher.final }
223223
end if has_cipher?("aes-128-gcm")
@@ -241,7 +241,7 @@ def test_aes_gcm_variable_iv_len
241241
cipher = new_encryptor("aes-128-gcm", key: key, iv_len: 8, iv: iv, auth_data: aad)
242242
assert_equal ct, cipher.update(pt) << cipher.final
243243
assert_equal tag, cipher.auth_tag
244-
cipher = new_decryptor("aes-128-gcm", key: key, iv_len: 8, iv: iv, auth_data: aad, auth_tag: tag)
244+
cipher = new_decryptor("aes-128-gcm", key: key, iv_len: 8, iv: iv, auth_tag: tag, auth_data: aad)
245245
assert_equal pt, cipher.update(ct) << cipher.final
246246
end if has_cipher?("aes-128-gcm")
247247

@@ -257,7 +257,7 @@ def test_aes_ocb_tag_len
257257
cipher = new_encryptor("aes-128-ocb", key: key, iv: iv, auth_data: aad)
258258
assert_equal ct, cipher.update(pt) << cipher.final
259259
assert_equal tag, cipher.auth_tag
260-
cipher = new_decryptor("aes-128-ocb", key: key, iv: iv, auth_data: aad, auth_tag: tag)
260+
cipher = new_decryptor("aes-128-ocb", key: key, iv: iv, auth_tag: tag, auth_data: aad)
261261
assert_equal pt, cipher.update(ct) << cipher.final
262262

263263
# RFC 7253 Appendix A; with 96 bits tag length
@@ -274,7 +274,7 @@ def test_aes_ocb_tag_len
274274
cipher = new_encryptor("aes-128-ocb", auth_tag_len: 12, key: key, iv: iv, auth_data: aad)
275275
assert_equal ct, cipher.update(pt) << cipher.final
276276
assert_equal tag, cipher.auth_tag
277-
cipher = new_decryptor("aes-128-ocb", auth_tag_len: 12, key: key, iv: iv, auth_data: aad, auth_tag: tag)
277+
cipher = new_decryptor("aes-128-ocb", auth_tag_len: 12, key: key, iv: iv, auth_tag: tag, auth_data: aad)
278278
assert_equal pt, cipher.update(ct) << cipher.final
279279

280280
end if has_cipher?("aes-128-ocb")

0 commit comments

Comments
 (0)