mirror of
https://github.com/slackhq/nebula.git
synced 2026-02-15 17:24:23 +01:00
V2 certificate format (#1216)
Co-authored-by: Nate Brown <nbrown.us@gmail.com> Co-authored-by: Jack Doan <jackdoan@rivian.com> Co-authored-by: brad-defined <77982333+brad-defined@users.noreply.github.com> Co-authored-by: Jack Doan <me@jackdoan.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io"
|
||||
@@ -41,14 +42,14 @@ func verify(args []string, out io.Writer, errOut io.Writer) error {
|
||||
|
||||
rawCACert, err := os.ReadFile(*vf.caPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error while reading ca: %s", err)
|
||||
return fmt.Errorf("error while reading ca: %w", err)
|
||||
}
|
||||
|
||||
caPool := cert.NewCAPool()
|
||||
for {
|
||||
rawCACert, err = caPool.AddCAFromPEM(rawCACert)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error while adding ca cert to pool: %s", err)
|
||||
return fmt.Errorf("error while adding ca cert to pool: %w", err)
|
||||
}
|
||||
|
||||
if rawCACert == nil || len(rawCACert) == 0 || strings.TrimSpace(string(rawCACert)) == "" {
|
||||
@@ -58,20 +59,30 @@ func verify(args []string, out io.Writer, errOut io.Writer) error {
|
||||
|
||||
rawCert, err := os.ReadFile(*vf.certPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to read crt; %s", err)
|
||||
return fmt.Errorf("unable to read crt: %w", err)
|
||||
}
|
||||
var errs []error
|
||||
for {
|
||||
if len(rawCert) == 0 {
|
||||
break
|
||||
}
|
||||
c, extra, err := cert.UnmarshalCertificateFromPEM(rawCert)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error while parsing crt: %w", err)
|
||||
}
|
||||
rawCert = extra
|
||||
_, err = caPool.VerifyCertificate(time.Now(), c)
|
||||
if err != nil {
|
||||
switch {
|
||||
case errors.Is(err, cert.ErrCaNotFound):
|
||||
errs = append(errs, fmt.Errorf("error while verifying certificate v%d %s with issuer %s: %w", c.Version(), c.Name(), c.Issuer(), err))
|
||||
default:
|
||||
errs = append(errs, fmt.Errorf("error while verifying certificate %+v: %w", c, err))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
c, _, err := cert.UnmarshalCertificateFromPEM(rawCert)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error while parsing crt: %s", err)
|
||||
}
|
||||
|
||||
_, err = caPool.VerifyCertificate(time.Now(), c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return errors.Join(errs...)
|
||||
}
|
||||
|
||||
func verifySummary() string {
|
||||
@@ -80,7 +91,7 @@ func verifySummary() string {
|
||||
|
||||
func verifyHelp(out io.Writer) {
|
||||
vf := newVerifyFlags()
|
||||
out.Write([]byte("Usage of " + os.Args[0] + " " + verifySummary() + "\n"))
|
||||
_, _ = out.Write([]byte("Usage of " + os.Args[0] + " " + verifySummary() + "\n"))
|
||||
vf.set.SetOutput(out)
|
||||
vf.set.PrintDefaults()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user