├── .github ├── dependabot.yml └── workflows │ ├── test-old.yml │ └── verify-old.yml ├── .golangci.yml ├── CODEOWNERS ├── CODE_OF_CONDUCT.md ├── CONTRIBUTORS.md ├── COPYRIGHT.txt ├── LICENSE ├── README.md └── old-sigstore-go ├── go.mod ├── go.sum └── pkg ├── root ├── provider.go └── tuf │ ├── client.go │ ├── client_test.go │ ├── options.go │ ├── store.go │ ├── store_test.go │ └── test_utils.go └── tlog ├── common.go ├── common_test.go ├── verify.go └── verify_test.go /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2022 The Sigstore Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | version: 2 17 | updates: 18 | - package-ecosystem: gomod 19 | directory: "/" 20 | schedule: 21 | interval: daily 22 | - package-ecosystem: gomod 23 | directory: "./old-sigstore-go" 24 | schedule: 25 | interval: daily 26 | - package-ecosystem: github-actions 27 | directory: "/" 28 | schedule: 29 | interval: daily 30 | -------------------------------------------------------------------------------- /.github/workflows/test-old.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2022 The Sigstore Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | name: test 17 | 18 | on: 19 | push: 20 | branches: [ main ] 21 | pull_request: 22 | branches: [ main ] 23 | 24 | jobs: 25 | unit_test: 26 | name: unit tests 27 | runs-on: ubuntu-latest 28 | 29 | strategy: 30 | matrix: 31 | go-version: 32 | - 1.18 33 | - 1.19 34 | - '1.20' 35 | 36 | steps: 37 | - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 38 | 39 | - name: Set up Go 40 | uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0 41 | with: 42 | go-version: ${{ matrix.go-version }} 43 | check-latest: true 44 | go-version-file: 'old-sigstore-go/go.mod' 45 | cache-dependency-path: 'old-sigstore-go/go.sum' 46 | 47 | - name: Build 48 | run: | 49 | cd old-sigstore-go 50 | go build -v ./... 51 | 52 | - name: Test 53 | run: | 54 | cd old-sigstore-go 55 | go test -v ./... 56 | 57 | - name: Ensure no files were modified as a result of the build 58 | run: git update-index --refresh && git diff-index --quiet HEAD -- || git diff --exit-code 59 | -------------------------------------------------------------------------------- /.github/workflows/verify-old.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2022 The Sigstore Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | name: verify 17 | 18 | on: 19 | push: 20 | branches: [ main ] 21 | pull_request: 22 | branches: [ main ] 23 | 24 | env: 25 | GO_VERSION: '1.20' 26 | 27 | jobs: 28 | license-check: 29 | name: license boilerplate check 30 | runs-on: ubuntu-latest 31 | steps: 32 | - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 33 | - uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0 34 | with: 35 | go-version: ${{ env.GO_VERSION }} 36 | - name: Install addlicense 37 | run: go install github.com/google/addlicense@v1.1.0 38 | - name: Check license headers 39 | run: | 40 | set -e 41 | addlicense -l apache -c 'The Sigstore Authors' -v * 42 | git diff --exit-code 43 | 44 | golangci: 45 | name: lint checks 46 | runs-on: ubuntu-latest 47 | steps: 48 | - uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 49 | - uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0 50 | with: 51 | go-version: ${{ env.GO_VERSION }} 52 | - name: golangci-lint 53 | uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0 54 | timeout-minutes: 5 55 | with: 56 | version: v1.54 57 | working-directory: old-sigstore-go 58 | only-new-issues: true 59 | -------------------------------------------------------------------------------- /.golangci.yml: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright 2022 The Sigstore Authors. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | --- 17 | run: 18 | concurrency: 6 19 | deadline: 5m 20 | issues: 21 | # Maximum issues count per one linter. Set to 0 to disable. Default is 50. 22 | max-issues-per-linter: 0 23 | 24 | # Maximum count of issues with the same text. Set to 0 to disable. Default is 3. 25 | max-same-issues: 0 26 | linters: 27 | enable: 28 | - unused 29 | - errcheck 30 | - gofmt 31 | - goimports 32 | - gosec 33 | - gocritic 34 | - misspell 35 | - revive 36 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | @sigstore/sigstore-go-codeowners 2 | 3 | # The CODEOWNERS are managed via a GitHub team, but the current list is (in alphabetical order): 4 | # 5 | # codysoyland 6 | # haydentherapper 7 | # steiza 8 | # znewman01 9 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at . All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at [http://contributor-covenant.org/version/1/4][version] 72 | 73 | [homepage]: http://contributor-covenant.org 74 | [version]: http://contributor-covenant.org/version/1/4/ -------------------------------------------------------------------------------- /CONTRIBUTORS.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | Please see the [sigstore/community CONTRIBUTING.md] for information on how to 4 | create a pull request and write a commit message. 5 | 6 | [sigstore/community CONTRIBUTING.md]: https://github.com/sigstore/community/blob/main/CONTRIBUTING.md 7 | 8 | ## Philosophy 9 | 10 | The primary goal of sigstore-go is build a reliable, robust library. This will 11 | be acheived by adhereing to the folllowing principles: 12 | 13 | - Learn from other libraries ([Java], [Rust], [Python], [Ruby]) and clients 14 | ([Gitsign], [Cosign], [policy-controller]). What was executed well and what 15 | should be avoided. 16 | - Optimal API design 17 | - Avoidance of any techincal debt (move fast, fix later). 18 | - Conformance to [Sigstore specifications][arch-docs] and integration with [data 19 | formats][protobuf-specs]. 20 | - Testability: 21 | - [Conformance tests]: high-level; suitable for compatibility testing. 22 | - [Test vectors]: low level; suitable for fuzzing. 23 | - Good fakes (the Sigstore infrastructure is written in Go, so it should be 24 | easy to run an in-memory copy). 25 | 26 | This library values good code quality thoughtful design and errs on 27 | the side of a more-involved review processes. 28 | 29 | [arch-docs]: https://github.com/sigstore/architecture-docs 30 | [protobuf-specs]: https://github.com/sigstore/protobuf-specs 31 | [Conformance tests]: https://github.com/trailofbits/sigstore-conformance 32 | [Test vectors]: https://github.com/sigstore/protobuf-specs/issues/15 33 | [Java]: https://github.com/sigstore/sigstore-java 34 | [Rust]: https://github.com/sigstore/sigstore-rs 35 | [Python]: https://github.com/sigstore/sigstore-python 36 | [Ruby]: https://github.com/sigstore/sigstore-ruby 37 | [Gitsign]: https://github.com/sigstore/gitsign 38 | [Cosign]: https://github.com/sigstore/cosign 39 | [policy-controller]: https://github.com/sigstore/policy-controller 40 | 41 | # Strategy/Process 42 | 43 | sigstore-go uses standard GitHub processes ([issues][sigstore-go-issue] and PRs) 44 | for most development. For general discussion, check out the [Sigstore Slack] 45 | instance, where sigstore-go happens on the `#sigstore-go` channel. You may also 46 | be interested in the `#clients` channel, which coordinates folks doing 47 | development for other language ecosystems/tools. We have a weekly meeting on the 48 | [Sigstore community calendar] called "Sigstore Golang Subgroup" with attached 49 | [meeting notes] (you may need to join [sigstore-dev@googlegroups.com] for access). 50 | 51 | If you'd like to contribute, the most helpful things are: 52 | 53 | - Contributing to cross-ecosystem efforts: 54 | - [Sigstore specificatons][arch-docs]: We expect the specifications to 55 | co-develop with sigstore-go. 56 | - [protobuf-specs]: There are a number of open design questions around the 57 | bundle format and verification protocols, as well as 58 | implementation/documentation work. 59 | - Fake implementations for Sigstore infrastructure ([Fulcio], [Rekor], [TSA]). 60 | - Testing: 61 | - [Conformance tests]: help write new tests and get them running across 62 | current clients. 63 | - [Test vectors]: help with test vector generation for common use cases, along 64 | with fuzzing/randomized testing and infrastructure (getting existing clients 65 | running these test vectors). 66 | - Design: propose top-level APIs for signing and verification (e.g., [#18](https://github.com/sigstore/sigstore-go/issues/18)). 67 | - Make sure that this captures keyless and key-full flows, online/offline 68 | verification, etc. 69 | - And "backtest" against existing implementations, especially Golang ones: 70 | would be be able to drop these in as replacements? 71 | - Code (but see below before jumping in) 72 | 73 | When contributing to this repository, please first discuss the change you wish 74 | to make via an [issue][sigstore-go-issue]. 75 | 76 | [Fulcio]: https://github.com/sigstore/fulcio 77 | [Rekor]: https://github.com/sigstore/rekor 78 | [TSA]: https://github.com/sigstore/timestamp-authority 79 | [Sigstore community calendar]: https://calendar.google.com/calendar/u/0?cid=ZnE0a2dvbTJjZTQzaG5jbmJjZmphMmNrMjBAZ3JvdXAuY2FsZW5kYXIuZ29vZ2xlLmNvbQ 80 | [meeting notes]: https://docs.google.com/document/d/1EcJIhqSS9E86cHAQXaXiu2_r1s0kNbHz4uLLwwGo-vw/edit#heading=h.td0phy2bwk06 81 | [sigstore-go-issue]: https://github.com/sigstore/sigstore-go/issues 82 | [Sigstore slack]: https://links.sigstore.dev/slack-invite 83 | [sigstore-dev@googlegroups.com]: https://groups.google.com/g/sigstore-dev 84 | 85 | ## Code 86 | 87 | To prevent ossification, all code that gets merged into the main branch must 88 | meet the quality bar we expect from the final release. While we *will* be able 89 | to revise it, since we shouldn't have any users for a while, there's still a lot 90 | of inertia to overcome (especially when review processes are stringent). 91 | 92 | Principles of development: 93 | 94 | **Test-driven.** Like, actually test-driven. Not "we require tests with every 95 | PR." The tests should be first. This ensures that the code is testable, by 96 | definition and avoids perfunctory tests that are inexpressive with limited 97 | coverage. If a change is hard to meaningfully test it should be considered a 98 | smell and we should change the code under test. 99 | 100 | The initial pass of a code review should *only* cover test code and changes to 101 | public interfaces; once that is "approved," reviewers can move on to 102 | implementation code. If contributors are so inclined, they can even send an 103 | initial PR including only the (failing) test changes with 104 | `panic("unimplemented")` sprinkled throughout implementation code). This pass 105 | should be conducted with an adversarial mindset: "I could imagine a way to 106 | implement this function in a way that passes the tests, but with a bug" should 107 | be considered a blocking objection. 108 | 109 | We strongly encourage testing techniques like randomized testing (including 110 | fuzzing) and parameterized testing. We'd be open to experimenting with mutation 111 | testing or symbolic execution as well. 112 | 113 | **Documentation-driven.** Just as with tests, we practice documentation-driven 114 | development. Every public API must have high-quality documentation before 115 | initial merge. 116 | 117 | After (or concurrent with) the preliminary test-focused review pass, reviewers 118 | should do an interface- and documentation-focused review pass before looking at 119 | implementation. During this pass, "I don't know what this does without looking 120 | at the implementation" is a blocking objection. 121 | 122 | The APIs themselves should be thoughtful and well-designed. For top-level APIs 123 | (those that we expect to be users' primary entry point into the library) this 124 | goes doubly. 125 | 126 | **High-quality code.** Before merge, code quality should be high. Multiple 127 | rounds of code review should be the norm. Commit history should be atomic. 128 | During review, "it isn't immediately obvious to me what this code does" should 129 | be considered a blocking objection. 130 | 131 | A few specific, idiosyncratic preferences: 132 | 133 | - Internal application code should be agnostic to encodings; parsing should 134 | happen at application boundaries (this minimizes [encoding issues]). 135 | Concretely, it is a non-goal to be able to pass structs directly to 136 | `json.Marshal()`. For instance, there should be no base64 encoding or decoding 137 | except in code that formats network requests or reads from disk. 138 | - Use interfaces heavily. This dovetails with our testability goals, allowing 139 | fake implementations of network services. Further, it decouples this library 140 | from its dependencies, allowing their replacement. 141 | - Primitive types should be rare in public APIs: use the compiler to prevent you 142 | from passing a signature where the binary data to be verified belongs. 143 | 144 | **Experiment freely.** This may seem like a contradiction—the rest of this 145 | section is about being slow and deliberate! However, it's hard to get any of 146 | these things right without actually trying them out. Contributors are encouraged 147 | to experiment in forks and build proofs-of-concept to share (regardless of 148 | tests, docs, etc.). 149 | 150 | Then, we can take components of those proofs-of-concept that we like and port 151 | them to sigstore-go, following the above guidance. This is roughly in line with 152 | the "[write one to throw away](https://wiki.c2.com/?PlanToThrowOneAway)" 153 | philosophy. 154 | 155 | [encoding issues]: https://github.com/sigstore/community/discussions/136 156 | 157 | ## Code of Conduct 158 | 159 | sigstore-go adheres to and enforces the [Contributor Covenant](http://contributor-covenant.org/version/1/4/) Code of Conduct. 160 | Please take a moment to read the [CODE_OF_CONDUCT.md](https://github.com/sigstore/sigstore-go/blob/master/CODE_OF_CONDUCT.md) document. 161 | -------------------------------------------------------------------------------- /COPYRIGHT.txt: -------------------------------------------------------------------------------- 1 | 2 | Copyright 2021 The Sigstore Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # sigstore-go-archived 2 | 3 | :warning: This project is archived and will no longer receive updates, we have a new project to replace, please refer to https://github.com/sigstore/sigstore-go 4 | 5 | This is a Go client library for [Sigstore](https://sigstore.dev/). 6 | 7 | The project is under early development and **you shouldn't depend on it** yet. In the long run, you should depend on sigstore-go instead of cosign or sigstore/sigstore if you need a Sigstore Go client library, but don't need support for OCI registries/containers. Use cosign if you need OCI support, or if you're looking for a CLI signing/verification tool. 8 | 9 | ## Sigstore Library Landscape 10 | 11 | *This section describes the desired end state after sigstore-go is complete, not the current state.* 12 | 13 | These are the dependency relationships for library projects under the [Sigstore organization](https://github.com/sigstore) ("s/s" is [sigstore/sigstore](https://github.com/sigstore/sigstore); darker-background libraries are shared across language ecosystems). 14 | 15 | ```mermaid 16 | graph LR 17 | cosign --> sigstore-go 18 | sigstore-go --> rekor 19 | sigstore-go --> fulcio 20 | sigstore-go --> s/s 21 | rekor --> s/s 22 | fulcio --> s/s 23 | rekor --> protobuf-specs 24 | fulcio --> protobuf-specs 25 | clients --> rekor 26 | clients --> fulcio 27 | sigstore-go --> protobuf-specs 28 | clients("sigstore-{ruby,js,java,python,rs}") --> protobuf-specs 29 | 30 | classDef shared fill:#bbf; 31 | class rekor,fulcio,protobuf-specs shared; 32 | ``` 33 | 34 | See [Sigstore in Golang](https://docs.google.com/document/d/1aZfk1TlzcuaO0uz76M9D26-gAvoZLn0oCAKvkbuhcPM/edit) for design rationale; you may need to join sigstore-dev@googlegroups.com for access. We have: 35 | 36 | * Infrastructure 37 | * [fulcio](https://github.com/sigstore/fulcio): The CA for Sigstore. Contains the Fulcio server implementation along with a basic generated client library. 38 | * [rekor](https://github.com/sigstore/rekor): The artifact log for Sigstore. Contains the Rekor server implementation along with a basic generated client library. 39 | * [protobuf-specs](https://github.com/sigstore/protobuf-specs): Definitions for common Sigstore data formats. 40 | * Golang 41 | * [sigstore/sigstore](https://github.com/sigstore/sigstore): Common code, used in both the infrastructure and clients. 42 | * sigstore-go: a Golang client library for Sigstore. 43 | * [cosign](https://github.com/sigstore/cosign): A library for using Sigstore to sign container images in OCI registries (along with a CLI). This is a relatively thin wrapper around sigstore-go. 44 | * Other language clients. 45 | 46 | ## Security 47 | 48 | Should you discover any security issues, please refer to Sigstore's [security 49 | process](https://github.com/sigstore/sigstore-go/security/policy). 50 | -------------------------------------------------------------------------------- /old-sigstore-go/go.mod: -------------------------------------------------------------------------------- 1 | module github.com/sigstore/sigstore-go 2 | 3 | go 1.19 4 | 5 | require ( 6 | github.com/cyberphone/json-canonicalization v0.0.0-20210303052042-6bc126869bf4 7 | github.com/theupdateframework/go-tuf v0.6.1 8 | ) 9 | 10 | require ( 11 | github.com/golang/protobuf v1.5.3 // indirect 12 | github.com/google/go-containerregistry v0.16.1 // indirect 13 | github.com/letsencrypt/boulder v0.0.0-20221109233200-85aa52084eaf // indirect 14 | github.com/opencontainers/go-digest v1.0.0 // indirect 15 | github.com/titanous/rocacheck v0.0.0-20171023193734-afe73141d399 // indirect 16 | golang.org/x/net v0.14.0 // indirect 17 | golang.org/x/term v0.11.0 // indirect 18 | golang.org/x/text v0.12.0 // indirect 19 | google.golang.org/genproto v0.0.0-20230706204954-ccb25ca9f130 // indirect 20 | google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e // indirect 21 | google.golang.org/genproto/googleapis/rpc v0.0.0-20230706204954-ccb25ca9f130 // indirect 22 | google.golang.org/grpc v1.56.2 // indirect 23 | google.golang.org/protobuf v1.31.0 // indirect 24 | gopkg.in/square/go-jose.v2 v2.6.0 // indirect 25 | gopkg.in/yaml.v3 v3.0.1 // indirect 26 | ) 27 | 28 | require ( 29 | github.com/secure-systems-lab/go-securesystemslib v0.7.0 // indirect 30 | github.com/sigstore/protobuf-specs v0.2.1 31 | github.com/sigstore/sigstore v1.7.3 32 | golang.org/x/crypto v0.12.0 // indirect 33 | golang.org/x/sys v0.11.0 // indirect 34 | ) 35 | -------------------------------------------------------------------------------- /old-sigstore-go/go.sum: -------------------------------------------------------------------------------- 1 | github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= 2 | github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= 3 | github.com/cyberphone/json-canonicalization v0.0.0-20210303052042-6bc126869bf4 h1:7AjYfmq7AmviXsuZjV5DcE7PuhJ4dWMi8gLllpLVDQY= 4 | github.com/cyberphone/json-canonicalization v0.0.0-20210303052042-6bc126869bf4/go.mod h1:uzvlm1mxhHkdfqitSA92i7Se+S9ksOn3a3qmv/kyOCw= 5 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 6 | github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a h1:yDWHCSQ40h88yih2JAcL6Ls/kVkSE8GFACTGVnMPruw= 7 | github.com/facebookgo/limitgroup v0.0.0-20150612190941-6abd8d71ec01 h1:IeaD1VDVBPlx3viJT9Md8if8IxxJnO+x0JCGb054heg= 8 | github.com/facebookgo/muster v0.0.0-20150708232844-fd3d7953fd52 h1:a4DFiKFJiDRGFD1qIcqGLX/WlUMD9dyLSLDt+9QZgt8= 9 | github.com/go-test/deep v1.1.0 h1:WOcxcdHcvdgThNXjw0t76K42FXTU7HpNQWHpA2HHNlg= 10 | github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= 11 | github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg= 12 | github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= 13 | github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= 14 | github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= 15 | github.com/google/go-containerregistry v0.16.1 h1:rUEt426sR6nyrL3gt+18ibRcvYpKYdpsa5ZW7MA08dQ= 16 | github.com/google/go-containerregistry v0.16.1/go.mod h1:u0qB2l7mvtWVR5kNcbFIhFY1hLbf8eeGapA+vbFDCtQ= 17 | github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= 18 | github.com/honeycombio/beeline-go v1.10.0 h1:cUDe555oqvw8oD76BQJ8alk7FP0JZ/M/zXpNvOEDLDc= 19 | github.com/honeycombio/libhoney-go v1.16.0 h1:kPpqoz6vbOzgp7jC6SR7SkNj7rua7rgxvznI6M3KdHc= 20 | github.com/jmhodges/clock v0.0.0-20160418191101-880ee4c33548 h1:dYTbLf4m0a5u0KLmPfB6mgxbcV7588bOCx79hxa5Sr4= 21 | github.com/klauspost/compress v1.16.5 h1:IFV2oUNUzZaz+XyusxpLzpzS8Pt5rh0Z16For/djlyI= 22 | github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= 23 | github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= 24 | github.com/letsencrypt/boulder v0.0.0-20221109233200-85aa52084eaf h1:ndns1qx/5dL43g16EQkPV/i8+b3l5bYQwLeoSBe7tS8= 25 | github.com/letsencrypt/boulder v0.0.0-20221109233200-85aa52084eaf/go.mod h1:aGkAgvWY/IUcVFfuly53REpfv5edu25oij+qHRFaraA= 26 | github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU= 27 | github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= 28 | github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= 29 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 30 | github.com/prometheus/client_golang v1.13.0 h1:b71QUfeo5M8gq2+evJdTPfZhYMAU0uKPkyPJ7TPsloU= 31 | github.com/prometheus/client_model v0.3.0 h1:UBgGFHqYdG/TPFD1B1ogZywDqEkwp3fBMvqdiQ7Xew4= 32 | github.com/prometheus/common v0.37.0 h1:ccBbHCgIiT9uSoFY0vX8H3zsNR5eLt17/RQLUvn8pXE= 33 | github.com/prometheus/procfs v0.8.0 h1:ODq8ZFEaYeCaZOJlZZdJA2AbQR98dSHSM1KW/You5mo= 34 | github.com/secure-systems-lab/go-securesystemslib v0.7.0 h1:OwvJ5jQf9LnIAS83waAjPbcMsODrTQUpJ02eNLUoxBg= 35 | github.com/secure-systems-lab/go-securesystemslib v0.7.0/go.mod h1:/2gYnlnHVQ6xeGtfIqFy7Do03K4cdCY0A/GlJLDKLHI= 36 | github.com/sigstore/protobuf-specs v0.2.1 h1:KIoM7E3C4uaK092q8YoSj/XSf9720f8dlsbYwwOmgEA= 37 | github.com/sigstore/protobuf-specs v0.2.1/go.mod h1:xPqQGnH/HllKuZ4VFPz/g+78epWM/NLRGl7Fuy45UdE= 38 | github.com/sigstore/sigstore v1.7.3 h1:HVVTfrMezJeLyl2xhJ8edzkrEGBa4KxjQZB4FlQ4JLU= 39 | github.com/sigstore/sigstore v1.7.3/go.mod h1:cl0c7Dtg3MM3c13L8pqqrfrmBa0eM3POcdtBepjylmw= 40 | github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= 41 | github.com/theupdateframework/go-tuf v0.6.1 h1:6J89fGjQf7s0mLmTG7p7pO/MbKOg+bIXhaLyQdmbKuE= 42 | github.com/theupdateframework/go-tuf v0.6.1/go.mod h1:LAFusuQsFNBnEyYoTuA5zZrF7iaQ4TEgBXm8lb6Vj18= 43 | github.com/titanous/rocacheck v0.0.0-20171023193734-afe73141d399 h1:e/5i7d4oYZ+C1wj2THlRK+oAhjeS/TRQwMfkIuet3w0= 44 | github.com/titanous/rocacheck v0.0.0-20171023193734-afe73141d399/go.mod h1:LdwHTNJT99C5fTAzDz0ud328OgXz+gierycbcIx2fRs= 45 | github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU= 46 | github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g= 47 | golang.org/x/crypto v0.12.0 h1:tFM/ta59kqch6LlvYnPa0yx5a83cL2nHflFhYKvv9Yk= 48 | golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= 49 | golang.org/x/net v0.14.0 h1:BONx9s002vGdD9umnlX1Po8vOZmrgH34qlHcD1MfK14= 50 | golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= 51 | golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM= 52 | golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 53 | golang.org/x/term v0.11.0 h1:F9tnn/DA/Im8nCwm+fX+1/eBwi4qFjRT++MhtVC4ZX0= 54 | golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU= 55 | golang.org/x/text v0.12.0 h1:k+n5B8goJNdU7hSvEtMUz3d1Q6D/XW4COJSJR6fN0mc= 56 | golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= 57 | golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 58 | google.golang.org/genproto v0.0.0-20230706204954-ccb25ca9f130 h1:Au6te5hbKUV8pIYWHqOUZ1pva5qK/rwbIhoXEUB9Lu8= 59 | google.golang.org/genproto v0.0.0-20230706204954-ccb25ca9f130/go.mod h1:O9kGHb51iE/nOGvQaDUuadVYqovW56s5emA88lQnj6Y= 60 | google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e h1:z3vDksarJxsAKM5dmEGv0GHwE2hKJ096wZra71Vs4sw= 61 | google.golang.org/genproto/googleapis/api v0.0.0-20230726155614-23370e0ffb3e/go.mod h1:rsr7RhLuwsDKL7RmgDDCUc6yaGr1iqceVb5Wv6f6YvQ= 62 | google.golang.org/genproto/googleapis/rpc v0.0.0-20230706204954-ccb25ca9f130 h1:2FZP5XuJY9zQyGM5N0rtovnoXjiMUEIUMvw0m9wlpLc= 63 | google.golang.org/genproto/googleapis/rpc v0.0.0-20230706204954-ccb25ca9f130/go.mod h1:8mL13HKkDa+IuJ8yruA3ci0q+0vsUz4m//+ottjwS5o= 64 | google.golang.org/grpc v1.56.2 h1:fVRFRnXvU+x6C4IlHZewvJOVHoOv1TUuQyoRsYnB4bI= 65 | google.golang.org/grpc v1.56.2/go.mod h1:I9bI3vqKfayGqPUAwGdOSu7kt6oIJLixfffKrpXqQ9s= 66 | google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= 67 | google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= 68 | google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8= 69 | google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= 70 | gopkg.in/alexcesaro/statsd.v2 v2.0.0 h1:FXkZSCZIH17vLCO5sO2UucTHsH9pc+17F6pl3JVCwMc= 71 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 72 | gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= 73 | gopkg.in/square/go-jose.v2 v2.6.0 h1:NGk74WTnPKBNUhNzQX7PYcTLUjoq7mzKk2OKbvwk2iI= 74 | gopkg.in/square/go-jose.v2 v2.6.0/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI= 75 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 76 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 77 | -------------------------------------------------------------------------------- /old-sigstore-go/pkg/root/provider.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2022 The Sigstore Authors. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | // This package implements a root provider interface that can be 17 | // 18 | // implemented with a TUF client or other 19 | package root 20 | 21 | // TrustedRootProvider is an interface that can generate a trusted 22 | // root, be it from a TUF client, local filesystem information, or 23 | // other method to retrieve the trusted root. 24 | type TrustedRootProvider interface { 25 | // GetTrustedRoot returns a TrustedRootStore containing the 26 | // Sigstore ecosystem information for a verification client to 27 | // consume. 28 | GetTrustedRoot() (interface{}, error) 29 | } 30 | -------------------------------------------------------------------------------- /old-sigstore-go/pkg/root/tuf/client.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2022 The Sigstore Authors. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | package tuf 17 | 18 | import ( 19 | "errors" 20 | "fmt" 21 | 22 | "github.com/theupdateframework/go-tuf/client" 23 | ) 24 | 25 | // This is a SigstoreTufClient. Note that this is not opinionated on 26 | // its usage and does not include a sync.Once for single intialization. Users 27 | // of the library are responsible for considering its usage in their application. 28 | // It is threadsafe. 29 | type SigstoreTufClient struct { 30 | // TODO: Add concurrency support for load operations. 31 | 32 | // client is the base TUF client. 33 | // TODO: Replace when go-tuf implements a TAP-4 multi-repository client. 34 | // https://github.com/theupdateframework/go-tuf/issues/348, then this 35 | // will be an interface. 36 | client *client.Client 37 | 38 | // local is the TUF local repository for accessing local trusted metadata. 39 | // TODO: As an optimization, use an in-memory store always, and sync to a 40 | // configured cache location during updates. 41 | local client.LocalStore 42 | 43 | // initialized detects whether a remote repository was configured into the 44 | // TUF client. 45 | initialized bool 46 | } 47 | 48 | // NewSigstoreTufClient creates a new client given client options. 49 | func NewSigstoreTufClient(opts *ClientOptions) (*SigstoreTufClient, error) { 50 | local, err := localStoreFromOpts(opts) 51 | if err != nil { 52 | return nil, err 53 | } 54 | return &SigstoreTufClient{local: local}, nil 55 | } 56 | 57 | // Initialize initializes the Sigstore TUF Client given a particular repository. 58 | // This WILL run a network call to the remote. The remote may be configured to a 59 | // local filesystem. 60 | // If you intend to load in TrustedRootStore information from fixed information, 61 | // create a new provider. 62 | func (s *SigstoreTufClient) Initialize(opts *RepositoryOptions) error { 63 | remote, err := remoteStoreFromOpts(opts) 64 | if err != nil { 65 | return fmt.Errorf("remoteStoreFromOpts: %w", err) 66 | } 67 | s.client = client.NewClient(s.local, remote) 68 | if err := s.client.Init(opts.Root); err != nil { 69 | return fmt.Errorf("initializing Sigstore TUF client: %w", err) 70 | } 71 | // Update with the TUF client. 72 | if _, err := s.client.Update(); err != nil { 73 | return fmt.Errorf("updating Sigstore TUF client: %w", err) 74 | } 75 | s.initialized = true 76 | return nil 77 | } 78 | 79 | // GetTrustedRoot returns a TrustedRootStore that can be ingested by verifiers. 80 | func (s *SigstoreTufClient) GetTrustedRootStore() error { 81 | if !s.initialized { 82 | // unexpected 83 | return errors.New("sigstore TUF client must be initialized before usage") 84 | } 85 | 86 | // This will check the local trusted metadata and assemble the TrustedRootStore 87 | return errors.New("unimplemented") 88 | } 89 | -------------------------------------------------------------------------------- /old-sigstore-go/pkg/root/tuf/client_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2022 The Sigstore Authors. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | package tuf 17 | 18 | import ( 19 | "fmt" 20 | "net/http" 21 | "net/http/httptest" 22 | "path/filepath" 23 | "testing" 24 | ) 25 | 26 | // TODO(asraa): Add support for: 27 | // - expired timestamps and other repository states with embedded testdata. 28 | // - concurrency 29 | func TestInitialize(t *testing.T) { 30 | t.Parallel() 31 | td := t.TempDir() 32 | 33 | // Create a new TUF repository 34 | testRepo := newTufRepository(t, td) 35 | testRepo.addTarget("foo.txt", []byte("hello"), nil) 36 | testRepo.publish() 37 | rootBytes := testRepo.root() 38 | 39 | // Serve remote repository. 40 | s := httptest.NewServer(http.FileServer(http.Dir(filepath.Join(td, "repository")))) 41 | t.Cleanup(func() { 42 | s.Close() 43 | }) 44 | 45 | testCases := []struct { 46 | name string 47 | tufOpts *ClientOptions 48 | repoOpts *RepositoryOptions 49 | wantClientErr bool 50 | wantInitErr bool 51 | }{ 52 | { 53 | name: "fail: unknown cache type", 54 | tufOpts: &ClientOptions{ 55 | CacheType: 3, 56 | }, 57 | repoOpts: &RepositoryOptions{}, 58 | wantClientErr: true, 59 | }, 60 | { 61 | name: "valid memory cache with fs remote", 62 | tufOpts: &ClientOptions{ 63 | CacheType: Memory, 64 | }, 65 | repoOpts: &RepositoryOptions{ 66 | Name: "sigstore-staging", 67 | Remote: fmt.Sprintf("file://%s/repository", td), 68 | Root: rootBytes, 69 | }, 70 | }, 71 | { 72 | name: "valid memory cache with http remote", 73 | tufOpts: &ClientOptions{ 74 | CacheType: Memory, 75 | }, 76 | repoOpts: &RepositoryOptions{ 77 | Name: "sigstore-staging", 78 | Remote: s.URL, 79 | Root: rootBytes, 80 | }, 81 | }, 82 | } 83 | for _, tc := range testCases { 84 | tc := tc 85 | t.Run(tc.name, func(t *testing.T) { 86 | t.Parallel() 87 | client, clientErr := NewSigstoreTufClient(tc.tufOpts) 88 | if clientErr != nil { 89 | if !tc.wantClientErr { 90 | t.Fatalf("NewSigstoreTufClient unexpectedly returned an error: %v", clientErr) 91 | } 92 | return 93 | } 94 | if tc.wantClientErr { 95 | t.Fatalf("NewSigstoreTufClient returned, expected error: %v", tc.wantClientErr) 96 | } 97 | initErr := client.Initialize(tc.repoOpts) 98 | if initErr != nil { 99 | if !tc.wantInitErr { 100 | t.Fatalf("Initialize unexpectedly returned an error: %v", initErr) 101 | } 102 | return 103 | } 104 | if tc.wantClientErr { 105 | t.Fatalf("Initialize returned, expected error: %v", tc.wantInitErr) 106 | } 107 | }) 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /old-sigstore-go/pkg/root/tuf/options.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2022 The Sigstore Authors. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | package tuf 17 | 18 | // CacheKind is used to designate an on-disk or in-memory cache. 19 | type CacheKind int 20 | 21 | const ( 22 | Memory CacheKind = iota 23 | Disk 24 | ) 25 | 26 | type ClientOptions struct { 27 | // This indicates whether the cache should be in the local filesystem or in-memory. 28 | // Default: Memory. 29 | CacheType CacheKind 30 | 31 | // CacheLocation is the location for the local cache. 32 | // Only applies when CacheType is Disk. 33 | // This directory will contain the metadata and targets cache for the TUF 34 | // client. 35 | CacheLocation string 36 | } 37 | 38 | // RepositoryOptions specify options for initializing a particular 39 | // repository in the TUF client. 40 | // Specifies a root.json, a remote, and a name. 41 | // 42 | // TODO: Replace with a map.json for a multi-repository setup. 43 | type RepositoryOptions struct { 44 | // The trusted root.json 45 | Root []byte 46 | 47 | // The location of the remote repository. 48 | Remote string 49 | 50 | // The name of the repository, used to populate the map.json. TODO: Make this 51 | // optional and use digest of the root. 52 | Name string 53 | } 54 | -------------------------------------------------------------------------------- /old-sigstore-go/pkg/root/tuf/store.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2022 The Sigstore Authors. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | package tuf 17 | 18 | import ( 19 | "errors" 20 | "fmt" 21 | "net/url" 22 | "os" 23 | 24 | "github.com/theupdateframework/go-tuf/client" 25 | tuf_filejsonstore "github.com/theupdateframework/go-tuf/client/filejsonstore" 26 | ) 27 | 28 | var ( 29 | errUnknownCacheType = errors.New("unknown cache type") 30 | errUnknownCacheLocation = errors.New("unknown cache location") 31 | ) 32 | 33 | // localStoreFromOpts creates a local store depending on the TUF configuration 34 | // and uses the RepositoryOptions to name the metadata directory. 35 | func localStoreFromOpts(opts *ClientOptions) (client.LocalStore, error) { 36 | switch opts.CacheType { 37 | case Disk: 38 | if opts.CacheLocation == "" { 39 | return nil, errUnknownCacheLocation 40 | } 41 | return tuf_filejsonstore.NewFileJSONStore(opts.CacheLocation) 42 | case Memory: 43 | return client.MemoryLocalStore(), nil 44 | } 45 | return nil, errUnknownCacheType 46 | } 47 | 48 | // remoteStoreFromOpts creates the remote store using the RepositoryOptions. 49 | // local files may be specified using the file URI scheme. 50 | func remoteStoreFromOpts(repoOpts *RepositoryOptions) (client.RemoteStore, error) { 51 | u, err := url.ParseRequestURI(repoOpts.Remote) 52 | if err != nil { 53 | return nil, fmt.Errorf("failed to parse URL %s: %w", repoOpts.Remote, err) 54 | } 55 | if u.Scheme != "file" { 56 | return client.HTTPRemoteStore(repoOpts.Remote, nil, nil) 57 | } 58 | // Use local filesystem for remote. 59 | return client.NewFileRemoteStore(os.DirFS(u.Path), "") 60 | } 61 | -------------------------------------------------------------------------------- /old-sigstore-go/pkg/root/tuf/store_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2022 The Sigstore Authors. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | package tuf 17 | 18 | import ( 19 | "errors" 20 | "fmt" 21 | "os" 22 | "path/filepath" 23 | "testing" 24 | ) 25 | 26 | func TestLocalStoreFromOpts(t *testing.T) { 27 | t.Parallel() 28 | dir := t.TempDir() 29 | created := filepath.Join(dir, "created") 30 | if err := os.Mkdir(created, 0o750); err != nil { 31 | t.Fatal(err) 32 | } 33 | testCases := []struct { 34 | name string 35 | opts *ClientOptions 36 | wantError error 37 | }{ 38 | { 39 | name: "unknown cache type", 40 | opts: &ClientOptions{ 41 | CacheType: 3, 42 | }, 43 | wantError: errUnknownCacheType, 44 | }, 45 | { 46 | name: "cache type memory", 47 | opts: &ClientOptions{ 48 | CacheType: Memory, 49 | }, 50 | }, 51 | { 52 | name: "cache type disk no location", 53 | opts: &ClientOptions{ 54 | CacheType: Disk, 55 | }, 56 | wantError: errUnknownCacheLocation, 57 | }, 58 | { 59 | name: "cache type disk new cache", 60 | opts: &ClientOptions{ 61 | CacheType: Disk, 62 | CacheLocation: filepath.Join(dir, "test"), 63 | }, 64 | }, 65 | { 66 | name: "cache type disk already created", 67 | opts: &ClientOptions{ 68 | CacheType: Disk, 69 | CacheLocation: created, 70 | }, 71 | }, 72 | } 73 | 74 | for _, tc := range testCases { 75 | tc := tc 76 | t.Run(tc.name, func(t *testing.T) { 77 | t.Parallel() 78 | _, err := localStoreFromOpts(tc.opts) 79 | if err != nil { 80 | if tc.wantError == nil { 81 | t.Fatalf("localStoreFromOpts unexpectedly returned an error: %v", err) 82 | } 83 | if !errors.Is(err, tc.wantError) { 84 | t.Fatalf("localStoreFromOpts returned %v, expected %v", err, tc.wantError) 85 | } 86 | return 87 | } 88 | if tc.wantError != nil { 89 | t.Errorf("localStoreFromOpts returned, expected error: %v", err) 90 | } 91 | }) 92 | } 93 | } 94 | 95 | func TestRemoteStoreFromOpts(t *testing.T) { 96 | fileRemote := t.TempDir() 97 | if err := os.Mkdir(filepath.Join(fileRemote, "targets"), 0o750); err != nil { 98 | t.Fatal(err) 99 | } 100 | 101 | testCases := []struct { 102 | name string 103 | opts *RepositoryOptions 104 | wantError bool 105 | }{ 106 | { 107 | name: "local file remote", 108 | opts: &RepositoryOptions{ 109 | Remote: fmt.Sprintf("file://%s", fileRemote), 110 | }, 111 | }, 112 | { 113 | name: "local file remote bad URI", 114 | opts: &RepositoryOptions{ 115 | Remote: "abc", 116 | }, 117 | wantError: true, 118 | }, 119 | { 120 | name: "local file remote does not exist", 121 | opts: &RepositoryOptions{ 122 | Remote: "file://abc", 123 | }, 124 | wantError: true, 125 | }, 126 | { 127 | name: "http file remote", 128 | opts: &RepositoryOptions{ 129 | Remote: "http://abc", 130 | }, 131 | }, 132 | } 133 | 134 | for _, tc := range testCases { 135 | tc := tc 136 | t.Run(tc.name, func(t *testing.T) { 137 | t.Parallel() 138 | _, err := remoteStoreFromOpts(tc.opts) 139 | if err != nil { 140 | if !tc.wantError { 141 | t.Fatalf("remoteStoreFromOpts unexpectedly returned an error: %v", err) 142 | } 143 | return 144 | } 145 | if tc.wantError { 146 | t.Errorf("remoteStoreFromOpts returned, expected error: %v", err) 147 | } 148 | }) 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /old-sigstore-go/pkg/root/tuf/test_utils.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2022 The Sigstore Authors. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | package tuf 17 | 18 | import ( 19 | "encoding/json" 20 | "os" 21 | "path/filepath" 22 | "testing" 23 | 24 | "github.com/theupdateframework/go-tuf" 25 | ) 26 | 27 | type TestRepository struct { 28 | targets map[string]json.RawMessage 29 | td string 30 | store tuf.LocalStore 31 | repo *tuf.Repo 32 | t *testing.T 33 | } 34 | 35 | // newTufRepository initializes a TUF repository with root, targets, snapshot, and timestamp roles 36 | func newTufRepository(t *testing.T, td string) *TestRepository { 37 | remote := tuf.FileSystemStore(td, nil) 38 | r, err := tuf.NewRepo(remote) 39 | if err != nil { 40 | t.Error(err) 41 | } 42 | if err := r.Init(false); err != nil { 43 | t.Error(err) 44 | } 45 | for _, role := range []string{"root", "targets", "snapshot", "timestamp"} { 46 | if _, err := r.GenKey(role); err != nil { 47 | t.Error(err) 48 | } 49 | } 50 | return &TestRepository{ 51 | targets: make(map[string]json.RawMessage), 52 | td: td, 53 | store: remote, 54 | repo: r, 55 | t: t, 56 | } 57 | } 58 | 59 | func (r *TestRepository) addTarget(name string, data []byte, custom json.RawMessage) { 60 | targetPath := filepath.FromSlash(filepath.Join(r.td, "staged", "targets", name)) 61 | if err := os.MkdirAll(filepath.Dir(targetPath), 0o755); err != nil { 62 | r.t.Error(err) 63 | } 64 | if err := os.WriteFile(targetPath, data, 0o600); err != nil { 65 | r.t.Error(err) 66 | } 67 | if err := r.repo.AddTarget(name, custom); err != nil { 68 | r.t.Error(err) 69 | } 70 | } 71 | 72 | func (r *TestRepository) publish() { 73 | if err := r.repo.Snapshot(); err != nil { 74 | r.t.Error(err) 75 | } 76 | if err := r.repo.Timestamp(); err != nil { 77 | r.t.Error(err) 78 | } 79 | if err := r.repo.Commit(); err != nil { 80 | r.t.Error(err) 81 | } 82 | } 83 | 84 | func (r *TestRepository) root() []byte { 85 | meta, err := r.store.GetMeta() 86 | if err != nil { 87 | r.t.Error(err) 88 | } 89 | rootBytes, ok := meta["root.json"] 90 | if !ok { 91 | r.t.Error(err) 92 | } 93 | return rootBytes 94 | } 95 | -------------------------------------------------------------------------------- /old-sigstore-go/pkg/tlog/common.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2022 The Sigstore Authors. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | /*This package implements common tlog functions*/ 17 | package tlog 18 | 19 | import ( 20 | "crypto" 21 | "crypto/sha256" 22 | "crypto/x509" 23 | "encoding/hex" 24 | "errors" 25 | 26 | rekor_v1 "github.com/sigstore/protobuf-specs/gen/pb-go/rekor/v1" 27 | ) 28 | 29 | // ComputeLogID generates a SHA256 hash of a DER-encoded public key, which is 30 | // the log ID of a transparency log. 31 | func ComputeLogID(pub crypto.PublicKey) (string, error) { 32 | pubBytes, err := x509.MarshalPKIXPublicKey(pub) 33 | if err != nil { 34 | return "", err 35 | } 36 | digest := sha256.Sum256(pubBytes) 37 | return hex.EncodeToString(digest[:]), nil 38 | } 39 | 40 | // GetLogID returns the hex-encoded log ID from the TransparencyLogEntry. 41 | func GetLogID(entry *rekor_v1.TransparencyLogEntry) (string, error) { 42 | if entry.GetLogId() == nil { 43 | return "", errors.New("entry missing Log ID") 44 | } 45 | 46 | if entry.LogId.GetKeyId() == nil { 47 | return "", errors.New("expected Key ID") 48 | } 49 | 50 | return hex.EncodeToString(entry.LogId.GetKeyId()), nil 51 | } 52 | -------------------------------------------------------------------------------- /old-sigstore-go/pkg/tlog/common_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2022 The Sigstore Authors. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | package tlog 17 | 18 | import ( 19 | "encoding/hex" 20 | "testing" 21 | 22 | common_v1 "github.com/sigstore/protobuf-specs/gen/pb-go/common/v1" 23 | rekor_v1 "github.com/sigstore/protobuf-specs/gen/pb-go/rekor/v1" 24 | "github.com/sigstore/sigstore/pkg/cryptoutils" 25 | ) 26 | 27 | const rekor = `-----BEGIN PUBLIC KEY----- 28 | MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE2G2Y+2tabdTV5BcGiBIx0a9fAFwr 29 | kBbmLSGtks4L3qX6yYY0zufBnhC8Ur/iy55GhWP/9A/bY2LhC30M9+RYtw== 30 | -----END PUBLIC KEY-----` 31 | 32 | func TestGetLogID(t *testing.T) { 33 | logID := []byte("foo") 34 | encodedLogID := hex.EncodeToString(logID) 35 | testCases := []struct { 36 | name string 37 | entry *rekor_v1.TransparencyLogEntry 38 | expectedID string 39 | wantErr bool 40 | }{ 41 | { 42 | name: "fail: missing entry log id", 43 | entry: &rekor_v1.TransparencyLogEntry{ 44 | LogIndex: int64(1), 45 | IntegratedTime: int64(1661794812), 46 | CanonicalizedBody: []byte("foo"), 47 | InclusionPromise: &rekor_v1.InclusionPromise{}, 48 | }, 49 | wantErr: true, 50 | }, 51 | { 52 | name: "fail: missing key id", 53 | entry: &rekor_v1.TransparencyLogEntry{ 54 | LogIndex: int64(1), 55 | LogId: &common_v1.LogId{}, 56 | IntegratedTime: int64(1661794812), 57 | CanonicalizedBody: []byte("foo"), 58 | InclusionPromise: &rekor_v1.InclusionPromise{}, 59 | }, 60 | wantErr: true, 61 | }, 62 | { 63 | name: "valid: prod rekor", 64 | entry: &rekor_v1.TransparencyLogEntry{ 65 | LogIndex: int64(1), 66 | LogId: &common_v1.LogId{ 67 | KeyId: logID, 68 | }, 69 | IntegratedTime: int64(1661794812), 70 | CanonicalizedBody: []byte("foo"), 71 | InclusionPromise: &rekor_v1.InclusionPromise{}, 72 | }, 73 | expectedID: encodedLogID, 74 | }, 75 | } 76 | for _, tc := range testCases { 77 | tc := tc 78 | t.Run(tc.name, func(t *testing.T) { 79 | t.Parallel() 80 | id, err := GetLogID(tc.entry) 81 | if err != nil { 82 | if !tc.wantErr { 83 | t.Errorf("GetLogId unexpectedly returned an error: %v", err) 84 | } 85 | return 86 | } 87 | if tc.wantErr { 88 | t.Errorf("GetLogId returned, expected error") 89 | return 90 | } 91 | if tc.expectedID != id { 92 | t.Errorf("expected id %s, got %s", tc.expectedID, id) 93 | } 94 | }) 95 | } 96 | } 97 | 98 | func TestComputeLogId(t *testing.T) { 99 | // Test the prod Rekor public key 100 | pubKey, err := cryptoutils.UnmarshalPEMToPublicKey([]byte(rekor)) 101 | if err != nil { 102 | t.Error(err) 103 | } 104 | id, err := ComputeLogID(pubKey) 105 | if err != nil { 106 | t.Fatal(err) 107 | } 108 | /* #nosec G101 */ 109 | expected := "c0d23d6ad406973f9559f3ba2d1ca01f84147d8ffc5b8445c224f98b9591801d" 110 | if id != expected { 111 | t.Fatalf("expected %s, got %s", expected, id) 112 | } 113 | } 114 | -------------------------------------------------------------------------------- /old-sigstore-go/pkg/tlog/verify.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2022 The Sigstore Authors. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | /*This package implements tlog verification functions */ 17 | package tlog 18 | 19 | import ( 20 | "bytes" 21 | "context" 22 | "encoding/base64" 23 | "encoding/json" 24 | "errors" 25 | "fmt" 26 | 27 | "github.com/cyberphone/json-canonicalization/go/src/webpki.org/jsoncanonicalizer" 28 | rekor_v1 "github.com/sigstore/protobuf-specs/gen/pb-go/rekor/v1" 29 | "github.com/sigstore/sigstore/pkg/signature" 30 | "github.com/sigstore/sigstore/pkg/signature/options" 31 | ) 32 | 33 | // VerificationPayload is a struct containing the payload the 34 | // SignedEntryTimestamp signs over. The signed payload is constructed from 35 | // the JSON canonicalized bytes of this struct. 36 | type VerificationPayload struct { 37 | Body interface{} `json:"body"` 38 | IntegratedTime int64 `json:"integratedTime"` 39 | LogIndex int64 `json:"logIndex"` 40 | LogID string `json:"logID"` 41 | } 42 | 43 | // VerifyTlogSET verifies the SignedEntryTimestamp (SET) for the given 44 | // TransparencyLogEntry using the trusted verifiers indexed by LogID. 45 | func VerifyTlogSET(ctx context.Context, 46 | entry *rekor_v1.TransparencyLogEntry, trustedKeys map[string]signature.Verifier, 47 | ) error { 48 | // Create the signed tlog verification payload. 49 | payload, err := verificationPayload(entry) 50 | if err != nil { 51 | return fmt.Errorf("creating verification payload: %w", err) 52 | } 53 | 54 | // Canonicalize using JSON canonicalizer 55 | contents, err := json.Marshal(payload) 56 | if err != nil { 57 | return fmt.Errorf("marshaling : %w", err) 58 | } 59 | canonicalized, err := jsoncanonicalizer.Transform(contents) 60 | if err != nil { 61 | return fmt.Errorf("canonicalizing: %w", err) 62 | } 63 | 64 | // Find the corresponding public key which generated the SET 65 | // We should already have a LogId, or else the verification payload would fail. 66 | entryLogID, err := GetLogID(entry) 67 | if err != nil { 68 | return fmt.Errorf("getting entry log ID: %w", err) 69 | } 70 | verifier, ok := trustedKeys[entryLogID] 71 | if !ok { 72 | return errors.New("rekor log public key not found for payload") 73 | } 74 | 75 | // Extract the SET from the tlog entry 76 | if entry.GetInclusionPromise() == nil { 77 | return errors.New("rekor entry missing inclusion promise") 78 | } 79 | sig := entry.InclusionPromise.SignedEntryTimestamp 80 | 81 | // Verify the SET over the payload 82 | if err := verifier.VerifySignature(bytes.NewReader(sig), 83 | bytes.NewReader(canonicalized), options.WithContext(ctx)); err != nil { 84 | return fmt.Errorf("unable to verify bundle: %w", err) 85 | } 86 | 87 | return nil 88 | } 89 | 90 | func verificationPayload(entry *rekor_v1.TransparencyLogEntry) (*VerificationPayload, error) { 91 | if entry.GetLogId() == nil { 92 | return nil, errors.New("TransparencyLogEntry missing LogId") 93 | } 94 | 95 | return &VerificationPayload{ 96 | Body: base64.StdEncoding.EncodeToString(entry.CanonicalizedBody), 97 | IntegratedTime: entry.IntegratedTime, 98 | LogIndex: entry.LogIndex, 99 | LogID: entry.LogId.String(), 100 | }, nil 101 | } 102 | -------------------------------------------------------------------------------- /old-sigstore-go/pkg/tlog/verify_test.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2022 The Sigstore Authors. 3 | // 4 | // Licensed under the Apache License, Version 2.0 (the "License"); 5 | // you may not use this file except in compliance with the License. 6 | // You may obtain a copy of the License at 7 | // 8 | // http://www.apache.org/licenses/LICENSE-2.0 9 | // 10 | // Unless required by applicable law or agreed to in writing, software 11 | // distributed under the License is distributed on an "AS IS" BASIS, 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | // See the License for the specific language governing permissions and 14 | // limitations under the License. 15 | 16 | /*This package implements tlog verification functions */ 17 | package tlog 18 | 19 | import ( 20 | "bytes" 21 | "context" 22 | "encoding/hex" 23 | "encoding/json" 24 | "testing" 25 | 26 | "github.com/cyberphone/json-canonicalization/go/src/webpki.org/jsoncanonicalizer" 27 | common_v1 "github.com/sigstore/protobuf-specs/gen/pb-go/common/v1" 28 | rekor_v1 "github.com/sigstore/protobuf-specs/gen/pb-go/rekor/v1" 29 | "github.com/sigstore/sigstore/pkg/signature" 30 | ) 31 | 32 | func TestVerifyTlogSET(t *testing.T) { 33 | t.Parallel() 34 | 35 | signer, _, err := signature.NewDefaultECDSASignerVerifier() 36 | if err != nil { 37 | t.Fatalf("error generating signer: %v", err) 38 | } 39 | 40 | logID, err := ComputeLogID(signer.Public()) 41 | if err != nil { 42 | t.Fatalf("getting log id: %v", err) 43 | } 44 | decodedLogID, err := hex.DecodeString(logID) 45 | if err != nil { 46 | t.Fatalf("decoding log id: %v", err) 47 | } 48 | 49 | tlogEntry := &rekor_v1.TransparencyLogEntry{ 50 | LogIndex: int64(1), 51 | LogId: &common_v1.LogId{ 52 | KeyId: decodedLogID, 53 | }, 54 | IntegratedTime: int64(1661794812), 55 | CanonicalizedBody: []byte("foo"), 56 | InclusionPromise: &rekor_v1.InclusionPromise{}, 57 | } 58 | payload, err := verificationPayload(tlogEntry) 59 | if err != nil { 60 | t.Fatal(err) 61 | } 62 | jsonPayload, err := json.Marshal(payload) 63 | if err != nil { 64 | t.Fatal(err) 65 | } 66 | canonicalized, err := jsoncanonicalizer.Transform(jsonPayload) 67 | if err != nil { 68 | t.Fatal(err) 69 | } 70 | tlogEntry.InclusionPromise.SignedEntryTimestamp, err = signer.SignMessage(bytes.NewReader(canonicalized)) 71 | if err != nil { 72 | t.Fatal(err) 73 | } 74 | 75 | trustedKey := map[string]signature.Verifier{ 76 | logID: signer, 77 | } 78 | 79 | testCases := []struct { 80 | name string 81 | entry *rekor_v1.TransparencyLogEntry 82 | keys map[string]signature.Verifier 83 | wantErr bool 84 | }{ 85 | { 86 | name: "valid: valid tlog set", 87 | keys: trustedKey, 88 | entry: tlogEntry, 89 | }, 90 | { 91 | name: "fail: missing trusted tlog key", 92 | entry: tlogEntry, 93 | keys: map[string]signature.Verifier{}, 94 | wantErr: true, 95 | }, 96 | { 97 | name: "fail: missing entry log id", 98 | entry: &rekor_v1.TransparencyLogEntry{ 99 | LogIndex: int64(1), 100 | IntegratedTime: int64(1661794812), 101 | CanonicalizedBody: []byte("foo"), 102 | InclusionPromise: &rekor_v1.InclusionPromise{}, 103 | }, 104 | wantErr: true, 105 | }, 106 | { 107 | name: "fail: missing entry promise", 108 | entry: &rekor_v1.TransparencyLogEntry{ 109 | LogIndex: int64(1), 110 | LogId: &common_v1.LogId{ 111 | KeyId: decodedLogID, 112 | }, 113 | IntegratedTime: int64(1661794812), 114 | CanonicalizedBody: []byte("foo"), 115 | }, 116 | wantErr: true, 117 | }, 118 | { 119 | name: "fail: invalid signature", 120 | wantErr: true, 121 | entry: &rekor_v1.TransparencyLogEntry{ 122 | LogIndex: int64(1), 123 | LogId: &common_v1.LogId{ 124 | KeyId: decodedLogID, 125 | }, 126 | IntegratedTime: int64(1661794812), 127 | CanonicalizedBody: []byte("foo"), 128 | InclusionPromise: &rekor_v1.InclusionPromise{ 129 | SignedEntryTimestamp: []byte("foo"), 130 | }, 131 | }, 132 | }, 133 | } 134 | for _, tc := range testCases { 135 | tc := tc 136 | t.Run(tc.name, func(t *testing.T) { 137 | t.Parallel() 138 | ctx := context.Background() 139 | err := VerifyTlogSET(ctx, tc.entry, tc.keys) 140 | if err != nil { 141 | if !tc.wantErr { 142 | t.Errorf("VerifyTlogSET unexpectedly returned an error: %v", err) 143 | } 144 | return 145 | } 146 | if tc.wantErr { 147 | t.Errorf("VerifyTlogSET returned, expected error") 148 | } 149 | }) 150 | } 151 | } 152 | --------------------------------------------------------------------------------