Class: Sigstore::TUF::TrustedMetadataSet
- Inherits:
-
Object
- Object
- Sigstore::TUF::TrustedMetadataSet
- Includes:
- Loggable
- Defined in:
- lib/sigstore/tuf/trusted_metadata_set.rb
Instance Method Summary collapse
- #[](role) ⇒ Object
- #include?(type) ⇒ Boolean
-
#initialize(root_data, envelope_type, reference_time: Time.now.utc) ⇒ TrustedMetadataSet
constructor
A new instance of TrustedMetadataSet.
- #root ⇒ Object
- #root=(data) ⇒ Object
- #snapshot ⇒ Object
- #snapshot=(data, trusted: false) ⇒ Object
- #timestamp ⇒ Object
- #timestamp=(data) ⇒ Object
- #update_delegated_targets(data, role, parent_role) ⇒ Object
Methods included from Loggable
Constructor Details
#initialize(root_data, envelope_type, reference_time: Time.now.utc) ⇒ TrustedMetadataSet
Returns a new instance of TrustedMetadataSet.
27 28 29 30 31 32 33 34 |
# File 'lib/sigstore/tuf/trusted_metadata_set.rb', line 27 def initialize(root_data, envelope_type, reference_time: Time.now.utc) @trusted_set = {} @reference_time = reference_time @envelope_type = envelope_type logger.debug { "Loading trusted root" } load_trusted_root(root_data) end |
Instance Method Details
#[](role) ⇒ Object
121 122 123 |
# File 'lib/sigstore/tuf/trusted_metadata_set.rb', line 121 def [](role) @trusted_set.fetch(role) end |
#include?(type) ⇒ Boolean
117 118 119 |
# File 'lib/sigstore/tuf/trusted_metadata_set.rb', line 117 def include?(type) @trusted_set.key?(type) end |
#root ⇒ Object
36 37 38 |
# File 'lib/sigstore/tuf/trusted_metadata_set.rb', line 36 def root @trusted_set.fetch("root") { raise Error::InvalidData, "missing root metadata" } end |
#root=(data) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/sigstore/tuf/trusted_metadata_set.rb', line 40 def root=(data) raise Error::BadUpdateOrder, "cannot update root after timestamp" if @trusted_set.key?("timestamp") , canonical_signed, signatures = load_data(Root, data, root) .verify_delegate("root", canonical_signed, signatures) raise Error::BadVersionNumber, "root version did not increment by one" if .version != root.version + 1 @trusted_set["root"] = logger.debug { "Updated root v#{metadata.version}" } end |
#snapshot ⇒ Object
52 53 54 |
# File 'lib/sigstore/tuf/trusted_metadata_set.rb', line 52 def snapshot @trusted_set.fetch("snapshot") end |
#snapshot=(data, trusted: false) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/sigstore/tuf/trusted_metadata_set.rb', line 88 def snapshot=(data, trusted: false) raise Error::BadUpdateOrder, "cannot update snapshot before timestamp" unless @trusted_set.key?("timestamp") raise Error::BadUpdateOrder, "cannot update snapshot after targets" if @trusted_set.key?("targets") = . .verify_length_and_hashes(data) unless trusted new_snapshot, = load_data(Snapshot, data, root) # If an existing trusted snapshot is updated, check for rollback attack if include?(Snapshot::TYPE) snapshot..each do |filename, file_info| new_file_info = new_snapshot.[filename] raise Error::RepositoryError, "new snapshot is missing info for #{filename}" unless new_file_info if new_file_info.version < file_info.version raise Error::BadVersionNumber, "expected #{filename} v#{new_file_info.version}, got v#{file_info.version}" end end end @trusted_set["snapshot"] = new_snapshot logger.debug { "Updated snapshot v#{new_snapshot.version}" } check_final_snapshot end |
#timestamp ⇒ Object
56 57 58 |
# File 'lib/sigstore/tuf/trusted_metadata_set.rb', line 56 def @trusted_set.fetch("timestamp") end |
#timestamp=(data) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/sigstore/tuf/trusted_metadata_set.rb', line 60 def (data) raise Error::BadUpdateOrder, "cannot update timestamp after snapshot" if @trusted_set.key?("snapshot") if root.expired?(@reference_time) raise Error::ExpiredMetadata, "final root.json expired at #{root.expires}, is #{@reference_time}" end , = load_data(Timestamp, data, root) if include?(Timestamp::TYPE) if .version < .version raise Error::BadVersionNumber, "timestamp version less than metadata version" end raise Error::EqualVersionNumber if .version == .version = . = . if .version < .version raise Error::BadVersionNumber, "snapshot version did not increase" end end @trusted_set["timestamp"] = end |
#update_delegated_targets(data, role, parent_role) ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/sigstore/tuf/trusted_metadata_set.rb', line 125 def update_delegated_targets(data, role, parent_role) raise Error::BadUpdateOrder, "cannot update targets before snapshot" unless @trusted_set.key?("snapshot") check_final_snapshot delegator = @trusted_set[parent_role] logger.debug { "Updating #{role} delegated by #{parent_role.inspect} to #{delegator.class}" } raise Error::BadUpdateOrder, "cannot load targets before delegator" unless delegator = snapshot.["#{role}.json"] raise Error::RepositoryError, "no metadata for role #{role} in snapshot" unless .verify_length_and_hashes(data) new_delegate, = load_data(Targets, data, delegator, role) version = new_delegate.version raise Error::BadVersionNumber, "expected #{role} v#{meta.version}, got v#{version}" if version != .version raise Error::ExpiredMetadata, "new #{role} is expired" if new_delegate.expired?(@reference_time) @trusted_set[role] = new_delegate logger.debug { "Updated #{role} v#{version}" } new_delegate end |