Sha256: 567ee9d2636912c789367c9a5a93a3b2d5a79981ee1aeda15b2fde56d1456c5f

Contents?: true

Size: 1.08 KB

Versions: 25

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

require "cose/algorithm"
require "cose/key/ec2"
require "webauthn/attestation_statement/base"

module WebAuthn
  module AttestationStatement
    class FidoU2f < Base
      class PublicKey
        COORDINATE_LENGTH = 32
        UNCOMPRESSED_FORM_INDICATOR = "\x04"

        def self.uncompressed_point?(data)
          data.size &&
            data.length == UNCOMPRESSED_FORM_INDICATOR.length + COORDINATE_LENGTH * 2 &&
            data[0] == UNCOMPRESSED_FORM_INDICATOR
        end

        def initialize(data)
          @data = data
        end

        def valid?
          data.size >= COORDINATE_LENGTH * 2 &&
            cose_key.x.length == COORDINATE_LENGTH &&
            cose_key.y.length == COORDINATE_LENGTH &&
            cose_key.alg == COSE::Algorithm.by_name("ES256").id
        end

        def to_uncompressed_point
          UNCOMPRESSED_FORM_INDICATOR + cose_key.x + cose_key.y
        end

        private

        attr_reader :data

        def cose_key
          @cose_key ||= COSE::Key::EC2.deserialize(data)
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
webauthn-3.3.0 lib/webauthn/attestation_statement/fido_u2f/public_key.rb
webauthn-3.2.2 lib/webauthn/attestation_statement/fido_u2f/public_key.rb
webauthn-3.2.1 lib/webauthn/attestation_statement/fido_u2f/public_key.rb
webauthn-3.2.0 lib/webauthn/attestation_statement/fido_u2f/public_key.rb
webauthn-3.1.0 lib/webauthn/attestation_statement/fido_u2f/public_key.rb
webauthn-3.0.0 lib/webauthn/attestation_statement/fido_u2f/public_key.rb
webauthn-3.0.0.alpha2 lib/webauthn/attestation_statement/fido_u2f/public_key.rb
webauthn-2.5.2 lib/webauthn/attestation_statement/fido_u2f/public_key.rb
webauthn-2.5.1 lib/webauthn/attestation_statement/fido_u2f/public_key.rb
webauthn-2.5.0 lib/webauthn/attestation_statement/fido_u2f/public_key.rb
webauthn-2.4.1 lib/webauthn/attestation_statement/fido_u2f/public_key.rb
webauthn-2.4.0 lib/webauthn/attestation_statement/fido_u2f/public_key.rb
webauthn-3.0.0.alpha1 lib/webauthn/attestation_statement/fido_u2f/public_key.rb
webauthn-2.3.0 lib/webauthn/attestation_statement/fido_u2f/public_key.rb
webauthn-2.2.1 lib/webauthn/attestation_statement/fido_u2f/public_key.rb
webauthn-2.2.0 lib/webauthn/attestation_statement/fido_u2f/public_key.rb
webauthn-2.1.0 lib/webauthn/attestation_statement/fido_u2f/public_key.rb
webauthn-2.0.0 lib/webauthn/attestation_statement/fido_u2f/public_key.rb
webauthn-2.0.0.beta1 lib/webauthn/attestation_statement/fido_u2f/public_key.rb
webauthn-1.18.0 lib/webauthn/attestation_statement/fido_u2f/public_key.rb