github.com/google/trillian-examples@v0.0.0-20240520080811-0d40d35cef0e/binary_transparency/firmware/cmd/publisher/publish.go (about)

     1  // Copyright 2020 Google LLC. All Rights Reserved.
     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  // publish is a demo tool to put firmware metadata into the log.
    16  package main
    17  
    18  import (
    19  	"context"
    20  	"flag"
    21  	"time"
    22  
    23  	"github.com/golang/glog"
    24  	"github.com/google/trillian-examples/binary_transparency/firmware/cmd/publisher/impl"
    25  	"github.com/google/trillian-examples/binary_transparency/firmware/internal/crypto"
    26  	"golang.org/x/mod/sumdb/note"
    27  )
    28  
    29  var (
    30  	logURL = flag.String("log_url", "http://localhost:8000", "Base URL of the log HTTP API")
    31  
    32  	deviceID   = flag.String("device", "", "the target device for the firmware")
    33  	revision   = flag.Uint64("revision", 1, "the version of the firmware")
    34  	binaryPath = flag.String("binary_path", "", "file path to the firmware binary")
    35  	timestamp  = flag.String("timestamp", "", "timestamp formatted as RFC3339, or empty to use current time")
    36  	timeout    = flag.Duration("timeout", 5*time.Minute, "Duration to wait for inclusion of submitted metadata")
    37  	outputPath = flag.String("output_path", "/tmp/update.ota", "File path to write the update package file to. This file is intended to be consumed by the flash_tool only.")
    38  )
    39  
    40  func main() {
    41  	flag.Parse()
    42  	ctx, cancel := context.WithTimeout(context.Background(), *timeout)
    43  	defer cancel()
    44  
    45  	testLogSigV, _ := note.NewVerifier(crypto.TestFTPersonalityPub)
    46  
    47  	if err := impl.Main(ctx, impl.PublishOpts{
    48  		LogURL:         *logURL,
    49  		DeviceID:       *deviceID,
    50  		Revision:       *revision,
    51  		BinaryPath:     *binaryPath,
    52  		Timestamp:      *timestamp,
    53  		OutputPath:     *outputPath,
    54  		LogSigVerifier: testLogSigV,
    55  	}); err != nil {
    56  		glog.Exitf(err.Error())
    57  	}
    58  }