Shopify / ruby-sigstore

Rubygems sigstore signing plugin
Apache License 2.0
7 stars 6 forks source link

Only accept gem files `gem signatures --sign` and `gem signatures --verify` #37

Closed rochlefebvre closed 2 years ago

rochlefebvre commented 2 years ago

Today, we can sign any random file. The verification retrieves and verifies the signature, but blows up when trying to open the gemspec.

➜  ruby-sigstore git:(add_rubocop) ✗ gem verify Rakefile
Verifying /Users/rochlefebvre/src/github.com/Shopify/ruby-sigstore/Rakefile
No valid signatures found for digest 098db0a032b4929f8d8b25bb176cecfe39e2f4bbfe9838c5ecb117c3ff9d7600
➜  ruby-sigstore git:(add_rubocop) ✗ gem sign Rakefile
Fulcio certificate chain
-----BEGIN CERTIFICATE-----
MIIDeDCCAv2gAwIBAgIUAMMu7NgFjIqCm5LQ9pMAjN1Cd40wCgYIKoZIzj0EAwMw
KjEVMBMGA1UEChMMc2lnc3RvcmUuZGV2MREwDwYDVQQDEwhzaWdzdG9yZTAeFw0y
MTExMjMyMDA5NDBaFw0yMTExMjMyMDI5MzlaMAAwggEiMA0GCSqGSIb3DQEBAQUA
A4IBDwAwggEKAoIBAQDWdtWhx05iY8LWQ4CARxTtVL1J39wB9MdivTwS4lUJrpV9
SI3EvQLC95xVg2OEoKHJta9Fs/Wm09YbaD9HdDdqTfWgYGHFwd9mtwkK6erLk8Fn
Ay8L5ker01aPOhHIuW6RlRp6eRUeF0AMcte8haTtkjXLz3kJP3/FBjQ19+tuVkmV
XIN+jwFdj63MFnRf1/7v8hCVaO1HUqPjZhM96QNbgw6JZmnKpKmVaO5FlQbDWdHM
2gQR+XyCZ6KQExJL/AyTAD1TeE76J0Q7cBYThS/HphVQfdhlqMa27XjYUA4xqyPL
c+PasURbzJZdOYaWUwy5CuAJwqmDthzLLZqtFyErAgMBAAGjggFeMIIBWjAOBgNV
HQ8BAf8EBAMCB4AwEwYDVR0lBAwwCgYIKwYBBQUHAwMwDAYDVR0TAQH/BAIwADAd
BgNVHQ4EFgQUEosT60JqnbhKtfYmighOYvlPqVkwHw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MjFHQBBmiQpMlEk6w2u
Su1KBtPsMAoGCCqGSM49BAMDA2gAMGUCMH8liWJfMui6vXXBhjDgY4MwslmN/TJx
Ve/83WrFomwmNf056y1X48F9c4m3a3ozXAIxAKjRay5/aj/jsKKGIkmQatjI8uup
Hr/+CxFvaJWmpYqNkLDGRU+9orzh5hI2RrcuaQ==
-----END CERTIFICATE-----

Sending gem digest, signature & certificate chain to transparency log.
https://rekor.sigstore.dev/api/v1/log/entries/f9e7a00793d259e4b29517bc5fc7d059e241664f9f3c118c3abcb53e3197faa6
➜  ruby-sigstore git:(add_rubocop) ✗ gem verify Rakefile
Verifying /Users/rochlefebvre/src/github.com/Shopify/ruby-sigstore/Rakefile
:noice:
ERROR:  While executing gem ... (ArgumentError)
    "se\");\n#" is not an octal string

We should be checking our arguments for gem-iness and error gracefully unless they are supported file types. Note that gem install --verify-signatures and gem build --sign probably check for us already.