Skip to content
Closed
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
7 changes: 0 additions & 7 deletions crypto/pem/pem.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ func EncodeX509(cert *x509.Certificate) ([]byte, error) {
}

// EncodeX509Chain will encode a list of *x509.Certificates into a PEM format chain.
// Self-signed certificates are not included as per
// https://datatracker.ietf.org/doc/html/rfc5246#section-7.4.2
// Certificates are output in the order they're given; if the input is not ordered
// as specified in RFC5246 section 7.4.2, the resulting chain might not be valid
// for use in TLS.
Expand All @@ -158,11 +156,6 @@ func EncodeX509Chain(certs []*x509.Certificate) ([]byte, error) {
continue
}

if cert.CheckSignatureFrom(cert) == nil {
// Don't include self-signed certificate
continue
}

err := pem.Encode(certPEM, &pem.Block{Type: "CERTIFICATE", Bytes: cert.Raw})
if err != nil {
return nil, err
Expand Down
18 changes: 18 additions & 0 deletions crypto/pem/pem_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package pem

import (
"testing"

"github.com/stretchr/testify/require"
)

func TestEncodeDecodePEMChain(t *testing.T) {
chain, err := DecodePEMCertificatesChain([]byte(selfSignedRootCert))
require.NoError(t, err)
require.NotEmpty(t, chain)

chainPEM, err := EncodeX509Chain(chain)
require.NoError(t, err)
require.NotEmpty(t, chainPEM)
require.Equal(t, string(selfSignedRootCert), string(chainPEM))
}
29 changes: 29 additions & 0 deletions crypto/pem/testdata_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright 2022 The Dapr Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package pem

const (
// good for 30 years
selfSignedRootCert = `-----BEGIN CERTIFICATE-----
MIIBYjCCAQegAwIBAgIRAKTEJxGnjLLxJHupLBXWs4EwCgYIKoZIzj0EAwIwDzEN
MAsGA1UEAxMEcm9vdDAgFw0yNTA4MjcxMDAzNDFaGA8yMDU1MDgyMDEwMDM0MVow
DzENMAsGA1UEAxMEcm9vdDBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABFK+gysd
ykg3PGGeMxupM+I/14VAQzHyUiBY5gCb/TwLPbsGVmr+IQhcVv9qrEUntBkURtsR
QIvpxgo1vdcDdrKjQjBAMA4GA1UdDwEB/wQEAwICpDAPBgNVHRMBAf8EBTADAQH/
MB0GA1UdDgQWBBR8yVxFTE2lUXehLqNPNPPb7aAxmzAKBggqhkjOPQQDAgNJADBG
AiEAnLIvHFK/8tg1+A5GmqBAga4CsgnBsBlaYE0nWGxhULACIQDNG7+1ibiKui7y
asNeuhl1GHo6ODBdh/8jPYtdwu9+DA==
-----END CERTIFICATE-----
` // #nosec G101
)
Loading