Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion commands/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,24 @@ func (i *InspectCmd) inspectPKToken(pktStr string) {
i.printf("\n--- Signature Information ---\n")
if pkt.Op != nil {
i.printf("Provider Signature (OP) exists\n")
hdrs := pkt.Op.ProtectedHeaders()
if hdrs != nil {
i.printJSONObject(hdrs)
}
}
if pkt.Cic != nil {
i.printf("Client Signature (CIC) exists\n")
hdrs := pkt.Cic.ProtectedHeaders()
if hdrs != nil {
i.printJSONObject(hdrs)
}
}
if pkt.Cos != nil {
i.printf("Cosigner Signature (COS) exists\n")
hdrs := pkt.Cos.ProtectedHeaders()
if hdrs != nil {
i.printJSONObject(hdrs)
}
}

// Print token metadata
Expand All @@ -172,10 +184,14 @@ func (i *InspectCmd) printJSON(data []byte) {
return
}

i.printJSONObject(obj)
}

func (i *InspectCmd) printJSONObject(obj any) {
pretty, err := json.MarshalIndent(obj, "", " ")
if err != nil {
i.printf("Error pretty-printing: %v\n", err)
i.printf("%s\n", string(data))
i.printf("%v\n", obj)
return
}

Expand Down
41 changes: 40 additions & 1 deletion commands/inspect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,46 @@ func TestInspectCmdJson(t *testing.T) {
require.Contains(t, output, ` "two"`)
}

func TestInspectCmd(t *testing.T) {
func TestInspectSSHCert(t *testing.T) {
tests := []struct {
name string
keyType KeyType
}{
{
name: "ECDSA Certificate",
keyType: ECDSA,
},
{
name: "ED25519 Certificate",
keyType: ED25519,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
pkt, signer, _ := Mocks(t, tt.keyType)
principals := []string{"guest", "dev"}

sshCertBytes, signKeyBytes, err := createSSHCert(pkt, signer, principals)
require.NoError(t, err)
require.NotNil(t, sshCertBytes)
require.NotNil(t, signKeyBytes)

buf := new(bytes.Buffer)
inspect := NewInspectCmd(string(sshCertBytes), buf)

err = inspect.Run()
require.NoError(t, err, "Unexpected error")

output := buf.String()
require.Contains(t, output, "--- SSH Certificate Information ---")
require.Contains(t, output, "[guest dev]")
require.Contains(t, output, "Provider Signature (OP) exists\n{\n \"alg\": \"RS256\",\n \"kid\": \"kid-")
require.Contains(t, output, "Client Signature (CIC) exists\n{\n \"alg\": \"")
})
}
}

func TestInspectKey(t *testing.T) {
dummyKey := "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINlDR6KRBqBZ1/UL96ltcZWQC7QTgru/ckbCrA/i3RfI your_email@example.com"

f, err := os.CreateTemp("", "opkssh")
Expand Down
Loading