Validate certificate chain

Write codeEasy16 min

Your task

A deployment tool inspects the certificate chains its services present before it will trust them. Each chain is a list of entries written as a subject name, a greater-than sign, then the name of the issuer that signed that subject, for example leaf>intermediate. Names never contain a greater-than sign and are compared exactly. A chain is in order when the issuer named by every entry is the subject of the next entry, and the last entry is self-issued, meaning its subject and its issuer are the same name. Return one verdict per chain in the order the chains arrive: empty for a chain holding no entries, ordered when the chain is in order, reversed when reversing the entries would put it in order, unanchored when the entries link correctly but the final one is not self-issued, and broken for anything else. Test those verdicts in that order.

Examples

chain_order_report(chains: list[list[str]]) -> list[str]
Example 1
Inputchain_order_report([["leaf>intermediate", "intermediate>root", "root>root"], ["root>root", "intermediate>root", "leaf>intermediate"], ["leaf>intermediate", "intermediate>root"]])
Output["ordered", "reversed", "unanchored"]
Example 2
Inputchain_order_report([["api.example>issuing-ca", "issuing-ca>root-ca", "root-ca>root-ca"], ["api.example>issuing-ca", "other-ca>root-ca", "root-ca>root-ca"], []])
Output["ordered", "broken", "empty"]
Example 3
Inputchain_order_report([["mid>root", "leaf>mid"]])
Output["broken"]