• 
      

    Add wider support and validation for valid SHA1/256 fingerprints.

    Review Request #14925 — Created March 17, 2026 and submitted

    Information

    Review Board
    release-7.1.x

    Reviewers

    CertificateFingerprints.from_string() now supports plain SHA1 and
    SHA256 strings (without the semicolons used in fingerprints). These will
    be converted into the correct format.

    The values are also now validated against regexes. This will key off
    the pattern and information needed to optionally normalize the string
    and then set it, based on the length of the string provided. If there
    isn't a suitable match, None will be returned.

    Unit tests pass.

    Summary ID
    Add wider support and validation for valid SHA1/256 fingerprints.
    `CertificateFingerprints.from_string()` now supports plain SHA1 and SHA256 strings (without the semicolons used in fingerprints). These will be converted into the correct format. The values are also now validated against regexes. This will key off the pattern and information needed to optionally normalize the string and then set it, based on the length of the string provided. If there isn't a suitable match, ``None`` will be returned.
    db7091e37d7b46b63a1a7ba68b3628c7ac5af3a3
    Description From Last Updated

    A SHA1 hash is 20 bytes, but that corresponds to 40 hex characters. Your test didn't catch this because the …

    david david

    Can we add a type hint here?

    david david

    Leftover debug code.

    maubin maubin

    It might be nice to switch to re.fullmatch() for these, to make it less fragile for future changes. I also …

    david david

    Might be nicer to do length == X and cls.SHA... here instead of nested if statements? Same with the elifs …

    maubin maubin
    maubin
    1. 
        
    2. reviewboard/certs/cert.py (Diff revision 1)
       
       
      Show all issues

      Leftover debug code.

    3. reviewboard/certs/cert.py (Diff revision 1)
       
       
       
      Show all issues

      Might be nicer to do length == X and cls.SHA... here instead of nested if statements? Same with the elifs below.

      1. This was done to short-circuit quickly if it matches the length but not the pattern. Say we get a string that's 95 chars, but not a valid SHA256 fingerprint. Combining the conditionals means we'd then check every other elif until we inevitably return None. I wanted to take the approach for this code that fails fast.

    4. 
        
    david
    1. 
        
    2. reviewboard/certs/cert.py (Diff revision 1)
       
       
      Show all issues

      A SHA1 hash is 20 bytes, but that corresponds to 40 hex characters. Your test didn't catch this because the invalid character happened to be within the first half of the hash.

    3. reviewboard/certs/cert.py (Diff revision 1)
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
       
      Show all issues

      It might be nice to switch to re.fullmatch() for these, to make it less fragile for future changes.

      I also agree with Michelle's comment about combining the conditionals--as long as length is listed first, it won't check the regex match.

      It might also be nice to order these to keep sha1 and sha256 together, instead of going in reverse order by length.

      1. I mentioned this in the comment to Michelle, but I want to short-circuit this as soon as we know the length is a match but the pattern is not.

        Thinking of another approach.

    4. 
        
    chipx86
    david
    1. 
        
    2. reviewboard/certs/cert.py (Diff revisions 1 - 2)
       
       
      Show all issues

      Can we add a type hint here?

    3. 
        
    maubin
    1. Ship It!
    2. 
        
    chipx86
    Review request changed
    Status:
    Completed
    Change Summary:
    Pushed to release-7.1.x (7968667)