| 1 |
// Copyright 2024 The Sigstore Authors. |
| 2 |
// |
| 3 |
// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
// you may not use this file except in compliance with the License. |
| 5 |
// You may obtain a copy of the License at |
| 6 |
// |
| 7 |
// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
// |
| 9 |
// Unless required by applicable law or agreed to in writing, software |
| 10 |
// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
// See the License for the specific language governing permissions and |
| 13 |
// limitations under the License. |
| 14 |
|
| 15 |
// Package main implements fake signer to be used in tests |
| 16 |
package main |
| 17 |
|
| 18 |
import ( |
| 19 |
"fmt" |
| 20 |
"os" |
| 21 |
|
| 22 |
"github.com/davecgh/go-spew/spew" |
| 23 |
"github.com/sigstore/sigstore/pkg/signature/kms/cliplugin/handler" |
| 24 |
) |
| 25 |
|
| 26 |
// See cliplugin.common.ProtocolVersion |
| 27 |
const expectedProtocolVersion = "v1" |
| 28 |
|
| 29 |
func main() { |
| 30 |
// we log to stderr, not stdout. stdout is reserved for the plugin return value. |
| 31 |
spew.Fdump(os.Stderr, os.Args) |
| 32 |
if protocolVersion := os.Args[1]; protocolVersion != expectedProtocolVersion { |
| 33 |
err := fmt.Errorf("expected protocol version: %s, got %s", expectedProtocolVersion, protocolVersion) |
| 34 |
handler.WriteErrorResponse(os.Stdout, err) |
| 35 |
panic(err) |
| 36 |
} |
| 37 |
|
| 38 |
pluginArgs, err := handler.GetPluginArgs(os.Args) |
| 39 |
if err != nil { |
| 40 |
handler.WriteErrorResponse(os.Stdout, err) |
| 41 |
panic(err) |
| 42 |
} |
| 43 |
spew.Fdump(os.Stderr, pluginArgs) |
| 44 |
|
| 45 |
signerVerifier := &LocalSignerVerifier{ |
| 46 |
hashFunc: pluginArgs.InitOptions.HashFunc, |
| 47 |
keyResourceID: pluginArgs.InitOptions.KeyResourceID, |
| 48 |
} |
| 49 |
|
| 50 |
resp, err := handler.Dispatch(os.Stdout, os.Stdin, pluginArgs, signerVerifier) |
| 51 |
if err != nil { |
| 52 |
// Dispatch() will have already called WriteResponse() with the error. |
| 53 |
panic(err) |
| 54 |
} |
| 55 |
spew.Fdump(os.Stderr, resp) |
| 56 |
} |