Skip to content

Commit

Permalink
Usability features (#20)
Browse files Browse the repository at this point in the history
* Rename TClaim to TrustClaim

The new name is both, consistent with TrustTier, and clearer.

* Add TrustClaim constants

Add constants definitions for the defined claim values across trust
vector claim categories.

* Usability features

Implement a number of changes and additions to aid in usability of this
library. No material changes are being made toe the forts of EAR or
AR4SI as part of this.

- Rename To/FromJSON to Marshal/UnmarshaJSON to be consistent with
  common golang conventions. Rename ToJSONPretty to MarshalJSONIndent
  for the same reason.
- Add AsMap() methods to TrustVector and AttestationResult that converts
  these structs to map[string]interface{}.
- Add UpdateStatusFromTrustVector() to AttestationResult, that brings
  Status into alignment with TrustVector values (unless it was
  explicitly set to a lower trust value).
- Add ToTrustTier and ToTrustClaim to convert arbitrary interfaces to
  corresponding structs.
- Add TrustClaim.GetTier() that returns the tier corresponding to the
  claim value.
- Add NewAttestationResult that returns a fully initialized attestation
  result.
- Switch to using jwt package for signing and verifying.

* Lower coverage requirements to 80%

Previous commit introduces an number of type switches with multitudes of
identical cases for all the different integer types. This technically lowers
statement coverage of the tests without materially affecting logical
coverage of the code.

Signed-off-by: setrofim <[email protected]>
  • Loading branch information
setrofim authored Nov 22, 2022
1 parent 1c8da35 commit b4b5ec6
Show file tree
Hide file tree
Showing 17 changed files with 1,221 additions and 224 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-go-cover.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# 1. Change workflow name from "cover 100%" to "cover ≥92.5%". Script will automatically use 92.5%.
# 2. Update README.md to use the new path to badge.svg because the path includes the workflow name.

name: cover ≥90.0%
name: cover ≥80.0%
on: [push, pull_request]
jobs:
cover:
Expand Down
2 changes: 1 addition & 1 deletion arc/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ the key in the default key file "skey.json", and save the result to "my-ear.jwt"
return fmt.Errorf("loading EAR claims-set from %q: %w", createClaims, err)
}

if err = ar.FromJSON(claimsSet); err != nil {
if err = ar.UnmarshalJSON(claimsSet); err != nil {
return fmt.Errorf("decoding EAR claims-set from %q: %w", createClaims, err)
}

Expand Down
10 changes: 5 additions & 5 deletions arc/cmd/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ func Test_CreateCmd_skey_not_ok_for_signing(t *testing.T) {
}
cmd.SetArgs(args)

expectedErr := `signing EAR: failed to generate signature for signer #0 (alg=ES256): failed to sign payload: failed to retrieve ecdsa.PrivateKey out of *jwk.ecdsaPublicKey: failed to produce ecdsa.PrivateKey from *jwk.ecdsaPublicKey: argument to AssignIfCompatible() must be compatible with *ecdsa.PublicKey (was *ecdsa.PrivateKey)`
expectedErr := `failed to generate signature for signer #0 (alg=ES256): failed to sign payload: failed to retrieve ecdsa.PrivateKey out of *jwk.ecdsaPublicKey: failed to produce ecdsa.PrivateKey from *jwk.ecdsaPublicKey: argument to AssignIfCompatible() must be compatible with *ecdsa.PublicKey (was *ecdsa.PrivateKey)`

err := cmd.Execute()
assert.EqualError(t, err, expectedErr)
assert.ErrorContains(t, err, expectedErr)
}

func Test_CreateCmd_input_file_not_found(t *testing.T) {
Expand Down Expand Up @@ -131,7 +131,7 @@ func Test_CreateCmd_input_file_bad_format(t *testing.T) {
}
cmd.SetArgs(args)

expectedErr := `decoding EAR claims-set from "ear-claims.json": missing mandatory 'eat_profile', 'status', 'iat'`
expectedErr := `decoding EAR claims-set from "ear-claims.json": missing mandatory 'ear.status', 'eat_profile', 'iat'`

err := cmd.Execute()
assert.EqualError(t, err, expectedErr)
Expand All @@ -154,10 +154,10 @@ func Test_CreateCmd_unknown_signing_alg(t *testing.T) {
}
cmd.SetArgs(args)

expectedErr := `signing EAR: jws.Sign: expected algorithm to be of type jwa.SignatureAlgorithm but got ("XYZ", jwa.InvalidKeyAlgorithm)`
expectedErr := `expected algorithm to be of type jwa.SignatureAlgorithm but got ("XYZ", jwa.InvalidKeyAlgorithm)`

err := cmd.Execute()
assert.EqualError(t, err, expectedErr)
assert.ErrorContains(t, err, expectedErr)
}

func Test_CreateCmd_ok(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion arc/cmd/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ embedded EAR claims-set and present a report of the trustworthiness vector.
fmt.Printf(">> %q signature successfully verified using %q\n", verifyInput, verifyPKey)

fmt.Println("[claims-set]")
if claimsSet, err = ar.ToJSONPretty(); err != nil {
if claimsSet, err = ar.MarshalJSONIndent("", " "); err != nil {
return fmt.Errorf("unable to re-serialize the EAR claims-set: %w", err)
}
fmt.Println(string(claimsSet))
Expand Down
8 changes: 4 additions & 4 deletions doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Package ear implements an EAT attestation result format based on the
information model defined in
https://datatracker.ietf.org/doc/draft-ietf-rats-ar4si/
Construction
# Construction
An AttestationResult object is constructed by populating the relevant fields.
The mandatory attributes are: status, timestamp and profile.
Expand Down Expand Up @@ -40,7 +40,7 @@ and their meaning.)
ar.TrustVector := &tv
Signing and Serializing
# Signing and Serializing
Once the AttestationResult is populated, it can be signed (i.e., wrapped in a
JWT) by invoking the Sign method:
Expand All @@ -61,7 +61,7 @@ In this case, the returned buf contains a signed ES256 JWT with the JSON
serialization of the AttestationResult object as its payload. This is the usual
JWT format that can be used as-is for interchange with other applications.
Parsing and Verifying
# Parsing and Verifying
On the consumer end of the protocol, when the EAT containing the attestation
result is received from a veraison verifier, the relying party needs to first
Expand Down Expand Up @@ -91,7 +91,7 @@ entity.
// handle troubles with appraisal
}
Pretty printing
# Pretty printing
The package provides a Report method that allows pretty printing of the
Trustworthiness Vector. The caller can request a short summary or a detailed
Expand Down
Loading

0 comments on commit b4b5ec6

Please sign in to comment.