aboutsummaryrefslogtreecommitdiffstats
path: root/ext/openssl
Commit message (Collapse)AuthorAgeFilesLines
* asn1: fix out-of-bounds read in decoding constructed objectstopic/asn1-fix-oob-read-constructedKazuki Yamaguchi2016-09-281-7/+6
| | | | | | | | | | 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
* Merge changes from Ruby trunk r56173..r56225Kazuki Yamaguchi2016-09-251-1/+1
|\ | | | | | | | | | | | | * ruby-trunk r56173..r56225: (1 commits) (r56225) fid typos [ci skip] Sync-with-trunk: r56225
| * fid typos [ci skip]nobu2016-09-251-1/+1
| | | | | | | | | | | | * fix typos, "a" before "Integer" to "an". [Fix GH-1438] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56225 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* | pkey: make PKey#verify check the existence of the public keyKazuki Yamaguchi2016-09-231-0/+40
| | | | | | | | | | | | | | | | | | | | | | | | 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
* | asn1: remove dead codeKazuki Yamaguchi2016-09-221-37/+0
| | | | | | | | | | | | | | | | Remove code relating DO_IT_VIA_RUBY. If DO_IT_VIA_RUBY is set to 1, OpenSSL::ASN1.decode will decode ASN.1 INTEGER values into a Ruby's Integer instead of OpenSSL::BN. However it would be too late to change now. Anyway, if we change out mind, we will rewrite it to avoid unnecessary conversions between BIGNUM.
* | asn1: avoid SYM2ID on runtimeKazuki Yamaguchi2016-09-221-58/+45
| | | | | | | | | | Store the Symbols rather than their ID. This simplifies the source code, and fixes the illegal assignment of ID value to VALUE type variables.
* | asn1: fix error path in ossl_asn1_default_tag()Kazuki Yamaguchi2016-09-221-7/+4
| | | | | | | | | | | | | | | | | | rb_class_superclass() returns nil when there is no available super class for the class object. Since the condition of the while statement is incorrect, we call rb_class_superclass() against nil. This fixes the segfault occurs with a code: OpenSSL::ASN1::Primitive.new("abc")
* | asn1: don't use assert() in decode_bool()Kazuki Yamaguchi2016-09-221-6/+5
|/ | | | | The length is not necessary 3. Fixes r55288 (0b1e59f2c11b, "openssl: avoid d2i_ASN1_BOOLEAN()", 2016-06-05).
* Merge changes from Ruby trunk r56028..r56173Kazuki Yamaguchi2016-09-171-1/+5
|\ | | | | | | | | | | | | | | | | * ruby-trunk r56028..r56173: (3 commits) (r56173) * ext/openssl/ossl_ssl.c (ssl_npn_select_cb_common): Fix co.. (r56147) openssl: workaround for Ubuntu's patched OpenSSL (r56098) openssl: import v2.0.0.beta.2 Sync-with-trunk: r56173
| * * ext/openssl/ossl_ssl.c (ssl_npn_select_cb_common): Fix compile errorngoto2016-09-171-1/+5
| | | | | | | | | | | | | | | | | | with old version of fcc (Fujitsu C Compiler) on Solaris 10. [Bug #12769] [ruby-dev:49809] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56173 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
| * openssl: import v2.0.0.beta.2rhe2016-09-174-406/+355
| | | | | | | | | | | | | | | | * {ext,test}/openssl: Import Ruby/OpenSSL 2.0.0.beta.2. The full commit history since v2.0.0.beta.1 can be found at: https://github.com/ruby/openssl/compare/v2.0.0.beta.1...v2.0.0.beta.2 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56098 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* | Use rb_obj_class() instead of CLASS_OF()Kazuki Yamaguchi2016-09-086-19/+18
| | | | | | | | | | | | CLASS_OF() (or, rb_class_of()) may return the singleton class of the object; so avoid using it and replace with rb_obj_class() that returns the actual class of the object.
* | Remove unneeded workaround for dependKazuki Yamaguchi2016-09-071-3/+1
| | | | | | | | | | | | r45944 exported the internal thread_native.h as ruby/thread_native.h. It does not depend on the thread model specific headers, so the workaround is no longer necessary.
* | pkey: make OpenSSL::PKey::EC::Group wrap an EC_GROUP directlytopic/pkey-ec-unlinkKazuki Yamaguchi2016-09-071-101/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As done for EC::Point, remove ossl_ec_group struct. This contains a breaking change. Modifications to an EC::Group returned by EC#group no longer affects the EC object unless set to the key explicitly using EC#group=. This is the common behavior in Ruby/OpenSSL, including other getter methods of EC such as EC#public_key. EC#group currently returns a EC::Group linked with the key, i.e. the EC::Group object holds a reference to an EC_GROUP that the EC_KEY owns. We use some ugly workaround - the ossl_ec_group struct has a flag 'dont_free' that indicates we must not free the EC_GROUP. But it is still not possible to control OpenSSL of free'ing the EC_GROUP, so, for example, the following code behaves strangely: ec = OpenSSL::PKey::EC.generate("prime256v1") group = ec.group p group.curve_name #=> "prime256v1" ec.group = OpenSSL::PKey::EC::Group.new("prime256v1") p group.curve_name #=> nil
* | pkey: make OpenSSL::PKey::EC::Point wrap an EC_POINT directlyKazuki Yamaguchi2016-09-071-64/+55
| | | | | | | | | | | | | | Currently an OpenSSL::PKey::EC::Point wraps an ossl_ec_point struct which has a pointer for EC_POINT. This commit make EC::Point wrap an EC_POINT directly in order to simplify the source code. There should be no changes on behavior seen from Ruby.
* | pkey: make ossl_pkey_ec.c follow the common macro namingKazuki Yamaguchi2016-09-071-127/+102
| | | | | | | | | | | | | | Make ossl_pkey_ec.c follow the general convension on macro names. Prefer CamelCase to Snake_Case and unify Require_*() and Get_*() macros into Get*() macros. There is nothing wrong with the style itself but it's hard to read if two different styles are mixed.
* | pkcs12: fix .new to handle strucuture with no keys or no certstopic/pkcs12-read-no-private-keyKazuki Yamaguchi2016-09-051-9/+11
| | | | | | | | | | | | | | | | | | | | 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]
* | ssl: eliminate SSLContext::INIT_VARStopic/ssl-eliminate-init-varsKazuki Yamaguchi2016-09-021-100/+110
| | | | | | | | | | | | | | | | | | | | | | | | Use rb_attr_get() instead of rb_iv_get() so that we can remove SSLContext::INIT_VARS. SSLContext::INIT_VARS contains the names of the instance variables used in SSLContext. SSLContext#initialize sets nil for those variables. It is necessary to suppress "instance variable @foo not initialized" warnings emitted by rb_iv_get(). The warnings can be avoided by using rb_attr_get() that does not check the existence of the variable. So use it.
* | ssl: hide callback_state from RubyKazuki Yamaguchi2016-09-021-1/+1
| | | | | | | | | | | | | | | | | | Remove '@' prefix from the variable name to hide it from Ruby. Currently a SSLSocket instance allows modifying the value of @callback_state if an user use Object#instance_variable_set. This is dangerous because the variable is used for storing the tag jump state - modifying it from Ruby can crash the process.
* | ssl: don't store selected {EC,}DH parameter in an instance variableKazuki Yamaguchi2016-09-021-4/+0
| | | | | | | | | | | | | | | | The OpenSSL::PKey::{DH,EC} object is stored in an instance variable to prevent the object from being GC'd (cf. r51460). However it turned out to be unnecessary. The underlying object, DH and EC_KEY, have a reference counter and OpenSSL increments it for the object returned by the callback functions.
* | ssl: check return value of SSL_CTX_set_alpn_protos()Kazuki Yamaguchi2016-08-301-1/+5
| | | | | | | | | | | | The function can fail on memory allocation error. Note that the function returns 0 on success unlike other almost all functions in OpenSSL.
* | ssl: catch exceptions raised in ALPN/NPN callbacksKazuki Yamaguchi2016-08-301-15/+47
|/ | | | | | | | | | | | | | | 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.
* * remove trailing spaces.svn2016-08-291-3/+3
| | | | git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56028 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
* Ruby/OpenSSL 2.0.0.beta.1v2.0.0.beta.1Kazuki Yamaguchi2016-08-291-1/+1
|
* pkey: use rb_attr_get() instead of rb_iv_get() in ossl_pkey_ec.cKazuki Yamaguchi2016-08-281-24/+29
| | | | | This suppresses runtime warning of "instance variable @group not initialized".
* x509ext: fix X509::ExtensionFactory#create_ext with configKazuki Yamaguchi2016-08-281-0/+2
| | | | | | | 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.
* Avoid unnecessary memory allocation in string2hex()Kazuki Yamaguchi2016-08-264-87/+56
| | | | | | | Remove string2hex() and replace with newly added ossl_bin2hex(). Since the output hex string is always returned to users as a String, we can avoid the memory allocation by writing directly to the String buffer. This also reduces some lines of code.
* Merge branch 'topic/cipher-auth-tag-len'Kazuki Yamaguchi2016-08-261-3/+45
|\ | | | | | | | | * 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-3/+45
| | | | | | | | | | | | 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.
* | ocsp: fix error queue leak on OCSP::{BasicResponse,Request}#verifyKazuki Yamaguchi2016-08-261-2/+2
| | | | | | | | | | OCSP_{basic,request}_verify() can return a negative value for verification failure.
* | ocsp: set properly OCSP_NOCERTS flag in OCSP::Request#signKazuki Yamaguchi2016-08-261-7/+9
| | | | | | | | | | | | The variable names 'flg' and 'flags' are mixed up and it doesn't set OCSP_NOCERTS flag correctly when the 'certs' argument is not given. [Bug #12704] [ruby-core:77061]
* | Adapt to OpenSSL changes after the 1.1.0-pre6Kazuki Yamaguchi2016-08-268-39/+67
| | | | | | | | | | | | | | Fix compiler errors and warnings. The order of parameters of X509_{CRL,REQ}_get0_signature() has been changed, and certificate and CRL time accessors have been reorganized: *_get_* functions are deprecated and replaced by *_get0_* that return a const pointer.
* | asn1: constify functionsKazuki Yamaguchi2016-08-264-11/+12
| | | | | | | | In order to avoid compiler warnings when build with OpenSSL 1.1.0.
* | bn: optimize try_convert_to_bnptr() for non-BN objectstopic/argument-conversionKazuki Yamaguchi2016-08-221-46/+55
| | | | | | | | | | | | | | | | | | | | | | Use the same logic as BN#initialize. It is used through GetBNPtr(). For example, with this change, the following code will be about 7x faster: puts Benchmark.measure { a = 0.to_bn b = 2 ** 2048 i = 0; a + b while (i += 1) <= 1_000_000 }
* | Avoid using *2FIX() where we don't know if it really fits in FixnumKazuki Yamaguchi2016-08-229-31/+28
| |
* | pkey: allow non-BN object as the multiplier in PKey::EC::Point#mulKazuki Yamaguchi2016-08-221-7/+6
| |
* | cipher: allow cipher name in GetCipherPtr()Kazuki Yamaguchi2016-08-221-3/+16
| | | | | | | | | | | | | | | | | | | | | | | | The function GetCipherPtr() is used when we want a const EVP_CIPHER that represents a cipher algorithm. This change allows users to write a code that exports a PKey encrypted without creating an OpenSSL::Cipher instance: pkey = OpenSSL::PKey.read(...) pkey.export("aes-128-cbc") { password } This is the same as what happened to GetDigestPtr() in r12128.
* | Merge pull request #59 from ruby/topic/doc-workKazuki Yamaguchi2016-08-221-14/+0
|\ \ | | | | | | [WIP] Add NEWS and update CONTRIBUTING.md
| * \ Merge branch 'master' into topic/doc-workKazuki Yamaguchi2016-08-0920-143/+355
| |\ \
| * | | Remove Install section from rdocKazuki Yamaguchi2016-07-281-14/+0
| | | |
* | | | x509store: fixup documentationtopic/fixup-docsKazuki Yamaguchi2016-08-222-32/+243
| | | |
* | | | pkey: fixup documentKazuki Yamaguchi2016-08-225-111/+243
| | | |
* | | | hmac: fixup documentationKazuki Yamaguchi2016-08-221-0/+28
| | | |
* | | | digest: cleanup documentationKazuki Yamaguchi2016-08-221-6/+5
| | | |
* | | | cipher: fixup documentationKazuki Yamaguchi2016-08-221-21/+27
| | | |
* | | | random: fix document styleKazuki Yamaguchi2016-08-221-7/+7
| | | |
* | | | ssl: fixup documentationKazuki Yamaguchi2016-08-222-61/+59
| | | |
* | | | Merge branch 'topic/cipher-doc-aead'Kazuki Yamaguchi2016-08-181-6/+8
|\ \ \ \ | | | | | | | | | | | | | | | | | | | | * topic/cipher-doc-aead: cipher: follow up for the previous documentation update
| * | | | cipher: follow up for the previous documentation updatetopic/cipher-doc-aeadKazuki Yamaguchi2016-08-161-6/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add some explaination about the associated data. Also fix the description of the AES-GCM example: the IV (nonce) doesn't need to be unpredictable.
* | | | | pkey: clear OpenSSL error queue on PKey::PKey#verify failuretopic/pkey-rsa-verify-error-queueKazuki Yamaguchi2016-08-171-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | Similar to 0789643d7333 or 9af69abcec15, EVP_VerifyFinal() may put an error to the error queue when the verification failed.