aboutsummaryrefslogtreecommitdiffstats
path: root/ext/openssl
Commit message (Collapse)AuthorAgeFilesLines
...
* | pkey: add missing return value check in PKey#{sign,verify}Kazuki Yamaguchi2016-10-141-8/+18
| | | | | | | | | | | | | | We are currently not checking the return value of EVP_{Sign,Verify}*() functions, but of course, this is a bad habit. So do check. Calls for EVP_{Sign,Verify}Init() are replaced by *_ex() functions as they does not return error but just ignore.
* | pkey: tighten buffer size for signatureKazuki Yamaguchi2016-10-144-14/+9
| | | | | | | | | | | | | | We allocate too large buffer for the generated signature. The resulting signature, or the RSA encryption result, should not be larger than the size returned by EVP_PKEY_size() (or, DSA_size(), RSA_size(), and ECDSA_size()).
* | Merge branch 'topic/pkey-ec-conversion-form'Kazuki Yamaguchi2016-10-091-20/+35
|\ \ | | | | | | | | | | | | * 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-20/+35
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-18/+21
| | | | | | | | | | | | | | | Implement Cipher#authenticated? even when the OpenSSL version does not support AEAD. It just returns false.
* | | cipher: fix documentation regarding default IVKazuki Yamaguchi2016-10-031-9/+4
| | | | | | | | | | | | | | | | | | | | | Remove a sentence "If not explicitly set, the OpenSSL default of an all-zeroes ("\\0") IV is used." It actually works so, but not guranteed by the OpenSSL API. At least I didn't find any formal documentation saying so.
* | | Avoid memory leak on rb_str_new()Kazuki Yamaguchi2016-10-034-63/+13
| | | | | | | | | | | | | | | Use ossl_membio2str() to convert a mem BIO to Ruby String. This fixes possible memory leak on rb_str_new() failure, and also reduces code.
* | | Merge branch 'topic/cipher-no-initialize-null-key'Kazuki Yamaguchi2016-09-281-12/+13
|\ \ \ | |_|/ |/| | | | | | | | * 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-12/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | | 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
| | | |