openssl-signature_algorithm-1.3.0/0000755000004100000410000000000014422530221017266 5ustar www-datawww-dataopenssl-signature_algorithm-1.3.0/Gemfile.lock0000644000004100000410000000270014422530221021507 0ustar www-datawww-dataPATH remote: . specs: openssl-signature_algorithm (1.2.1) openssl (> 2.0) GEM remote: https://rubygems.org/ specs: appraisal (2.2.0) bundler rake thor (>= 0.14.0) ast (2.4.2) byebug (11.1.1) diff-lcs (1.3) ed25519 (1.2.4) json (2.6.3) openssl (3.0.0) parallel (1.22.1) parser (3.2.1.0) ast (~> 2.4.1) rainbow (3.1.1) rake (13.0.1) regexp_parser (2.7.0) rexml (3.2.5) rspec (3.9.0) rspec-core (~> 3.9.0) rspec-expectations (~> 3.9.0) rspec-mocks (~> 3.9.0) rspec-core (3.9.1) rspec-support (~> 3.9.1) rspec-expectations (3.9.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.9.0) rspec-mocks (3.9.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.9.0) rspec-support (3.9.2) rubocop (1.45.1) json (~> 2.3) parallel (~> 1.10) parser (>= 3.2.0.0) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) rubocop-ast (>= 1.24.1, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.24.1) parser (>= 3.1.1.0) ruby-progressbar (1.11.0) thor (1.0.1) unicode-display_width (2.4.2) PLATFORMS ruby DEPENDENCIES appraisal (~> 2.2) byebug (~> 11.0) ed25519 (~> 1.2) openssl-signature_algorithm! rake (~> 13.0) rspec (~> 3.0) rubocop (~> 1.0) BUNDLED WITH 2.3.26 openssl-signature_algorithm-1.3.0/.rspec0000644000004100000410000000010414422530221020376 0ustar www-datawww-data--format documentation --color --require spec_helper --order random openssl-signature_algorithm-1.3.0/README.md0000644000004100000410000001005514422530221020546 0ustar www-datawww-data# OpenSSL::SignatureAlgorithm > ECDSA, EdDSA, RSA-PSS and RSA-PKCS#1 signature algorithms for ruby Sign and verify using signature algorithm wrappers, instead of key objects. Provides `OpenSSL::SignatureAlgorithm::ECDSA`, `OpenSSL::SignatureAlgorithm::EdDSA`, `OpenSSL::SignatureAlgorithm::RSAPSS` and `OpenSSL::SignatureAlgorithm::RSAPKCS1` ruby object wrappers on top of `OpenSSL::PKey::EC` and `OpenSSL::PKey::RSA`, so that you can reason in terms of the algorithms and do less when signing or verifying signatures. Loosely inspired by [rbnacl](https://github.com/RubyCrypto/rbnacl)'s [Digital Signatures](https://github.com/RubyCrypto/rbnacl/wiki/Digital-Signatures) interface. [![Gem](https://img.shields.io/gem/v/openssl-signature_algorithm.svg?style=flat-square&color=informational)](https://rubygems.org/gems/openssl-signature_algorithm) [![Actions Build](https://github.com/cedarcode/openssl-signature_algorithm/workflows/build/badge.svg)](https://github.com/cedarcode/openssl-signature_algorithm/actions) ## Installation Add this line to your application's Gemfile: ```ruby gem 'openssl-signature_algorithm' ``` And then execute: $ bundle install Or install it yourself as: $ gem install openssl-signature_algorithm ## Usage ### ECDSA ```ruby to_be_signed = "to-be-signed" # Signer algorithm = OpenSSL::SignatureAlgorithm::ECDSA.new signing_key = algorithm.generate_signing_key signature = algorithm.sign(to_be_signed) # Signer sends verify key to Verifier verify_key_string = signing_key.verify_key.serialize # Verifier verify_key = OpenSSL::SignatureAlgorithm::ECDSA::VerifyKey.deserialize(verify_key_string) algorithm = OpenSSL::SignatureAlgorithm::ECDSA.new algorithm.verify_key = verify_key algorithm.verify(signature, to_be_signed) ``` ### EdDSA Requires adding the `ed25519` gem to your `Gemfile` ```ruby require "openssl/signature_algorithm/eddsa" to_be_signed = "to-be-signed" # Signer algorithm = OpenSSL::SignatureAlgorithm::EdDSA.new signing_key = algorithm.generate_signing_key signature = algorithm.sign(to_be_signed) # Signer sends verify key to Verifier verify_key_string = signing_key.verify_key.serialize # Verifier verify_key = OpenSSL::SignatureAlgorithm::EdDSA::VerifyKey.deserialize(verify_key_string) algorithm = OpenSSL::SignatureAlgorithm::EdDSA.new algorithm.verify_key = verify_key algorithm.verify(signature, to_be_signed) ``` ### RSA-PSS ```ruby to_be_signed = "to-be-signed" # Signer algorithm = OpenSSL::SignatureAlgorithm::RSAPSS.new signing_key = algorithm.generate_signing_key signature = algorithm.sign(to_be_signed) # Signer sends verify key to Verifier verify_key_string = signing_key.verify_key.serialize # Verifier verify_key = OpenSSL::SignatureAlgorithm::RSAPSS::VerifyKey.deserialize(verify_key_string) algorithm = OpenSSL::SignatureAlgorithm::RSAPSS.new algorithm.verify_key = verify_key algorithm.verify(signature, to_be_signed) ``` ### RSA-PKCS1_v1.5 ```ruby to_be_signed = "to-be-signed" # Signer algorithm = OpenSSL::SignatureAlgorithm::RSAPKCS1.new signing_key = algorithm.generate_signing_key signature = algorithm.sign(to_be_signed) # Signer sends verify key to Verifier verify_key_string = signing_key.verify_key.serialize # Verifier verify_key = OpenSSL::SignatureAlgorithm::RSAPKCS1::VerifyKey.deserialize(verify_key_string) algorithm = OpenSSL::SignatureAlgorithm::RSAPKCS1.new algorithm.verify_key = verify_key algorithm.verify(signature, to_be_signed) ``` ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/cedarcode/openssl-signature_algorithm. openssl-signature_algorithm-1.3.0/bin/0000755000004100000410000000000014422530221020036 5ustar www-datawww-dataopenssl-signature_algorithm-1.3.0/bin/console0000755000004100000410000000061014422530221021423 0ustar www-datawww-data#!/usr/bin/env ruby # frozen_string_literal: true require "bundler/setup" require "openssl/signature_algorithm" # You can add fixtures and/or initialization code here to make experimenting # with your gem easier. You can also use a different console, if you like. # (If you use this, don't forget to add pry to your Gemfile!) # require "pry" # Pry.start require "irb" IRB.start(__FILE__) openssl-signature_algorithm-1.3.0/bin/setup0000755000004100000410000000020314422530221021117 0ustar www-datawww-data#!/usr/bin/env bash set -euo pipefail IFS=$'\n\t' set -vx bundle install # Do any other automated setup that you need to do here openssl-signature_algorithm-1.3.0/gemfiles/0000755000004100000410000000000014422530221021061 5ustar www-datawww-dataopenssl-signature_algorithm-1.3.0/gemfiles/.bundle/0000755000004100000410000000000014422530221022410 5ustar www-datawww-dataopenssl-signature_algorithm-1.3.0/gemfiles/.bundle/config0000644000004100000410000000002614422530221023576 0ustar www-datawww-data--- BUNDLE_RETRY: "1" openssl-signature_algorithm-1.3.0/gemfiles/openssl_2_1.gemfile0000644000004100000410000000040414422530221024535 0ustar www-datawww-data# This file was generated by Appraisal source "https://rubygems.org" gem "appraisal", "~> 2.2" gem "byebug", "~> 11.0" gem "ed25519", "~> 1.2" gem "rake", "~> 13.0" gem "rspec", "~> 3.0" gem "rubocop", "~> 1.0" gem "openssl", "~> 2.1.0" gemspec path: "../" openssl-signature_algorithm-1.3.0/gemfiles/openssl_3_1.gemfile0000644000004100000410000000040414422530221024536 0ustar www-datawww-data# This file was generated by Appraisal source "https://rubygems.org" gem "appraisal", "~> 2.2" gem "byebug", "~> 11.0" gem "ed25519", "~> 1.2" gem "rake", "~> 13.0" gem "rspec", "~> 3.0" gem "rubocop", "~> 1.0" gem "openssl", "~> 3.1.0" gemspec path: "../" openssl-signature_algorithm-1.3.0/gemfiles/openssl_2_2.gemfile0000644000004100000410000000040414422530221024536 0ustar www-datawww-data# This file was generated by Appraisal source "https://rubygems.org" gem "appraisal", "~> 2.2" gem "byebug", "~> 11.0" gem "ed25519", "~> 1.2" gem "rake", "~> 13.0" gem "rspec", "~> 3.0" gem "rubocop", "~> 1.0" gem "openssl", "~> 2.2.0" gemspec path: "../" openssl-signature_algorithm-1.3.0/gemfiles/openssl_3_0.gemfile0000644000004100000410000000040414422530221024535 0ustar www-datawww-data# This file was generated by Appraisal source "https://rubygems.org" gem "appraisal", "~> 2.2" gem "byebug", "~> 11.0" gem "ed25519", "~> 1.2" gem "rake", "~> 13.0" gem "rspec", "~> 3.0" gem "rubocop", "~> 1.0" gem "openssl", "~> 3.0.0" gemspec path: "../" openssl-signature_algorithm-1.3.0/CHANGELOG.md0000644000004100000410000000663214422530221021106 0ustar www-datawww-data# Changelog ## [v1.3.0] - 2023-02-15 - Loose OpenSSL dependency to support 3.1 users. Thanks @bdewater <3 ## [v1.2.1] - 2022-06-05 - Support OpenSSL ~>3.0.0. Credits to @ClearlyClaire <3 ## [v1.1.1] - 2021-02-11 ### Fixed - Fix error asking for ed25519 gem when actually not using EdDSA ## [v1.1.0] - 2021-02-11 ### Added - EdDSA support added (requires adding the `ed25519` gem to your `Gemfile`) ([@santiagorodriguez96]) ## [v1.0.0] - 2020-07-08 ### Added - ECDSA with **secp256k1** curve support added: ```rb OpenSSL::SignatureAlgorithm::ECDSA.new(curve: "secp256k1") ``` - Algorithm **arguments** are now **optional**. The following works: ```rb OpenSSL::SignatureAlgorithm::ECDSA.new # defaults to ECDSA with SHA-256 and NIST P256 curve # Same as OpenSSL::SignatureAlgorithm::ECDSA.new(hash_function: "SHA256", curve: "prime256v1") OpenSSL::SignatureAlgorithm::RSAPSS.new # defaults to SHA-256 # Same as OpenSSL::SignatureAlgorithm::RSAPSS.new(hash_function: "SHA256") OpenSSL::SignatureAlgorithm::RSAPKCS1.new # defaults to SHA-256 # Same as OpenSSL::SignatureAlgorithm::RSAPSS.new(hash_function: "SHA256") ``` ### Changed - Algorithm **instantiation** changed. The positional argument `digest_length` is replaced with keyword arguments, `hash_function:` for RSA algorithms and `hash_function:` and `curve:` for ECDSA. None are required arguments, you get sane defaults if you don't provide any arguments. Code migration examples: ```rb # Change this # OpenSSL::SignatureAlgorithm::ECDSA.new("256") # to OpenSSL::SignatureAlgorithm::ECDSA.new(hash_function: "SHA256") ``` ```rb # Change this # OpenSSL::SignatureAlgorithm::RSAPSS.new("384") # to OpenSSL::SignatureAlgorithm::RSAPSS.new(hash_function: "SHA384") ``` ## [v0.4.0] - 2020-01-31 ### Added - `VerifyKey` serialization and deserialization for easy transmission over the network ## [v0.3.0] - 2020-01-30 ### Added - Support ruby v2.4 (without RSA-PSS) ## [v0.2.0] - 2020-01-29 ### Added - `OpenSSL::SignatureAlgorithm::ECDSA#verify` now supports raw (non DER) signatures ## [v0.1.1] - 2020-01-29 ### Fixed - Fixed error in `OpenSSL::SignatureAlgorithm::RSAPSS#sign` ## [v0.1.0] - 2020-01-29 ### Added - `OpenSSL::SignatureAlgorithm::ECDSA` - `OpenSSL::SignatureAlgorithm::RSAPSS` - `OpenSSL::SignatureAlgorithm::RSAPKCS1` [v1.3.0]: https://github.com/cedarcode/openssl-signature_algorithm/compare/v1.2.1...v1.3.0/ [v1.2.1]: https://github.com/cedarcode/openssl-signature_algorithm/compare/v1.1.1...v1.2.1/ [v1.1.1]: https://github.com/cedarcode/openssl-signature_algorithm/compare/v1.1.0...v1.1.1/ [v1.1.0]: https://github.com/cedarcode/openssl-signature_algorithm/compare/v1.0.0...v1.1.0/ [v1.0.0]: https://github.com/cedarcode/openssl-signature_algorithm/compare/v0.4.0...v1.0.0/ [v0.4.0]: https://github.com/cedarcode/openssl-signature_algorithm/compare/v0.3.0...v0.4.0/ [v0.3.0]: https://github.com/cedarcode/openssl-signature_algorithm/compare/v0.2.0...v0.3.0/ [v0.2.0]: https://github.com/cedarcode/openssl-signature_algorithm/compare/v0.1.1...v0.2.0/ [v0.1.1]: https://github.com/cedarcode/openssl-signature_algorithm/compare/v0.1.0...v0.1.1/ [v0.1.0]: https://github.com/cedarcode/openssl-signature_algorithm/compare/41887c277dc7fa0c884ccf8924cf990ff76784d9...v0.1.0/ [@santiagorodriguez96]: https://github.com/santiagorodriguez96 [@ClearlyClaire]: https://github.com/clearlyclaire [@bdewater]: https://github.com/bdewater openssl-signature_algorithm-1.3.0/.rubocop.yml0000644000004100000410000000500714422530221021542 0ustar www-datawww-dataAllCops: TargetRubyVersion: 2.4 DisabledByDefault: true NewCops: disable Exclude: - "gemfiles/**/*" - "vendor/bundle/**/*" Bundler: Enabled: true Gemspec: Enabled: true Layout: Enabled: true Layout/LineLength: Max: 120 Lint: Enabled: true Lint/MissingSuper: Enabled: false Naming: Enabled: true Security: Enabled: true Style/BlockComments: Enabled: true Style/CaseEquality: Enabled: true Style/ClassAndModuleChildren: Enabled: true Style/ClassMethods: Enabled: true Style/ClassVars: Enabled: true Style/CommentAnnotation: Enabled: true Style/ConditionalAssignment: Enabled: true Style/DefWithParentheses: Enabled: true Style/Dir: Enabled: true Style/EachForSimpleLoop: Enabled: true Style/EachWithObject: Enabled: true Style/EmptyBlockParameter: Enabled: true Style/EmptyCaseCondition: Enabled: true Style/EmptyElse: Enabled: true Style/EmptyLambdaParameter: Enabled: true Style/EmptyLiteral: Enabled: true Style/EvenOdd: Enabled: true Style/ExpandPathArguments: Enabled: true Style/For: Enabled: true Style/FrozenStringLiteralComment: Enabled: true Style/GlobalVars: Enabled: true Style/HashSyntax: Enabled: true Style/IdenticalConditionalBranches: Enabled: true Style/IfInsideElse: Enabled: true Style/InverseMethods: Enabled: true Style/MethodCallWithoutArgsParentheses: Enabled: true Style/MethodDefParentheses: Enabled: true Style/MultilineMemoization: Enabled: true Style/MutableConstant: Enabled: true Style/NestedParenthesizedCalls: Enabled: true Style/OptionalArguments: Enabled: true Style/ParenthesesAroundCondition: Enabled: true Style/RedundantBegin: Enabled: true Style/RedundantConditional: Enabled: true Style/RedundantException: Enabled: true Style/RedundantFreeze: Enabled: true Style/RedundantInterpolation: Enabled: true Style/RedundantParentheses: Enabled: true Style/RedundantPercentQ: Enabled: true Style/RedundantReturn: Enabled: true Style/RedundantSelf: Enabled: true Style/Semicolon: Enabled: true Style/SingleLineMethods: Enabled: true Style/SpecialGlobalVars: Enabled: true Style/SymbolLiteral: Enabled: true Style/TrailingBodyOnClass: Enabled: true Style/TrailingBodyOnMethodDefinition: Enabled: true Style/TrailingBodyOnModule: Enabled: true Style/TrailingMethodEndStatement: Enabled: true Style/TrivialAccessors: Enabled: true Style/UnpackFirst: Enabled: true Style/YodaCondition: Enabled: true Style/ZeroLengthPredicate: Enabled: true openssl-signature_algorithm-1.3.0/Appraisals0000644000004100000410000000041214422530221021305 0ustar www-datawww-data# frozen_string_literal: true appraise "openssl_3_1" do gem "openssl", "~> 3.1.0" end appraise "openssl_3_0" do gem "openssl", "~> 3.0.0" end appraise "openssl_2_2" do gem "openssl", "~> 2.2.0" end appraise "openssl_2_1" do gem "openssl", "~> 2.1.0" end openssl-signature_algorithm-1.3.0/.gitignore0000644000004100000410000000023314422530221021254 0ustar www-datawww-data/.bundle/ /.yardoc /_yardoc/ /coverage/ /doc/ /pkg/ /spec/reports/ /tmp/ # rspec failure tracking .rspec_status .byebug_history /gemfiles/*.gemfile.lock openssl-signature_algorithm-1.3.0/openssl-signature_algorithm.gemspec0000644000004100000410000000241214422530221026362 0ustar www-datawww-data# frozen_string_literal: true require_relative 'lib/openssl/signature_algorithm/version' Gem::Specification.new do |spec| spec.name = "openssl-signature_algorithm" spec.version = OpenSSL::SignatureAlgorithm::VERSION spec.authors = ["Gonzalo Rodriguez"] spec.email = ["gonzalo@cedarcode.com"] spec.license = "Apache-2.0" spec.summary = "ECDSA, EdDSA, RSA-PSS and RSA-PKCS#1 algorithms for ruby" spec.description = spec.summary spec.homepage = "https://github.com/cedarcode/openssl-signature_algorithm" spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0") spec.metadata["homepage_uri"] = spec.homepage spec.metadata["source_code_uri"] = spec.homepage spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/master/CHANGELOG.md" # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. spec.files = Dir.chdir(File.expand_path(__dir__)) do `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } end spec.bindir = "exe" spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ["lib"] spec.add_runtime_dependency "openssl", "> 2.0" end openssl-signature_algorithm-1.3.0/LICENSE0000644000004100000410000002613514422530221020302 0ustar www-datawww-data Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. openssl-signature_algorithm-1.3.0/Rakefile0000644000004100000410000000031714422530221020734 0ustar www-datawww-data# frozen_string_literal: true require "bundler/gem_tasks" require "rspec/core/rake_task" require "rubocop/rake_task" RSpec::Core::RakeTask.new(:spec) RuboCop::RakeTask.new task default: [:rubocop, :spec] openssl-signature_algorithm-1.3.0/lib/0000755000004100000410000000000014422530221020034 5ustar www-datawww-dataopenssl-signature_algorithm-1.3.0/lib/openssl/0000755000004100000410000000000014422530221021517 5ustar www-datawww-dataopenssl-signature_algorithm-1.3.0/lib/openssl/signature_algorithm/0000755000004100000410000000000014422530221025566 5ustar www-datawww-dataopenssl-signature_algorithm-1.3.0/lib/openssl/signature_algorithm/version.rb0000644000004100000410000000015214422530221027576 0ustar www-datawww-data# frozen_string_literal: true module OpenSSL module SignatureAlgorithm VERSION = "1.3.0" end end openssl-signature_algorithm-1.3.0/lib/openssl/signature_algorithm/ecdsa.rb0000644000004100000410000000666214422530221027204 0ustar www-datawww-data# frozen_string_literal: true require "delegate" require "openssl" require "openssl/signature_algorithm/base" module OpenSSL module SignatureAlgorithm class ECDSA < Base BYTE_LENGTH = 8 class SigningKey < DelegateClass(OpenSSL::PKey::EC) def initialize(*args) super(OpenSSL::PKey::EC.generate(*args)) end def verify_key VerifyKey.new(group, public_key.to_bn) end end class VerifyKey < DelegateClass(OpenSSL::PKey::EC::Point) def initialize(*args) super(OpenSSL::PKey::EC::Point.new(*args)) end def self.deserialize(pem_string) new(OpenSSL::PKey::EC.new(pem_string).public_key) end def serialize ec_key.to_pem end def ec_key @ec_key ||= begin # RFC5480 SubjectPublicKeyInfo asn1 = OpenSSL::ASN1::Sequence( [ OpenSSL::ASN1::Sequence( [ OpenSSL::ASN1::ObjectId("id-ecPublicKey"), OpenSSL::ASN1::ObjectId(group.curve_name), ] ), OpenSSL::ASN1::BitString(to_octet_string(:uncompressed)) ] ) OpenSSL::PKey::EC.new(asn1.to_der) end end def verify(*args) ec_key.verify(*args) end end ACCEPTED_PARAMETERS = [ { curve: "prime256v1", hash_function: "SHA256" }, { curve: "secp384r1", hash_function: "SHA384" }, { curve: "secp521r1", hash_function: "SHA512" }, { curve: "secp256k1", hash_function: "SHA256" } ].freeze attr_reader :curve, :hash_function def initialize(curve: nil, hash_function: nil) @curve, @hash_function = pick_parameters(curve, hash_function) end def generate_signing_key @signing_key = SigningKey.new(curve) end def compatible_verify_key?(key) super && key.respond_to?(:group) && key.group.curve_name == curve end private # Borrowed from jwt rubygem. # https://github.com/jwt/ruby-jwt/blob/7a6a3f1dbaff806993156d1dff9c217bb2523ff8/lib/jwt/security_utils.rb#L34-L39 # # Hopefully this will be provided by openssl rubygem in the future. def formatted_signature(signature) n = (verify_key_length.to_f / BYTE_LENGTH).ceil if signature.size == n * 2 r = signature[0..(n - 1)] s = signature[n..-1] OpenSSL::ASN1::Sequence.new([r, s].map { |int| OpenSSL::ASN1::Integer.new(OpenSSL::BN.new(int, 2)) }).to_der else signature end end def verify_key_length verify_key.group.degree end def pick_parameters(curve, hash_function) parameters = ACCEPTED_PARAMETERS.detect do |params| if curve if hash_function params[:curve] == curve && params[:hash_function] == hash_function else params[:curve] == curve end elsif hash_function params[:hash_function] == hash_function else true end end if parameters [parameters[:curve], parameters[:hash_function]] else raise(OpenSSL::SignatureAlgorithm::UnsupportedParameterError, "Unsupported algorithm parameters") end end end end end openssl-signature_algorithm-1.3.0/lib/openssl/signature_algorithm/rsapss.rb0000644000004100000410000000131014422530221027421 0ustar www-datawww-data# frozen_string_literal: true require "openssl" require "openssl/signature_algorithm/rsa" module OpenSSL module SignatureAlgorithm class RSAPSS < RSA def sign(data) signing_key.sign_pss(hash_function, data, salt_length: :max, mgf1_hash: mgf1_hash_function) end def verify(signature, verification_data) verify_key.verify_pss( hash_function, signature, verification_data, salt_length: :auto, mgf1_hash: mgf1_hash_function ) || raise(OpenSSL::SignatureAlgorithm::SignatureVerificationError, "Signature verification failed") end def mgf1_hash_function hash_function end end end end openssl-signature_algorithm-1.3.0/lib/openssl/signature_algorithm/base.rb0000644000004100000410000000224014422530221027023 0ustar www-datawww-data# frozen_string_literal: true require "openssl" require "openssl/signature_algorithm/error" module OpenSSL module SignatureAlgorithm class SignatureVerificationError < Error; end class UnsupportedParameterError < Error; end class VerifyKeyError < Error; end class Base attr_reader :signing_key, :verify_key def verify_key=(key) if compatible_verify_key?(key) @verify_key = key else raise(OpenSSL::SignatureAlgorithm::VerifyKeyError, "Incompatible verify key for algorithm") end end def compatible_verify_key?(verify_key) verify_key.respond_to?(:verify) end def sign(data) signing_key.sign(hash_function, data) end def verify(signature, verification_data) formatted_signature = if respond_to?(:formatted_signature, true) formatted_signature(signature) else signature end verify_key.verify(hash_function, formatted_signature, verification_data) || raise(OpenSSL::SignatureAlgorithm::SignatureVerificationError, "Signature verification failed") end end end end openssl-signature_algorithm-1.3.0/lib/openssl/signature_algorithm/error.rb0000644000004100000410000000017114422530221027243 0ustar www-datawww-data# frozen_string_literal: true module OpenSSL module SignatureAlgorithm class Error < StandardError; end end end openssl-signature_algorithm-1.3.0/lib/openssl/signature_algorithm/rsa.rb0000644000004100000410000000243614422530221026705 0ustar www-datawww-data# frozen_string_literal: true require "delegate" require "openssl" require "openssl/signature_algorithm/base" module OpenSSL module SignatureAlgorithm class RSA < Base class SigningKey < DelegateClass(OpenSSL::PKey::RSA) def initialize(*args) super(OpenSSL::PKey::RSA.new(*args)) end def verify_key VerifyKey.new(public_key.to_pem) end end class VerifyKey < DelegateClass(OpenSSL::PKey::RSA) class << self alias_method :deserialize, :new end def initialize(*args) super(OpenSSL::PKey::RSA.new(*args)) end def serialize to_pem end end ACCEPTED_HASH_FUNCTIONS = ["SHA256", "SHA384", "SHA512"].freeze DEFAULT_KEY_SIZE = 2048 attr_reader :hash_function def initialize(hash_function: self.class::ACCEPTED_HASH_FUNCTIONS.first) if self.class::ACCEPTED_HASH_FUNCTIONS.include?(hash_function) @hash_function = hash_function else raise(OpenSSL::SignatureAlgorithm::UnsupportedParameterError, "Unsupported hash function '#{hash_function}'") end end def generate_signing_key(size: DEFAULT_KEY_SIZE) @signing_key = SigningKey.new(size) end end end end openssl-signature_algorithm-1.3.0/lib/openssl/signature_algorithm/eddsa.rb0000644000004100000410000000215314422530221027174 0ustar www-datawww-data# frozen_string_literal: true begin gem "ed25519", ">= 1.0.0" require "ed25519" rescue LoadError warn "OpenSSL::SignatureAlgorithm::EdDSA requires the ed25519 gem, version 1.0 or higher. "\ "Please add it to your Gemfile: `gem \"ed25519\", \"~> 1.0\"`" raise end require "openssl/signature_algorithm/base" module OpenSSL module SignatureAlgorithm class EdDSA < Base class SigningKey < ::Ed25519::SigningKey def verify_key VerifyKey.new(keypair[32, 32]) end end class VerifyKey < ::Ed25519::VerifyKey def self.deserialize(key_bytes) new(key_bytes) end def serialize to_bytes end end def generate_signing_key @signing_key = SigningKey.generate end def sign(data) signing_key.sign(data) end def verify(signature, verification_data) verify_key.verify(signature, verification_data) rescue ::Ed25519::VerifyError raise(OpenSSL::SignatureAlgorithm::SignatureVerificationError, "Signature verification failed") end end end end openssl-signature_algorithm-1.3.0/lib/openssl/signature_algorithm/rsapkcs1.rb0000644000004100000410000000026214422530221027642 0ustar www-datawww-data# frozen_string_literal: true require "openssl" require "openssl/signature_algorithm/rsa" module OpenSSL module SignatureAlgorithm class RSAPKCS1 < RSA end end end openssl-signature_algorithm-1.3.0/lib/openssl/signature_algorithm.rb0000644000004100000410000000046714422530221026122 0ustar www-datawww-data# frozen_string_literal: true require "openssl/signature_algorithm/ecdsa" require "openssl/signature_algorithm/error" require "openssl/signature_algorithm/rsapss" require "openssl/signature_algorithm/rsapkcs1" require "openssl/signature_algorithm/version" module OpenSSL module SignatureAlgorithm end end openssl-signature_algorithm-1.3.0/Gemfile0000644000004100000410000000043614422530221020564 0ustar www-datawww-data# frozen_string_literal: true source "https://rubygems.org" # Specify your gem's dependencies in openssl-signature_algorithm.gemspec gemspec gem "appraisal", "~> 2.2" gem "byebug", "~> 11.0" gem "ed25519", "~> 1.2" gem "rake", "~> 13.0" gem "rspec", "~> 3.0" gem "rubocop", "~> 1.0" openssl-signature_algorithm-1.3.0/.github/0000755000004100000410000000000014422530221020626 5ustar www-datawww-dataopenssl-signature_algorithm-1.3.0/.github/workflows/0000755000004100000410000000000014422530221022663 5ustar www-datawww-dataopenssl-signature_algorithm-1.3.0/.github/workflows/build.yml0000644000004100000410000000274314422530221024513 0ustar www-datawww-data# This workflow uses actions that are not certified by GitHub. # They are provided by a third-party and are governed by # separate terms of service, privacy policy, and support # documentation. # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby name: build on: push jobs: test: runs-on: ubuntu-20.04 strategy: fail-fast: false matrix: ruby-version: - 3.2.0 - 3.1.3 - 3.0.5 - 2.7.7 - 2.6.6 - 2.5.8 - 2.4.10 gemfile: - openssl_3_1 - openssl_3_0 - openssl_2_2 - openssl_2_1 exclude: - ruby-version: '2.4.10' gemfile: openssl_3_0 - ruby-version: '2.5.8' gemfile: openssl_3_0 - ruby-version: '2.4.10' gemfile: openssl_3_1 - ruby-version: '2.5.8' gemfile: openssl_3_1 env: BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile steps: - uses: actions/checkout@v2 - run: rm Gemfile.lock - name: Set up Ruby ${{ matrix.ruby }} uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby-version }} bundler-cache: true - name: Run rubocop run: bundle exec rubocop if: ${{ matrix.ruby == '3.2.0' }} - name: Run tests run: bundle exec rspec