File: root.go

package info (click to toggle)
golang-github-cloudflare-cfssl 1.6.5-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 6,220 kB
  • sloc: asm: 1,936; javascript: 652; makefile: 94; sql: 89; sh: 64; python: 11
file content (47 lines) | stat: -rw-r--r-- 1,058 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2012 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package system

import (
	"crypto/x509"
	"encoding/pem"
	"errors"
)

func appendPEM(roots []*x509.Certificate, pemCerts []byte) ([]*x509.Certificate, bool) {
	var ok bool

	for len(pemCerts) > 0 {
		var block *pem.Block
		block, pemCerts = pem.Decode(pemCerts)
		if block == nil {
			break
		}
		if block.Type != "CERTIFICATE" || len(block.Headers) != 0 {
			continue
		}

		cert, err := x509.ParseCertificate(block.Bytes)
		if err != nil {
			continue
		}

		roots = append(roots, cert)
		ok = true
	}

	return roots, ok
}

// New returns a new certificate pool loaded with the system
// roots. The provided argument is not used; it is included for
// compatibility with other functions.
func New(metadata map[string]string) ([]*x509.Certificate, error) {
	roots := initSystemRoots()
	if len(roots) == 0 {
		return nil, errors.New("transport: unable to find system roots")
	}
	return roots, nil
}