Skip to content

Commit

Permalink
add DNS name validation, remove TODO
Browse files Browse the repository at this point in the history
Signed-off-by: liudui <[email protected]>
  • Loading branch information
xichengliudui committed Aug 13, 2021
1 parent 2558e7d commit 18d8bb1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion proxy-identity/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"errors"
"fmt"
"io/ioutil"
"k8s.io/apimachinery/pkg/util/validation"
"k8s.io/apimachinery/pkg/util/validation/field"
"os"
"path/filepath"
"syscall"
Expand Down Expand Up @@ -124,11 +126,14 @@ func generateAndStoreKey(p string) (key *ecdsa.PrivateKey, err error) {
}

func generateAndStoreCSR(p, id string, key *ecdsa.PrivateKey) ([]byte, error) {
// TODO do proper DNS name validation.
if id == "" {
return nil, errors.New("a non-empty identity is required")
}

if err := validation.IsFullyQualifiedDomainName(field.NewPath(""), id).ToAggregate(); err != nil {
return nil, errors.New("a qualified DNS identity is required")
}

csr := x509.CertificateRequest{
Subject: pkix.Name{CommonName: id},
DNSNames: []string{id},
Expand Down

0 comments on commit 18d8bb1

Please sign in to comment.