Procházet zdrojové kódy

Fix setter of basic constraints.

Mariano Cano před 6 roky
rodič
revize
0847af16cb
1 změnil soubory, kde provedl 11 přidání a 3 odebrání
  1. 11 3
      x509util/extensions.go

+ 11 - 3
x509util/extensions.go

@@ -293,9 +293,17 @@ type BasicConstraints struct {
 // Set sets the basic constraints to the given certificate.
 // Set sets the basic constraints to the given certificate.
 func (b BasicConstraints) Set(c *x509.Certificate) {
 func (b BasicConstraints) Set(c *x509.Certificate) {
 	c.IsCA = b.IsCA
 	c.IsCA = b.IsCA
-	c.MaxPathLen = b.MaxPathLen
-	if c.MaxPathLen < 0 {
-		c.MaxPathLen = -1
+	if c.IsCA {
+		c.BasicConstraintsValid = true
+		switch {
+		case b.MaxPathLen == 0:
+			c.MaxPathLen = b.MaxPathLen
+			c.MaxPathLenZero = true
+		case b.MaxPathLen < 0:
+			c.MaxPathLen = -1
+		default:
+			c.MaxPathLen = b.MaxPathLen
+		}
 	}
 	}
 }
 }