Commit graph

53 commits

Author SHA1 Message Date
Aditya Sirish A Yelgundhalli
a3fedc1524
sigstore: Add support for private sigstore instances
Signed-off-by: Aditya Sirish A Yelgundhalli <ayelgundhall@bloomberg.net>
2024-10-16 15:14:38 -04:00
Aditya Sirish A Yelgundhalli
2f0be5c46f
*: Refactor TUF
This is a massive commit that isn't easy to split up, my apologies to
reviewers. Here's everything that's happening.

First, the base tuf package now includes interfaces for RootMetadata,
TargetsMetadata, Rule, and Principal. The first two are self-explanatory. Rule
represents some protection rule, currently matched by the Delegation schema,
while Principal defines a new take on who a trusted party is. Existing schemas
have been moved into a v01 subpackage. v01 also includes a Key type based on
signerverifier.SSLibKey which implements the Principal interface. This means
that expectations elsewhere (such as in repository and policy) re a principal
can be met by existing policy metadata.

Second, with most of the policy metadata manipulations having moved to the tuf
package, this commit drops them from the policy package as they were thin
wrappers. While we originally kept them around for the purposes of migrating
versions when a repository must move from the old metadata schema to a newer
one, it doesn't make sense to implement this in every individual manipulation
function.

Finally, the rest of the packages that handle keys (for adding to metadata or
for signing / verifying) have been updated to use either
signerverifier.SSLibKey directly or the new Principal interface, depending on
what the purpose is. For now, the idea is to continue using the
signerverifier.SSLibKey representation of a key itself for the signature
verification flows, though we may eventually move that into gittuf rather than
rely on go-securesystemslib. Note that some of the transitions have been
included in this commit for compatibility reasons, and subsequent PRs will
update that. For example, the GitHub app pull request approval attestation must
be updated to not use tufv01.Key objects to represent approvers.

Signed-off-by: Aditya Sirish A Yelgundhalli <ayelgundhall@bloomberg.net>
2024-10-15 12:58:44 -04:00
Aditya Sirish A Yelgundhalli
8a43f4fffd
*: Remove vendored signerverifier library
Signed-off-by: Aditya Sirish A Yelgundhalli <ayelgundhall@bloomberg.net>
2024-10-10 13:30:32 -04:00
Aditya Sirish A Yelgundhalli
6a1acb0ac4
*: Allow use of Sigstore for root metadata
Signed-off-by: Aditya Sirish A Yelgundhalli <ayelgundhall@bloomberg.net>
2024-10-10 13:25:30 -04:00
Aditya Sirish A Yelgundhalli
f1473c53e5
*: Add sigstore signer for metadata
Signed-off-by: Aditya Sirish A Yelgundhalli <ayelgundhall@bloomberg.net>
2024-10-09 16:13:01 -04:00
Aditya Sirish A Yelgundhalli
f7dd00b7bd
*: Remove use of signerverifier dispatcher
Signed-off-by: Aditya Sirish A Yelgundhalli <ayelgundhall@bloomberg.net>
2024-10-09 12:59:32 -04:00
Aditya Sirish A Yelgundhalli
a5a9ff1e7d
*: Move policy metadata manipulations to tuf package
Signed-off-by: Aditya Sirish A Yelgundhalli <ayelgundhall@bloomberg.net>
2024-10-09 12:59:32 -04:00
Aditya Sirish A Yelgundhalli
9ed0c936d4
*: Use signerverifier/ssh for git signing / verifying
Signed-off-by: Aditya Sirish A Yelgundhalli <ayelgundhall@bloomberg.net>
2024-10-09 11:08:45 -04:00
Aditya Sirish A Yelgundhalli
634b1cd98e
*: Remove legacy key types
This commit drops support for the legacy / custom securesystemslib key format.
This format was used in two forms:
a) In tests
b) On disk in the policy state for the root keys

To address the removal, tests have been updated to use SSH keys (via the
ssh-keygen signer). This makes up the majority of the diff for this commit, and
includes some additions to the ssh package to more easily load test artifacts.

Additionally, we don't need to store a policy state's root keys on disk for
that ref. This was an error in our initial design, and it actually leads to
complications in ensuring that the policy state's on disk keys match the keys
listed in the state's root metadata. This commit updates it so only the root
metadata's record of the root keys are used, with the keys directory omitted
for future policy states. However, we maintain backwards compatibility for
policy states that include the keys on disk, we just ignore them.

Signed-off-by: Aditya Sirish A Yelgundhalli <ayelgundhall@bloomberg.net>
2024-10-04 14:58:50 -04:00
Pat Zielinski
d571facb8d *: Add copyright notice to code files
Signed-off-by: Pat Zielinski <70954403+patzielinski@users.noreply.github.com>
2024-09-27 15:28:12 -04:00
Aditya Sirish A Yelgundhalli
6093b595d2
third_party: Vendor go-securesystemslib/dsse
This vendors go-securesystemslib's dsse package in preparation for
adding support for DSSE signature extensions.

Signed-off-by: Aditya Sirish A Yelgundhalli <ayelgundhall@bloomberg.net>
2024-09-26 14:29:00 -04:00
Aditya Sirish A Yelgundhalli
d8f72d9fef
*: Add support for GitHub pull request approval attestation
Signed-off-by: Aditya Sirish A Yelgundhalli <ayelgundhall@bloomberg.net>
2024-08-14 11:16:28 -04:00
Aditya Sirish A Yelgundhalli
576ba3bc0e *: Adds SSH support to verification APIs
Signed-off-by: Aditya Sirish A Yelgundhalli <ayelgundhall@bloomberg.net>
2024-06-18 12:14:49 -04:00
Aditya Sirish A Yelgundhalli
cb50e982ed ssh: Fit SignerVerifier interface
Signed-off-by: Aditya Sirish A Yelgundhalli <ayelgundhall@bloomberg.net>
2024-06-17 10:06:08 -04:00
Lukas Puehringer
03f4398733 Re-design ssh Key as Verifier only
Previously, ssh Key satisfied both the dsse.Verifier interface and
served as TUF metadata key container. Unfortunately, it didn't seem
feasible to wire up the key container with the current TUF metadata
implementation, which uses SSlibKey.

This commit re-designs the ssh key implementation to use SSlibKey as key
container and a separate Verifier for verification.

See https://github.com/gittuf/gittuf/pull/429#issuecomment-2151588628
for more detailed design considerations.

Change details:

* Replace ssh Key with ssh Verifier, which satisfies the dsse.Verifier
  interface, but is otherwise a black box (no key details exposed).
* Change NewKeyFromFile to return an SSlibKey, to be included in TUF
  metadata.
* Add NewVerifierFromKey function to create an ssh Verifier from a
  corresponding SSlibKey, e.g. included in TUF metadata, to verify
  a signature from an ssh Signer.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-06-06 12:42:04 +02:00
Lukas Puehringer
e3331743da Rename Import to NewKeyFromFile
This seems to a convention in gittuf and go generally.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-06-06 12:23:26 +02:00
Lukas Puehringer
bda7be008e Add SSHKeyType constant
May be used to choose the appropriate ssh verifier function for an sslib
key.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-06-06 12:22:14 +02:00
Aditya Sirish
4824c30df3
Merge pull request #414 from lukpueh/sign-with-ssh-keygen 2024-06-03 06:17:01 -04:00
Lukas Puehringer
a7aca9781c Setup key pairs for ssh tests
Depending on the version, ssh-keygen might require both public and
private key file, for (passwordless) export (-e) and sign (-Y sign)
operations.

The function to load a public key from the unencrypted header of a private key
was only added recently, see
2b13d3934d

This commit makes sure that ssh tests always have access to public and
private key under the expected names: `<private>` and `<private>`.pub

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-05-31 12:24:42 +02:00
Lukas Puehringer
303bf06fa8 Use TrimSpace instead of Trim(space)
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-05-29 18:06:05 +02:00
Lukas Puehringer
05ff7c2df2 Change SSH signature namespace to "git"
This is what git also uses. See
https://github.com/gittuf/gittuf/pull/414#discussion_r1618687916

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-05-29 18:06:00 +02:00
Lukas Puehringer
8a2e5e9efe Add spdx header to test file
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-05-29 18:06:00 +02:00
Lukas Puehringer
15d79dd6dc Use context Background instead of TODO in ssh test
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-05-29 18:06:00 +02:00
Lukas Puehringer
b09802a314 Create ssh test data for a loop only once
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-05-29 18:06:00 +02:00
Lukas Puehringer
ad47487011 Remove testutils and setup ssh tests inline
Follow Aditya's suggestion to "embed" all needed testfiles (ssh keys and
askpass script) as bytes and write them to a tmp dir where needed:
https://github.com/gittuf/gittuf/pull/414#discussion_r1618647676

Removes previously added testutils.go

**Interesting discovery**
In order to sign with an "rsa" key, ssh-keygen seems to expect an
"rsa.pub" in the same directory. This is not the case for encrypted rsa,
no for plaintext or encrypted ecdsa or ed25519.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-05-29 18:05:52 +02:00
Lukas Puehringer
aa4aa7c0aa Use go doc style in docstrings in ssh.go
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-05-29 15:51:29 +02:00
Lukas Pühringer
4cc4961c81 Rename loadSigner to loadSSHSigner in dsse_test
Co-authored-by: Aditya Sirish <8928778+adityasaky@users.noreply.github.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-05-29 15:46:38 +02:00
Lukas Puehringer
03056641fa Skip encrypted key test on Windows
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-05-28 17:15:35 +02:00
Lukas Puehringer
41927e3422 Make parseSSH2Key work on Windows
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-05-28 17:10:36 +02:00
Lukas Puehringer
e68209f782 Improve error message in parseSSH2Key
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-05-28 12:12:18 +02:00
Lukas Puehringer
526cc28306 test: fix misc lint
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-05-28 11:49:48 +02:00
Lukas Puehringer
cef189d902 test: define test script constant in testutils
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-05-28 11:18:47 +02:00
Lukas Puehringer
48200326de test: add ssh key fixture
Create "testutils" file in "common" package with test setup helper for
ssh keys and file copy helper.

- The ssh keys test setup function creates a test temp dir (for the
  duration of the passed test), copies ssh keys from testdata and sets a
  restrictive permission, as required by ssh-keygen.

- Kudos to @ivanayov, whose "copy" implementation in go-tuf I copied

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-05-28 11:18:32 +02:00
Lukas Puehringer
d4b5116d52 Add new ssh package based on ssh-keygen
* A Key struct, similar to tuf.Key, to be included in TUF metadata (not
  yet implemented), which implements the DSSE Verifier interface, to
  verify signatures created with Signer.

* A Signer struct, which implements the DSSE Signer interface, to create
  signatures using `ssh-keygen` and a path to a key.

* An Import function, to import a Key using `ssh-keygen` and a path to a
  key.

For signing and Key import paths to either public or private, plaintext
or encrypted, rsa, ecdsa or ed25519 keys are supported (akin to git's
user.signingKey configuration).

Also adds basic smoke tests for the `ssh` package, and replaces updates
dsse tests to use this module.

Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2024-05-27 17:02:39 +02:00
Aditya Sirish
14b052f3f8 *: Remove TUF fields that don't apply to gittuf
The original root and targets metadata schemas were taken directly from
the TUF specification. As such, they include fields that we don't use in
gittuf.

Removed Fields:

1. SpecVersion: this field identifies the version of the TUF
   specification the metadata conforms to. We don't conform to the TUF
   specification.

2. ConsistentSnapshot: this boolean field indicates if the repository
   uses consistent snapshots as defined in the TUF specification. We
   don't use this (and in fact we don't use snapshot metadata at all as
   the RSL effectively serves the snapshot role).

3. Version: this field is an incrementing integer that identifies the
   version of the metadata for the specific role. In TUF, this is used
   to ensure we have a consistent set of metadata via the snapshot role.
   As before, the RSL gives us this property naturally.

Note that we still don't use the Expires field in gittuf verification.
We need to explore what it means for policy metadata to expire in a Git
repository and whether the expiry check (for the latest policy metadata)
applies the same way it does in TUF.

Signed-off-by: Aditya Sirish <aditya@saky.in>
2024-05-26 13:33:21 +05:30
Aditya Sirish
03159de27f
*: Centralize test artifacts
Signed-off-by: Aditya Sirish <aditya@saky.in>
2024-01-15 00:23:47 -05:00
Aditya Sirish
33af1b8887
signerverifier: Support legacy private key format
Signed-off-by: Aditya Sirish <aditya@saky.in>
2024-01-15 00:23:47 -05:00
Aditya Sirish
3397ac9bad
*: Vendor go-sslib with new signerverifier flows
Signed-off-by: Aditya Sirish <aditya@saky.in>
2024-01-15 00:22:53 -05:00
Aditya Sirish
a575ae7708
dsse: Check if signature from key ID exists
Signed-off-by: Aditya Sirish <aditya@saky.in>
2024-01-03 11:11:03 -05:00
Aditya Sirish
a540ccc7f4
*: Switch to tagged go-sslib
Also updates sigstore/sigstore thaqt incorporates the change in
go-sslib.

Signed-off-by: Aditya Sirish <aditya@saky.in>
2023-12-21 09:50:39 -05:00
Aditya Sirish
52100193d8
Merge pull request #119 from gittuf/fix-nil-delegations
Fix nil delegations
2023-10-12 10:55:29 -04:00
Pat Zielinski
d0905e7816 Add SPDX License Identifiers to code files
Signed-off-by: Pat Zielinski <70954403+patzielinski@users.noreply.github.com>
2023-10-09 08:09:34 -04:00
Aditya Sirish
0ac8c139e6
repository: Update import alias for sslib DSSE
Signed-off-by: Aditya Sirish <aditya@saky.in>
2023-09-15 15:01:47 -04:00
Aditya Sirish
f7eb00a6d6
*: Clean up GPG key load from bytes
Signed-off-by: Aditya Sirish <aditya@saky.in>
2023-09-13 11:26:19 -04:00
Josh Soref
18f035ce74 spelling: into
Signed-off-by: Josh Soref <2119212+jsoref@users.noreply.github.com>
2023-09-01 16:09:30 -04:00
Aditya Sirish
3192cdb861
Rename module to use gittuf org
Signed-off-by: Aditya Sirish <aditya@saky.in>
2023-08-30 13:13:54 -04:00
Aditya Sirish
0d4be41b91
Early gitsign support
This commit introduces early, experimental support for gitsign
signatures on git commits. It uses TAP-18 to specify sigstore identity
constraints in delegations.

The feature introduced here depends on unreleased prototype code in
go-securesystemslib and is also insufficiently tested due to some
sigstore library constraints.

See: #73

Signed-off-by: Aditya Sirish <aditya@saky.in>
2023-08-07 15:27:37 -04:00
Aditya Sirish
24244629a7
gitinterface, sv: Add support for GPG signing
Signed-off-by: Aditya Sirish <aditya@saky.in>
2023-06-20 15:48:00 -07:00
Aditya Sirish
dce78c9307
signerverifier, tuf: Use go-securesystemslib signerverifier
Signed-off-by: Aditya Sirish <aditya@saky.in>
2023-06-20 15:26:47 -07:00
Aditya Sirish
8a3056401c
signerverifier, tuf: Add Targets and fix KeyID bug
In some scenarios, keyIDs weren't automatically populated. This fixes
that and in doing so, modifies the ID() API to return an error.

Signed-off-by: Aditya Sirish <aditya@saky.in>
2023-05-19 14:01:52 -04:00