cedarcode / tpm-key_attestation

TPM 2.0 Key Attestation validation in ruby
https://rubygems.org/gems/tpm-key_attestation
Apache License 2.0
10 stars 6 forks source link

Fix loading files on Windows by using File.binread instead of open #20

Closed johnnyshields closed 11 months ago

johnnyshields commented 11 months ago

File.open does not work across all operating systems (particularly Windows) for binary files like DER format. File.binread is preferred here.

See: https://stackoverflow.com/a/30081354

This PR also adds tests across operating systems

santiagorodriguez96 commented 11 months ago

Hey @johnnyshields! Thank you so much for your contribution!

Out of curiosity: did you run into an error because of this when using windows?

Code looks good! 🙂

johnnyshields commented 11 months ago

Yes, correct. I use Windows for dev sometimes.

santiagorodriguez96 commented 11 months ago

I see! Would you mind sharing the specific error that you were getting? Just for completeness 🙂

salmanasiddiqui commented 11 months ago

This is the error which occurs

C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/tpm-key_attestation-0.12.0/lib/tpm/key_attestation.rb:18:in `initialize': PEM_read_bio_X509: no start line (Expecting: CERTIFICATE) (OpenSSL::X509::CertificateError)
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/tpm-key_attestation-0.12.0/lib/tpm/key_attestation.rb:18:in `new'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/tpm-key_attestation-0.12.0/lib/tpm/key_attestation.rb:18:in `block (2 levels) in <class:KeyAttestation>'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/tpm-key_attestation-0.12.0/lib/tpm/key_attestation.rb:18:in `open'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/tpm-key_attestation-0.12.0/lib/tpm/key_attestation.rb:18:in `block in <class:KeyAttestation>'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/tpm-key_attestation-0.12.0/lib/tpm/key_attestation.rb:17:in `map'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/tpm-key_attestation-0.12.0/lib/tpm/key_attestation.rb:17:in `<class:KeyAttestation>'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/tpm-key_attestation-0.12.0/lib/tpm/key_attestation.rb:12:in `<module:TPM>'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/tpm-key_attestation-0.12.0/lib/tpm/key_attestation.rb:11:in `<main>'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/webauthn-3.1.0/lib/webauthn/attestation_statement/tpm.rb:5:in `<main>'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/webauthn-3.1.0/lib/webauthn/attestation_statement.rb:9:in `<main>'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/webauthn-3.1.0/lib/webauthn/attestation_object.rb:6:in `<main>'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/webauthn-3.1.0/lib/webauthn/authenticator_attestation_response.rb:8:in `<main>'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/webauthn-3.1.0/lib/webauthn/public_key_credential_with_attestation.rb:3:in `<main>'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/webauthn-3.1.0/lib/webauthn/credential.rb:6:in `<main>'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/webauthn-3.1.0/lib/webauthn/relying_party.rb:4:in `<main>'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/webauthn-3.1.0/lib/webauthn/configuration.rb:4:in `<main>'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/webauthn-3.1.0/lib/webauthn.rb:3:in `<main>'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:38:in `require'
        from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/runtime.rb:60:in `block (2 levels) in require'
        from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/runtime.rb:55:in `each'
        from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/runtime.rb:55:in `block in require'
        from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/runtime.rb:44:in `each'
        from C:/Ruby32-x64/lib/ruby/3.2.0/bundler/runtime.rb:44:in `require'
        from C:/Ruby32-x64/lib/ruby/3.2.0/bundler.rb:196:in `require'
        from D:/Projects/identity/config/application.rb:9:in `<main>'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/railties-7.1.2/lib/rails/command/actions.rb:15:in `require_application!'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/railties-7.1.2/lib/rails/command/environment_argument.rb:31:in `require_application!'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/railties-7.1.2/lib/rails/command/actions.rb:19:in `boot_application!'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/railties-7.1.2/lib/rails/commands/console/console_command.rb:105:in `perform'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/thor-1.3.0/lib/thor/command.rb:28:in `run'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/thor-1.3.0/lib/thor/invocation.rb:127:in `invoke_command'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/railties-7.1.2/lib/rails/command/base.rb:178:in `invoke_command'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/thor-1.3.0/lib/thor.rb:527:in `dispatch'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/railties-7.1.2/lib/rails/command/base.rb:73:in `perform'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/railties-7.1.2/lib/rails/command.rb:71:in `block in invoke'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/railties-7.1.2/lib/rails/command.rb:149:in `with_argv'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/railties-7.1.2/lib/rails/command.rb:69:in `invoke'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/railties-7.1.2/lib/rails/commands.rb:18:in `<main>'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from <internal:C:/Ruby32-x64/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
        from C:/Ruby32-x64/lib/ruby/gems/3.2.0/gems/bootsnap-1.17.0/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:32:in `require'
        from bin/rails:4:in `<main>'
johnnyshields commented 11 months ago

Yep thats the one! Thanks

santiagorodriguez96 commented 11 months ago

@salmanasiddiqui @johnnyshields Thank you so much!

johnnyshields commented 11 months ago

@santiagorodriguez96 awesome, thanks! Appreciate if you can cut a release for this.

santiagorodriguez96 commented 10 months ago

@santiagorodriguez96 awesome, thanks! Appreciate if you can cut a release for this.

Will do! Sorry for the late response I went on PTO 🙃