pax_global_header00006660000000000000000000000064151165025670014522gustar00rootroot0000000000000052 comment=0dece9808f950ab15231004ba2ac0188c38a3887 golang-github-tink-crypto-tink-go-hcvault-2.4.0/000077500000000000000000000000001511650256700215475ustar00rootroot00000000000000golang-github-tink-crypto-tink-go-hcvault-2.4.0/LICENSE000066400000000000000000000261361511650256700225640ustar00rootroot00000000000000 Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. golang-github-tink-crypto-tink-go-hcvault-2.4.0/README.md000066400000000000000000000033641511650256700230340ustar00rootroot00000000000000# Tink Go HashiCorp Vault extension [tink_go_hcvault_gomod_badge_gcp_ubuntu]: https://storage.googleapis.com/tink-kokoro-build-badges/tink-go-hcvault-gomod-gcp-ubuntu.svg [tink_go_hcvault_gomod_badge_macos]: https://storage.googleapis.com/tink-kokoro-build-badges/tink-go-hcvault-gomod-macos-external.svg **Test** | **GCP Ubuntu** | **MacOS** -------- | --------------------------------------------------------------- | --------- Gomod | [![Gomod_GcpUbuntu][tink_go_hcvault_gomod_badge_gcp_ubuntu]](#) | [![Gomod_MacOs][tink_go_hcvault_gomod_badge_macos]](#) This is an extension to the [Tink Go](https://github.com/tink-crypto/tink-go) library that provides support for HashiCorp Vault. The latest version is 2.4.0. The official documentation is available at https://developers.google.com/tink. ## Contact and mailing list If you want to contribute, please read [CONTRIBUTING](docs/CONTRIBUTING.md) and send us pull requests. You can also report bugs or file feature requests. If you'd like to talk to the developers or get notified about major product updates, you may want to subscribe to our [mailing list](https://groups.google.com/forum/#!forum/tink-users). ## Maintainers Tink is maintained by (A-Z): - Moreno Ambrosin - Taymon Beal - William Conner - Thomas Holenstein - Stefan Kölbl - Charles Lee - Cindy Lin - Fernando Lobato Meeser - Ioana Nedelcu - Sophie Schmieg - Elizaveta Tretiakova - Jürg Wullschleger Alumni: - Haris Andrianakis - Daniel Bleichenbacher - Tanuj Dhir - Thai Duong - Atul Luykx - Rafael Misoczki - Quan Nguyen - Bartosz Przydatek - Enzo Puig - Laurent Simon - Veronika Slívová - Paula Vidas golang-github-tink-crypto-tink-go-hcvault-2.4.0/docs/000077500000000000000000000000001511650256700224775ustar00rootroot00000000000000golang-github-tink-crypto-tink-go-hcvault-2.4.0/docs/CONTRIBUTING.md000066400000000000000000000002151511650256700247260ustar00rootroot00000000000000# How to contribute Please see the [developer documentation](https://developers.google.com/tink/contributing) on how to contribute to Tink. golang-github-tink-crypto-tink-go-hcvault-2.4.0/docs/SECURITY.md000066400000000000000000000004131511650256700242660ustar00rootroot00000000000000To report a security issue, please use http://g.co/vulnz. We use http://g.co/vulnz for our intake and coordination, and disclose vulnerabilities using GitHub Security Advisory. The Google Security Team will respond within 5 working days of your report on g.co/vulnz. golang-github-tink-crypto-tink-go-hcvault-2.4.0/go.mod000066400000000000000000000023071511650256700226570ustar00rootroot00000000000000module github.com/tink-crypto/tink-go-hcvault/v2 go 1.24.0 toolchain go1.24.4 require ( github.com/hashicorp/vault/api v1.20.0 github.com/tink-crypto/tink-go/v2 v2.5.0 ) require ( github.com/cenkalti/backoff/v4 v4.3.0 // indirect github.com/go-jose/go-jose/v4 v4.0.5 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-cleanhttp v0.5.2 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect github.com/hashicorp/go-retryablehttp v0.7.7 // indirect github.com/hashicorp/go-rootcerts v1.0.2 // indirect github.com/hashicorp/go-secure-stdlib/parseutil v0.1.6 // indirect github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 // indirect github.com/hashicorp/go-sockaddr v1.0.2 // indirect github.com/hashicorp/hcl v1.0.1-vault-7 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/ryanuber/go-glob v1.0.0 // indirect golang.org/x/crypto v0.45.0 // indirect golang.org/x/net v0.47.0 // indirect golang.org/x/sys v0.38.0 // indirect golang.org/x/text v0.31.0 // indirect golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 // indirect google.golang.org/protobuf v1.36.8 // indirect ) golang-github-tink-crypto-tink-go-hcvault-2.4.0/go.sum000066400000000000000000000165221511650256700227100ustar00rootroot00000000000000github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8= github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= github.com/go-jose/go-jose/v4 v4.0.5 h1:M6T8+mKZl/+fNNuFHvGIzDz7BTLQPIounk/b9dw3AaE= github.com/go-jose/go-jose/v4 v4.0.5/go.mod h1:s3P1lRrkT8igV8D9OjyL4WRyHvjB6a4JSllnOrmmBOA= github.com/go-test/deep v1.0.2 h1:onZX1rnHT3Wv6cqNgYyFOOlgVKJrksuCMCRvJStbMYw= github.com/go-test/deep v1.0.2/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ= github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k= github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU= github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk= github.com/hashicorp/go-rootcerts v1.0.2 h1:jzhAVGtqPKbwpyCPELlgNWhE1znq+qwJtW5Oi2viEzc= github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8= github.com/hashicorp/go-secure-stdlib/parseutil v0.1.6 h1:om4Al8Oy7kCm/B86rLCLah4Dt5Aa0Fr5rYBG60OzwHQ= github.com/hashicorp/go-secure-stdlib/parseutil v0.1.6/go.mod h1:QmrqtbKuxxSWTN3ETMPuB+VtEiBJ/A9XhoYGv8E1uD8= github.com/hashicorp/go-secure-stdlib/strutil v0.1.1/go.mod h1:gKOamz3EwoIoJq7mlMIRBpVTAUn8qPCrEclOKKWhD3U= github.com/hashicorp/go-secure-stdlib/strutil v0.1.2 h1:kes8mmyCpxJsI7FTwtzRqEy9CdjCtrXrXGuOpxEA7Ts= github.com/hashicorp/go-secure-stdlib/strutil v0.1.2/go.mod h1:Gou2R9+il93BqX25LAKCLuM+y9U2T4hlwvT1yprcna4= github.com/hashicorp/go-sockaddr v1.0.2 h1:ztczhD1jLxIRjVejw8gFomI1BQZOe2WoVOu0SyteCQc= github.com/hashicorp/go-sockaddr v1.0.2/go.mod h1:rB4wwRAUzs07qva3c5SdrY/NEtAUjGlgmH/UkBUC97A= github.com/hashicorp/hcl v1.0.1-vault-7 h1:ag5OxFVy3QYTFTJODRzTKVZ6xvdfLLCA1cy/Y6xGI0I= github.com/hashicorp/hcl v1.0.1-vault-7/go.mod h1:XYhtn6ijBSAj6n4YqAaf7RBPS4I06AItNorpy+MoQNM= github.com/hashicorp/vault/api v1.20.0 h1:KQMHElgudOsr+IbJgmbjHnCTxEpKs9LnozA1D3nozU4= github.com/hashicorp/vault/api v1.20.0/go.mod h1:GZ4pcjfzoOWpkJ3ijHNpEoAxKEsBJnVljyTe3jM2Sms= github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-wordwrap v1.0.0/go.mod h1:ZXFpozHsX6DPmq2I0TCekCxypsnAUbP2oI0UX1GXzOo= github.com/mitchellh/mapstructure v1.4.1/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI= github.com/ryanuber/columnize v2.1.0+incompatible/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts= github.com/ryanuber/go-glob v1.0.0 h1:iQh3xXAumdQ+4Ufa5b25cRpC5TYKlno6hsv6Cb3pkBk= github.com/ryanuber/go-glob v1.0.0/go.mod h1:807d1WSdnB0XRJzKNil9Om6lcp/3a0v4qIHxIXzX/Yc= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/tink-crypto/tink-go/v2 v2.5.0 h1:B8KLF6AofxdBIE4UJIaFbmoj5/1ehEtt7/MmzfI4Zpw= github.com/tink-crypto/tink-go/v2 v2.5.0/go.mod h1:2WbBA6pfNsAfBwDCggboaHeB2X29wkU8XHtGwh2YIk8= golang.org/x/crypto v0.45.0 h1:jMBrvKuj23MTlT0bQEOBcAE0mjg8mK9RXFhRH6nyF3Q= golang.org/x/crypto v0.45.0/go.mod h1:XTGrrkGJve7CYK7J8PEww4aY7gM3qMCElcJQ8n8JdX4= golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY= golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc= golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks= golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM= golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM= golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 h1:NusfzzA6yGQ+ua51ck7E3omNUX/JuqbFSaRGqU8CcLI= golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= google.golang.org/protobuf v1.36.8 h1:xHScyCOEuuwZEc6UtSOvPbAT4zRh0xcNRYekJwfqyMc= google.golang.org/protobuf v1.36.8/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= golang-github-tink-crypto-tink-go-hcvault-2.4.0/integration/000077500000000000000000000000001511650256700240725ustar00rootroot00000000000000golang-github-tink-crypto-tink-go-hcvault-2.4.0/integration/hcvault/000077500000000000000000000000001511650256700255405ustar00rootroot00000000000000golang-github-tink-crypto-tink-go-hcvault-2.4.0/integration/hcvault/hcvault_aead.go000066400000000000000000000136411511650256700305140ustar00rootroot00000000000000// Copyright 2019 Google Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package hcvault import ( "encoding/base64" "errors" "fmt" "strings" "github.com/hashicorp/vault/api" "github.com/tink-crypto/tink-go/v2/tink" ) // vaultAEAD represents a HashiCorp Vault service to a particular URI. type vaultAEAD struct { encKeyPath string decKeyPath string client *api.Logical associatedDataName string } var _ tink.AEAD = (*vaultAEAD)(nil) const ( encryptSegment = "encrypt" decryptSegment = "decrypt" defaultAssociatedDataName = "associated_data" legacyAssociatedDataName = "context" ) type aeadParams struct { associatedDataName string } // AEADOption is an interface for defining options that are passed to [NewAEAD]. type AEADOption interface{ set(*aeadParams) error } type option func(*aeadParams) error func (o option) set(a *aeadParams) error { return o(a) } // WithLegacyContextParamater lets the remote AEAD populate the "context" parameter // in encrypt and decrypt requests instead of the "associated_data". // // Using this option makes the AEAD compatible with the instance returned by GetAEAD // from the KMSClient returned by NewClient. For new keys, this option should not be used. // // ## Warning // // Vault only uses the "context" parameter for keys which have derivation enabled // (with "derived=true") and ignores it otherwise. For such keys, the "context" // parameter is required to be non-empty. // // Therefore: // // - for keys with "derived=false", you should only use empty associated data. // // - for keys with "derived=true", you should only use non-empty associated data. // // With Tink's "KMS envelope AEAD", always use a key with "derived=false". // // For reference, see https://developer.hashicorp.com/vault/api-docs/secret/transit. func WithLegacyContextParamater() AEADOption { return option(func(a *aeadParams) error { a.associatedDataName = legacyAssociatedDataName return nil }) } // NewAEAD returns a new remote AEAD primitive for a HashiCorp Vault service. func NewAEAD(keyPath string, client *api.Logical, opts ...AEADOption) (tink.AEAD, error) { params := &aeadParams{ associatedDataName: defaultAssociatedDataName, } // Process options, if any. for _, opt := range opts { if err := opt.set(params); err != nil { return nil, fmt.Errorf("failed setting option: %v", err) } } encKeyPath, decKeyPath, err := getEndpointPaths(keyPath) if err != nil { return nil, err } a := &vaultAEAD{ encKeyPath: encKeyPath, decKeyPath: decKeyPath, client: client, associatedDataName: params.associatedDataName, } return a, nil } func extractCiphertext(secret *api.Secret) ([]byte, error) { if secret == nil { return nil, errors.New("secret is nil") } c, ok := secret.Data["ciphertext"] if !ok { return nil, errors.New("no ciphertext") } ciphertext, ok := c.(string) if !ok { return nil, errors.New("invalid ciphertext") } if len(ciphertext) == 0 { return nil, errors.New("empty ciphertext") } return []byte(ciphertext), nil } // Encrypt encrypts the plaintext data using a key stored in HashiCorp Vault. func (a *vaultAEAD) Encrypt(plaintext, associatedData []byte) ([]byte, error) { // Create an encryption request map according to Vault REST API: // https://www.vaultproject.io/api/secret/transit/index.html#encrypt-data. req := map[string]any{ "plaintext": base64.StdEncoding.EncodeToString(plaintext), a.associatedDataName: base64.StdEncoding.EncodeToString(associatedData), } secret, err := a.client.Write(a.encKeyPath, req) if err != nil { return nil, err } return extractCiphertext(secret) } func extractPlaintext(secret *api.Secret) ([]byte, error) { // Note that when a valid ciphertext of the empty string is decrypted, // secret.Data["plaintext"] may not be set. So we allow that. if secret == nil { return []byte{}, nil } p, ok := secret.Data["plaintext"] if !ok { return []byte{}, nil } plaintext64, ok := p.(string) if !ok { return nil, errors.New("invalid plaintext") } plaintext, err := base64.StdEncoding.DecodeString(plaintext64) if err != nil { return nil, err } return plaintext, nil } // Decrypt decrypts the ciphertext using a key stored in HashiCorp Vault. func (a *vaultAEAD) Decrypt(ciphertext, associatedData []byte) ([]byte, error) { // Create a decryption request map according to Vault REST API: // https://www.vaultproject.io/api/secret/transit/index.html#decrypt-data. req := map[string]any{ "ciphertext": string(ciphertext), a.associatedDataName: base64.StdEncoding.EncodeToString(associatedData), } secret, err := a.client.Write(a.decKeyPath, req) if err != nil { return nil, err } return extractPlaintext(secret) } // getEndpointPaths transforms keyPath into the Vault transit encrypt and decrypt // paths. The keyPath is expected to have the form "/{mount-path}/keys/{keyName}", which will // be transformed to // "{mount-path}/encrypt/{keyName}" and "{mount-path}/decrypt/{keyName}". func getEndpointPaths(keyPath string) (encryptPath, decryptPath string, err error) { parts := strings.Split(keyPath, "/") length := len(parts) if length < 4 || parts[0] != "" || parts[length-2] != "keys" { return "", "", errors.New("malformed keyPath") } parts[length-2] = encryptSegment encryptPath = strings.Join(parts[1:], "/") parts[length-2] = decryptSegment decryptPath = strings.Join(parts[1:], "/") return encryptPath, decryptPath, nil } golang-github-tink-crypto-tink-go-hcvault-2.4.0/integration/hcvault/hcvault_aead_internal_test.go000066400000000000000000000114461511650256700334500ustar00rootroot00000000000000// Copyright 2023 Google LLC // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package hcvault import ( "bytes" "testing" "github.com/hashicorp/vault/api" ) func TestGetEndpointPaths(t *testing.T) { for _, tc := range []struct { desc string path string enc string dec string err string }{ { desc: "simple", path: "/transit/keys/foo", enc: "transit/encrypt/foo", dec: "transit/decrypt/foo", }, { desc: "escaped", path: "/transit/keys/this%2Band+that", enc: "transit/encrypt/this%2Band+that", dec: "transit/decrypt/this%2Band+that", }, { desc: "sub-path", path: "/teams/billing/something/transit/keys/pci-key", enc: "teams/billing/something/transit/encrypt/pci-key", dec: "teams/billing/something/transit/decrypt/pci-key", }, { desc: "transit-twice", path: "/transit/keys/something/transit/keys/my-key", enc: "transit/keys/something/transit/encrypt/my-key", dec: "transit/keys/something/transit/decrypt/my-key", }, { desc: "mount-not-named-transit", path: "/cipher/keys/hi", enc: "cipher/encrypt/hi", dec: "cipher/decrypt/hi", }, { desc: "no leading slash", path: "transit/keys/foo", err: "malformed keyPath", }, { desc: "empty", path: "", err: "malformed keyPath", }, { desc: "slash-only", path: "/", err: "malformed keyPath", }, { desc: "not-transit", path: "/foo/bar/baz", err: "malformed keyPath", }, { desc: "not-end-of-path", path: "/transit/keys/bar/baz", err: "malformed keyPath", }, } { t.Run(tc.desc, func(t *testing.T) { encPath, decPath, err := getEndpointPaths(tc.path) if err == nil { if tc.err != "" { t.Errorf("getEndpointPaths(%q) err is nil, want %q", tc.path, tc.err) } } else { if tc.err != err.Error() { t.Errorf("getEndpointPaths(%q) err = %v; want %q", tc.path, err, tc.err) } } if encPath != tc.enc { t.Errorf("getEndpointPaths(%q) encryptPath = %q, want %q", tc.path, encPath, tc.enc) } if decPath != tc.dec { t.Errorf("getEndpointPaths(%q) decryptPath = %q, want %q", tc.path, decPath, tc.dec) } }) } } func TestExtractCiphertextFails(t *testing.T) { for _, tc := range []struct { desc string secret *api.Secret }{ { desc: "nil", secret: nil, }, { desc: "empty data", secret: &api.Secret{ Data: map[string]any{}, }, }, { desc: "empty ciphertext", secret: &api.Secret{ Data: map[string]any{"ciphertext": ""}, }, }, { desc: "wrong type", secret: &api.Secret{ Data: map[string]any{"ciphertext": 123}, }, }, } { t.Run(tc.desc, func(t *testing.T) { _, err := extractCiphertext(tc.secret) if err == nil { t.Error("extractCiphertext() err is nil, want error") } }) } } func TestExtractCiphertextWorks(t *testing.T) { secret := &api.Secret{ Data: map[string]any{"ciphertext": "ciphertext"}, } got, err := extractCiphertext(secret) if err != nil { t.Fatalf("extractCiphertext() err = %q, want nil", err) } want := []byte("ciphertext") if !bytes.Equal(got, want) { t.Errorf("extractCiphertext() = %q, want %q", got, want) } } func TestExtractPlaintextFails(t *testing.T) { for _, tc := range []struct { desc string secret *api.Secret }{ { desc: "wrong type", secret: &api.Secret{ Data: map[string]any{"plaintext": 123}, }, }, } { t.Run(tc.desc, func(t *testing.T) { _, err := extractPlaintext(tc.secret) if err == nil { t.Error("extractPlaintext() err is nil, want error") } }) } } func TestExtractPlaintextWorks(t *testing.T) { for _, tc := range []struct { desc string secret *api.Secret want []byte }{ { desc: "normal", secret: &api.Secret{ Data: map[string]any{"plaintext": "cGxhaW50ZXh0"}, }, want: []byte("plaintext"), }, { desc: "empty plaintext", secret: &api.Secret{ Data: map[string]any{"plaintext": ""}, }, want: []byte{}, }, { desc: "empty data", secret: &api.Secret{ Data: map[string]any{}, }, want: []byte{}, }, } { t.Run(tc.desc, func(t *testing.T) { got, err := extractPlaintext(tc.secret) if err != nil { t.Fatalf("extractPlaintext() err = %q, want nil", err) } if !bytes.Equal(got, tc.want) { t.Errorf("extractPlaintext() = %q, want %q", got, tc.want) } }) } } golang-github-tink-crypto-tink-go-hcvault-2.4.0/integration/hcvault/hcvault_aead_test.go000066400000000000000000000403341511650256700315520ustar00rootroot00000000000000// Copyright 2019 Google Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package hcvault_test import ( "bytes" "crypto/tls" "crypto/x509" "encoding/base64" "encoding/json" "fmt" "net/http" "net/http/httptest" "strings" "testing" vault_api "github.com/hashicorp/vault/api" "github.com/tink-crypto/tink-go-hcvault/v2/integration/hcvault" ) const ( keyURITmpl = "%s/transit/keys/key-1" token = "mytoken" ) func TestVaultNewAEAD_EncryptDecrypt(t *testing.T) { server, _, tlsConfig := newServer(t) defer server.Close() client := newVaultAPIClient(t, server.URL, token, tlsConfig) aead, err := hcvault.NewAEAD("/transit/keys/key-1", client.Logical()) if err != nil { t.Fatalf("hcvault.NewAEAD() err = %v, want nil", err) } plaintext := []byte("plaintext") associatedData := []byte("associatedData") ciphertext, err := aead.Encrypt(plaintext, associatedData) if err != nil { t.Fatalf("aead.Encrypt(plaintext, associatedData) err = %v, want nil", err) } gotPlaintext, err := aead.Decrypt(ciphertext, associatedData) if err != nil { t.Fatalf("aead.Decrypt(ciphertext, associatedData) err = %v, want nil", err) } if !bytes.Equal(gotPlaintext, plaintext) { t.Errorf("aead.Decrypt(ciphertext, associatedData) = %s, want %s", gotPlaintext, plaintext) } otherAssociatedData := []byte("otherAssociatedData") _, err = aead.Decrypt(ciphertext, otherAssociatedData) if err == nil { t.Error("aead.Decrypt(ciphertext, otherAssociatedData) err = nil, want error") } } func TestVaultNewClientWithAEADOptions_EncryptDecrypt(t *testing.T) { server, uriPrefix, tlsConfig := newServer(t) defer server.Close() client := newVaultAPIClient(t, server.URL, token, tlsConfig) keyURI := uriPrefix + "/transit/keys/key-1" tinkClient, err := hcvault.NewClientWithAEADOptions(keyURI, client.Logical()) if err != nil { t.Fatalf("hcvault.NewClientWithAEADOptions() err = %v, want nil", err) } aead, err := tinkClient.GetAEAD(keyURI) if err != nil { t.Fatalf("tinkClient.GetAEAD() err = %v, want nil", err) } plaintext := []byte("plaintext") associatedData := []byte("associatedData") ciphertext, err := aead.Encrypt(plaintext, associatedData) if err != nil { t.Fatalf("aead.Encrypt(plaintext, associatedData) err = %v, want nil", err) } gotPlaintext, err := aead.Decrypt(ciphertext, associatedData) if err != nil { t.Fatalf("aead.Decrypt(ciphertext, associatedData) err = %v, want nil", err) } if !bytes.Equal(gotPlaintext, plaintext) { t.Fatalf("aead.Decrypt(ciphertext, associatedData) = %s, want %s", gotPlaintext, plaintext) } otherAssociatedData := []byte("otherAssociatedData") _, err = aead.Decrypt(ciphertext, otherAssociatedData) if err == nil { t.Error("aead.Decrypt(ciphertext, otherAssociatedData) err = nil, want error") } } func TestVaultNewAEAD_DecryptWithFixedCiphertext(t *testing.T) { server, _, tlsConfig := newServer(t) defer server.Close() client := newVaultAPIClient(t, server.URL, token, tlsConfig) aead, err := hcvault.NewAEAD("/transit/keys/key-1", client.Logical()) if err != nil { t.Fatalf("hcvault.NewAEAD() err = %v, want nil", err) } // associatedData is passed as "context" parameter to vault decrypt. plaintext := []byte("plaintext") associatedData := []byte("associatedData") ciphertext := fakeEncrypt(plaintext, associatedData, nil) gotPlaintext, err := aead.Decrypt(ciphertext, associatedData) if err != nil { t.Fatalf("aead.Decrypt(ciphertext, associatedData) err = %v, want nil", err) } if !bytes.Equal(gotPlaintext, plaintext) { t.Fatalf("aead.Decrypt(ciphertext, associatedData) = %s, want %s", gotPlaintext, associatedData) } } func TestVaultNewAEADWithLegacyContextParamater_isCompatible(t *testing.T) { server, uriPrefix, tlsConfig := newServer(t) defer server.Close() client := newVaultAPIClient(t, server.URL, token, tlsConfig) // Create AEAD with NewAEAD using WithLegacyContextParamater. aead1, err := hcvault.NewAEAD("/transit/keys/key-1", client.Logical(), hcvault.WithLegacyContextParamater()) if err != nil { t.Fatalf("hcvault.NewAEAD() err = %v, want nil", err) } keyURI := uriPrefix + "/transit/keys/key-1" // Create AEAD with hcvault.NewClientWithAEADOptions using WithLegacyContextParamater and GetAEAD. hcvaultClient2, err := hcvault.NewClientWithAEADOptions( uriPrefix, client.Logical(), hcvault.WithLegacyContextParamater()) if err != nil { t.Fatalf("hcvault.NewClientWithAEADOptions() err = %v, want nil", err) } aead2, err := hcvaultClient2.GetAEAD(keyURI) if err != nil { t.Fatalf("hcvaultClient2.GetAEAD(%q) err = %v, want nil", keyURI, err) } // Create AEAD with hcvault.NewClient and GetAEAD. hcvaultClient3, err := hcvault.NewClient(uriPrefix, tlsConfig, token) if err != nil { t.Fatalf("hcvault.NewClient() err = %v, want nil", err) } aead3, err := hcvaultClient3.GetAEAD(keyURI) if err != nil { t.Fatalf("hcvaultClient3.GetAEAD(%q) err = %v, want nil", keyURI, err) } plaintext := []byte("plaintext") associatedData := []byte("associatedData") ciphertext2, err := aead2.Encrypt(plaintext, associatedData) if err != nil { t.Fatalf("aead2.Encrypt(plaintext, associatedData) err = %v, want nil", err) } gotPlaintext1, err := aead1.Decrypt(ciphertext2, associatedData) if err != nil { t.Fatalf("aead1.Decrypt(ciphertext2, associatedData) err = %v, want nil", err) } if !bytes.Equal(gotPlaintext1, plaintext) { t.Fatalf("aead1.Decrypt(ciphertext2, associatedData) = %s, want %s", gotPlaintext1, plaintext) } ciphertext3, err := aead3.Encrypt(plaintext, associatedData) if err != nil { t.Fatalf("aead2.Encrypt(plaintext, associatedData) err = %v, want nil", err) } gotPlaintext2, err := aead2.Decrypt(ciphertext3, associatedData) if err != nil { t.Fatalf("aead2.Decrypt(ciphertext3, associatedData) err = %v, want nil", err) } if !bytes.Equal(gotPlaintext2, plaintext) { t.Fatalf("aead2.Decrypt(ciphertext3, associatedData) = %s, want %s", gotPlaintext2, plaintext) } ciphertext1, err := aead1.Encrypt(plaintext, associatedData) if err != nil { t.Fatalf("aead2.Encrypt(plaintext, associatedData) err = %v, want nil", err) } gotPlaintext3, err := aead3.Decrypt(ciphertext1, associatedData) if err != nil { t.Fatalf("aead2.Decrypt(ciphertext1, associatedData) err = %v, want nil", err) } if !bytes.Equal(gotPlaintext3, plaintext) { t.Fatalf("aead2.Decrypt(ciphertext1, associatedData) = %s, want %s", gotPlaintext2, plaintext) } } func TestVaultClientAEAD_EncryptDecrypt(t *testing.T) { server, uriPrefix, tlsConfig := newServer(t) defer server.Close() client, err := hcvault.NewClient(uriPrefix, tlsConfig, token) if err != nil { t.Fatalf("hcvault.NewClient() err = %v, want nil", err) } keyURI := fmt.Sprintf(keyURITmpl, uriPrefix) aead, err := client.GetAEAD(keyURI) if err != nil { t.Fatalf("client.GetAEAD(%q) err = %v, want nil", keyURI, err) } plaintext := []byte("plaintext") context := []byte("context") ciphertext, err := aead.Encrypt(plaintext, context) if err != nil { t.Fatalf("aead.Encrypt(plaintext, context) err = %v, want nil", err) } gotPlaintext, err := aead.Decrypt(ciphertext, context) if err != nil { t.Fatalf("aead.Decrypt(ciphertext, context) err = %v, want nil", err) } if !bytes.Equal(gotPlaintext, plaintext) { t.Fatalf("aead.Decrypt(ciphertext, context) = %s, want %s", gotPlaintext, plaintext) } invalidContext := []byte("invalidContext") _, err = aead.Decrypt(ciphertext, invalidContext) if err == nil { t.Error("aead.Decrypt(ciphertext, invalidContext) err = nil, want error") } } func TestVaultClientAEAD_DecryptWithFixedCiphertext(t *testing.T) { server, uriPrefix, tlsConfig := newServer(t) defer server.Close() client, err := hcvault.NewClient(uriPrefix, tlsConfig, token) if err != nil { t.Fatalf("hcvault.NewClient() err = %v, want nil", err) } keyURI := fmt.Sprintf(keyURITmpl, uriPrefix) aead, err := client.GetAEAD(keyURI) if err != nil { t.Fatalf("client.GetAEAD(%q) err = %v, want nil", keyURI, err) } // associatedData is passed as "context" parameter to vault decrypt. plaintext := []byte("plaintext") context := []byte("context") ciphertext := fakeEncrypt(plaintext, nil, context) gotPlaintext, err := aead.Decrypt(ciphertext, context) if err != nil { t.Fatalf("aead.Decrypt(ciphertext, context) err = %v, want nil", err) } if !bytes.Equal(gotPlaintext, plaintext) { t.Fatalf("aead.Decrypt(ciphertext, context) = %s, want %s", gotPlaintext, plaintext) } } func TestGetAEADFailWithBadKeyURI(t *testing.T) { server, uriPrefix, tlsConfig := newServer(t) defer server.Close() client, err := hcvault.NewClient(uriPrefix, tlsConfig, token) if err != nil { t.Fatalf("hcvault.NewClient() err = %v, want nil", err) } for _, test := range []struct { name string keyURI string }{ { name: "empty", keyURI: fmt.Sprintf("%s/", uriPrefix), }, { name: "without slash", keyURI: fmt.Sprintf("%s/badKeyUri", uriPrefix), }, { name: "with one slash", keyURI: fmt.Sprintf("%s/bad/KeyUri", uriPrefix), }, { name: "with three slash", keyURI: fmt.Sprintf("%s/one/two/three/four", uriPrefix), }, } { t.Run(test.name, func(t *testing.T) { if _, err := client.GetAEAD(test.keyURI); err == nil { t.Errorf("client.GetAEAD(%q) err = nil, want error", test.keyURI) } }) } } // newVaultAPIClient creates a new vault API client func newVaultAPIClient(t *testing.T, url string, token string, tlsConfig *tls.Config) *vault_api.Client { t.Helper() httpClient := vault_api.DefaultConfig().HttpClient transport := httpClient.Transport.(*http.Transport) transport.TLSClientConfig = tlsConfig.Clone() cfg := &vault_api.Config{ Address: url, HttpClient: httpClient, } client, err := vault_api.NewClient(cfg) if err != nil { t.Fatal(err) } client.SetToken(token) return client } type closeFunc func() error // newServer returns a fake, TLS-enabled Vault server, an "hcvault://" URI // prefix for accessing it, and a TLS configuration which trusts the servers // certificate. // // Once finished with the server, it's Close() method should be called. // // The URL and TLS configuration can be passed to hcvault.NewClient(). // // The URL can also be used to construct valid key URIs for the server. func newServer(t *testing.T) (server *httptest.Server, uriPrefix string, clientTLSConfig *tls.Config) { server = httptest.NewTLSServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { switch r.RequestURI { // Encrypt case "/v1/transit/encrypt/key-1": decoder := json.NewDecoder(r.Body) var encReq = make(map[string]string) if err := decoder.Decode(&encReq); err != nil { http.Error(w, fmt.Sprintf("Cannot decode encryption request: %s", err), 400) return } plaintext, err := base64.StdEncoding.DecodeString(encReq["plaintext"]) if err != nil { http.Error(w, "plaintext must be base64 encoded", 400) return } context, err := base64.StdEncoding.DecodeString(encReq["context"]) if err != nil { http.Error(w, "context must be base64 encoded", 400) return } associatedData, err := base64.StdEncoding.DecodeString(encReq["associated_data"]) if err != nil { http.Error(w, "associated_data must be base64 encoded", 400) return } ciphertext := fakeEncrypt(plaintext, associatedData, context) resp := map[string]any{ "data": map[string]string{ "ciphertext": string(ciphertext), }, } respBytes, err := json.Marshal(resp) if err != nil { t.Fatalf("Cannot encode encrypted data: %v", err) } if _, err := w.Write(respBytes); err != nil { t.Fatalf("Cannot send encrypted data response: %v", err) } // Decrypt case "/v1/transit/decrypt/key-1": decoder := json.NewDecoder(r.Body) var decReq = make(map[string]string) if err := decoder.Decode(&decReq); err != nil { http.Error(w, fmt.Sprintf("Cannot decode decryption request: %s", err), 400) return } ciphertext := []byte(decReq["ciphertext"]) context, err := base64.StdEncoding.DecodeString(decReq["context"]) if err != nil { http.Error(w, "context must be base64 encoded", 400) return } associatedData, err := base64.StdEncoding.DecodeString(decReq["associated_data"]) if err != nil { http.Error(w, "associated_data must be base64 encoded", 400) return } plaintext, err := fakeDecrypt(ciphertext, associatedData, context) if err != nil { http.Error(w, fmt.Sprintf("Cannot decrypt ciphertext: %s", err), 400) return } resp := map[string]any{ "data": map[string]string{ "plaintext": base64.StdEncoding.EncodeToString(plaintext), }, } respBytes, err := json.Marshal(resp) if err != nil { t.Fatalf("Cannot encode encrypted data: %v", err) } if _, err := w.Write(respBytes); err != nil { t.Fatalf("Cannot send encrypted data response: %v", err) } default: http.NotFound(w, r) } })) uriPrefix = strings.Replace(server.URL, "https", "hcvault", 1) certpool := x509.NewCertPool() certpool.AddCert(server.Certificate()) clientTLSConfig = &tls.Config{RootCAs: certpool} return server, uriPrefix, clientTLSConfig } // The ciphertext returned by HC Vault is of the form: // // vault:v1: // // where ciphertext is base64-encoded. See: // https://developer.hashicorp.com/vault/api-docs/secret/transit#sample-request-13 // // The ciphertext returned by this fake implementation is of the form: // // enc::: // // where context, associatedData and plaintext are base64-encoded. // It is deterministic and not secure. func fakeEncrypt(plaintext, associatedData, context []byte) []byte { s := fmt.Sprintf( "enc:%s:%s:%s", base64.StdEncoding.EncodeToString(context), base64.StdEncoding.EncodeToString(associatedData), base64.StdEncoding.EncodeToString(plaintext), ) return []byte(s) } func TestFakeEncrypt(t *testing.T) { want := []byte("enc:Y29udGV4dA==:YXNzb2NpYXRlZERhdGE=:cGxhaW50ZXh0") got := fakeEncrypt([]byte("plaintext"), []byte("associatedData"), []byte("context")) if !bytes.Equal(got, want) { t.Errorf("fakeEncrypt(plaintext, associatedData, context) = %q, want %q", got, want) } } func TestFakeEncryptWithoutAssociatedData(t *testing.T) { want := []byte("enc:Y29udGV4dA==::cGxhaW50ZXh0") got := fakeEncrypt([]byte("plaintext"), nil, []byte("context")) if !bytes.Equal(got, want) { t.Errorf("fakeEncrypt(plaintext, nil, context) = %q, want %q", got, want) } } func TestFakeEncryptWithoutContext(t *testing.T) { want := []byte("enc::YXNzb2NpYXRlZERhdGE=:cGxhaW50ZXh0") got := fakeEncrypt([]byte("plaintext"), []byte("associatedData"), nil) if !bytes.Equal(got, want) { t.Errorf("fakeEncrypt(plaintext, associatedData, nil) = %q, want %q", got, want) } } func fakeDecrypt(ciphertext, associatedData, context []byte) ([]byte, error) { ct := string(ciphertext) parts := strings.Split(ct, ":") if len(parts) != 4 || parts[0] != "enc" { return nil, fmt.Errorf("malformed ciphertext: %s", ciphertext) } context2, err := base64.StdEncoding.DecodeString(parts[1]) if err != nil { return nil, err } if !bytes.Equal(context, context2) { return nil, fmt.Errorf("invalid context: %s != %s", context2, context) } associatedData2, err := base64.StdEncoding.DecodeString(parts[2]) if err != nil { return nil, err } if !bytes.Equal(associatedData2, associatedData) { return nil, fmt.Errorf("invalid associatedData: %s != %s", associatedData2, associatedData) } plaintext, err := base64.StdEncoding.DecodeString(parts[3]) if err != nil { return nil, err } return plaintext, nil } func TestFakeEncryptDecrypt(t *testing.T) { ciphertext := fakeEncrypt([]byte("plaintext"), []byte("associatedData"), []byte("context")) got, err := fakeDecrypt(ciphertext, []byte("associatedData"), []byte("context")) if err != nil { t.Errorf("fakeDecrypt() err = %v, want nil", err) } if want := []byte("plaintext"); !bytes.Equal(got, want) { t.Errorf("fakeDecrypt() = %q, want %q", got, want) } } ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������golang-github-tink-crypto-tink-go-hcvault-2.4.0/integration/hcvault/hcvault_client.go���������������0000664�0000000�0000000�00000010050�15116502567�0031067�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������// Copyright 2019 Google Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. // Package hcvault provides integration with the [HashiCorp Vault]. // // [HashiCorp Vault]: https://www.vaultproject.io/. package hcvault import ( "crypto/tls" "errors" "fmt" "net/http" "net/url" "strings" "github.com/hashicorp/vault/api" "github.com/tink-crypto/tink-go/v2/core/registry" "github.com/tink-crypto/tink-go/v2/tink" ) const ( vaultPrefix = "hcvault://" ) // vaultClient represents a client that connects to the HashiCorp Vault backend. type vaultClient struct { keyURIPrefix string client *api.Logical aeadOpts []AEADOption } var _ registry.KMSClient = (*vaultClient)(nil) // NewClientWithAEADOptions returns a new client. // uriPrefix parameter is a valid URI which must have "hcvault" scheme and // vault server address and port. Specific key URIs will be matched against this // prefix to determine if the client supports the key or not. func NewClientWithAEADOptions(uriPrefix string, client *api.Logical, aeadOpts ...AEADOption) (registry.KMSClient, error) { if !strings.HasPrefix(strings.ToLower(uriPrefix), vaultPrefix) { return nil, fmt.Errorf("key URI must start with %s", vaultPrefix) } return &vaultClient{ keyURIPrefix: uriPrefix, client: client, aeadOpts: aeadOpts, }, nil } // NewClient returns a new client to HashiCorp Vault. // // # Warning regarding associated data // // For backwards compatibility, the AEAD implementation returned by this client // uses the associated_data value to populate the "context" parameter in encrypt // and decrypt requests, instead of using the "associated_data" request parameter. // This is an artifact of the "associated_data" parameter not being present when // this package was implemented. // // Vault only uses the "context" parameter for keys which have derivation enabled // (with "derived=true") and ignores it otherwise. For such keys, the "context" // parameter is required to be non-empty. // // Therefore: // - for keys with "derived=false", you should only use empty associated data. // - for keys with "derived=true", you should only use non-empty associated data. // // With Tink's "KMS envelope AEAD", always use a key with "derived=false". // // For reference, see https://developer.hashicorp.com/vault/api-docs/secret/transit. // // Deprecated. Use NewClientWithAEADOptions instead. func NewClient(uriPrefix string, tlsCfg *tls.Config, token string) (registry.KMSClient, error) { httpClient := api.DefaultConfig().HttpClient transport := httpClient.Transport.(*http.Transport) if tlsCfg == nil { tlsCfg = &tls.Config{} } else { tlsCfg = tlsCfg.Clone() } transport.TLSClientConfig = tlsCfg vurl, err := url.Parse(uriPrefix) if err != nil { return nil, err } cfg := &api.Config{ Address: "https://" + vurl.Host, HttpClient: httpClient, } client, err := api.NewClient(cfg) if err != nil { return nil, err } client.SetToken(token) return NewClientWithAEADOptions(uriPrefix, client.Logical(), WithLegacyContextParamater()) } // Supported returns true if this client does support keyURI. func (c *vaultClient) Supported(keyURI string) bool { return strings.HasPrefix(keyURI, c.keyURIPrefix) } // GetAEAD gets an AEAD backed by keyURI. func (c *vaultClient) GetAEAD(keyURI string) (tink.AEAD, error) { if !c.Supported(keyURI) { return nil, errors.New("unsupported keyURI") } u, err := url.Parse(keyURI) if err != nil || u.Scheme != "hcvault" { return nil, errors.New("malformed keyURI") } keyPath := u.EscapedPath() return NewAEAD(keyPath, c.client, c.aeadOpts...) } ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������golang-github-tink-crypto-tink-go-hcvault-2.4.0/integration/hcvault/hcvault_client_test.go����������0000664�0000000�0000000�00000004017�15116502567�0032134�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������// Copyright 2019 Google Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package hcvault_test import ( "crypto/tls" "log" "net/http" "github.com/hashicorp/vault/api" "github.com/tink-crypto/tink-go/v2/aead" "github.com/tink-crypto/tink-go-hcvault/v2/integration/hcvault" ) func Example() { const keyURI = "hcvault://hcvault.corp.com:8200/transit/keys/key-1" httpClient := api.DefaultConfig().HttpClient transport := httpClient.Transport.(*http.Transport) transport.TLSClientConfig = tlsConfig() cfg := &api.Config{ Address: "https://hcvault.corp.com:8200", HttpClient: httpClient, } apiClient, err := api.NewClient(cfg) if err != nil { log.Fatal(err) } apiClient.SetToken(vaultToken()) kmsClient, err := hcvault.NewClientWithAEADOptions(keyURI, apiClient.Logical()) if err != nil { log.Fatal(err) } kekAEAD, err := kmsClient.GetAEAD(keyURI) if err != nil { log.Fatal(err) } dekTemplate := aead.AES128CTRHMACSHA256KeyTemplate() a := aead.NewKMSEnvelopeAEAD2(dekTemplate, kekAEAD) if err != nil { log.Fatal(err) } if err != nil { log.Fatal(err) } plaintext := []byte("plaintext") associatedData := []byte("associatedData") ciphertext, err := a.Encrypt(plaintext, associatedData) if err != nil { log.Fatal(err) } _, err = a.Decrypt(ciphertext, associatedData) if err != nil { log.Fatal(err) } } func tlsConfig() *tls.Config { // Return a TLS configuration used to communicate with Vault server via HTTPS. return nil } func vaultToken() string { return "" // Your Vault token. } �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������golang-github-tink-crypto-tink-go-hcvault-2.4.0/kokoro/���������������������������������������������0000775�0000000�0000000�00000000000�15116502567�0023053�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������golang-github-tink-crypto-tink-go-hcvault-2.4.0/kokoro/create_github_release_branch.sh��������������0000664�0000000�0000000�00000004373�15116502567�0031240�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������#!/bin/bash # Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ################################################################################ set -euo pipefail # Fail if RELEASE_VERSION is not set. if [[ -z "${RELEASE_VERSION:-}" ]]; then echo "RELEASE_VERSION must be set" >&2 exit 1 fi IS_KOKORO="false" if [[ -n "${KOKORO_ARTIFACTS_DIR:-}" ]]; then IS_KOKORO="true" fi readonly IS_KOKORO # If not defined, default to /tmp. : "${TMPDIR:="/tmp"}" # WARNING: Setting this environment varialble to "true" will cause this script # to actually perform a release. : "${DO_MAKE_RELEASE:="false"}" if [[ ! "${DO_MAKE_RELEASE}" =~ ^(false|true)$ ]]; then echo "DO_MAKE_RELEASE must be either \"true\" or \"false\"" >&2 exit 1 fi if [[ "${IS_KOKORO}" == "true" ]] ; then readonly TINK_BASE_DIR="$(echo "${KOKORO_ARTIFACTS_DIR}"/git*)" cd "${TINK_BASE_DIR}/tink_go_hcvault" fi GITHUB_RELEASE_UTIL_OPTS=() if [[ "${IS_KOKORO}" == "true" ]] ; then # Note: KOKORO_GIT_COMMIT is populated by Kokoro. GITHUB_RELEASE_UTIL_OPTS+=( -c "${KOKORO_GIT_COMMIT}" -t "${GITHUB_ACCESS_TOKEN}" ) fi if [[ "${DO_MAKE_RELEASE}" == "true" ]]; then GITHUB_RELEASE_UTIL_OPTS+=( -r ) fi readonly GITHUB_RELEASE_UTIL_OPTS # If running on Kokoro, TMPDIR is populated with the tmp folder. readonly TMP_DIR="$(mktemp -d "${TMPDIR}/release_XXXXXX")" readonly RELEASE_UTIL_SCRIPT="$(pwd)/kokoro/testutils/github_release_util.sh" if [[ ! -f "${RELEASE_UTIL_SCRIPT}" ]]; then echo "${RELEASE_UTIL_SCRIPT} not found." echo "Make sure you run this script from the root of tink-go-hcvault." return 1 fi pushd "${TMP_DIR}" # Create a release branch. "${RELEASE_UTIL_SCRIPT}" "${GITHUB_RELEASE_UTIL_OPTS[@]}" create_branch \ "${RELEASE_VERSION}" tink-go-hcvault popd ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������golang-github-tink-crypto-tink-go-hcvault-2.4.0/kokoro/create_github_release_tag.sh�����������������0000664�0000000�0000000�00000004370�15116502567�0030553�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������#!/bin/bash # Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ################################################################################ set -euo pipefail # Fail if RELEASE_VERSION is not set. if [[ -z "${RELEASE_VERSION:-}" ]]; then echo "RELEASE_VERSION must be set" >&2 exit 1 fi IS_KOKORO="false" if [[ -n "${KOKORO_ARTIFACTS_DIR:-}" ]]; then IS_KOKORO="true" fi readonly IS_KOKORO # If not defined, default to /tmp. : "${TMPDIR:="/tmp"}" # WARNING: Setting this environment varialble to "true" will cause this script # to actually perform a release. : "${DO_MAKE_RELEASE:="false"}" if [[ ! "${DO_MAKE_RELEASE}" =~ ^(false|true)$ ]]; then echo "DO_MAKE_RELEASE must be either \"true\" or \"false\"" >&2 exit 1 fi if [[ "${IS_KOKORO}" == "true" ]] ; then readonly TINK_BASE_DIR="$(echo "${KOKORO_ARTIFACTS_DIR}"/git*)" cd "${TINK_BASE_DIR}/tink_go_hcvault" fi GITHUB_RELEASE_UTIL_OPTS=() if [[ "${IS_KOKORO}" == "true" ]] ; then # Note: KOKORO_GIT_COMMIT is populated by Kokoro. GITHUB_RELEASE_UTIL_OPTS+=( -c "${KOKORO_GIT_COMMIT}" -t "${GITHUB_ACCESS_TOKEN}" ) fi if [[ "${DO_MAKE_RELEASE}" == "true" ]]; then GITHUB_RELEASE_UTIL_OPTS+=( -r ) fi readonly GITHUB_RELEASE_UTIL_OPTS # If running on Kokoro, TMPDIR is populated with the tmp folder. readonly TMP_DIR="$(mktemp -d "${TMPDIR}/release_XXXXXX")" readonly RELEASE_UTIL_SCRIPT="$(pwd)/kokoro/testutils/github_release_util.sh" if [[ ! -f "${RELEASE_UTIL_SCRIPT}" ]]; then echo "${RELEASE_UTIL_SCRIPT} not found." echo "Make sure you run this script from the root of tink-go-hcvault." return 1 fi pushd "${TMP_DIR}" # Create a release branch. "${RELEASE_UTIL_SCRIPT}" "${GITHUB_RELEASE_UTIL_OPTS[@]}" create_tag \ "${RELEASE_VERSION}" tink-go-hcvault popd ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������golang-github-tink-crypto-tink-go-hcvault-2.4.0/kokoro/gcp_ubuntu/����������������������������������0000775�0000000�0000000�00000000000�15116502567�0025226�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������golang-github-tink-crypto-tink-go-hcvault-2.4.0/kokoro/gcp_ubuntu/gomod/����������������������������0000775�0000000�0000000�00000000000�15116502567�0026333�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������golang-github-tink-crypto-tink-go-hcvault-2.4.0/kokoro/gcp_ubuntu/gomod/run_tests.sh����������������0000664�0000000�0000000�00000004354�15116502567�0030723�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������#!/bin/bash # Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ################################################################################ # By default when run locally this script runs the command below directly on the # host. The CONTAINER_IMAGE variable can be set to run on a custom container # image for local testing. E.g.: # # CONTAINER_IMAGE="gcr.io/tink-test-infrastructure/linux-tink-go-base:latest" \ # sh ./kokoro/gcp_ubuntu/gomod/run_tests.sh # Generated with openssl rand -hex 10 echo "===========================================================================" echo "Tink Script ID: c4ca71c9525173f869e1 (to quickly find the script from logs)" echo "===========================================================================" set -euo pipefail RUN_COMMAND_ARGS=() if [[ -n "${KOKORO_ROOT:-}" ]]; then readonly TINK_BASE_DIR="$(echo "${KOKORO_ARTIFACTS_DIR}"/git*)" cd "${TINK_BASE_DIR}/tink_go_hcvault" source "kokoro/testutils/go_test_container_images.sh" CONTAINER_IMAGE="${TINK_GO_BASE_IMAGE}" RUN_COMMAND_ARGS+=( -k "${TINK_GCR_SERVICE_KEY}" ) fi readonly CONTAINER_IMAGE if [[ -n "${CONTAINER_IMAGE:-}" ]]; then RUN_COMMAND_ARGS+=( -c "${CONTAINER_IMAGE}" ) fi ./kokoro/testutils/docker_execute.sh "${RUN_COMMAND_ARGS[@]}" \ ./kokoro/testutils/check_go_generated_files_up_to_date.sh . cat <<EOF > env_variables.txt GOARCH EOF RUN_COMMAND_ARGS+=( -e env_variables.txt ) readonly RUN_COMMAND_ARGS cat <<EOF > _run_test.sh #!/bin/bash set -euo pipefail set -x go build -v ./... go test -v ./... EOF chmod +x _run_test.sh # Run cleanup on EXIT. trap cleanup EXIT cleanup() { rm -rf _run_test.sh rm -rf env_variables.txt } ./kokoro/testutils/docker_execute.sh "${RUN_COMMAND_ARGS[@]}" \ ./_run_test.sh ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������golang-github-tink-crypto-tink-go-hcvault-2.4.0/kokoro/macos_external/������������������������������0000775�0000000�0000000�00000000000�15116502567�0026057�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������golang-github-tink-crypto-tink-go-hcvault-2.4.0/kokoro/macos_external/gomod/������������������������0000775�0000000�0000000�00000000000�15116502567�0027164�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������golang-github-tink-crypto-tink-go-hcvault-2.4.0/kokoro/macos_external/gomod/run_tests.sh������������0000664�0000000�0000000�00000002452�15116502567�0031551�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������#!/bin/bash # Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ################################################################################ # Generated with openssl rand -hex 10 echo "===========================================================================" echo "Tink Script ID: b7593f8a5de3fa62cbf4 (to quickly find the script from logs)" echo "===========================================================================" set -euo pipefail if [[ -n "${KOKORO_ROOT:-}" ]]; then readonly TINK_BASE_DIR="$(echo "${KOKORO_ARTIFACTS_DIR}"/git*)" cd "${TINK_BASE_DIR}/tink_go_hcvault" fi # Sourcing required to update callers environment. source ./kokoro/testutils/install_go.sh echo "Using go binary from $(which go): $(go version)" ( set -x go build -v ./... go test -v ./... ) ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������golang-github-tink-crypto-tink-go-hcvault-2.4.0/kokoro/testutils/�����������������������������������0000775�0000000�0000000�00000000000�15116502567�0025113�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������golang-github-tink-crypto-tink-go-hcvault-2.4.0/kokoro/testutils/BUILD.bazel������������������������0000664�0000000�0000000�00000001253�15116502567�0026772�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������package(default_visibility = ["//:__subpackages__"]) licenses(["notice"]) sh_binary( name = "test_utils", srcs = ["test_utils.sh"], ) sh_binary( name = "github_release_util", srcs = ["github_release_util.sh"], ) sh_test( name = "github_release_util_test", size = "small", srcs = ["github_release_util_test.sh"], args = [ "$(rlocationpath :github_release_util.sh)", "$(rlocationpath :test_utils)", ], data = [ ":github_release_util.sh", ":test_utils", ], target_compatible_with = select({ "@platforms//os:windows": ["@platforms//:incompatible"], "//conditions:default": [], }), ) �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������check_go_generated_files_up_to_date.sh��������������������������������������������������������������0000775�0000000�0000000�00000005146�15116502567�0034546�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000�golang-github-tink-crypto-tink-go-hcvault-2.4.0/kokoro/testutils�������������������������������������������������������������������������������������������������������#!/bin/bash # Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ################################################################################ # This scripts checks that a given Go workspace has its generated Bazel files up # to date. usage() { echo "Usage: $0 [-h] [-c <compat value (default 1.19)>] <go project dir>" echo " -c: Value to pass to `-compat`. Default to 1.19." echo " -h: Help. Print this usage information." exit 1 } COMPAT="1.19" GO_PROJECT_DIR= process_args() { # Parse options. while getopts "hc:" opt; do case "${opt}" in c) COMPAT="${OPTARG}" ;; *) usage ;; esac done shift $((OPTIND - 1)) readonly GO_PROJECT_DIR="$1" if [[ -z "${GO_PROJECT_DIR}" ]]; then usage fi } main() { process_args "$@" ( cd "${GO_PROJECT_DIR}" local -r temp_dir_current_generated_files="$(mktemp -dt \ current_tink_go_build_files.XXXXXX)" local -r go_generated_files=( ./go.mod ./go.sum ) # Copy all current generated files into temp_dir_current_generated_files. local -r current_go_generated_files=( "${go_generated_files[@]}" ) for generated_file_path in "${current_go_generated_files[@]}"; do mkdir -p \ "$(dirname \ "${temp_dir_current_generated_files}/${generated_file_path}")" cp "${generated_file_path}" \ "${temp_dir_current_generated_files}/${generated_file_path}" done # Update build files. go mod tidy -compat="${COMPAT}" # Compare current with new build files. local -r new_go_generated_files=( "${go_generated_files[@]}" ) for generated_file_path in "${new_go_generated_files[@]}"; do if ! cmp -s "${generated_file_path}" \ "${temp_dir_current_generated_files}/${generated_file_path}"; then echo "ERROR: ${generated_file_path} needs to be updated. Please follow \ the instructions on go/tink-workflows#update-go-build." >&2 echo "Diff for ${generated_file_path}:" diff "${generated_file_path}" \ "${temp_dir_current_generated_files}/${generated_file_path}" exit 1 fi done ) } main "$@" ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������golang-github-tink-crypto-tink-go-hcvault-2.4.0/kokoro/testutils/docker_execute.sh������������������0000775�0000000�0000000�00000007262�15116502567�0030452�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������#!/bin/bash # Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ################################################################################ # Utility script to run a command in a new docker container. # # This script must be run from inside the Tink library to run the command for. # # NOTE: When running in a new container, this script mounts the parent folder of # `pwd`. Other dependencies, if any, are assumed to be located there. For # example, if running tink-py tests, this script assumes: # - pwd => /path/to/parent/tink-py # - mount path => /path/to/parent # - ls /path/to/parent => tink_cc tink_py. set -eo pipefail usage() { cat <<EOF Usage: $0 [-c <container image>] [-k <service key file path>] <command> -c: [Optional] Container image to run the command on. -k: [Optional] Service key file path for pulling the image from the Google Artifact Registry (https://cloud.google.com/artifact-registry). -e: [Optional] File containing a list of environment variables to pass to Docker using --env-file (see https://docs.docker.com/engine/reference/commandline/run/#env). -m: [Optional] Additional --mount argument to pass to the Docker command (see https://docs.docker.com/reference/cli/docker/container/run/#mount). -h: Help. Print this usage information. EOF exit 1 } # Args. COMMAND= # Options. CONTAINER_IMAGE_NAME= GCR_SERVICE_KEY_PATH= DOCKER_ENV_FILE= DOCKER_MOUNT_ARG= ####################################### # Process command line arguments. ####################################### process_args() { # Parse options. while getopts "hc:k:e:m:" opt; do case "${opt}" in c) CONTAINER_IMAGE_NAME="${OPTARG}" ;; k) GCR_SERVICE_KEY_PATH="${OPTARG}" ;; e) DOCKER_ENV_FILE="${OPTARG}" ;; m) DOCKER_MOUNT_ARG="${OPTARG}" ;; *) usage ;; esac done shift $((OPTIND - 1)) readonly CONTAINER_IMAGE_NAME readonly GCR_SERVICE_KEY_PATH readonly DOCKER_ENV_FILE readonly DOCKER_MOUNT_ARG readonly COMMAND=("$@") } main() { process_args "$@" if [[ -z "${CONTAINER_IMAGE_NAME:-}" ]]; then echo "Running command on the host" time "${COMMAND[@]}" else echo "Running command on a new container from image ${CONTAINER_IMAGE_NAME}" if [[ ! -z "${GCR_SERVICE_KEY_PATH:-}" ]]; then # Activate service account to read from a private artifact registry repo. gcloud auth activate-service-account --key-file="${GCR_SERVICE_KEY_PATH}" gcloud config set project tink-test-infrastructure gcloud auth configure-docker us-docker.pkg.dev --quiet fi local -r path_to_mount="$(dirname "$(pwd)")" local -r library_to_test="$(basename "$(pwd)")" time docker pull "${CONTAINER_IMAGE_NAME}" local docker_opts=( --network="host" --mount type=bind,src="${path_to_mount}",dst=/deps --workdir=/deps/"${library_to_test}" --rm ) if [[ -n "${DOCKER_ENV_FILE}" ]]; then docker_opts+=( --env-file="${DOCKER_ENV_FILE}" ) fi if [[ -n ${DOCKER_MOUNT_ARG} ]] ; then docker_opts+=( --mount "${DOCKER_MOUNT_ARG}" ) fi readonly docker_opts time docker run "${docker_opts[@]}" "${CONTAINER_IMAGE_NAME}" \ bash -c "$(echo "${COMMAND[@]}")" fi } main "$@" ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������golang-github-tink-crypto-tink-go-hcvault-2.4.0/kokoro/testutils/github_release_util.sh�������������0000775�0000000�0000000�00000016272�15116502567�0031501�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������#!/bin/bash # Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ################################################################################ # This script performs a source release on GitHub for a given repo, that is: # - Creates a release branch (if it does not yet exist), # - Creates a release tag. set -eo pipefail # Parameters and arguments. These will be populated/modified by args parsing. # Options. # Whether to actually create a release. This is false by default and meant to # prevent accidental releases. DO_RUN_ACTION="false" # Commit at which to make the release. If unspecified, the release is made from # HEAD. COMMIT_HASH= # Optional personal access token. ACCESS_TOKEN= # Arguments. # Action to be performed. ACTION= # This must be of the form `MAJOR.MINOR.PATCH`. VERSION= # Repo name after github.com/tink-crypto/, e.g., tink-cc. REPO_NAME= # Derived variables. GITHUB_REPO_URL= RELEASE_BRANCH= TAG= GITHUB_REFS= BRANCH_EXISTS="false" # Constants. readonly GITHUB_ORG_URL="github.com/tink-crypto" usage() { echo "Usage: $0 [-rh] [-c <commit hash>] [-t <access token>] <action> \\" echo " <version> <repository>" echo " <action>: The action to be performed (crete_branch|create_tag)." echo " <version>: The version identifier in MAJOR.MINOR.PATCH format." echo " <repository>: The name of the repository (e.g. \"tink-cc\")." echo " -c: Commit hash to use as HEAD of the release branch (optional)." echo " -t: Access token. Without this, the default is SSH (optional)." echo " -r: Whether to actually create a release; this is false by default." echo " -h: Show this help message." exit 1 } process_params() { while getopts "rhc:t:" opt; do case "${opt}" in r) DO_RUN_ACTION="true" ;; c) COMMIT_HASH="${OPTARG}" ;; t) ACCESS_TOKEN="${OPTARG}" ;; *) usage ;; esac done shift $((OPTIND - 1)) readonly DO_RUN_ACTION readonly COMMIT_HASH readonly ACCESS_TOKEN ACTION="$1" if [[ ! "${ACTION}" =~ create_branch|create_tag ]]; then echo "ERROR: Expected (create_branch|create_tag) got ${ACTION}" >&2 usage fi readonly ACTION VERSION="$2" if [[ ! "${VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9a-z]*)?$ ]]; then echo "ERROR: Invalid version format: expected MAJOR.MINOR.PATCH or MAJOR.MINOR.PATCH-pre, got \${VERSION}" >&2 usage fi readonly VERSION REPO_NAME="$3" if [[ -z "${REPO_NAME}" ]]; then echo "ERROR: Repo name must be specified." >&2 usage fi readonly REPO_NAME # Use SSH by default. local protocol_and_credentials="ssh://git" if [[ -n "${ACCESS_TOKEN}" ]]; then protocol_and_credentials="https://ise-crypto:${ACCESS_TOKEN}" fi readonly protocol_and_credentials GITHUB_REPO_URL="${protocol_and_credentials}@${GITHUB_ORG_URL}/${REPO_NAME}" readonly GITHUB_REPO_URL # Release branch is only MAJOR.MINOR. readonly RELEASE_BRANCH="$(echo "${VERSION}" | cut -d'.' -f1,2)" # Splitting declaration and assignment guarantees correct propagation of the # exit code of the subshell. local GITHUB_REFS GITHUB_REFS="$(git ls-remote "${GITHUB_REPO_URL}")" readonly GITHUB_REFS local -r expected_release_branch="refs/heads/${RELEASE_BRANCH}" if echo "${GITHUB_REFS}" | grep "${expected_release_branch}" > /dev/null; then BRANCH_EXISTS="true" fi readonly BRANCH_EXISTS if [[ "${ACTION}" == "create_tag" ]]; then if [[ "${BRANCH_EXISTS}" == "false" ]]; then echo "ERROR: The release branch does not exist in \ ${GITHUB_ORG_URL}/${REPO_NAME}." >&2 return 1 fi local -r release_tag="v${VERSION}" local -r expected_release_tag="refs/tags/${release_tag}" if echo "${GITHUB_REFS}" | grep "${expected_release_tag}" > /dev/null; then echo "ERROR The tag \"${release_tag}\" already exists in \ ${GITHUB_ORG_URL}/${REPO_NAME}." >&2 return 1 fi fi } ####################################### # Prints a command # # Args: # Command to execute. # ####################################### print_command() { printf '%q ' '+' "$@" echo } ####################################### # Runs a command if DO_RUN_ACTION is true. # # Args: # Command to execute. # Globals: # DO_RUN_ACTION # ####################################### run_command() { if [[ "${DO_RUN_ACTION}" == "false" ]]; then echo " *** Dry run, command not executed. ***" return 0 fi # Actually run the command. "$@" return $? } ####################################### # Prints and runs a command. # # Args: # Command to execute. # ####################################### print_and_run_command() { print_command "$@" run_command "$@" } ####################################### # Creates and checks out to the release branch. # # If COMMIT_HASH is specified, use COMMIT_HASH as HEAD for the branch. # # Globals: # RELEASE_BRANCH # COMMIT_HASH # ####################################### git_create_release_branch() { if [[ "${BRANCH_EXISTS}" == "true" ]]; then echo "WARNING: The release branch already exists. Nothing to do." return 0 fi # Target branch does not exist so we create the release branch. if [[ -n "${COMMIT_HASH:-}" ]]; then # Use COMMIT_HASH as HEAD for this branch. print_and_run_command git branch "${RELEASE_BRANCH}" "${COMMIT_HASH}" else print_and_run_command git branch "${RELEASE_BRANCH}" fi print_and_run_command git push origin "${RELEASE_BRANCH}" } ####################################### # Creates a release tag. # # Globals: # RELEASE_BRANCH # REPO_NAME # VERSION # ####################################### git_create_release_tag() { if [[ "${BRANCH_EXISTS}" == "false" ]]; then echo "ERROR: The release branch does not exist in \ ${GITHUB_ORG_URL}/${REPO_NAME}." >&2 return 1 fi local -r release_tag="v${VERSION}" local -r expected_release_tag="refs/tags/${release_tag}" if echo "${GITHUB_REFS}" | grep "${expected_release_tag}" > /dev/null; then echo "ERROR The tag \"${release_tag}\" already exists in \ ${GITHUB_ORG_URL}/${REPO_NAME}." >&2 return 1 fi print_and_run_command git checkout "${RELEASE_BRANCH}" print_and_run_command git tag -a "${release_tag}" \ -m "${REPO_NAME} version ${VERSION}" print_and_run_command git push origin "${release_tag}" } main() { process_params "$@" # Avoid logging the full URL; replace GIT_URL with a version that omits user # and access token. local -r protocol="$(echo "${GITHUB_REPO_URL}" | cut -d':' -f1)" local -r github_repo="$(echo "${GITHUB_REPO_URL}" | cut -d'@' -f2)" print_command git clone "${protocol}://...@${github_repo}" run_command git clone "${GITHUB_REPO_URL}" print_and_run_command cd "${REPO_NAME}" case "${ACTION}" in create_branch) git_create_release_branch ;; create_tag) git_create_release_tag ;; esac } main "$@" ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������golang-github-tink-crypto-tink-go-hcvault-2.4.0/kokoro/testutils/github_release_util_test.sh��������0000775�0000000�0000000�00000030151�15116502567�0032530�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������#!/bin/bash # Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ################################################################################ DEFAULT_DIR="$(pwd)" if [[ -n "${TEST_SRCDIR}" ]]; then DEFAULT_DIR="${TEST_SRCDIR}" fi readonly DEFAULT_DIR readonly CLI="${DEFAULT_DIR}/${1:-"github_release_util.sh"}" readonly TEST_UTILS="${DEFAULT_DIR}/${2:-test_utils.sh}" # Load the test library. source "${TEST_UTILS}" test_GitHubReleaseUtil_CreateBranchMinorSucceeds() { cd "${TEST_CASE_TMPDIR}" local -r expected_git_cmds_file="${TEST_CASE_TMPDIR}/expected_cmds.txt" cat << EOF > ${expected_git_cmds_file} git ls-remote ssh://git@github.com/tink-crypto/some-repo git clone ssh://git@github.com/tink-crypto/some-repo git branch 1.6 git push origin 1.6 EOF local -r actual_git_cmds_file="${TEST_CASE_TMPDIR}/actual_git_cmds_file.txt" # Mock git command. git() { local -r command="$1" shift 1 cmd_and_args="git ${command} $@" echo "${cmd_and_args}" >> "${actual_git_cmds_file}" case "${command}" in "ls-remote") cat << EOF 6c68b48c884e0aeb983b8864f35187d9584d0d74 HEAD 6c68b48c884e0aeb983b8864f35187d9584d0d74 refs/heads/main EOF ;; "clone") local -r repo_name="${1##*/}" mkdir "${repo_name}" ;; *) ;; # Do nothing esac } # Run this in the caller's environment. ( source "${CLI}" -r create_branch 1.6.0 some-repo &> /dev/null ) ASSERT_CMD_SUCCEEDED ASSERT_FILE_EQUALS "${actual_git_cmds_file}" "${expected_git_cmds_file}" } test_GitHubReleaseUtil_CreateBranchMinorWithCommitSucceeds() { cd "${TEST_CASE_TMPDIR}" local -r expected_git_cmds_file="${TEST_CASE_TMPDIR}/expected_cmds.txt" cat << EOF > ${expected_git_cmds_file} git ls-remote ssh://git@github.com/tink-crypto/some-repo git clone ssh://git@github.com/tink-crypto/some-repo git branch 1.6 6c68b48c884e0aeb983b8864f35187d9584d0d74 git push origin 1.6 EOF local -r actual_git_cmds_file="${TEST_CASE_TMPDIR}/actual_git_cmds_file.txt" # Mock git command. git() { local -r command="$1" shift 1 cmd_and_args="git ${command} $@" echo "${cmd_and_args}" >> "${actual_git_cmds_file}" case "${command}" in "ls-remote") cat << EOF 6c68b48c884e0aeb983b8864f35187d9584d0d74 HEAD 6c68b48c884e0aeb983b8864f35187d9584d0d74 refs/heads/main EOF ;; "clone") local -r repo_name="${1##*/}" mkdir "${repo_name}" ;; *) ;; # Do nothing esac } # Run this in the caller's environment. ( source "${CLI}" -r -c 6c68b48c884e0aeb983b8864f35187d9584d0d74 \ create_branch 1.6.0 some-repo &> /dev/null ) ASSERT_CMD_SUCCEEDED ASSERT_FILE_EQUALS "${actual_git_cmds_file}" "${expected_git_cmds_file}" } test_GitHubReleaseUtil_CreateTagPatchSucceeds() { cd "${TEST_CASE_TMPDIR}" local -r expected_git_cmds_file="${TEST_CASE_TMPDIR}/expected_cmds.txt" cat << EOF > ${expected_git_cmds_file} git ls-remote ssh://git@github.com/tink-crypto/some-repo git clone ssh://git@github.com/tink-crypto/some-repo git checkout 1.6 git tag -a v1.6.2 -m some-repo version 1.6.2 git push origin v1.6.2 EOF local -r actual_git_cmds_file="${TEST_CASE_TMPDIR}/actual_git_cmds_file.txt" # Mock git command. git() { local -r command="$1" shift 1 cmd_and_args="git ${command} $@" echo "${cmd_and_args}" >> "${actual_git_cmds_file}" case "${command}" in "ls-remote") cat << EOF 6c68b48c884e0aeb983b8864f35187d9584d0d74 HEAD 6c68b48c884e0aeb983b8864f35187d9584d0d74 refs/heads/main 9940095f3081a116fa7a1337ad5ba27a3ccc59fe refs/heads/1.6 EOF ;; "clone") local -r repo_name="${1##*/}" mkdir "${repo_name}" ;; *) ;; # Do nothing. esac } # Run this in the caller's environment. ( source "${CLI}" -r -c 6c68b48c884e0aeb983b8864f35187d9584d0d74 \ create_tag 1.6.2 some-repo &> /dev/null ) ASSERT_CMD_SUCCEEDED ASSERT_FILE_EQUALS "${actual_git_cmds_file}" "${expected_git_cmds_file}" } test_GitHubReleaseUtil_CreateBranchFailsWhenLsRemoteFails() { cd "${TEST_CASE_TMPDIR}" local -r expected_git_cmds_file="${TEST_CASE_TMPDIR}/expected_cmds.txt" cat << EOF > ${expected_git_cmds_file} git ls-remote ssh://git@github.com/tink-crypto/some-repo EOF local actual_git_cmds_file="${TEST_CASE_TMPDIR}/actual_cmds.txt" # Mock git command. git() { local -r command="$1" shift 1 cmd_and_args="git ${command} $@" echo "${cmd_and_args}" >> "${actual_git_cmds_file}" case "${command}" in "ls-remote") return 1 ;; *) ;; # Do nothing. esac } # Run this in a subshell to prevent exiting on failure. ( source "${CLI}" -r create_branch 1.6.2 some-repo &> /dev/null ) ASSERT_CMD_FAILED ASSERT_FILE_EQUALS "${actual_git_cmds_file}" "${expected_git_cmds_file}" echo "" > "${actual_git_cmds_file}" } test_GitHubReleaseUtil_CreateBranchFailsWhenCloneFails() { cd "${TEST_CASE_TMPDIR}" local -r expected_git_cmds_file="${TEST_CASE_TMPDIR}/expected_cmds.txt" cat << EOF > ${expected_git_cmds_file} git ls-remote ssh://git@github.com/tink-crypto/some-repo git clone ssh://git@github.com/tink-crypto/some-repo EOF local actual_git_cmds_file="${TEST_CASE_TMPDIR}/actual_cmds.txt" # Mock git command. git() { local -r command="$1" shift 1 cmd_and_args="git ${command} $@" echo "${cmd_and_args}" >> "${actual_git_cmds_file}" case "${command}" in "ls-remote") cat << EOF 6c68b48c884e0aeb983b8864f35187d9584d0d74 HEAD 6c68b48c884e0aeb983b8864f35187d9584d0d74 refs/heads/main EOF ;; "clone") return 1 ;; *) ;; # Do nothing. esac } # Run this in a subshell to prevent exiting on failure. ( source "${CLI}" -r create_branch 1.6.2 some-repo &> /dev/null ) ASSERT_CMD_FAILED ASSERT_FILE_EQUALS "${actual_git_cmds_file}" "${expected_git_cmds_file}" } test_GitHubReleaseUtil_CreateTagFailsIfBranchDoesNotExist() { cd "${TEST_CASE_TMPDIR}" local -r expected_git_cmds_file="${TEST_CASE_TMPDIR}/expected_cmds.txt" cat << EOF > ${expected_git_cmds_file} git ls-remote ssh://git@github.com/tink-crypto/some-repo EOF local actual_git_cmds_file="${TEST_CASE_TMPDIR}/actual_cmds.txt" # Mock git command. git() { local -r command="$1" shift 1 cmd_and_args="git ${command} $@" echo "${cmd_and_args}" >> "${actual_git_cmds_file}" case "${command}" in "ls-remote") cat << EOF 6c68b48c884e0aeb983b8864f35187d9584d0d74 HEAD 6c68b48c884e0aeb983b8864f35187d9584d0d74 refs/heads/main EOF ;; *) ;; # Do nothing. esac } # Run this in a subshell to prevent exiting on failure. ( source "${CLI}" -r create_tag 1.6.2 some-repo &> /dev/null ) ASSERT_CMD_FAILED ASSERT_FILE_EQUALS "${actual_git_cmds_file}" "${expected_git_cmds_file}" } test_GitHubReleaseUtil_CreateTagFailsIfReleaseTagAlreadyExists() { cd "${TEST_CASE_TMPDIR}" local -r expected_git_cmds_file="${TEST_CASE_TMPDIR}/expected_cmds.txt" cat << EOF > ${expected_git_cmds_file} git ls-remote ssh://git@github.com/tink-crypto/some-repo EOF local actual_git_cmds_file="${TEST_CASE_TMPDIR}/actual_cmds.txt" # Mock git command. git() { local -r command="$1" shift 1 cmd_and_args="git ${command} $@" echo "${cmd_and_args}" >> "${actual_git_cmds_file}" case "${command}" in "ls-remote") cat << EOF 6c68b48c884e0aeb983b8864f35187d9584d0d74 HEAD 6c68b48c884e0aeb983b8864f35187d9584d0d74 refs/heads/main 112a7d3a0453a1d926448519f94fe5a91c69be45 refs/heads/1.6 8c266441044c4dfaf7560e21663a8037043b750b refs/tags/v1.6.2 195ec3c1edeee8877ab5dc287f95c4402e3fb510 refs/tags/v1.6.1 c6f48771296bca0bd22724b208abafeae7d7b764 refs/tags/v1.6.0 EOF ;; *) ;; # Do nothing. esac } # Run this in a subshell to prevent exiting on failure. ( source "${CLI}" -r create_tag 1.6.2 some-repo &> /dev/null ) ASSERT_CMD_FAILED ASSERT_FILE_EQUALS "${actual_git_cmds_file}" "${expected_git_cmds_file}" } test_GitHubReleaseUtil_FailsWhenInvalidVersion() { cd "${TEST_CASE_TMPDIR}" for action in create_branch create_tag; do ( source "${CLI}" -r "${action}" 1 some-repo &> /dev/null ) ASSERT_CMD_FAILED ( source "${CLI}" -r "${action}" 1.2 some-repo &> /dev/null ) ASSERT_CMD_FAILED ( source "${CLI}" -r "${action}" 1.2.a some-repo &> /dev/null ) ASSERT_CMD_FAILED ( source "${CLI}" -r "${action}" a.b.c some-repo &> /dev/null ) ASSERT_CMD_FAILED ( source "${CLI}" -r "${action}" 1.2.3.4 some-repo &> /dev/null ) ASSERT_CMD_FAILED ( source "${CLI}" -r "${action}" invalid some-repo &> /dev/null ) ASSERT_CMD_FAILED done } test_GitHubReleaseUtil_FailsWhenNoRepoNameIsGiven() { cd "${TEST_CASE_TMPDIR}" for action in create_branch create_tag; do # Run this in a subshell to prevent exiting on failure. ( source "${CLI}" -r "${action}" 1.6.0 &> /dev/null ) ASSERT_CMD_FAILED done } test_GitHubReleaseUtil_CreateBranchUsesCorrectGithubToken() { cd "${TEST_CASE_TMPDIR}" local -r access_token="a227da63673c236090a067c3f96b62e74dbd5857" local -r expected_url="https://ise-crypto:${access_token}@github.com/tink-crypto/some-repo" local -r expected_git_cmds_file="${TEST_CASE_TMPDIR}/expected_cmds.txt" cat << EOF > ${expected_git_cmds_file} git ls-remote ${expected_url} git clone ${expected_url} git branch 1.6 git push origin 1.6 EOF local -r actual_git_cmds_file="${TEST_CASE_TMPDIR}/actual_git_cmds_file.txt" # Mock git command. git() { local -r command="$1" shift 1 cmd_and_args="git ${command} $@" echo "${cmd_and_args}" >> "${actual_git_cmds_file}" case "${command}" in "ls-remote") cat << EOF 6c68b48c884e0aeb983b8864f35187d9584d0d74 HEAD 6c68b48c884e0aeb983b8864f35187d9584d0d74 refs/heads/main EOF ;; "clone") local -r repo_name="${1##*/}" mkdir "${repo_name}" ;; *) ;; # Do nothing esac } # Run this in the caller's environment. ( source "${CLI}" -r -t "${access_token}" create_branch 1.6.0 some-repo \ &> /dev/null ) ASSERT_CMD_SUCCEEDED ASSERT_FILE_EQUALS "${actual_git_cmds_file}" "${expected_git_cmds_file}" } test_GitHubReleaseUtil_CreateTagUsesCorrectGithubToken() { cd "${TEST_CASE_TMPDIR}" local -r access_token="a227da63673c236090a067c3f96b62e74dbd5857" local -r expected_url="https://ise-crypto:${access_token}@github.com/tink-crypto/some-repo" local -r expected_git_cmds_file="${TEST_CASE_TMPDIR}/expected_cmds.txt" cat << EOF > ${expected_git_cmds_file} git ls-remote ${expected_url} git clone ${expected_url} git checkout 1.6 git tag -a v1.6.2 -m some-repo version 1.6.2 git push origin v1.6.2 EOF local -r actual_git_cmds_file="${TEST_CASE_TMPDIR}/actual_git_cmds_file.txt" # Mock git command. git() { local -r command="$1" shift 1 cmd_and_args="git ${command} $@" echo "${cmd_and_args}" >> "${actual_git_cmds_file}" case "${command}" in "ls-remote") cat << EOF 6c68b48c884e0aeb983b8864f35187d9584d0d74 HEAD 6c68b48c884e0aeb983b8864f35187d9584d0d74 refs/heads/main 112a7d3a0453a1d926448519f94fe5a91c69be45 refs/heads/1.6 EOF ;; "clone") local -r repo_name="${1##*/}" mkdir "${repo_name}" ;; *) ;; # Do nothing esac } # Run this in the caller's environment. ( source "${CLI}" -r -t "${access_token}" create_tag 1.6.2 some-repo \ &> /dev/null ) ASSERT_CMD_SUCCEEDED ASSERT_FILE_EQUALS "${actual_git_cmds_file}" "${expected_git_cmds_file}" } main() { run_all_tests "$@" } main "$@" �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������golang-github-tink-crypto-tink-go-hcvault-2.4.0/kokoro/testutils/go_test_container_images.sh��������0000664�0000000�0000000�00000002400�15116502567�0032476�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������#!/bin/bash # Copyright 2023 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ################################################################################ _image_prefix() { local -r artifact_registry_url="us-docker.pkg.dev" local -r test_project="tink-test-infrastructure" local -r artifact_registry_repo="tink-ci-images" echo "${artifact_registry_url}/${test_project}/${artifact_registry_repo}" } # Linux container images for Tink Go libraries. readonly TINK_GO_BASE_IMAGE_NAME="linux-tink-go-base" # Image from 2025-08-29. readonly TINK_GO_BASE_IMAGE_HASH="10d07e34459058b7654aa2db6b8f553c36a6d80847153883995e54c02bf56e85" readonly TINK_GO_BASE_IMAGE="$(_image_prefix)/${TINK_GO_BASE_IMAGE_NAME}@sha256:${TINK_GO_BASE_IMAGE_HASH}" unset -f _image_prefix ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������golang-github-tink-crypto-tink-go-hcvault-2.4.0/kokoro/testutils/install_go.sh����������������������0000775�0000000�0000000�00000004300�15116502567�0027602�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������#!/bin/bash # Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ################################################################################ # This script installs a recent version of Go into a temporary directory. The Go # bin directory is then added to the PATH environment variable. # # NOTE: This script MUST be sourced to update the environment of the calling # script. # # Usage instructions: # # source ./kokoro/testutils/install_go.sh set -eo pipefail readonly GO_VERSION="1.24.0" readonly GO_LINUX_AMD64_SHA256="dea9ca38a0b852a74e81c26134671af7c0fbe65d81b0dc1c5bfe22cf7d4c8858" readonly GO_DARWIN_AMD64_SHA256="7af054e5088b68c24b3d6e135e5ca8d91bbd5a05cb7f7f0187367b3e6e9e05ee" readonly PLATFORM="$(uname | tr '[:upper:]' '[:lower:]')" install_temp_go() { local go_platform local go_sha256 case "${PLATFORM}" in "linux") go_platform="linux-amd64" go_sha256="${GO_LINUX_AMD64_SHA256}" ;; "darwin") go_platform="darwin-amd64" go_sha256="${GO_DARWIN_AMD64_SHA256}" ;; *) echo "Unsupported platform, unable to install Go." exit 1 ;; esac readonly go_platform readonly go_sha256 local -r go_archive="go${GO_VERSION}.${go_platform}.tar.gz" local -r go_url="https://go.dev/dl/${go_archive}" local -r go_tmpdir=$(mktemp -dt tink-go.XXXXXX) ( set -x cd "${go_tmpdir}" curl -OLsS "${go_url}" # The explicit "-" to specify stdin in sha256sum is needed on MacOS sequoia echo "${go_sha256} ${go_archive}" | sha256sum -c - tar -xzf "${go_archive}" ) export GOROOT="${go_tmpdir}/go" export PATH="${go_tmpdir}/go/bin:${PATH}" } if [[ -n "${KOKORO_ARTIFACTS_DIR:-}" ]] ; then install_temp_go fi ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������golang-github-tink-crypto-tink-go-hcvault-2.4.0/kokoro/testutils/test_utils.sh����������������������0000775�0000000�0000000�00000010316�15116502567�0027652�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������#!/bin/bash # Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. ################################################################################ # Set of utilities to run unit tests for bash scripts. # # Example usage: # From your test script: # source some/path/to/test_utils.sh # # # Test functions must be defined as follows: # test_<Test Name>_<Test Case Name>() { # # Do some ground work. # # Run the test script. # ./path/to/script_to_test <input1> <input2> ... # ASSERT_CMD_SUCCEEDED # ASSERT_FILE_EQUALS <file1> <file2> # } # # # Finds all the functions starting with `test_`, extracts test name and # # test case, and run them. # run_all_tests "$@" # # This is either set by Bazel or generated. : "${TEST_TMPDIR:="$(mktemp -td test.XXXXX)"}" readonly TEST_TMPDIR # Temporary directory for the testcase to use. TEST_CASE_TMPDIR= # Current test name. _CURRENT_TEST_SCOPE= # Current test case. _CURRENT_TEST_CASE= # True if at least one of the test cases terminated with an error. _HAS_ERROR="false" _print_testcase_failed_and_exit() { echo "[ FAILED ] ${_CURRENT_TEST_SCOPE}.${_CURRENT_TEST_CASE}" exit 1 } ####################################### # Starts a new test case. # # Globals: # _CURRENT_TEST_SCOPE # _CURRENT_TEST_CASE ####################################### _start_test_case() { echo "[ RUN ] ${_CURRENT_TEST_SCOPE}.${_CURRENT_TEST_CASE}" # Create a tmp dir for the test case. TEST_CASE_TMPDIR="${TEST_TMPDIR}/${_CURRENT_TEST_SCOPE}/${_CURRENT_TEST_CASE}" mkdir -p "${TEST_CASE_TMPDIR}" } ####################################### # Ends a test case printing a success message. # # Globals: # _CURRENT_TEST_SCOPE # _CURRENT_TEST_CASE ####################################### _end_test_case_with_success() { test_case="$1" echo "[ OK ] ${_CURRENT_TEST_SCOPE}.${_CURRENT_TEST_CASE}" } ####################################### # Returns the list of tests defined in the test script. # # A test case is a function of the form: # test_<Test Name>_<Test Case> # # This function returns all the functions starting with `test_`. # # Globals: # None # Arguments: # None ####################################### _get_all_tests() { declare -F | while read line; do case "${line}" in "declare -f test_"*) echo "${line#declare -f }" ;; esac done } ####################################### # Runs a given test function. # # A test case is a function of the form: # test_<Test Name>_<Test Case> # # This script extracts test name and test case from the name. # # Globals: # _CURRENT_TEST_SCOPE # Arguments: # None ####################################### _do_run_test() { test_function="$1" IFS=_ read _CURRENT_TEST_SCOPE _CURRENT_TEST_CASE <<< "${test_function#test_}" _start_test_case ( # Make sure we exit only when assertions fail. set +e "${test_function}" ) local -r result=$? if (( $result == 0 )); then _end_test_case_with_success else _HAS_ERROR="true" fi } ####################################### # Runs all the test cases defined in the test script file. # Globals: # None # Arguments: # None # ####################################### run_all_tests() { for test in $(_get_all_tests); do _do_run_test "${test}" done # Make sure we return an error code for the failing test if [[ "${_HAS_ERROR}" == "true" ]]; then exit 1 fi } ASSERT_CMD_SUCCEEDED() { if (( $? != 0 )); then _print_testcase_failed_and_exit fi } ASSERT_CMD_FAILED() { if (( $? == 0 )); then _print_testcase_failed_and_exit fi } ASSERT_FILE_EQUALS() { input_file="$1" expected_file="$2" if ! diff "${input_file}" "${expected_file}"; then _print_testcase_failed_and_exit fi } ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������