Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRL validation improvements #482

Conversation

iamnotacake
Copy link
Contributor

@iamnotacake iamnotacake commented Jan 18, 2022

CRL contains revoked certificates as a simple list, which means validating certificates is O(N).
Most certificates will be valid which means validator would have to search through the whole list each time.
This improvement is about making verification O(1) operations thanks to map being used instead of plain array.

Checklist

CRL contains revoked certificates as a simple list, which means
validating certificates is O(N). Most certificates will be valid
which means validator would have to search through the whole list
each time. This improvement is about making verification O(1) operations
thanks to `map` being used instead of plain array.
Continuing development of this improvement.
Failing tests are currently commented.
network/crl.go Outdated Show resolved Hide resolved
network/crl_test.go Outdated Show resolved Hide resolved
network/crl.go Outdated
Fetched time.Time // When this CRL was fetched and cached
CRL pkix.CertificateList
Fetched time.Time // When this CRL was fetched and cached
CRL pkix.CertificateList // Parsed CRL itself
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, why we store it as value and make several copy operations if v.Client.Fetch(url, allowLocal) returns pointer? can we store just pointer and avoid extra copies?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plus, what about to encapsulate all this fields and use CRLCacheItem as interface, and initialize it with constructor?
because previously we initialized with cacheItem := &CRLCacheItem{Fetched: time.Now(), CRL: *crl}
now we prepare map for it, set nil for a field of CRL result and only after that create struct value with:

cacheItem := &CRLCacheItem{
		Fetched:             time.Now(),
		CRL:                 *crl,
		RevokedCertificates: revokedCertificates,
	}

But it's not DefaultCRLVerifier responsibility to know how CacheItem works. It should initialize it with CRL result and CacheItem prepare itself and his map as it wants. And just provide simple API how to create item and how to get info about revoked cert: CacheItem.Get(cert *x509.Certificate)(revokedCert, ok)

And it is encapsulates that it uses SerialNumber of certificate for map, not some hash or any other cert fields.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do it in next CRL-related PR? Gonna mention your comment in the task.

network/crl.go Outdated Show resolved Hide resolved
network/crl.go Outdated
return ErrUnknownCRLExtensionOID
}
log.WithField("oid", extension.Id.String()).Debugln("CRL: Unable to process non-critical extension with unknown Object ID")
revokedCertificate, ok := cacheItem.RevokedCertificates[cert.SerialNumber.Text(16)]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we use same integer in several places, lets use constant for that to avoid remembering in future changes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW, you also proposed using base62 for this to have smaller strings. But seems like .Text() has special implementation for power-of-two bases, which makes me think this should work faster with no division involved. Then I will make the constant and set it to 32. A bit longer that base62, but hashing should be faster.

@iamnotacake iamnotacake marked this pull request as ready for review January 20, 2022 10:43
Copy link
Collaborator

@vixentael vixentael left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 performance ++

@iamnotacake iamnotacake merged commit c633e4b into cossacklabs:master Jan 21, 2022
@iamnotacake iamnotacake deleted the anatolii/T1830-crl-caching-improvements branch January 21, 2022 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants