Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
# starting with go 1.24 the GODEBUG=x509sha1=1 flag has been removed.
# many tests rely on sha1 certificates. After resolving #1413 we can
# run these on stable and oldstable again. Min version (1.20) can
# always be run.
go: ['1.23', '1.22', '1.20']
# Go 1.27 is the module minimum (crypto/mldsa).
go: ['1.27']
services:
# Label used to access the service container
postgres:
Expand Down Expand Up @@ -46,7 +43,6 @@ jobs:

env:
GOFLAGS: "-mod=vendor"
GODEBUG: "x509sha1=1"
BUILD_TAGS: "postgresql"
PGHOST: localhost
MYSQL_HOST: 127.0.0.1
Expand All @@ -68,6 +64,13 @@ jobs:
- run: ./bin/goose -path certdb/mysql up;
- name: Test
run: ./test.sh
- name: Test ML-DSA in FIPS mode
env:
GOFIPS140: latest
GODEBUG: "fips140=on"
run: |
go test ./csr ./signer ./helpers ./helpers/derhelpers ./crl ./bundler -run MLDSA
go test ./initca -run '^(TestInitCA|TestRenewMLDSA)$'
- uses: codecov/codecov-action@v4

golangci:
Expand All @@ -77,12 +80,8 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.20"
go-version: "1.27"
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@v9
with:
# There is a breaking change in 1.58 that causes the linter not to recognize
# internal imports or standard library imports and results in linting errors
# that cannot be ignored.
# e.g certdb/certdb.go:5:2: could not import encoding/json (Config.Importer.Import(encoding/json) returned nil but no error) (typecheck)
version: v1.57
version: v2.13.2
21 changes: 15 additions & 6 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
version: "2"

linters:
disable:
- staticcheck
default: none
enable:
- govet
- gosimple
- ineffassign
- unused
- errcheck
exclusions:
paths:
# Fork of an old crypto/tls; test.sh skips it too.
- scan/crypto
rules:
# The stray comma in the Name.OID struct tag hides its yaml key, so YAML
# libraries use their default key. Fixing it would change YAML behavior.
- path: csr/csr\.go
linters:
- govet
text: structtag
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=${TARGETPLATFORM} golang:1.20
FROM --platform=${TARGETPLATFORM} golang:1.27

ARG TARGETPLATFORM
ARG BUILDPLATFORM
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.20-alpine AS builder
FROM golang:1.27-alpine AS builder

WORKDIR /workdir
COPY . /workdir
Expand Down
24 changes: 8 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

CFSSL is CloudFlare's PKI/TLS swiss army knife. It is both a command line
tool and an HTTP API server for signing, verifying, and bundling TLS
certificates. It requires Go 1.20+ to build.
certificates. It requires Go 1.27+ to build.

Note that certain linux distributions have certain algorithms removed
(RHEL-based distributions in particular), so the golang from the
Expand All @@ -30,7 +30,7 @@ CFSSL consists of:
### Building

Building cfssl requires a
[working Go 1.20+ installation](http://golang.org/doc/install).
[working Go 1.27+ installation](http://golang.org/doc/install).

```
$ git clone git@github.com:cloudflare/cfssl.git
Expand Down Expand Up @@ -61,7 +61,7 @@ You can set the `GOOS` and `GOARCH` environment variables to have Go cross compi

### Installation

Installation requires a [working Go 1.20+ installation](http://golang.org/doc/install).
Installation requires a [working Go 1.27+ installation](http://golang.org/doc/install).
Alternatively, [prebuilt binaries are available](https://github.com/cloudflare/cfssl/releases)

```
Expand Down Expand Up @@ -337,7 +337,7 @@ for configuring and running the CA.
verifying certificates. It can be installed with

```
go get github.com/cloudflare/cfssl/cmd/mkbundle
go install github.com/cloudflare/cfssl/cmd/mkbundle@latest
```

It takes a collection of certificates, checks for CRL revocation (OCSP
Expand Down Expand Up @@ -377,19 +377,11 @@ filenames in the following way:
Instead of saving to a file, you can pass `-stdout` to output the encoded
contents to standard output.

### Static Builds
### Embedded Web Assets

By default, the web assets are accessed from disk, based on their
relative locations. If you wish to distribute a single,
statically-linked, `cfssl` binary, you’ll want to embed these resources
before building. This can by done with the
[go.rice](https://github.com/GeertJohan/go.rice) tool.

```
pushd cli/serve && rice embed-go && popd
```

Then building with `go build` will use the embedded resources.
The web assets served by `cfssl serve` are embedded in the binary with
`go:embed`, so `go build` needs no extra step to produce a single `cfssl`
binary that includes them.

### Additional Documentation

Expand Down
19 changes: 19 additions & 0 deletions bundler/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"crypto/ecdsa"
"crypto/ed25519"
"crypto/mldsa"
"crypto/rsa"
"crypto/x509"
"crypto/x509/pkix"
Expand Down Expand Up @@ -112,6 +113,21 @@ func (b *Bundle) MarshalJSON() ([]byte, error) {
keyType = "DSA"
case x509.Ed25519:
keyType = "Ed25519"
case x509.MLDSA:
if pub, ok := b.Cert.PublicKey.(*mldsa.PublicKey); ok {
switch {
case pub.Parameters() == mldsa.MLDSA44():
keyType = "ML-DSA-44"
case pub.Parameters() == mldsa.MLDSA65():
keyType = "ML-DSA-65"
case pub.Parameters() == mldsa.MLDSA87():
keyType = "ML-DSA-87"
default:
keyType = "ML-DSA"
}
} else {
keyType = "ML-DSA"
}
default:
keyType = "Unknown"
}
Expand All @@ -126,6 +142,9 @@ func (b *Bundle) MarshalJSON() ([]byte, error) {
case ed25519.PrivateKey:
keyBytes, _ = derhelpers.MarshalEd25519PrivateKey(key)
keyString = PemBlockToString(&pem.Block{Type: "Ed25519 PRIVATE KEY", Bytes: keyBytes})
case *mldsa.PrivateKey:
keyBytes, _ = x509.MarshalPKCS8PrivateKey(key)
keyString = PemBlockToString(&pem.Block{Type: "PRIVATE KEY", Bytes: keyBytes})
Comment thread
ang-cloudflare marked this conversation as resolved.
Resolved
case fmt.Stringer:
keyString = key.String()
}
Expand Down
37 changes: 35 additions & 2 deletions bundler/bundler.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"crypto"
"crypto/ecdsa"
"crypto/ed25519"
"crypto/mldsa"
"crypto/rsa"
"crypto/tls"
"crypto/x509"
Expand All @@ -18,6 +19,7 @@ import (
"net/http"
"os"
"path/filepath"
"slices"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -55,6 +57,7 @@ const (
const (
sha2Warning = "The bundle contains certificates signed with advanced hash functions such as SHA2, which are problematic for certain operating systems, e.g. Windows XP SP2."
ecdsaWarning = "The bundle contains ECDSA signatures, which are problematic for certain operating systems, e.g. Windows XP, Android 2.2 and Android 2.3."
mldsaWarning = "The bundle contains ML-DSA keys, which many operating systems and TLS clients do not support yet."
expiringWarningStub = "The bundle is expiring within 30 days."
untrustedWarningStub = "The bundle may not be trusted by the following platform(s):"
ubiquityWarning = "Unable to measure bundle ubiquity: No platform metadata present."
Expand Down Expand Up @@ -603,6 +606,14 @@ func (b *Bundler) Bundle(certs []*x509.Certificate, key crypto.Signer, flavor Bu
if !(bytes.Equal(cert.PublicKey.(ed25519.PublicKey), ed25519PublicKey)) {
return nil, errors.New(errors.PrivateKeyError, errors.KeyMismatch)
}
case cert.PublicKeyAlgorithm == x509.MLDSA:
var mldsaPublicKey *mldsa.PublicKey
if mldsaPublicKey, ok = key.Public().(*mldsa.PublicKey); !ok {
return nil, errors.New(errors.PrivateKeyError, errors.KeyMismatch)
}
if !cert.PublicKey.(*mldsa.PublicKey).Equal(mldsaPublicKey) {
return nil, errors.New(errors.PrivateKeyError, errors.KeyMismatch)
}
default:
return nil, errors.New(errors.PrivateKeyError, errors.NotRSAOrECCOrEd25519)
}
Expand All @@ -611,6 +622,7 @@ func (b *Bundler) Bundle(certs []*x509.Certificate, key crypto.Signer, flavor Bu
case cert.PublicKeyAlgorithm == x509.RSA:
case cert.PublicKeyAlgorithm == x509.ECDSA:
case cert.PublicKeyAlgorithm == x509.Ed25519:
case cert.PublicKeyAlgorithm == x509.MLDSA:
default:
return nil, errors.New(errors.PrivateKeyError, errors.NotRSAOrECCOrEd25519)
}
Expand Down Expand Up @@ -693,10 +705,10 @@ func (b *Bundler) Bundle(certs []*x509.Certificate, key crypto.Signer, flavor Bu
statusCode |= errors.BundleNotUbiquitousBit
messages = append(messages, sha2Warning)
}
// Check if bundle contains ECDSA signatures.
// Check if bundle contains ECDSA or ML-DSA keys.
if ubiquity.ChainKeyAlgoUbiquity(bundle.Chain) <= ubiquity.ECDSA256Ubiquity {
statusCode |= errors.BundleNotUbiquitousBit
messages = append(messages, ecdsaWarning)
messages = append(messages, keyAlgoWarnings(bundle.Chain)...)
}

// when forcing a bundle, bundle ubiquity doesn't matter
Expand Down Expand Up @@ -752,6 +764,27 @@ func addSHA1DeprecationWarnings(statusCode int, messages []string, chain []*x509
return statusCode, append(messages, sha1Messages...)
}

// keyAlgoWarnings names the non-ubiquitous public-key algorithms in chain.
// Chains without an ML-DSA key always get the ECDSA warning, which is also
// what key algorithms that ubiquity cannot score have historically received.
func keyAlgoWarnings(chain []*x509.Certificate) []string {
hasMLDSA := chainHasKeyAlgo(chain, x509.MLDSA)
var warnings []string
if !hasMLDSA || chainHasKeyAlgo(chain, x509.ECDSA) {
warnings = append(warnings, ecdsaWarning)
}
if hasMLDSA {
warnings = append(warnings, mldsaWarning)
}
return warnings
}

func chainHasKeyAlgo(chain []*x509.Certificate, algo x509.PublicKeyAlgorithm) bool {
return slices.ContainsFunc(chain, func(cert *x509.Certificate) bool {
return cert.PublicKeyAlgorithm == algo
})
}

// checkExpiringCerts returns indices of certs that are expiring within 30 days.
func checkExpiringCerts(chain []*x509.Certificate) (expiringIntermediates []int) {
now := time.Now()
Expand Down
34 changes: 34 additions & 0 deletions bundler/bundler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const (
interL1Key = "testdata/inter-L1.key"
interL2SHA2 = "testdata/inter-L2.pem"
interL2Key = "testdata/inter-L2.key"
// EC-ACC root from cloudflare/cfssl_trust, which has a negative serial.
negativeSerialRoot = "testdata/negative-serial-root.pem"
)

// Simply create a bundler
Expand Down Expand Up @@ -61,6 +63,38 @@ func TestNewBundlerMissingIntermediate(t *testing.T) {
errorCheck(t, err)
}

func TestNewBundlerFromPEMAcceptsNegativeSerialRoot(t *testing.T) {
caBundlePEM, err := os.ReadFile(testCaBundle)
if err != nil {
t.Fatal(err)
}
negativeSerialPEM, err := os.ReadFile(negativeSerialRoot)
if err != nil {
t.Fatal(err)
}
intBundlePEM, err := os.ReadFile(testIntCaBundle)
if err != nil {
t.Fatal(err)
}

caBundlePEM = bytes.Join([][]byte{caBundlePEM, negativeSerialPEM}, []byte("\n"))
b, err := NewBundlerFromPEM(caBundlePEM, intBundlePEM)
if err != nil {
t.Fatalf("NewBundlerFromPEM rejected a root bundle containing a negative-serial root: %v", err)
}

root, err := helpers.ParseCertificatePEM(negativeSerialPEM)
if err != nil {
t.Fatal(err)
}
if root.SerialNumber.Sign() >= 0 {
t.Fatalf("%s serial number %s is not negative", negativeSerialRoot, root.SerialNumber)
}
if !b.KnownIssuers[string(root.Signature)] {
t.Fatal("negative-serial root is missing from the bundler's known issuers")
}
}

// JSON object of a bundle
type bundleObject struct {
Bundle string `json:"bundle"`
Expand Down
Loading
Loading