Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add chain in response for all CAs, fix newlines in response #341

Merged
merged 1 commit into from
Jan 22, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ func fakeCTLogServer(t *testing.T) *httptest.Server {
}
var chain certChain
json.Unmarshal(body, &chain)
if len(chain.Chain) != 1 {
t.Fatalf("Did not get expected chain for input, wanted 1 entry, got %d", len(chain.Chain))
if len(chain.Chain) != 2 {
t.Fatalf("Did not get expected chain for input, wanted 2 entries, got %d", len(chain.Chain))
}
// Just make sure we can decode it.
for _, chainEntry := range chain.Chain {
Expand Down
11 changes: 9 additions & 2 deletions pkg/api/ca.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,21 @@ func signingCert(w http.ResponseWriter, req *http.Request) {
handleFulcioAPIError(w, req, http.StatusInternalServerError, err, failedToMarshalCert)
return
}
fmt.Fprintf(&ret, "%s\n", finalPEM)
fmt.Fprintf(&ret, "%s", finalPEM)
if finalPEM[len(finalPEM)-1] != '\n' {
fmt.Fprintf(&ret, "\n")
}

finalChainPEM, err := csc.ChainPEM()
if err != nil {
handleFulcioAPIError(w, req, http.StatusInternalServerError, err, failedToMarshalCert)
return
}
if len(finalChainPEM) > 0 {
fmt.Fprintf(&ret, "%s\n", finalChainPEM)
fmt.Fprintf(&ret, "%s", finalChainPEM)
if finalPEM[len(finalChainPEM)-1] != '\n' {
fmt.Fprintf(&ret, "\n")
}
}

// Set the SCT and Content-Type headers, and then respond with a 201 Created.
Expand Down
2 changes: 1 addition & 1 deletion pkg/ca/fileca/fileca.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (fca *fileCA) CreateCertificate(_ context.Context, subject *challenges.Chal
return nil, err
}

return ca.CreateCSCFromDER(subject, finalCertBytes, nil)
return ca.CreateCSCFromDER(subject, finalCertBytes, fca.certs)
}

func (fca *fileCA) Root(ctx context.Context) ([]byte, error) {
Expand Down
8 changes: 4 additions & 4 deletions pkg/ca/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func CreateCSCFromPEM(subject *challenges.ChallengeResult, cert string, chain []
return c, nil
}

func CreateCSCFromDER(subject *challenges.ChallengeResult, cert, chain []byte) (c *CodeSigningCertificate, err error) {
func CreateCSCFromDER(subject *challenges.ChallengeResult, cert []byte, chain []*x509.Certificate) (c *CodeSigningCertificate, err error) {
c = &CodeSigningCertificate{
Subject: subject,
}
Expand All @@ -76,14 +76,14 @@ func CreateCSCFromDER(subject *challenges.ChallengeResult, cert, chain []byte) (
}

// convert to X509 and store both formats
c.FinalChain, err = x509.ParseCertificates(chain)
c.FinalChain = chain
if err != nil {
return nil, err
}
buf := bytes.Buffer{}
for i, chainCert := range c.FinalChain {
for _, chainCert := range c.FinalChain {
buf.Write(cryptoutils.PEMEncode(cryptoutils.CertificatePEMType, chainCert.Raw))
if i != len(c.FinalChain) {
if chainCert.Raw[len(chainCert.Raw)-1] != '\n' {
buf.WriteRune('\n')
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/ca/x509ca/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (x *X509CA) CreateCertificate(_ context.Context, subject *challenges.Challe
return nil, err
}

return ca.CreateCSCFromDER(subject, finalCertBytes, nil)
return ca.CreateCSCFromDER(subject, finalCertBytes, []*x509.Certificate{x.RootCA})
}

func AdditionalExtensions(subject *challenges.ChallengeResult) []pkix.Extension {
Expand Down