/// Verify and update the root metadata.
Verify and update the root metadata.
Verify and update the root metadata .
pub fn update_root(&mut self, raw_root: &RawSignedMetadata<D, RootMetadata>) -> Result<()> {
        let verified = {
            let trusted_root = &self.trusted_root;
            /////////////////////////////////////////
            // TUF-1.0.5 §5.1.3:
            //
            //     Check signatures. Version N+1 of the root metadata file MUST have been signed
            //     by: (1) a threshold of keys specified in the trusted root metadata file (version
            //     N), and (2) a threshold of keys specified in the new root metadata file being
            //     validated (version N+1). If version N+1 is not signed as required, discard it,
            //     abort the update cycle, and report the signature failure. On the next update
            //     cycle, begin at step 0 and version N of the root metadata file.  Verify the
            //     trusted root signed the new root.
            let new_root = verify::verify_signatures(
                raw_root,
                trusted_root.root().threshold(),
                trusted_root.root_keys(),
            )?;
            // Verify the new root signed itself.
            let new_root = verify::verify_signatures(
                raw_root,
                new_root.root().threshold(),
                new_root.root_keys(),
            )?;
            /////////////////////////////////////////
            // TUF-1.0.5 §5.1.4:
            //
            //     Check for a rollback attack. The version number of the trusted root metadata
            //     file (version N) must be less than or equal to the version number of the new
            //     root metadata file (version N+1). Effectively, this means checking that the
            //     version number signed in the new root metadata file is indeed N+1. If the
            //     version of the new root metadata file is less than the trusted metadata file,
            //     discard it, abort the update cycle, and report the rollback attack. On the next
            //     update cycle, begin at step 0 and version N of the root metadata file.
            let next_root_version = trusted_root.version().checked_add(1).ok_or_else(|| {
                Error::VerificationFailure("root version should be less than max u32".into())
            })?;
            if new_root.version() != next_root_version {
                return Err(Error::VerificationFailure(format!(
                    "Attempted to roll back root metadata at version {} to {}.",
                    trusted_root.version(),
                    new_root.version()
                )));
            }
            /////////////////////////////////////////
            // TUF-1.0.5 §5.1.5:
            //
            //     Note that the expiration of the new (intermediate) root metadata file does not matter yet, because we will check for it in step 1.8.
            /////////////////////////////////////////
            // TUF-1.0.5 §5.1.8:
            //
            //     Check for a freeze attack. The latest known time should be lower than the
            //     expiration timestamp in the trusted root metadata file (version N). If the
            //     trusted root metadata file has expired, abort the update cycle, report the
            //     potential freeze attack. On the next update cycle, begin at step 0 and version N
            //     of the root metadata file.
            // FIXME: root metadata expiration is performed in Client. We should restructure things
            // such that it is performed here.
            new_root
        };
        /////////////////////////////////////////
        // TUF-1.0.5 §5.1.9:
        //
        //     If the timestamp and / or snapshot keys have been rotated, then delete the
        //     trusted timestamp and snapshot metadata files. This is done in order to recover
        //     from fast-forward attacks after the repository has been compromised and
        //     recovered. A fast-forward attack happens when attackers arbitrarily increase the
        //     version numbers of: (1) the timestamp metadata, (2) the snapshot metadata, and /
        //     or (3) the targets, or a delegated targets, metadata file in the snapshot
        //     metadata. Please see the Mercury paper for more details.
        self.purge_metadata();
        /////////////////////////////////////////
        // TUF-1.0.5 §5.1.6:
        //
        //     1.6. Set the trusted root metadata file to the new root metadata file.
        self.trusted_root = verified;
        Ok(())
    }
pub fn update_root ( & mut self , raw_root : & RawSignedMetadata < D , RootMetadata > ) -> Result < ( ) > { let verified = { let trusted_root = & self . trusted_root ; ///////////////////////////////////////// // TUF-1.0.5 §5.1.3: // //     Check signatures. Version N+1 of the root metadata file MUST have been signed //     by: (1) a threshold of keys specified in the trusted root metadata file (version //     N), and (2) a threshold of keys specified in the new root metadata file being //     validated (version N+1). If version N+1 is not signed as required, discard it, //     abort the update cycle, and report the signature failure. On the next update //     cycle, begin at step 0 and version N of the root metadata file.  Verify the //     trusted root signed the new root. let new_root = verify :: verify_signatures ( raw_root , trusted_root . root ( ) . threshold ( ) , trusted_root . root_keys ( ) , ) ? ; // Verify the new root signed itself. let new_root = verify :: verify_signatures ( raw_root , new_root . root ( ) . threshold ( ) , new_root . root_keys ( ) , ) ? ; ///////////////////////////////////////// // TUF-1.0.5 §5.1.4: // //     Check for a rollback attack. The version number of the trusted root metadata //     file (version N) must be less than or equal to the version number of the new //     root metadata file (version N+1). Effectively, this means checking that the //     version number signed in the new root metadata file is indeed N+1. If the //     version of the new root metadata file is less than the trusted metadata file, //     discard it, abort the update cycle, and report the rollback attack. On the next //     update cycle, begin at step 0 and version N of the root metadata file. let next_root_version = trusted_root . version ( ) . checked_add ( 1 ) . ok_or_else ( | | { Error :: VerificationFailure ( " " . into ( ) ) } ) ? ; if new_root . version ( ) != next_root_version { return Err ( Error :: VerificationFailure ( format ! ( " " trusted_root version ( ) new_root version ( ) ) ) ) ; } ///////////////////////////////////////// // TUF-1.0.5 §5.1.5: // //     Note that the expiration of the new (intermediate) root metadata file does not matter yet, because we will check for it in step 1.8. ///////////////////////////////////////// // TUF-1.0.5 §5.1.8: // //     Check for a freeze attack. The latest known time should be lower than the //     expiration timestamp in the trusted root metadata file (version N). If the //     trusted root metadata file has expired, abort the update cycle, report the //     potential freeze attack. On the next update cycle, begin at step 0 and version N //     of the root metadata file. // FIXME: root metadata expiration is performed in Client. We should restructure things // such that it is performed here. new_root } ; ///////////////////////////////////////// // TUF-1.0.5 §5.1.9: // //     If the timestamp and / or snapshot keys have been rotated, then delete the //     trusted timestamp and snapshot metadata files. This is done in order to recover //     from fast-forward attacks after the repository has been compromised and //     recovered. A fast-forward attack happens when attackers arbitrarily increase the //     version numbers of: (1) the timestamp metadata, (2) the snapshot metadata, and / //     or (3) the targets, or a delegated targets, metadata file in the snapshot //     metadata. Please see the Mercury paper for more details. self . purge_metadata ( ) ; ///////////////////////////////////////// // TUF-1.0.5 §5.1.6: // //     1.6. Set the trusted root metadata file to the new root metadata file. self . trusted_root = verified ; Ok ( ( ) ) }
Verify and update the root metadata.
Verify and update the root metadata .
&mut self
raw_root
&RawSignedMetadata<D, RootMetadata>