tpm-key_attestation-0.12.0/0000755000004100000410000000000014406434117015633 5ustar www-datawww-datatpm-key_attestation-0.12.0/Gemfile.lock0000644000004100000410000000264114406434117020060 0ustar www-datawww-dataPATH remote: . specs: tpm-key_attestation (0.11.0) bindata (~> 2.4) openssl (> 2.0) openssl-signature_algorithm (~> 1.0) GEM remote: https://rubygems.org/ specs: appraisal (2.2.0) bundler rake thor (>= 0.14.0) ast (2.4.2) bindata (2.4.14) byebug (11.1.3) diff-lcs (1.4.4) jaro_winkler (1.5.4) openssl (3.1.0) openssl-signature_algorithm (1.2.1) openssl (> 2.0, < 3.1) parallel (1.20.1) parser (3.0.0.0) ast (~> 2.4.1) rainbow (3.0.0) rake (13.0.3) rexml (3.2.4) rspec (3.10.0) rspec-core (~> 3.10.0) rspec-expectations (~> 3.10.0) rspec-mocks (~> 3.10.0) rspec-core (3.10.1) rspec-support (~> 3.10.0) rspec-expectations (3.10.1) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.10.0) rspec-mocks (3.10.2) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.10.0) rspec-support (3.10.2) rubocop (0.80.1) jaro_winkler (~> 1.5.1) parallel (~> 1.10) parser (>= 2.7.0.1) rainbow (>= 2.2.2, < 4.0) rexml ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 1.7) ruby-progressbar (1.11.0) thor (1.1.0) unicode-display_width (1.6.1) PLATFORMS ruby DEPENDENCIES appraisal (~> 2.2.0) byebug (~> 11.0) rake (~> 13.0) rspec (~> 3.0) rubocop (~> 0.80.1) tpm-key_attestation! BUNDLED WITH 2.2.8 tpm-key_attestation-0.12.0/.rspec0000644000004100000410000000005514406434117016750 0ustar www-datawww-data--color --require spec_helper --order random tpm-key_attestation-0.12.0/README.md0000644000004100000410000000331514406434117017114 0ustar www-datawww-data# tpm-key_attestation TPM Key Attestation utitlies [![Gem](https://img.shields.io/gem/v/tpm-key_attestation.svg?style=flat-square&color=informational)](https://rubygems.org/gems/tpm-key_attestation) [![Actions Build](https://github.com/cedarcode/tpm-key_attestation/workflows/build/badge.svg)](https://github.com/cedarcode/tpm-key_attestation/actions) [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-informational.svg?style=flat-square)](https://conventionalcommits.org) ## Installation Add this line to your application's Gemfile: ```ruby gem 'tpm-key_attestation' ``` And then execute: $ bundle install Or install it yourself as: $ gem install tpm-key_attestation ## Usage ```ruby key_attestation = TPM::KeyAttestation.new( certify_info, signature, certified_object, signing_key, quilifying_data, signature_algorithm: TPM::ALG_RSAPSS # Supported values: TPM::ALG_RSAPSS, TPM::ALG_RSASSA, TPM::ALG_ECDSA (default TPM::ALG_RSASSA) ) if key_attestation.valid? key_attestation.key end ``` ## 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/tpm-key_attestation. tpm-key_attestation-0.12.0/bin/0000755000004100000410000000000014406434117016403 5ustar www-datawww-datatpm-key_attestation-0.12.0/bin/console0000755000004100000410000000060014406434117017767 0ustar www-datawww-data#!/usr/bin/env ruby # frozen_string_literal: true require "bundler/setup" require "tpm/key_attestation" # 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__) tpm-key_attestation-0.12.0/bin/setup0000755000004100000410000000020314406434117017464 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 tpm-key_attestation-0.12.0/gemfiles/0000755000004100000410000000000014406434117017426 5ustar www-datawww-datatpm-key_attestation-0.12.0/gemfiles/openssl_2_1.gemfile0000644000004100000410000000036114406434117023104 0ustar www-datawww-data# This file was generated by Appraisal source "https://rubygems.org" gem "appraisal", "~> 2.2.0" gem "byebug", "~> 11.0" gem "rake", "~> 13.0" gem "rspec", "~> 3.0" gem "rubocop", "~> 0.80.1" gem "openssl", "~> 2.1.0" gemspec path: "../" tpm-key_attestation-0.12.0/gemfiles/openssl_3_1.gemfile0000644000004100000410000000036114406434117023105 0ustar www-datawww-data# This file was generated by Appraisal source "https://rubygems.org" gem "appraisal", "~> 2.2.0" gem "byebug", "~> 11.0" gem "rake", "~> 13.0" gem "rspec", "~> 3.0" gem "rubocop", "~> 0.80.1" gem "openssl", "~> 3.1.0" gemspec path: "../" tpm-key_attestation-0.12.0/gemfiles/openssl_2_2.gemfile0000644000004100000410000000036114406434117023105 0ustar www-datawww-data# This file was generated by Appraisal source "https://rubygems.org" gem "appraisal", "~> 2.2.0" gem "byebug", "~> 11.0" gem "rake", "~> 13.0" gem "rspec", "~> 3.0" gem "rubocop", "~> 0.80.1" gem "openssl", "~> 2.2.0" gemspec path: "../" tpm-key_attestation-0.12.0/gemfiles/openssl_3_0.gemfile0000644000004100000410000000036114406434117023104 0ustar www-datawww-data# This file was generated by Appraisal source "https://rubygems.org" gem "appraisal", "~> 2.2.0" gem "byebug", "~> 11.0" gem "rake", "~> 13.0" gem "rspec", "~> 3.0" gem "rubocop", "~> 0.80.1" gem "openssl", "~> 3.0.0" gemspec path: "../" tpm-key_attestation-0.12.0/CHANGELOG.md0000644000004100000410000000514114406434117017445 0ustar www-datawww-data# Changelog ## [v0.12.0] - 2022-07-05 - Loose OpenSSL dependency to support 3.2 users. Credits to @stanhu <3 ## [v0.11.0] - 2022-07-05 - Support OpenSSL ~>3.0.0. Credits to @ClearlyClaire <3 ## [v0.10.0] - 2020-07-09 ### Added - Support ECDSA with NIST P384 and P521 curves ## [v0.9.0] - 2020-05-31 ### Fixed - Fixed compatibility with OpenSSL-C (libssl) v1.0.2 ([@santiagorodriguez96]) ## [v0.8.0] - 2020-03-29 ### Changed - Update `openssl-signature_algorithm` gem dependency from `v0.3` to `v0.4`. ## [v0.7.0] - 2020-02-25 ### Added - `TPM::KeyAttestation#valid?` performs certificate path validation. In other words, it verifies trust up to an acceptable trusted root certificate. ### Changed - Rename `TPM::EKCertificate` to `TPM::AIKCertificate` to fix semantics ## [v0.6.0] - 2020-01-30 ### Changed - `TPM::KeyAttestation.new` now accepts `signature_algorithm` and `hash_algorithm` in TPM format in replacement of `JOSE` format `algorithm` string ## [v0.5.0] - 2020-01-23 ### Added - `TPM::KeyAttestation#valid?` also checks there's at least a well-formatted key in the attestation ## [v0.4.0] - 2020-01-20 ### Added - Suport verification of RSA-PSS key attestations ## [v0.3.0] - 2020-01-20 ### Added - `TPM::KeyAttestation#key` returns attested key as an instance of `OpenSSL::PKey::PKey` ## [v0.2.0] - 2020-01-16 ### Added - `TPM::KeyAttestation#valid?` ## [v0.1.0] - 2020-01-15 ### Added - `TPM::EKCertificate` wrapper - `TPM::SAttest` wrapper [v0.12.0]: https://github.com/cedarcode/tpm-key_attestation/compare/v0.11.0...v0.12.0/ [v0.11.0]: https://github.com/cedarcode/tpm-key_attestation/compare/v0.10.0...v0.11.0/ [v0.10.0]: https://github.com/cedarcode/tpm-key_attestation/compare/v0.9.0...v0.10.0/ [v0.9.0]: https://github.com/cedarcode/tpm-key_attestation/compare/v0.8.0...v0.9.0/ [v0.8.0]: https://github.com/cedarcode/tpm-key_attestation/compare/v0.7.0...v0.8.0/ [v0.7.0]: https://github.com/cedarcode/tpm-key_attestation/compare/v0.6.0...v0.7.0/ [v0.6.0]: https://github.com/cedarcode/tpm-key_attestation/compare/v0.5.0...v0.6.0/ [v0.5.0]: https://github.com/cedarcode/tpm-key_attestation/compare/v0.4.0...v0.5.0/ [v0.4.0]: https://github.com/cedarcode/tpm-key_attestation/compare/v0.3.0...v0.4.0/ [v0.3.0]: https://github.com/cedarcode/tpm-key_attestation/compare/v0.2.0...v0.3.0/ [v0.2.0]: https://github.com/cedarcode/tpm-key_attestation/compare/v0.1.0...v0.2.0/ [v0.1.0]: https://github.com/cedarcode/tpm-key_attestation/compare/57c926ef7e83830cee8d111fdc5ccaf99ab2e861...v0.1.0/ [@santiagorodriguez96]: https://github.com/santiagorodriguez96 [@ClearlyClaire]: https://github.com/ClearlyClaire tpm-key_attestation-0.12.0/.rubocop.yml0000644000004100000410000000471714406434117020116 0ustar www-datawww-dataAllCops: TargetRubyVersion: 2.4 DisabledByDefault: true Exclude: - "gemfiles/**/*" - "vendor/bundle/**/*" Bundler: Enabled: true Gemspec: Enabled: true Layout: Enabled: true Layout/LineLength: Max: 120 Lint: Enabled: true 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 tpm-key_attestation-0.12.0/Appraisals0000644000004100000410000000041214406434117017652 0ustar www-datawww-data# frozen_string_literal: true appraise "openssl_2_2" do gem "openssl", "~> 2.2.0" end appraise "openssl_2_1" do gem "openssl", "~> 2.1.0" end appraise "openssl_3_0" do gem "openssl", "~> 3.0.0" end appraise "openssl_3_1" do gem "openssl", "~> 3.1.0" end tpm-key_attestation-0.12.0/.gitignore0000644000004100000410000000023314406434117017621 0ustar www-datawww-data/.bundle/ /.yardoc /_yardoc/ /coverage/ /doc/ /pkg/ /spec/reports/ /tmp/ # rspec failure tracking .rspec_status /gemfiles/*.gemfile.lock .byebug_history tpm-key_attestation-0.12.0/LICENSE0000644000004100000410000002613514406434117016647 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. tpm-key_attestation-0.12.0/tpm-key_attestation.gemspec0000644000004100000410000000233314406434117023206 0ustar www-datawww-data# frozen_string_literal: true require_relative 'lib/tpm/key_attestation/version' Gem::Specification.new do |spec| spec.name = "tpm-key_attestation" spec.version = TPM::KeyAttestation::VERSION spec.authors = ["Gonzalo"] spec.license = "Apache-2.0" spec.summary = "TPM Key Attestation verifier" spec.homepage = "https://github.com/cedarcode/tpm-key_attestation" 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_dependency "bindata", "~> 2.4" spec.add_dependency "openssl", "> 2.0" spec.add_dependency "openssl-signature_algorithm", "~> 1.0" end tpm-key_attestation-0.12.0/Rakefile0000644000004100000410000000031714406434117017301 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] tpm-key_attestation-0.12.0/lib/0000755000004100000410000000000014406434117016401 5ustar www-datawww-datatpm-key_attestation-0.12.0/lib/tpm/0000755000004100000410000000000014406434117017201 5ustar www-datawww-datatpm-key_attestation-0.12.0/lib/tpm/t_public/0000755000004100000410000000000014406434117021002 5ustar www-datawww-datatpm-key_attestation-0.12.0/lib/tpm/t_public/s_ecc_parms.rb0000644000004100000410000000056714406434117023615 0ustar www-datawww-data# frozen_string_literal: true require "bindata" module TPM class TPublic < BinData::Record # Section 12.2.3.6 in https://trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-2-Structures-01.38.pdf class SEccParms < BinData::Record endian :big uint16 :symmetric uint16 :scheme uint16 :curve_id uint16 :kdf end end end tpm-key_attestation-0.12.0/lib/tpm/t_public/s_rsa_parms.rb0000644000004100000410000000057414406434117023646 0ustar www-datawww-data# frozen_string_literal: true require "bindata" module TPM class TPublic < BinData::Record # Section 12.2.3.5 in https://trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-2-Structures-01.38.pdf class SRsaParms < BinData::Record endian :big uint16 :symmetric uint16 :scheme uint16 :key_bits uint32 :exponent end end end tpm-key_attestation-0.12.0/lib/tpm/aik_certificate.rb0000644000004100000410000000531314406434117022636 0ustar www-datawww-data# frozen_string_literal: true require "delegate" require "openssl" require "tpm/constants" module TPM # Section 3.2 in https://www.trustedcomputinggroup.org/wp-content/uploads/Credential_Profile_EK_V2.0_R14_published.pdf class AIKCertificate < SimpleDelegator ASN_V3 = 2 EMPTY_NAME = OpenSSL::X509::Name.new([]).freeze SAN_DIRECTORY_NAME = 4 OID_TCG = "2.23.133" OID_TCG_AT_TPM_MANUFACTURER = "#{OID_TCG}.2.1" OID_TCG_AT_TPM_MODEL = "#{OID_TCG}.2.2" OID_TCG_AT_TPM_VERSION = "#{OID_TCG}.2.3" OID_TCG_KP_AIK_CERTIFICATE = "#{OID_TCG}.8.3" def self.from_der(certificate_der) new(OpenSSL::X509::Certificate.new(certificate_der)) end def conformant? in_use? && valid_version? && valid_extended_key_usage? && valid_basic_constraints? && empty_subject? && valid_subject_alternative_name? end private def in_use? now = Time.now not_before < now && now < not_after end def valid_version? version == ASN_V3 end def valid_basic_constraints? basic_constraints = extension("basicConstraints") basic_constraints && basic_constraints.value == "CA:FALSE" && basic_constraints.critical? end def valid_extended_key_usage? extended_key_usage = extension("extendedKeyUsage") extended_key_usage && extended_key_usage.value == OID_TCG_KP_AIK_CERTIFICATE && !extended_key_usage.critical? end def empty_subject? subject.eql?(EMPTY_NAME) end def valid_subject_alternative_name? if san_extension san_extension.critical? && !tpm_manufacturer.empty? && TPM::VENDOR_IDS[tpm_manufacturer] && !tpm_model.empty? && !tpm_version.empty? end end def extension(oid) extensions.detect { |ext| ext.oid == oid } end def tpm_manufacturer if san_name san_name.assoc(OID_TCG_AT_TPM_MANUFACTURER).at(1) end end def tpm_model if san_name san_name.assoc(OID_TCG_AT_TPM_MODEL).at(1) end end def tpm_version if san_name san_name.assoc(OID_TCG_AT_TPM_VERSION).at(1) end end def san_name if san_extension san_asn1 = OpenSSL::ASN1.decode(san_extension).find do |val| val.tag_class == :UNIVERSAL && val.tag == OpenSSL::ASN1::OCTET_STRING end directory_name = OpenSSL::ASN1.decode(san_asn1.value).find do |val| val.tag_class == :CONTEXT_SPECIFIC && val.tag == SAN_DIRECTORY_NAME end OpenSSL::X509::Name.new(directory_name.value.first).to_a end end def san_extension extension("subjectAltName") end end end tpm-key_attestation-0.12.0/lib/tpm/s_attest/0000755000004100000410000000000014406434117021027 5ustar www-datawww-datatpm-key_attestation-0.12.0/lib/tpm/s_attest/s_certify_info.rb0000644000004100000410000000057614406434117024366 0ustar www-datawww-data# frozen_string_literal: true require "bindata" require "tpm/sized_buffer" require "tpm/tpm2b_name" module TPM class SAttest < BinData::Record # Section 10.12.3 in https://trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-2-Structures-01.38.pdf class SCertifyInfo < BinData::Record tpm2b_name :name sized_buffer :qualified_name end end end tpm-key_attestation-0.12.0/lib/tpm/certify_validator.rb0000644000004100000410000000432114406434117023240 0ustar www-datawww-data# frozen_string_literal: true require "openssl/signature_algorithm" require "tpm/constants" require "tpm/s_attest" module TPM class CertifyValidator attr_reader :info, :signature, :nonce, :public_area, :signature_algorithm, :hash_algorithm TPM_SIGNATURE_ALG_TO_OPENSSL = { ALG_RSASSA => OpenSSL::SignatureAlgorithm::RSAPKCS1, ALG_RSAPSS => OpenSSL::SignatureAlgorithm::RSAPSS, ALG_ECDSA => OpenSSL::SignatureAlgorithm::ECDSA }.freeze TPM_HASH_ALG_TO_OPENSSL = { ALG_SHA1 => "SHA1", ALG_SHA256 => "SHA256", ALG_SHA384 => "SHA384", ALG_SHA512 => "SHA512" }.freeze def initialize(info, signature, nonce, public_area, signature_algorithm: ALG_RSASSA, hash_algorithm: ALG_SHA256) @info = info @signature = signature @nonce = nonce @public_area = public_area @signature_algorithm = signature_algorithm @hash_algorithm = hash_algorithm end def valid?(signing_key) valid_info? && valid_signature?(signing_key) end private def valid_info? attest.attested_type == TPM::ST_ATTEST_CERTIFY && attest.extra_data.buffer == nonce && attest.magic == TPM::GENERATED_VALUE && attest.attested.name.valid_for?(public_area.name) end def valid_signature?(verify_key) openssl_signature_algorithm = openssl_signature_algorithm_class.new(**openssl_signature_algorithm_parameters) openssl_signature_algorithm.verify_key = verify_key openssl_signature_algorithm.verify(signature, info) rescue OpenSSL::SignatureAlgorithm::Error false end def attest @attest ||= TPM::SAttest.deserialize(info) end def openssl_signature_algorithm_parameters parameters = { hash_function: openssl_hash_function } if public_area.ecc? parameters[:curve] = public_area.openssl_curve_name end parameters end def openssl_hash_function TPM_HASH_ALG_TO_OPENSSL[hash_algorithm] || raise("Unsupported hash algorithm #{hash_algorithm}") end def openssl_signature_algorithm_class TPM_SIGNATURE_ALG_TO_OPENSSL[signature_algorithm] || raise("Unsupported signature algorithm #{signature_algorithm}") end end end tpm-key_attestation-0.12.0/lib/tpm/certificates/0000755000004100000410000000000014406434117021646 5ustar www-datawww-datatpm-key_attestation-0.12.0/lib/tpm/certificates/NationZ/0000755000004100000410000000000014406434117023230 5ustar www-datawww-datatpm-key_attestation-0.12.0/lib/tpm/certificates/NationZ/RootCA/0000755000004100000410000000000014406434117024357 5ustar www-datawww-datatpm-key_attestation-0.12.0/lib/tpm/certificates/NationZ/RootCA/EkRootCA.crt0000644000004100000410000000153614406434117026505 0ustar www-datawww-data-----BEGIN CERTIFICATE----- MIICRDCCAcqgAwIBAgIBATAKBggqhkjOPQQDAzBrMQswCQYDVQQGEwJDTjEhMB8G A1UECgwYTmF0aW9ueiBUZWNobm9sb2dpZXMgSW5jMRswGQYDVQQLDBJOYXRpb256 IFRQTSBEZXZpY2UxHDAaBgNVBAMME05hdGlvbnogVFBNIFJvb3QgQ0EwHhcNMTcw NTEyMDAwMDAwWhcNNDcwNTEzMDAwMDAwWjBrMQswCQYDVQQGEwJDTjEhMB8GA1UE CgwYTmF0aW9ueiBUZWNobm9sb2dpZXMgSW5jMRswGQYDVQQLDBJOYXRpb256IFRQ TSBEZXZpY2UxHDAaBgNVBAMME05hdGlvbnogVFBNIFJvb3QgQ0EwdjAQBgcqhkjO PQIBBgUrgQQAIgNiAATvuDTN8TNvp3A9fSjWpDARLmvz7ItQrDq/mmuzvzInwQfs YKUUJza4MXB3yS0PH1jjv1YMvaIBIalAgc+kahScQUy6W2fy6hd36pazmc/vQfG3 Gdhw56gGwRHx4rn4TuqjQjBAMB0GA1UdDgQWBBQ6vP8I314BDCtkB4vHzpUG9Aj9 5DAPBgNVHRMBAf8EBTADAQH/MA4GA1UdDwEB/wQEAwIBBjAKBggqhkjOPQQDAwNo ADBlAjApzqSmd4cCMKC7slJ4NE/7zweXZx89JzSEnEWGcq78jbbXCw6yM+R4nCNX phflI9QCMQCeFOAvyR+DQvThfGFINABej+1zeDVIjuZHat3FHVyV0UQVClPgMlZu TntipXwGOVY= -----END CERTIFICATE----- tpm-key_attestation-0.12.0/lib/tpm/certificates/AMD/0000755000004100000410000000000014406434117022247 5ustar www-datawww-datatpm-key_attestation-0.12.0/lib/tpm/certificates/AMD/RootCA/0000755000004100000410000000000014406434117023376 5ustar www-datawww-datatpm-key_attestation-0.12.0/lib/tpm/certificates/AMD/RootCA/AMD-fTPM-ECC-RootCA.crt0000644000004100000410000000140614406434117027033 0ustar www-datawww-data00#E"Zd+?0 *H=0v10U  Engineering1 0 UUS10U Sunnyvale1 0 UCA10U Advanced Micro Devices10 UAMDTPM0 160101050000Z 410101050000Z0v10U  Engineering1 0 UUS10U Sunnyvale1 0 UCA10U Advanced Micro Devices10 UAMDTPM0Y0*H=*H=B(FAwrZ &T" 4'>RgP \Zo"Qٕ[&=`ҾW00U0# +7+8~rc0U8~rc0U008+,0*0(+0http://ftpm.amd.com/pki/ocsp0,U%0#0!http://ftpm.amd.com/pki/crl0CU <0:08 +xe 0*0(+https://ftpm.amd.com/pki/cps0 *H=H0E!ErX+A1 p 5>ӗ@mm=:4m[t!$zR=!>&tpm-key_attestation-0.12.0/lib/tpm/certificates/AMD/RootCA/AMD-fTPM-RSA-RootCA.crt0000644000004100000410000000221414406434117027064 0ustar www-datawww-data00p&M9<][IN!0  *H  0v10U  Engineering1 0 UUS10U Sunnyvale1 0 UCA10U Advanced Micro Devices10 UAMDTPM0 141023143432Z 391023143432Z0v10U  Engineering1 0 UUS10U Sunnyvale1 0 UCA10U Advanced Micro Devices10 UAMDTPM0"0  *H 0 BMV}x-P @Dw%s+TP ɬ+|p/Ғy:6ON .i7c)Q$ ({=xR@#WRDIzc߾ggaW[U,,2n9OvLfzOK Y7d<-^ Z8+[So)qg0xM`D̛+带A 0 0U0# +7+WT_yiQB!x_h/0UWT_yiQB!x_h/0U008+,0*0(+0http://ftpm.amd.com/pki/ocsp0,U%0#0!http://ftpm.amd.com/pki/crl0=U 60402U 0*0(+https://ftpm.amd.com/pki/cps0  *H  ܀c'i٬1 7pw zT`vXqn{Ȉ`Q҇zFMk4֤.Hi[0̨0՛O7 !/>Geav;/2LMe!E+8[iu߁/9=MZ9>Osb=A;[2%֒-(iPKШ09^+ngd|hJ[.13@Ybi/jctpm-key_attestation-0.12.0/lib/tpm/certificates/Atmel/0000755000004100000410000000000014406434117022710 5ustar www-datawww-datatpm-key_attestation-0.12.0/lib/tpm/certificates/Atmel/RootCA/0000755000004100000410000000000014406434117024037 5ustar www-datawww-datatpm-key_attestation-0.12.0/lib/tpm/certificates/Atmel/RootCA/Atmel TPM Root Signing Module.der0000644000004100000410000000105714406434117031712 0ustar www-datawww-data0+0Рp?!nի2+ITx0 *H=0s1 0 UUS10UColorado10UColorado Springs10 U Atmel1&0$UAtmel TPM Root Signing Module0 101231000000Z 401231000000Z0s1 0 UUS10UColorado10UColorado Springs10 U Atmel1&0$UAtmel TPM Root Signing Module0Y0*H=*H=B}sfsGZ|k ՚̈^ 0\ ex gIi&6z|B@{lM[+ B0@0U0U00U1]m ["xW0 *H=I0F!۸ED\ThJG&ʎf!9q,\k_8-+`boVtpm-key_attestation-0.12.0/lib/tpm/certificates/Intel/0000755000004100000410000000000014406434117022721 5ustar www-datawww-datatpm-key_attestation-0.12.0/lib/tpm/certificates/Intel/RootCA/0000755000004100000410000000000014406434117024050 5ustar www-datawww-datatpm-key_attestation-0.12.0/lib/tpm/certificates/Intel/RootCA/EKRootPublicKey.cer0000644000004100000410000000117314406434117027520 0ustar www-datawww-data0w0O#"F;ݷ~(@O0 *H=01 0 U US1 0 U CA10U Santa Clara10U Intel Corporation1!0U TPM EK root cert signing10U www.intel.com0 140115000000Z 491231235959Z01 0 U US1 0 U CA10U Santa Clara10U Intel Corporation1!0U TPM EK root cert signing10U www.intel.com0Y0*H=*H=B}Q,Jo?v]}l)W!CC߶[Oa hV:TŞf0d0U#0ROե!G {[w0UROե!G {[w0U00U0 *H=G0D %tTY=b pd 2 ,o!E%Fx6TN1Hdtpm-key_attestation-0.12.0/lib/tpm/certificates/STMicro/0000755000004100000410000000000014406434117023166 5ustar www-datawww-datatpm-key_attestation-0.12.0/lib/tpm/certificates/STMicro/RootCA/0000755000004100000410000000000014406434117024315 5ustar www-datawww-datatpm-key_attestation-0.12.0/lib/tpm/certificates/STMicro/RootCA/STM TPM ECC Root CA 01.crt0000644000004100000410000000131414406434117030036 0ustar www-datawww-data00OG,˧ 0 *H=01;09U 2GlobalSign Trusted Computing Certificate Authority10U  GlobalSign1705U.GlobalSign Trusted Platform Module ECC Root CA0 151028000000Z 380119031407Z0N1 0 UCH10U STMicroelectronics NV10USTM TPM ECC Root CA 010v0*H=+"bn8̊@| JS骆qKrUfۯ`tz0[m=9GwuR:J܍wڕ:*SDiG00U0U00U V< CrS)0U#0a> [&^)aG00LU E0C0A +2Z0402+&https://www.globalsign.com/repository/0 *H=g0d0Z{<2u!rSз\U6rrt7V0bL-ǕרKV6HVg1c|w GL11tpm-key_attestation-0.12.0/lib/tpm/certificates/STMicro/RootCA/GlobalSign Trusted Computing CA.crt0000644000004100000410000000173314406434117032661 0ustar www-datawww-data00   0  *H  01;09U 2GlobalSign Trusted Computing Certificate Authority10U  GlobalSign1301U*GlobalSign Trusted Platform Module Root CA0 090318100000Z 490318100000Z01;09U 2GlobalSign Trusted Computing Certificate Authority10U  GlobalSign1301U*GlobalSign Trusted Platform Module Root CA0"0  *H 0 -0$ڶƅqC̈r=ǁU#DZQ_c3drx3ǯ[v= (ghӈ!_b?NséAuR)6Bxؿ8tW/~y1b{宲9]R 1v٨12iS ekndtpm-key_attestation-0.12.0/lib/tpm/certificates/STMicro/RootCA/ST TPM Root Certificate.crt0000644000004100000410000000202014406434117031077 0ustar www-datawww-data0 0 "l~0  *H  01;09U 2GlobalSign Trusted Computing Certificate Authority10U  GlobalSign1301U*GlobalSign Trusted Platform Module Root CA0 090728120000Z 391231235959Z0J1 0 UCH10U STMicroelectronics NV10USTM TPM EK Root CA0"0  *H 0 }'C,+zm[vI!<ǠrϤfzyElKmtk5- x jpokx">V²)ʹ5q}hWAtn3@J)MQ ZVEYz ՓjO.bk҆-zHf_uKqX2zPYw3!rt;2Wu|2Ǵ~rEc0a0U0U00Ua> [&^)aG00U#0a> [&^)aG00 *H=g0d0wMZ7PgS'E >U. |P߲{04Ǥtt {h"<ʮ L"Bd3a6..Nctpm-key_attestation-0.12.0/lib/tpm/certificates/Microsoft/0000755000004100000410000000000014406434117023613 5ustar www-datawww-datatpm-key_attestation-0.12.0/lib/tpm/certificates/Microsoft/RootCA/0000755000004100000410000000000014406434117024742 5ustar www-datawww-data././@LongLink0000644000000000000000000000016300000000000011603 Lustar rootroottpm-key_attestation-0.12.0/lib/tpm/certificates/Microsoft/RootCA/Microsoft TPM Root Certificate Authority 2014.certpm-key_attestation-0.12.0/lib/tpm/certificates/Microsoft/RootCA/Microsoft TPM Root Certificate Auth0000644000004100000410000000277114406434117033253 0ustar www-datawww-data00ݠ]0N 'IiP]0  *H  01 0 UUS10U Washington10URedmond10U Microsoft Corporation1604U-Microsoft TPM Root Certificate Authority 20140 141210213119Z 391210213928Z01 0 UUS10U Washington10URedmond10U Microsoft Corporation1604U-Microsoft TPM Root Certificate Authority 20140"0  *H 0 ʷG!H,a?H)ۃaFaS*(`pn8 14w8. )*mTh!Ƶ`^#6+EVޗM"e6|N"<` 1LHw :, ^!_N|ו4sWò#* hyPqOkLj:XdHv/r~M\gNoπӄ򠧙NZic2Ʒi1צ傖pR͕wYtn;pj*Sܺ0߉xUPWEwؕ֙@|$#(C olR."DԹu$Uq.+!WTn sXXP\nxHc>5MuUY[XY0ղ}?ykAl/HL=ҵ٥$.zx#y}fTѤݭ4f67Lf9Vt$>dSƢ`Y#aނ?H)GK-SG<ЭcX=!r%z4/km9H˒liE‘JxslCl* fF}yC{!38Q娓M̫ҥZaߏ̇)wp2=tpm-key_attestation-0.12.0/lib/tpm/certificates/Nuvoton/0000755000004100000410000000000014406434117023316 5ustar www-datawww-datatpm-key_attestation-0.12.0/lib/tpm/certificates/Nuvoton/RootCA/0000755000004100000410000000000014406434117024445 5ustar www-datawww-datatpm-key_attestation-0.12.0/lib/tpm/certificates/Nuvoton/RootCA/Nuvoton TPM Root CA 1110.cer0000644000004100000410000000101214406434117030736 0ustar www-datawww-data008dc0 *H=0U1S0UNuvoton TPM Root CA 11100%U Nuvoton Technology Corporation0 UTW0 150511084333Z 350507084333Z0U1S0UNuvoton TPM Root CA 11100%U Nuvoton Technology Corporation0 UTW0Y0*H=*H=B5dn#Wfxw$N u&3ÂOSDboUFp" ߠφcwf0d0U0U00UԶKi`w0U#0ԶKi`w0 *H=H0E!rsy],A*O h*C g"?g'/V7PLީbDtpm-key_attestation-0.12.0/lib/tpm/certificates/Nuvoton/RootCA/Nuvoton TPM Root CA 2110.cer0000644000004100000410000000101214406434117030737 0ustar www-datawww-data00?/<0 *H=0U1S0UNuvoton TPM Root CA 21100%U Nuvoton Technology Corporation0 UTW0 151019043200Z 351015043200Z0U1S0UNuvoton TPM Root CA 21100%U Nuvoton Technology Corporation0 UTW0Y0*H=*H=B6o?b266WE{x2"%7WX=Ǯc,ɭ7$$f0d0U0U00UyRbxPqqj50U#0yRbxPqqj50 *H=H0E!8#Rte]ŢHJTn (>zxph6hHtpm-key_attestation-0.12.0/lib/tpm/certificates/Nuvoton/RootCA/NTC TPM EK Root CA 01.cer0000644000004100000410000000151614406434117030041 0ustar www-datawww-data0J02]0  *H 0R1P0UNTC TPM EK Root CA 010%U Nuvoton Technology Corporation0 UTW0 120711162930Z 320711162930Z0R1P0UNTC TPM EK Root CA 010%U Nuvoton Technology Corporation0 UTW0"0  *H 0 6a>2Rᨤr=Qk6 ȴ<Ξʄ+2EDWX"LJ10}I3#-e A.w~ pȴn99~⹧𴻜ds'q\_*35L}$;;ߋ뇞!'Ag:&0$0U0U00  *H AC9<,/^IJW~mwP<"JRMU(c{ /]2'AZ+m@F9?.DwwpWכ$e6 le]Oڽt[czO ~Kf7͔Oε53;^5G=nh,qU3Vlܟ/u!V\|ڡ l97B*l_S>takie nhnŘ &тtpm-key_attestation-0.12.0/lib/tpm/certificates/Nuvoton/RootCA/Nuvoton TPM Root CA 2010.cer0000644000004100000410000000162614406434117030751 0ustar www-datawww-data00zX !0  *H 0U1S0UNuvoton TPM Root CA 20100%U Nuvoton Technology Corporation0 UTW0 150423065919Z 350419065919Z0U1S0UNuvoton TPM Root CA 20100%U Nuvoton Technology Corporation0 UTW0"0  *H 0 ƕQ9it{;gL eֿ=r{ ,7t(m^f0d0U0U00U#00C$ tP0U0C$ tP0  *H ғ'>hKyKB}y5cqQq$;g5 B:;X %(Ez3:ЏX18k1Uޛޗk`d( lu0J}sGP zu1?1+b릉|'cH#z+a:}raE\D(ui9X"RE[Uk^ 6"%Rp|FRg:5 [6fE'"[Z CY+\%Wtpm-key_attestation-0.12.0/lib/tpm/certificates/Nuvoton/RootCA/Nuvoton TPM Root CA 2011.cer0000644000004100000410000000162614406434117030752 0ustar www-datawww-data00z('y0  *H 0U1S0UNuvoton TPM Root CA 20110%U Nuvoton Technology Corporation0 UTW0 170911071012Z 370907071012Z0U1S0UNuvoton TPM Root CA 20110%U Nuvoton Technology Corporation0 UTW0"0  *H 0 ˲.aYg=mG^>\Ya.MיΰLȍ9a?WC(( xtf0d0U0U00U/{_1 ǻUG0U#0/{_1 ǻUG0 *H=H0E!ʄ_!pQdA6`})ufG(H C慕m~);ꦤ /obbDtpm-key_attestation-0.12.0/lib/tpm/certificates/Nuvoton/RootCA/NTC TPM EK Root CA ARSUF 01.cer0000644000004100000410000000153514406434117030703 0ustar www-datawww-data0Y0A %An:0  *H 0X1V0"UNTC TPM EK Root CA ARSUF 010%U Nuvoton Technology Corporation0 UTW0 140401183438Z 340328183438Z0X1V0"UNTC TPM EK Root CA ARSUF 010%U Nuvoton Technology Corporation0 UTW0"0  *H 0 ɣlʪʤQ6R`#HS lrU44%>2E[ʔUH *3XΆ=Y+Ο_W{q"L(Ɩxa\?B`f}npi+|Mst"ٓN 43yj,&zfe 0I ߔ(ZPݦv/-/C@ ED~/w6LJqEXᄞnV%ۅqx.&0$0U0U00  *H {zdn32>r)&BO<Q[7=o>isE0joaKj6/͕X-CQᗯMXe?gϿnY'19-[ؿJuV2|t A 3w\ߑf E`JO91rWD!*j_7izi&Rq%ps[}X{ dTorImOi2[a'-$rIL?${FJ"Щ'tpm-key_attestation-0.12.0/lib/tpm/certificates/Nuvoton/RootCA/Nuvoton TPM Root CA 1014.cer0000644000004100000410000000162614406434117030754 0ustar www-datawww-data00zmtgz0  *H 0U1S0UNuvoton TPM Root CA 10140%U Nuvoton Technology Corporation0 UTW0 170821110336Z 370817110336Z0U1S0UNuvoton TPM Root CA 10140%U Nuvoton Technology Corporation0 UTW0"0  *H 0 wSvoLӵjp0[#xmI|nn>-%\z[T"Nz?:^ID<q.}~ :o'غZYĜh9 K;Dp5a<&9 DHjfWU]UFҼTdiJ4}m?jrr\n8kGu} R ڑf0d0U0U00U#0Gr`|0UGr`|0  *H BT1l C~:]]9#X"{KJ 塥X_f@wĨfN]Ldt]py 9d65jMQw ۋXc,T3nNHTwG>sVӉ~D|$>Ƕϱtpm-key_attestation-0.12.0/lib/tpm/certificates/Nuvoton/RootCA/Nuvoton TPM Root CA 1013.cer0000644000004100000410000000162614406434117030753 0ustar www-datawww-data00zH |M0  *H 0U1S0UNuvoton TPM Root CA 10130%U Nuvoton Technology Corporation0 UTW0 150511084325Z 350507084325Z0U1S0UNuvoton TPM Root CA 10130%U Nuvoton Technology Corporation0 UTW0"0  *H 0 daSgў1zd@ޤHEcI6a TB?PߛΕF'}2ov ͅg {Ia-4WM|d{(*a"ӈ=g?'(87!aVeqDYCQ[ N:V:_cٷ(M'<_s'l?D_+Phngl}5 \AX R%PeM-Չi=f0d0U0U00U#07)* k/C0U7)* k/C0  *H \c=`J!kZZ "H&o]{Lgv93Im 3 Af)דF.!b=!Dd :-򟋭(L]VHri5xy8Ŋj%dW{ .&8e},+` ޴!L0S0g{p=a OE.M8FW*>ݫ9M oU!Z޽:ytpm-key_attestation-0.12.0/lib/tpm/certificates/Nuvoton/RootCA/Nuvoton TPM Root CA 2111.cer0000644000004100000410000000101314406434117030741 0ustar www-datawww-data00 Qk10 *H=0U1S0UNuvoton TPM Root CA 21110%U Nuvoton Technology Corporation0 UTW0 170911070949Z 370907070949Z0U1S0UNuvoton TPM Root CA 21110%U Nuvoton Technology Corporation0 UTW0Y0*H=*H=Bڜܰ>A?Dgc,,;l'Asv n(͍9} od$ƥf0d0U0U00U#*Ӿ7JDrJRW.0U#0#*Ӿ7JDrJRW.0 *H=H0E ^mN, _bQ7g6J̠p.(!,YW+\pխCV]ݯ M2N$tpm-key_attestation-0.12.0/lib/tpm/certificates/Nuvoton/RootCA/NTC TPM EK Root CA 02.cer0000644000004100000410000000151614406434117030042 0ustar www-datawww-data0J02c0  *H 0R1P0UNTC TPM EK Root CA 020%U Nuvoton Technology Corporation0 UTW0 120711163324Z 320711163324Z0R1P0UNTC TPM EK Root CA 020%U Nuvoton Technology Corporation0 UTW0"0  *H 0 jhSՀ6aDʻ3) ϖ8D/Š_+`m[7{C,̘ge _+V4j L8S'fvyTڊj q;q>#Gg9 Ù6j{aMG;5haa6fsqnQvYZt"3EYʫɔ7&0$0U0U00  *H ,+VpR[QaTrATX[ !4Fi#ъOP:Ȳ\'E׸hۈ0>B9/yvy݈ۅ= %&jZ!S%}M޻+*Kٸ:@~g@WV={l: 0{/PJLVI(d}و1+!8U >0XCv|B8A>GE !tJe'8stpm-key_attestation-0.12.0/lib/tpm/certificates/Infineon/0000755000004100000410000000000014406434117023413 5ustar www-datawww-datatpm-key_attestation-0.12.0/lib/tpm/certificates/Infineon/RootCA/0000755000004100000410000000000014406434117024542 5ustar www-datawww-datatpm-key_attestation-0.12.0/lib/tpm/certificates/Infineon/RootCA/Infineon OPTIGA(TM) RSA Root CA.crt0000644000004100000410000000265714406434117032137 0ustar www-datawww-data000  *H  0w1 0 UDE1!0U Infineon Technologies AG10U OPTIGA(TM) Devices1(0&U Infineon OPTIGA(TM) RSA Root CA0 130726000000Z 430725235959Z0w1 0 UDE1!0U Infineon Technologies AG10U OPTIGA(TM) Devices1(0&U Infineon OPTIGA(TM) RSA Root CA0"0  *H 0 S31;B5\{܀4*E(g۔Tkh MP{KzfXLr8WD8b .Ap +GqH!:n"/vGa˟,g%R{bd&W&Pd5 Y?lc3z#ւeI~9ׇKq|I#fX|xbH,GdWx.zPHVDGԅ9@^9+$`765F{#rzVD/Tr7SnSEsF#*׋#m߈hܲ1Q}'׃p\!Rv&}=X0R}!^p sm0Gn'&Oro ѕINܔC3sPwe҂>r2`IHm$2i,pĀKiQ.V *n "/5㬍kIB0@0UܻVueA0U0U00  *H  aLw2`,R[U/fcJ SJ4!3H2wTއ%7X DD?-W[A`*yqzv$ #:>2DKn)-9e}⓫Z Fce6#4HKL#!fjkatkY(qY$ ;` >KwC)_K/!>؞H([+YY(0K:nsK|Ʉ~p u/ 6 dɯHajêC+J;*!XBFNkՕ%<‹ڸ땮`GkLݫيdL!KsɆ HdFgg2u!EwIq*zql N0)Lw(Lcp2Zlu;(CqɤSӑͫŮRTJ \ļ}0 z;`n(ː(1h&TsuyTwZ>eS2l"TjTr6K LZ iu٬yHtpm-key_attestation-0.12.0/lib/tpm/certificates/Infineon/RootCA/IFX-RootCA.cer0000644000004100000410000000177314406434117027020 0ustar www-datawww-data00ߠsq/ˑ =K(0  *H 01 0 UUS10U VeriSign, Inc.1;09U 2VeriSign Trusted Computing Certification Authority110/U(VeriSign Trusted Platform Module Root CA0 051025000000Z 451024235959Z01 0 UUS10U VeriSign, Inc.1;09U 2VeriSign Trusted Computing Certification Authority110/U(VeriSign Trusted Platform Module Root CA0"0  *H 0 Pk@{cUs!9ep~$ᝥL?˕{;dJd y9HqԦ&=0v/#]7\B]YoOP=-.Dii(ؔķ=,%fwB$=ۏ6eUd/WΩ _EZl d6}qOF99MdE+xn~tpm-key_attestation-0.12.0/lib/tpm/certificates/Infineon/RootCA/Infineon OPTIGA(TM) ECC Root CA.crt0000644000004100000410000000113714406434117032074 0ustar www-datawww-data0[00 *H=0w1 0 UDE1!0U Infineon Technologies AG10U OPTIGA(TM) Devices1(0&U Infineon OPTIGA(TM) ECC Root CA0 130726000000Z 430725235959Z0w1 0 UDE1!0U Infineon Technologies AG10U OPTIGA(TM) Devices1(0&U Infineon OPTIGA(TM) ECC Root CA0v0*H=+"b&|KV Zϲ<7S Q NIcmNـ/,̿2С:oIkxts銗mx06CB0@0UJJz@9~J0U0U00 *H=g0d0:A8lBdd0 NmĢo߿c &0nY9Io/u}?: d837U^?htpm-key_attestation-0.12.0/lib/tpm/certificates/Infineon/RootCA/IFX TPM EK Root CA.cer0000644000004100000410000000212414406434117027733 0ustar www-datawww-data0P08G$!?} ͇HZ0  *H 01 0 UUS10U VeriSign, Inc.1;09U 2VeriSign Trusted Computing Certification Authority110/U(VeriSign Trusted Platform Module Root CA0 051025000000Z 301024235959Z0m1 0 UDE10UBavaria1!0U Infineon Technologies AG1 0 U AIM10UIFX TPM EK Root CA0"0  *H 0 &jX4Amt+-O/hÿK ԓ= 0Yd:*w<$O+D٭aw XVE*MbrK`ngJ ɋVaE5$9uC-7YVQ"%00U00XU N0L0J `HE/0;09+-http://www.verisign.com/repository/index.html0U0UVDcrE TB0U#0 D&7Eo0  *H X|ٓyoM5GpOϷO|E-7]suw0Fo>v~-WMiJf/B^M?PDłC׿:~õ /)fg-O: "AMD", "id:41544D4C" => "Atmel", "id:4252434D" => "Broadcom", "id:49424D00" => "IBM", "id:49465800" => "Infineon", "id:494E5443" => "Intel", "id:4C454E00" => "Lenovo", "id:4E534D20" => "National Semiconductor", "id:4E545A00" => "Nationz", "id:4E544300" => "Nuvoton Technology", "id:51434F4D" => "Qualcomm", "id:534D5343" => "SMSC", "id:53544D20" => "ST Microelectronics", "id:534D534E" => "Samsung", "id:534E5300" => "Sinosun", "id:54584E00" => "Texas Instruments", "id:57454300" => "Winbond", "id:524F4343" => "Fuzhou Rockchip", }.freeze end tpm-key_attestation-0.12.0/lib/tpm/t_public.rb0000644000004100000410000000551114406434117021331 0ustar www-datawww-data# frozen_string_literal: true require "bindata" require "openssl" require "tpm/constants" require "tpm/sized_buffer" require "tpm/t_public/s_ecc_parms" require "tpm/t_public/s_rsa_parms" module TPM # Section 12.2.4 in https://trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-2-Structures-01.38.pdf class TPublic < BinData::Record BYTE_LENGTH = 8 CURVE_TPM_TO_OPENSSL = { TPM::ECC_NIST_P256 => "prime256v1", TPM::ECC_NIST_P384 => "secp384r1", TPM::ECC_NIST_P521 => "secp521r1", }.freeze BN_BASE = 2 RSA_KEY_DEFAULT_PUBLIC_EXPONENT = 2**16 + 1 ECC_UNCOMPRESSED_POINT_INDICATOR = "\x04" class << self alias_method :deserialize, :read end endian :big uint16 :alg_type uint16 :name_alg # :object_attributes skip length: 4 sized_buffer :auth_policy choice :parameters, selection: :alg_type do s_ecc_parms TPM::ALG_ECC s_rsa_parms TPM::ALG_RSA end choice :unique, selection: :alg_type do sized_buffer TPM::ALG_ECC sized_buffer TPM::ALG_RSA end def rsa? alg_type == TPM::ALG_RSA end def ecc? alg_type == TPM::ALG_ECC end def key if parameters.symmetric == TPM::ALG_NULL if ecc? ecc_key elsif rsa? rsa_key else raise "Type #{alg_type} not supported" end end end def openssl_curve_name if ecc? CURVE_TPM_TO_OPENSSL[parameters.curve_id] || raise("Unknown curve #{parameters.curve_id}") end end private def ecc_key if parameters.scheme == TPM::ALG_ECDSA group = OpenSSL::PKey::EC::Group.new(openssl_curve_name) point = OpenSSL::PKey::EC::Point.new(group, bn(ECC_UNCOMPRESSED_POINT_INDICATOR + unique.buffer.value)) # RFC5480 SubjectPublicKeyInfo asn1 = OpenSSL::ASN1::Sequence( [ OpenSSL::ASN1::Sequence( [ OpenSSL::ASN1::ObjectId("id-ecPublicKey"), OpenSSL::ASN1::ObjectId(group.curve_name), ] ), OpenSSL::ASN1::BitString(point.to_octet_string(:uncompressed)) ] ) OpenSSL::PKey::EC.new(asn1.to_der) end end def rsa_key case parameters.scheme when TPM::ALG_RSASSA, TPM::ALG_RSAPSS, TPM::ALG_NULL n = unique.buffer.value if parameters.key_bits / BYTE_LENGTH == n.size # PKCS#1 RSAPublicKey asn1 = OpenSSL::ASN1::Sequence( [ OpenSSL::ASN1::Integer.new(bn(n)), OpenSSL::ASN1::Integer.new(bn(RSA_KEY_DEFAULT_PUBLIC_EXPONENT)), ] ) OpenSSL::PKey::RSA.new(asn1.to_der) end end end def bn(data) if data OpenSSL::BN.new(data, BN_BASE) end end end end tpm-key_attestation-0.12.0/lib/tpm/public_area.rb0000644000004100000410000000136514406434117022001 0ustar www-datawww-data# frozen_string_literal: true require "openssl" require "tpm/t_public" module TPM TPM_TO_OPENSSL_HASH_ALG = { TPM::ALG_SHA1 => "SHA1", TPM::ALG_SHA256 => "SHA256" }.freeze class PublicArea attr_reader :object def initialize(object) @object = object end def name [name_alg].pack("n") + name_digest end def key t_public.key end def ecc? t_public.ecc? end def openssl_curve_name t_public.openssl_curve_name end private def name_digest OpenSSL::Digest.digest(TPM_TO_OPENSSL_HASH_ALG[name_alg], object) end def name_alg t_public.name_alg end def t_public @t_public ||= TPM::TPublic.deserialize(object) end end end tpm-key_attestation-0.12.0/lib/tpm/sized_buffer.rb0000644000004100000410000000052414406434117022176 0ustar www-datawww-data# frozen_string_literal: true require "bindata" module TPM # Section 10.4 in https://trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-2-Structures-01.38.pdf class SizedBuffer < BinData::Record endian :big uint16 :buffer_size, value: lambda { buffer.size } string :buffer, read_length: :buffer_size end end tpm-key_attestation-0.12.0/lib/tpm/key_attestation.rb0000644000004100000410000000511314406434117022735 0ustar www-datawww-data# frozen_string_literal: true require "openssl" require "tpm/key_attestation/version" require "tpm/aik_certificate" require "tpm/certify_validator" require "tpm/constants" require "tpm/public_area" module TPM class KeyAttestation # https://docs.microsoft.com/en-us/windows-server/security/guarded-fabric-shielded-vm/guarded-fabric-install-trusted-tpm-root-certificates TRUSTED_CERTIFICATES = begin pattern = File.expand_path(File.join(__dir__, "certificates", "*", "RootCA", "*.*")) Dir.glob(pattern).map do |filename| File.open(filename) { |file| OpenSSL::X509::Certificate.new(file) } end end class Error < StandardError; end attr_reader( :certify_info, :signature, :certified_key, :certificates, :signature_algorithm, :hash_algorithm, :qualifying_data, :trusted_certificates ) def initialize( certify_info, signature, certified_key, certificates, qualifying_data, signature_algorithm: ALG_RSASSA, hash_algorithm: ALG_SHA256, trusted_certificates: TRUSTED_CERTIFICATES ) @certify_info = certify_info @signature = signature @certified_key = certified_key @certificates = certificates @signature_algorithm = signature_algorithm @hash_algorithm = hash_algorithm @qualifying_data = qualifying_data @trusted_certificates = trusted_certificates end def key if valid? public_area.key end end def valid? certify_validator.valid?(aik_certificate.public_key) && aik_certificate.conformant? && trustworthy? end private def certify_validator @certify_validator ||= TPM::CertifyValidator.new( certify_info, signature, qualifying_data, public_area, signature_algorithm: signature_algorithm, hash_algorithm: hash_algorithm ) end def trustworthy? x509_certificates = certificates.map { |c| OpenSSL::X509::Certificate.new(c) } trust_store.verify(x509_certificates[0], x509_certificates[1..-1]) end def trust_store @trust_store ||= OpenSSL::X509::Store.new.tap do |trust_store| trusted_certificates.uniq(&:serial).each { |trusted_certificate| trust_store.add_cert(trusted_certificate) } end end def aik_certificate @aik_certificate ||= TPM::AIKCertificate.from_der(certificates.first) end def public_area @public_area ||= TPM::PublicArea.new(certified_key) end end end tpm-key_attestation-0.12.0/Gemfile0000644000004100000410000000040314406434117017123 0ustar www-datawww-data# frozen_string_literal: true source "https://rubygems.org" # Specify your gem's dependencies in tpm-key_attestation.gemspec gemspec gem "appraisal", "~> 2.2.0" gem "byebug", "~> 11.0" gem "rake", "~> 13.0" gem "rspec", "~> 3.0" gem "rubocop", "~> 0.80.1" tpm-key_attestation-0.12.0/.github/0000755000004100000410000000000014406434117017173 5ustar www-datawww-datatpm-key_attestation-0.12.0/.github/workflows/0000755000004100000410000000000014406434117021230 5ustar www-datawww-datatpm-key_attestation-0.12.0/.github/workflows/build.yml0000644000004100000410000000240714406434117023055 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: - '3.2' - '3.1' - '3.0' - '2.7' - '2.6' - '2.5' - '2.4' gemfile: - openssl_2_2 - openssl_2_1 - openssl_3_0 - openssl_3_1 exclude: - ruby: '2.4' gemfile: openssl_3_0 - ruby: '2.5' gemfile: openssl_3_0 - ruby: '2.4' gemfile: openssl_3_1 - ruby: '2.5' gemfile: openssl_3_1 env: BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile steps: - uses: actions/checkout@v2 - run: rm Gemfile.lock - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} bundler-cache: true - run: bundle exec rake tpm-key_attestation-0.12.0/SECURITY.md0000644000004100000410000000030314406434117017420 0ustar www-datawww-data# Security Policy ## Reporting a Vulnerability If you have discovered a security bug, please send an email to security@cedarcode.com instead of posting to the GitHub issue tracker. Thank you!