lab7: исправления по независимому ревью

This commit is contained in:
Vladislav Kunetskiy
2026-11-10 14:22:47 +03:00
parent d1dc6d6b78
commit 30b6672058
18 changed files with 20572 additions and 20366 deletions
+42 -8
View File
@@ -274,6 +274,24 @@ func (l *Loader) verifyOwnChain(cert *tls.Certificate) ([][]*x509.Certificate, e
return chains, nil
}
func (l *Loader) mountedRoots(files Files) (map[string]struct{}, error) {
trust, err := secretfile.Read(files.CA)
if err != nil {
return nil, fmt.Errorf("read tls trust: %w", err)
}
issuers, err := parseCertificates(trust)
if err != nil {
return nil, err
}
current := map[string]struct{}{}
for _, cert := range issuers {
if bytes.Equal(cert.RawIssuer, cert.RawSubject) {
current[string(cert.Raw)] = struct{}{}
}
}
return current, nil
}
func (l *Loader) checkTrust(files Files) error {
trust, err := secretfile.Read(files.CA)
if err != nil {
@@ -282,16 +300,10 @@ func (l *Loader) checkTrust(files Files) error {
if bytes.Equal(trust, l.trust) {
return nil
}
issuers, err := parseCertificates(trust)
current, err := l.mountedRoots(files)
if err != nil {
return err
}
current := map[string]struct{}{}
for _, cert := range issuers {
if bytes.Equal(cert.RawIssuer, cert.RawSubject) {
current[string(cert.Raw)] = struct{}{}
}
}
// Adding roots (prepare overlap) is safe before a restart; removing a
// startup root requires a restart and fails closed.
for raw := range l.trustRoots {
@@ -302,8 +314,30 @@ func (l *Loader) checkTrust(files Files) error {
return nil
}
// VerifyTrustExact closes readiness unless the mounted roots equal the startup
// roots. A superset is safe for handshakes but not for the frozen TLS pools.
func (l *Loader) VerifyTrustExact() error {
files, err := l.files.snapshot()
if err != nil {
return err
}
current, err := l.mountedRoots(files)
if err != nil {
return err
}
if len(current) != len(l.trustRoots) {
return errors.New("tls trust differs from startup; restart required")
}
for raw := range l.trustRoots {
if _, ok := current[raw]; !ok {
return errors.New("tls trust differs from startup; restart required")
}
}
return nil
}
// VerifyTrust reports whether the mounted trust bundle still contains every
// root loaded at startup. Readiness uses it to retire un-restarted replicas.
// root loaded at startup. Kept for handshake-level subset checks.
func (l *Loader) VerifyTrust() error {
return l.verifyTrust()
}