Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Add an endorser command line tool #240

Merged
merged 6 commits into from
Jul 21, 2023
Merged

Conversation

rbehjati
Copy link
Contributor

@rbehjati rbehjati commented Jul 20, 2023

Have tested with the following commands:

Provenance-less endorsement:

go run cmd/endorser/main.go \
 --binary_digest=sha256:1234 \
 --binary_name=binary \
 --verification_options=testdata/skip_verification.textproto

Resulting endorsement:

{
    "_type": "https://in-toto.io/Statement/v0.1",
    "predicateType": "https://github.com/project-oak/transparent-release/claim/v1",
    "subject": [
        {
            "name": "binary",
            "digest": {
                "sha256": "1234"
            }
        }
    ],
    "predicate": {
        "claimType": "https://github.com/project-oak/transparent-release/endorsement/v2",
        "issuedOn": "2023-07-20T19:38:48.780747796+01:00",
        "validity": {
            "notBefore": "2023-07-21T00:00:00Z",
            "notAfter": "2023-10-18T00:00:00Z"
        }
    }
}

Normal endorsement with linked provenance:

go run cmd/endorser/main.go \
 --binary_digest=sha256:39051983bbb600bbfb91bd22ee4c976420f8f0c6a895fd083dcb0d153ddd5fd6 \
 --binary_name=oak_echo_raw_enclave_app \
 --provenance_uris=https://ent-server-62sa4xcfia-ew.a.run.app/raw/sha256:b28696a8341443e3ba433373c60fe1eba8d96f28c8aff6c5ee03d752dd3b399b \
 --verification_options=testdata/skip_verification.textproto

Resulting endorsement:

{
    "_type": "https://in-toto.io/Statement/v0.1",
    "predicateType": "https://github.com/project-oak/transparent-release/claim/v1",
    "subject": [
        {
            "name": "oak_echo_raw_enclave_app",
            "digest": {
                "sha256": "39051983bbb600bbfb91bd22ee4c976420f8f0c6a895fd083dcb0d153ddd5fd6"
            }
        }
    ],
    "predicate": {
        "claimType": "https://github.com/project-oak/transparent-release/endorsement/v2",
        "issuedOn": "2023-07-20T19:33:34.793557441+01:00",
        "validity": {
            "notBefore": "2023-07-21T00:00:00Z",
            "notAfter": "2023-10-18T00:00:00Z"
        },
        "evidence": [
            {
                "role": "Provenance",
                "uri": "https://ent-server-62sa4xcfia-ew.a.run.app/raw/sha256:b28696a8341443e3ba433373c60fe1eba8d96f28c8aff6c5ee03d752dd3b399b",
                "digest": {
                    "sha256": "b28696a8341443e3ba433373c60fe1eba8d96f28c8aff6c5ee03d752dd3b399b"
                }
            }
        ]
    }
}

@rbehjati rbehjati requested a review from tiziano88 July 20, 2023 18:52
generates an endorsement statement, with the given provenances listed in the endorsement statement's
evidence field.

Example execution with not provenances:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Example execution with not provenances:
Example execution without provenances:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed :)

)

// layout represents the expected date format.
const layout = "20060102"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What format is this? Why not use ISO 8601? If it cannot be changed, could you add a comment here explaining why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is ISO 8601. Both YYYY-MM-DD and YYYYMMDD are allowed (wikipedia). But, changed it to YYYY-MM-DD.

Comment on lines 58 to 66
binaryDigest := flag.String("binary_digest", "", "Digest of the binary to endorse, of the form alg:value. Accepted values for alg include sha256, and sha2-256")
binaryName := flag.String("binary_name", "", "Name of the binary to endorse. Should match the name in provenances, if provenance URIs are provided.")
verificationOptions := flag.String("verification_options", "", "Output path to a textproto file containing verification options.")
endorsementPath := flag.String("endorsement_path", "endorsement.json", "Output path to store the generated endorsement statement in.")
notBefore := flag.String("not_before", defaultNotBefore,
"Optional - The date from which the endorsement is effective. The expected date format is YYYYMMDD. Defaults to 1 day after the issuance date.")
notAfter := flag.String("not_after", defaultNotAfter,
"Required - The expiry date of the endorsement. The expected date format is YYYYMMDD. Defaults to 90 day after the issuance date.")
flag.Var(&provenanceURIs, "provenance_uris", "URIs of the provenances.")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think flags are normally in the top level scope, unless they need to be dynamically generated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

binaryName := flag.String("binary_name", "", "Name of the binary to endorse. Should match the name in provenances, if provenance URIs are provided.")
verificationOptions := flag.String("verification_options", "", "Output path to a textproto file containing verification options.")
endorsementPath := flag.String("endorsement_path", "endorsement.json", "Output path to store the generated endorsement statement in.")
notBefore := flag.String("not_before", defaultNotBefore,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Setting the default to a dynamic value seems confusing; if someone runs the --help command, they will see the default change all the time I think? It seems more appropriate to leave that empty, and if so rely on some logic to deal with the default

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Removed the defaults from the flag, but these defaults are used if no value is specified.


bytes, err := json.MarshalIndent(endorsement, "", " ")
if err != nil {
log.Fatalf("could not marshal the fuzzing claim: %v", err)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which fuzzing claim?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. sloppy copy-paste. Fixed.

}

func main() {
// Current time in UTC time zone since it is used by OSS-Fuzz.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the connection with OSS-Fuzz?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! Copy-paste! Fixed.

Copy link
Contributor Author

@rbehjati rbehjati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review.

generates an endorsement statement, with the given provenances listed in the endorsement statement's
evidence field.

Example execution with not provenances:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed :)

)

// layout represents the expected date format.
const layout = "20060102"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is ISO 8601. Both YYYY-MM-DD and YYYYMMDD are allowed (wikipedia). But, changed it to YYYY-MM-DD.

}

func main() {
// Current time in UTC time zone since it is used by OSS-Fuzz.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! Copy-paste! Fixed.

binaryName := flag.String("binary_name", "", "Name of the binary to endorse. Should match the name in provenances, if provenance URIs are provided.")
verificationOptions := flag.String("verification_options", "", "Output path to a textproto file containing verification options.")
endorsementPath := flag.String("endorsement_path", "endorsement.json", "Output path to store the generated endorsement statement in.")
notBefore := flag.String("not_before", defaultNotBefore,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Removed the defaults from the flag, but these defaults are used if no value is specified.

Comment on lines 58 to 66
binaryDigest := flag.String("binary_digest", "", "Digest of the binary to endorse, of the form alg:value. Accepted values for alg include sha256, and sha2-256")
binaryName := flag.String("binary_name", "", "Name of the binary to endorse. Should match the name in provenances, if provenance URIs are provided.")
verificationOptions := flag.String("verification_options", "", "Output path to a textproto file containing verification options.")
endorsementPath := flag.String("endorsement_path", "endorsement.json", "Output path to store the generated endorsement statement in.")
notBefore := flag.String("not_before", defaultNotBefore,
"Optional - The date from which the endorsement is effective. The expected date format is YYYYMMDD. Defaults to 1 day after the issuance date.")
notAfter := flag.String("not_after", defaultNotAfter,
"Required - The expiry date of the endorsement. The expected date format is YYYYMMDD. Defaults to 90 day after the issuance date.")
flag.Var(&provenanceURIs, "provenance_uris", "URIs of the provenances.")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


bytes, err := json.MarshalIndent(endorsement, "", " ")
if err != nil {
log.Fatalf("could not marshal the fuzzing claim: %v", err)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. sloppy copy-paste. Fixed.

@rbehjati rbehjati force-pushed the cmd-endorser branch 3 times, most recently from 83bf39e to a81d632 Compare July 21, 2023 14:04
@rbehjati rbehjati merged commit 9fb29cf into project-oak:main Jul 21, 2023
8 checks passed
@rbehjati rbehjati deleted the cmd-endorser branch July 21, 2023 14:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants