mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-28 23:39:07 +01:00
[management] optimize posture cache (#8366)
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
package nmdata
|
||||
|
||||
import (
|
||||
"crypto/x509"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/netbirdio/netbird/shared/management/certposture"
|
||||
@@ -9,8 +11,21 @@ import (
|
||||
// CertificateCheck is the slim twin of posture.CertificateCheck.
|
||||
type CertificateCheck struct {
|
||||
CACertificates []string
|
||||
|
||||
rootsOnce sync.Once
|
||||
roots *x509.CertPool
|
||||
rootsErr error
|
||||
}
|
||||
|
||||
func (c *CertificateCheck) check(peer *Peer) (bool, error) {
|
||||
return certposture.AnyChainMatchesCAs(peer.Meta.Certificates, c.CACertificates, time.Now()), nil
|
||||
if len(peer.Meta.Certificates) == 0 {
|
||||
return false, nil
|
||||
}
|
||||
c.rootsOnce.Do(func() {
|
||||
c.roots, c.rootsErr = certposture.ParseCAs(c.CACertificates)
|
||||
})
|
||||
if c.rootsErr != nil {
|
||||
return false, c.rootsErr
|
||||
}
|
||||
return certposture.AnyChainMatchesPool(peer.Meta.Certificates, c.roots, time.Now()), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user