mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-26 04:58:10 +02:00
fix pem normalization when file has no trailing newline (#5645)
This commit is contained in:
parent
9631d9ff1c
commit
4988aea751
2 changed files with 11 additions and 0 deletions
|
@ -14,6 +14,11 @@ import (
|
||||||
// If the PEM data contains multiple certificates, signing certificates
|
// If the PEM data contains multiple certificates, signing certificates
|
||||||
// will be moved after the things they sign.
|
// will be moved after the things they sign.
|
||||||
func NormalizePEM(data []byte) []byte {
|
func NormalizePEM(data []byte) []byte {
|
||||||
|
// make sure the file has a trailing newline
|
||||||
|
if len(data) > 0 && !bytes.HasSuffix(data, []byte{'\n'}) {
|
||||||
|
data = append(data, '\n')
|
||||||
|
}
|
||||||
|
|
||||||
type Segment struct {
|
type Segment struct {
|
||||||
ID int
|
ID int
|
||||||
Data []byte
|
Data []byte
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package cryptutil_test
|
package cryptutil_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"slices"
|
"slices"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
@ -23,6 +24,11 @@ func TestNormalizePEM(t *testing.T) {
|
||||||
input: slices.Concat(rootCA.PublicPEM, intermediateCA.PublicPEM, cert.PublicPEM, cert.PrivateKeyPEM),
|
input: slices.Concat(rootCA.PublicPEM, intermediateCA.PublicPEM, cert.PublicPEM, cert.PrivateKeyPEM),
|
||||||
expect: slices.Concat(cert.PublicPEM, cert.PrivateKeyPEM, intermediateCA.PublicPEM, rootCA.PublicPEM),
|
expect: slices.Concat(cert.PublicPEM, cert.PrivateKeyPEM, intermediateCA.PublicPEM, rootCA.PublicPEM),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
// make sure we handle a file without a trailing newline
|
||||||
|
input: slices.Concat(intermediateCA.PublicPEM, bytes.TrimRight(cert.PublicPEM, "\n")),
|
||||||
|
expect: slices.Concat(cert.PublicPEM, intermediateCA.PublicPEM),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
input: slices.Concat(cert.PublicPEM, cert.PrivateKeyPEM, intermediateCA.PublicPEM, rootCA.PublicPEM),
|
input: slices.Concat(cert.PublicPEM, cert.PrivateKeyPEM, intermediateCA.PublicPEM, rootCA.PublicPEM),
|
||||||
expect: slices.Concat(cert.PublicPEM, cert.PrivateKeyPEM, intermediateCA.PublicPEM, rootCA.PublicPEM),
|
expect: slices.Concat(cert.PublicPEM, cert.PrivateKeyPEM, intermediateCA.PublicPEM, rootCA.PublicPEM),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue