-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix null pointer crash and incorrect error statuses (#526)
The gRPC and legacy servers did not check if the public key was provided before accesses it, causing a null pointer exception if no public key was provided in the request. The errors from the gRPC server to the legacy server were being wrapped, and the original error status was being lost. Signed-off-by: Hayden Blauzvern <[email protected]>
- Loading branch information
1 parent
d834c55
commit 38798fe
Showing
6 changed files
with
139 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,7 +47,9 @@ import ( | |
"github.com/sigstore/fulcio/pkg/generated/protobuf" | ||
"github.com/sigstore/sigstore/pkg/cryptoutils" | ||
"google.golang.org/grpc" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/credentials/insecure" | ||
"google.golang.org/grpc/status" | ||
"google.golang.org/grpc/test/bufconn" | ||
"gopkg.in/square/go-jose.v2" | ||
"gopkg.in/square/go-jose.v2/jwt" | ||
|
@@ -117,6 +119,9 @@ func TestMissingGetTrustBundleFails(t *testing.T) { | |
if err.Error() != expectedNoRootMessage { | ||
t.Errorf("got an unexpected error: %q wanted: %q", err, expectedNoRootMessage) | ||
} | ||
if status.Code(err) != codes.Internal { | ||
t.Fatalf("expected invalid argument, got %v", status.Code(err)) | ||
} | ||
} | ||
|
||
func TestGetTrustBundleSuccess(t *testing.T) { | ||
|
@@ -649,6 +654,66 @@ func TestAPIWithInsecurePublicKey(t *testing.T) { | |
if err == nil || !strings.Contains(err.Error(), "The public key supplied in the request is insecure") { | ||
t.Fatalf("expected insecure public key error, got %v", err) | ||
} | ||
if status.Code(err) != codes.InvalidArgument { | ||
t.Fatalf("expected invalid argument, got %v", status.Code(err)) | ||
} | ||
} | ||
|
||
// Tests API with no public key | ||
func TestAPIWithoutPublicKey(t *testing.T) { | ||
emailSigner, emailIssuer := newOIDCIssuer(t) | ||
|
||
// Create a FulcioConfig that supports these issuers. | ||
cfg, err := config.Read([]byte(fmt.Sprintf(`{ | ||
"OIDCIssuers": { | ||
%q: { | ||
"IssuerURL": %q, | ||
"ClientID": "sigstore", | ||
"Type": "email" | ||
} | ||
} | ||
}`, emailIssuer, emailIssuer))) | ||
if err != nil { | ||
t.Fatalf("config.Read() = %v", err) | ||
} | ||
|
||
emailSubject := "[email protected]" | ||
|
||
// Create an OIDC token using this issuer's signer. | ||
tok, err := jwt.Signed(emailSigner).Claims(jwt.Claims{ | ||
Issuer: emailIssuer, | ||
IssuedAt: jwt.NewNumericDate(time.Now()), | ||
Expiry: jwt.NewNumericDate(time.Now().Add(30 * time.Minute)), | ||
Subject: emailSubject, | ||
Audience: jwt.Audience{"sigstore"}, | ||
}).Claims(customClaims{Email: emailSubject, EmailVerified: true}).CompactSerialize() | ||
if err != nil { | ||
t.Fatalf("CompactSerialize() = %v", err) | ||
} | ||
|
||
ctClient, eca := createCA(cfg, t) | ||
ctx := context.Background() | ||
server, conn := setupGRPCForTest(ctx, t, cfg, ctClient, eca) | ||
defer func() { | ||
server.Stop() | ||
conn.Close() | ||
}() | ||
|
||
client := protobuf.NewCAClient(conn) | ||
|
||
_, err = client.CreateSigningCertificate(ctx, &protobuf.CreateSigningCertificateRequest{ | ||
Credentials: &protobuf.Credentials{ | ||
Credentials: &protobuf.Credentials_OidcIdentityToken{ | ||
OidcIdentityToken: tok, | ||
}, | ||
}, | ||
}) | ||
if err == nil || !strings.Contains(err.Error(), "The public key supplied in the request could not be parsed") { | ||
t.Fatalf("expected parsing public key error, got %v", err) | ||
} | ||
if status.Code(err) != codes.InvalidArgument { | ||
t.Fatalf("expected invalid argument, got %v", status.Code(err)) | ||
} | ||
} | ||
|
||
// Stand up a very simple OIDC endpoint. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.