// Optimal chains are the shortest chains, with newest intermediates and most advanced crypto suite being the tie breaker. func optimalChains(chains [][]*x509.Certificate) [][]*x509.Certificate { // Find shortest chains chains = ubiquity.Filter(chains, ubiquity.CompareChainLength) // Find the chains with longest expiry. chains = ubiquity.Filter(chains, ubiquity.CompareChainExpiry) // Find the chains with more advanced crypto suite chains = ubiquity.Filter(chains, ubiquity.CompareChainCryptoSuite) return chains }
// Force chains returns the input bundle (plus one verified root CA) as the highest ranked ones if possible. // If there doesn't exist such bundle, fall back to the most ubiquitous bundle. func forceChains(input []*x509.Certificate, chains [][]*x509.Certificate) [][]*x509.Certificate { // Filter out chains that are the same as the input certs. var candidateChains [][]*x509.Certificate for _, chain := range chains { if !diff(chain[:len(chain)-1], input) { candidateChains = append(candidateChains, chain) } } if len(candidateChains) == 0 { candidateChains = chains } // Filter out chains with highest cross platform ubiquity. return ubiquity.Filter(candidateChains, ubiquity.ComparePlatformUbiquity) }
// Ubiquitous chains are the chains with highest platform coverage and break ties with the optimal strategy. func ubiquitousChains(chains [][]*x509.Certificate) [][]*x509.Certificate { // Filter out chains with highest cross platform ubiquity. chains = ubiquity.Filter(chains, ubiquity.ComparePlatformUbiquity) // Prefer that all intermediates are SHA-2 certs if the leaf is a SHA-2 cert, in order to improve ubiquity. chains = ubiquity.Filter(chains, ubiquity.CompareSHA2Homogeneity) // Filter shortest chains chains = ubiquity.Filter(chains, ubiquity.CompareChainLength) // Filter chains with highest signature hash ubiquity. chains = ubiquity.Filter(chains, ubiquity.CompareChainHashUbiquity) // Filter chains with highest keyAlgo ubiquity. chains = ubiquity.Filter(chains, ubiquity.CompareChainKeyAlgoUbiquity) // Filter chains with intermediates that last longer. chains = ubiquity.Filter(chains, ubiquity.CompareExpiryUbiquity) // Use the optimal strategy as final tie breaker. return optimalChains(chains) }