Class: Sigstore::SBundle

Inherits:
Bundle::V1::Bundle
  • Object
show all
Defined in:
lib/sigstore/models.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSBundle

Returns a new instance of SBundle.



123
124
125
126
127
128
# File 'lib/sigstore/models.rb', line 123

def initialize(*)
  super
  @bundle_type = BundleType.from_media_type(media_type)
  validate_version!
  freeze
end

Instance Attribute Details

#bundle_typeObject (readonly)

Returns the value of attribute bundle_type.



121
122
123
# File 'lib/sigstore/models.rb', line 121

def bundle_type
  @bundle_type
end

#leaf_certificateObject (readonly)

Returns the value of attribute leaf_certificate.



121
122
123
# File 'lib/sigstore/models.rb', line 121

def leaf_certificate
  @leaf_certificate
end

Class Method Details

.for_cert_bytes_and_signature(cert_bytes, signature) ⇒ Object



130
131
132
133
134
135
136
137
138
139
# File 'lib/sigstore/models.rb', line 130

def self.for_cert_bytes_and_signature(cert_bytes, signature)
  bundle = Bundle::V1::Bundle.new
  bundle.media_type = BundleType::BUNDLE_0_3.media_type
  bundle.verification_material = Bundle::V1::VerificationMaterial.new
  bundle.verification_material.certificate = Common::V1::X509Certificate.new
  bundle.verification_material.certificate.raw_bytes = cert_bytes
  bundle.message_signature = Common::V1::MessageSignature.new
  bundle.message_signature.signature = signature
  new(bundle)
end

Instance Method Details

#expected_tlog_entry(hashed_input) ⇒ Object



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/sigstore/models.rb', line 141

def expected_tlog_entry(hashed_input)
  case content
  when :message_signature
    expected_hashed_rekord_tlog_entry(hashed_input)
  when :dsse_envelope
    rekor_entry = verification_material.tlog_entries.first
    canonicalized_body = begin
      JSON.parse(rekor_entry.canonicalized_body)
    rescue JSON::ParserError
      raise Error::InvalidBundle, "expected canonicalized_body to be JSON"
    end

    case kind_version = canonicalized_body.values_at("kind", "apiVersion")
    when %w[dsse 0.0.1]
      expected_dsse_0_0_1_tlog_entry
    when %w[intoto 0.0.2]
      expected_intoto_0_0_2_tlog_entry
    else
      raise Error::InvalidRekorEntry, "Unhandled rekor entry kind/version: #{kind_version.inspect}"
    end
  else
    raise Error::InvalidBundle, "expected either message_signature or dsse_envelope"
  end
end