aboutsummaryrefslogtreecommitdiffstats
path: root/test
Commit message (Collapse)AuthorAgeFilesLines
* Merge changes from Ruby trunk r56492..r56927Kazuki Yamaguchi2016-11-302-5/+5
|\ | | | | | | | | | | | | | | * ruby-trunk r56492..r56927: (2 commits) (r56927) parse.y: ambiguous parentheses (r56578) openssl/ut_eof.rb: rename TestEOF Sync-with-trunk: r56927
| * openssl/ut_eof.rb: rename TestEOFnobu2016-11-302-5/+5
| | | | | | | | | | | | | | * test/openssl/ut_eof.rb (OpenSSL::TestEOF): move TestEOF module under OpenSSL to get rid of conflict with test/ruby/ut_eof.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56578 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* | test: fix fragile test casesKazuki Yamaguchi2016-11-309-128/+66
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix the fragile test cases that are sensitive to the difference between Time.now.to_i and time(2). When issuing test certificates, we are typically setting the current time fetched by Time.now to the notBefore field. Time.now uses clock_gettime(2) with CLOCK_REALTIME. On the other hand, OpenSSL uses time(2) in its certificate verification code. On Linux/x86-64, time(2) is implemented not to return the adjusted 'current time' like Time.now, but to return the wall clock seconds at the last tick. This results in that time(2) called later may return an earlier time, causing the certificate verification to fail with 'certificate is not yet valid' error. So, create test certificates with notBefore<Time.now to avoid this. Since it's awful to do "Time.now - 1" everywhere, make the notBefore and notAfter fields optional with defaults with margin.
* | ssl: make OpenSSL::SSL::SSLContext#freeze an alias of #setuptopic/ssl-make-sslctx-freeze-alias-of-setupKazuki Yamaguchi2016-11-291-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | SSLSocket#setup uses the frozen state as "SSL_CTX is already set up". If an user manually freeze the context, it misunderstands as if #setup is already called, leading to unexpected behaviors because parameters the user set won't be actually set to the underlying SSL_CTX and thus ignored. Ideally, #setup should go and be replaced with setters. But we don't do this now because it is not that simple: some of them would produce new ordering issues, e.g. 'ca_file' property which loads a file into SSL_CTX::cert_store and 'cert_store' which replaces SSL_CTX::cert_store would conflict. Fixing this properly would require deprecating 'ca_file' first. So, let's take the second best way: make it "just work" instead of break silently. Fixes: https://github.com/ruby/openssl/issues/85
* | engine: undef alloc functionKazuki Yamaguchi2016-11-161-7/+0
| | | | | | | | | | | | This prevents users from allocating OpenSSL::Engine instance using OpenSSL::Engine.allocate. Undef'ing alloc function also allows us to remove explicit undef of OpenSSL::Engine.new and #initialize_copy.
* | Merge branch 'topic/asn1-fix-oob-read-constructed'Kazuki Yamaguchi2016-11-071-0/+23
|\ \ | |/ |/| | | | | * topic/asn1-fix-oob-read-constructed: asn1: fix out-of-bounds read in decoding constructed objects
| * asn1: fix out-of-bounds read in decoding constructed objectstopic/asn1-fix-oob-read-constructedKazuki Yamaguchi2016-09-281-0/+23
| | | | | | | | | | | | | | | | | | | | OpenSSL::ASN1.{decode,decode_all,traverse} have a bug of out-of-bounds read. int_ossl_asn1_decode0_cons() does not give the correct available length to ossl_asn1_decode() when decoding the inner components of a constructed object. This can cause out-of-bounds read if a crafted input given. Reference: https://hackerone.com/reports/170316
* | test/test_pair: revert workaround added by r42790Kazuki Yamaguchi2016-10-241-12/+6
| | | | | | | | | | | | | | It was added as a workaround for "bad write retry" error that occurs when SSLSocket#write_nonblock is retried with a different String. This is now fixed by r54466 ("openssl: accept moving write buffer for write_nonblock", 2016-03-31).
* | Merge branch 'topic/test-static-test-vector'Kazuki Yamaguchi2016-10-174-56/+56
|\ \ | | | | | | | | | | | | * topic/test-static-test-vector: test/test_pkey_*: refine sign/verify tests
| * | test/test_pkey_*: refine sign/verify teststopic/test-static-test-vectorKazuki Yamaguchi2016-10-164-56/+56
| | | | | | | | | | | | | | | | | | | | | | | | 20a88ace0778 ("test: refactor PKey::PKey#{sign,verify} tests", 2016-07-07) was not a good idea in the sense of readability. So, let's revert it. Also, static test vectors generated by BouncyCastle are added to ensure #verify correctly accept valid signatures and reject invalid signatures.
* | | Merge branch 'topic/test-static-test-vector'Kazuki Yamaguchi2016-10-092-263/+218
|\| | | | | | | | | | | | | | | | | * topic/test-static-test-vector: test/test_hmac: use static test vectors test/test_cipher: use static test vectors
| * | test/test_hmac: use static test vectorsKazuki Yamaguchi2016-10-091-25/+19
| | | | | | | | | | | | | | | Ensure that OpenSSL::HMAC works as expected by comparing the result with known correct test vectors.
| * | test/test_cipher: use static test vectorsKazuki Yamaguchi2016-10-091-238/+199
| | | | | | | | | | | | | | | | | | | | | | | | | | | Compare the result with static test vectors rather than just testing that the encryption result can be decrypted. The current test cases wouldn't catch failure if both the encryption and decryption routines are broken. Test vectors are taken from external sources as noted in the comments.
* | | Merge branch 'topic/pkey-ec-conversion-form'Kazuki Yamaguchi2016-10-091-0/+4
|\ \ \ | |/ / |/| | | | | | | | * topic/pkey-ec-conversion-form: pkey: allow specifying conversion form in EC::Point#to_bn
| * | pkey: allow specifying conversion form in EC::Point#to_bntopic/pkey-ec-conversion-formKazuki Yamaguchi2016-09-281-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, when we want to convert a point data into an octet string with non-default conversion form, we have to set the desirable form to the associated EC::Group beforehand. This is inconvenient and counterintuitive because the conversion form is not actually related to the EC group. point = ... point.group.point_conversion_form = :compressed point.to_bn So, allow specifying the form as an optional parameter, like this: point = ... point.to_bn(:compressed)
* | | cipher: always define Cipher#authenticated?Kazuki Yamaguchi2016-10-041-11/+11
| | | | | | | | | | | | | | | Implement Cipher#authenticated? even when the OpenSSL version does not support AEAD. It just returns false.
* | | test/test_digest: compare with literalsKazuki Yamaguchi2016-09-283-24/+17
| | | | | | | | | | | | | | | Compare with pre-calculated string literals rather than the output of Digest::MD5 (ext/digest).
* | | Merge branch 'topic/cipher-no-initialize-null-key'Kazuki Yamaguchi2016-09-281-6/+23
|\ \ \ | |_|/ |/| | | | | | | | * topic/cipher-no-initialize-null-key: cipher: don't set dummy encryption key in Cipher#initialize
| * | cipher: don't set dummy encryption key in Cipher#initializetopic/cipher-no-initialize-null-keyKazuki Yamaguchi2016-09-281-6/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Remove the encryption key initialization from Cipher#initialize. This is effectively a revert of r32723 ("Avoid possible SEGV from AES encryption/decryption", 2011-07-28). r32723, which added the key initialization, was a workaround for Ruby Bug #2768. For some certain ciphers, calling EVP_CipherUpdate() before setting an encryption key caused segfault. It was not a problem until OpenSSL implemented GCM mode - the encryption key could be overridden by repeated calls of EVP_CipherInit_ex(). But, it is not the case for AES-GCM ciphers. Setting a key, an IV, a key, in this order causes the IV to be reset to an all-zero IV. The problem of Bug #2768 persists on the current versions of OpenSSL. So, make Cipher#update raise an exception if a key is not yet set by the user. Since encrypting or decrypting without key does not make any sense, this should not break existing applications. Users can still call Cipher#key= and Cipher#iv= multiple times with their own responsibility. Reference: https://bugs.ruby-lang.org/issues/2768 Reference: https://bugs.ruby-lang.org/issues/8221 Reference: https://github.com/ruby/openssl/issues/49
* | | test/test_ssl: suppress syntax warningKazuki Yamaguchi2016-09-281-2/+2
| | | | | | | | | | | | | | | Add parentheses around regexp literals to suppress "ambiguous first argument; put parentheses or a space even after `/' operator" warning.
* | | pkey: make PKey#verify check the existence of the public keyKazuki Yamaguchi2016-09-231-0/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Check existence of the public key in the PKey object before starting verifying a signature. For RSA keys, EVP_VerifyFinal() internally calls RSA_size(), which requires the existence of RSA::n. Since we allow instatiating PKey::RSA without any key materials, calling PKey#verify against an empty PKey::RSA causes segfault. Reference: https://bugs.ruby-lang.org/issues/12783
* | | test/test_asn1: remove pointless begin-endKazuki Yamaguchi2016-09-221-193/+117
|/ /
* | test/test_ssl: fix test_ctx_optionsKazuki Yamaguchi2016-09-171-2/+2
| | | | | | | | | | | | | | Reorder the assertions. The fix in f9c04779a84b was incomplete - setting nil as the options is also affected by the Ubuntu's patch: http://rubyci.s3.amazonaws.com/ubuntu/ruby-trunk/log/20160917T063002Z.fail.html.gz
* | test/test_ssl: workaround for Ubuntu patch for SSL_CTX_*_optionsKazuki Yamaguchi2016-09-131-2/+5
|/ | | | | The patch included in Ubuntu's libssl1.0.0 1.0.2g-1ubuntu4.3 package forcibly adds SSL_OP_NO_SSLv3 option.
* test/utils: remove use_anon_cipher option from SSLTestCase#start_servertopic/ssl-test-cleanupKazuki Yamaguchi2016-09-072-7/+8
| | | | | | | | | Only TestSSL#test_post_connect_check_with_anon_ciphers uses it. The option just sets 'ADH-AES256-GCM-SHA384' as the available cipher suites and set the security level of the context to 0 - both can be achieved using ctx_proc option of start_server. And we don't have to stick to the cipher suite 'ADH-AES256-GCM-SHA384' so specify 'aNULL' instead. This allows removing the cipher suite existence check.
* test/test_ssl: refactor SNI testsKazuki Yamaguchi2016-09-071-169/+40
| | | | | | | test_servername_cb{,_sets_context_on_the_socket,_can_return_nil, _calls_setup_on_returned_ctx} and test_tlsext_hostname are highly overlapping. So unify them into a single test_tlsext_hostname. The test coverage does not change.
* test/test_pair: extract IO-like methods tests from test_ssl.rbKazuki Yamaguchi2016-09-072-97/+45
| | | | | Move a test case of SSLSocket#gets to test_pair.rb, and remove test cases from test_ssl.rb which duplicate the tests in test_pair.rb
* test/test_ssl: move DH and ECDH tests from test_pair.rbKazuki Yamaguchi2016-09-072-141/+117
| | | | | | test_pair.rb is the file for tests of IO-like methods - the test cases in OpenSSL::TestPairM run twice with different underlying socket type. test_ssl.rb is more appropriate file for {EC,}DH tests.
* test/test_ssl: simplify SSL context options testsKazuki Yamaguchi2016-09-071-53/+18
| | | | | | Unify test cases for SSLContext#options. Also add an assertion to test_sslctx_set_params for OP_NO_COMPRESSION and OP_DONT_INSERT_EMPTY_FRAGMENTS.
* test/test_ssl: test SSLSocket#{cert,peer_cert,peer_cert_chain}Kazuki Yamaguchi2016-09-071-11/+29
| | | | Add an explicit test case for them.
* test/test_ssl: remove 'STARTTLS' code from test/utils.rbKazuki Yamaguchi2016-09-072-27/+35
| | | | | Move it to TestSSL#test_starttls using the server_proc option of start_server, as it is the only user of the 'STARTTLS' code.
* test/utils: make SSLTestCase#start_server take keyword argumentsKazuki Yamaguchi2016-09-073-50/+42
| | | | | | | | | Convert the two mandatory parameters, verify_mode and start_immediately, into keyword arguments with a default value. The verify_mode parameter is only useful for client certificate authentication. So most test cases sets to OpenSSL::SSL::VERIFY_NONE. Also the start_immediately option is usually set to true.
* pkcs12: fix .new to handle strucuture with no keys or no certstopic/pkcs12-read-no-private-keyKazuki Yamaguchi2016-09-051-0/+106
| | | | | | | | | | It's possible that a PKCS #12 strucuture holds zero private keys. At such a time PKCS12_parse() returns NULL as the private key. Likewise, when the strucuture does not contain the corresponding certificate to the private key, PKCS12_parse() returns NULL as the certificate. Reported and fix suggested by Masahiro Tomita <tommy@tmtm.org>. [ruby-dev:49776] [Bug #12726]
* test/test_ssl: fix test_alpn_protocol_selection_cancel againKazuki Yamaguchi2016-08-301-2/+2
| | | | | | | | | 's2.connect' can block indefinitely depending on the version of OpenSSL. Since the point of the test case is to check the failure path on ALPN protocol selection callback, that is called on the server side, just avoid blocking with SSLSocket#connect_nonblock on the client side. The callback is called just after receiving the Client Hello so calling SSLSocket#connect_nonblock once should be sufficient.
* ssl: catch exceptions raised in ALPN/NPN callbacksKazuki Yamaguchi2016-08-301-0/+1
| | | | | | | | | | | | | | | They aren't exception safe - they are called during parsing the Client/Server Hello from OpenSSL code. An exception raised in the callbacks escapes directly from OpenSSL code so it can break internal status of OpenSSL. We have a procedure for handling such exceptions raised during an handshake: catch them and store the state number in the SSLSocket object, and then check it in ossl_ssl_start() and re-raise after the control turned back to our side. This fixes the instability of TestSSL::test_alpn_protocol_selection_cancel.
* test: move test_partial_record_read into test_pair.rbKazuki Yamaguchi2016-08-282-35/+10
| | | | It can make use of ssl_pair. This allows removing 6 secs sleep.
* x509ext: fix X509::ExtensionFactory#create_ext with configKazuki Yamaguchi2016-08-281-9/+15
| | | | | | | The assumption in commit 1b1d520818e0 ("x509ext: fix memory leak in X509::ExtensionFactory#config=") was wrong. The uninitialized X509V3_CTX::db can be referred through "r2i" functions when creating certain types of extension that use them.
* Remove test/mdebugKazuki Yamaguchi2016-08-263-118/+0
| | | | | It was not implemented in a good way - for example it doesn't compile on Windows and causes 'rake compile' to fail... So remove for now.
* Merge branch 'topic/cipher-auth-tag-len'Kazuki Yamaguchi2016-08-261-0/+33
|\ | | | | | | | | * topic/cipher-auth-tag-len: cipher: add Cipher#auth_tag_len=
| * cipher: add Cipher#auth_tag_len=topic/cipher-auth-tag-lenKazuki Yamaguchi2016-08-141-0/+33
| | | | | | | | | | | | Add a method to set the authentication tag length to be generate by an AEAD ciphers. In particular, OCB mode which is implemented in OpenSSL 1.1.0 requires this.
* | test/test_pkey: fix merge conflict errorKazuki Yamaguchi2016-08-261-2/+2
| |
* | test/test_ocsp: ignore test failure due to a bug in old OpenSSLKazuki Yamaguchi2016-08-261-1/+11
| | | | | | | | Reference: https://rt.openssl.org/Ticket/Display.html?id=2560
* | test/test_ocsp: cleanupKazuki Yamaguchi2016-08-261-44/+50
| | | | | | | | Remove unnecessary or duplicate assertions, and merge test cases.
* | test/test_ocsp: remove broken assertionsKazuki Yamaguchi2016-08-261-2/+0
| | | | | | | | | | The removed assertions are wrong and testing a bug - the verification must fail because OpenSSL shouldn't find the signer's certificate.
* | pkey: allow non-BN object as the multiplier in PKey::EC::Point#mulKazuki Yamaguchi2016-08-221-7/+8
| |
* | Merge branch 'topic/fixup-tests'Kazuki Yamaguchi2016-08-195-562/+62
|\ \ | | | | | | | | | | | | | | | * topic/fixup-tests: test: remove unused methods test/test_ssl: fix failure on Windows
| * | test: remove unused methodstopic/fixup-testsKazuki Yamaguchi2016-08-193-521/+6
| | | | | | | | | | | | They are imported from Ruby tree but unused in this tree.
| * | test/test_ssl: fix failure on WindowsKazuki Yamaguchi2016-08-192-41/+56
| | | | | | | | | | | | | | | Due to the difference in error handling, the error raised by SSLSocket#connect may differ.
* | | Merge branch 'topic/fixup-tests'Kazuki Yamaguchi2016-08-186-594/+559
|\| | | | | | | | | | | | | | | | | | | | | | | * topic/fixup-tests: test: refactor PKey::PKey#{sign,verify} tests test: rework PEM/DER encoding and decoding tests test/test_pkey_ec: stop iterating all curves test/test_pkey_dh: refine OpenSSL::PKey::DH::DEFAULT_* tests
| * | test: refactor PKey::PKey#{sign,verify} testsKazuki Yamaguchi2016-08-183-41/+49
| | | | | | | | | | | | | | | RSA, DSA and EC should work in the same way, so extract to a new file, test/test_pkey.rb.