...

Source file src/github.com/google/certificate-transparency-go/client/ctclient/cmd/get_sth.go

Documentation: github.com/google/certificate-transparency-go/client/ctclient/cmd

     1  // Copyright 2022 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  package cmd
    16  
    17  import (
    18  	"context"
    19  	"fmt"
    20  
    21  	ct "github.com/google/certificate-transparency-go"
    22  	"github.com/spf13/cobra"
    23  )
    24  
    25  func init() {
    26  	rootCmd.AddCommand(&cobra.Command{
    27  		Use:     fmt.Sprintf("get-sth %s", connectionFlags),
    28  		Aliases: []string{"sth"},
    29  		Short:   "Fetch the latest STH of the log",
    30  		Args:    cobra.MaximumNArgs(0),
    31  		Run: func(cmd *cobra.Command, _ []string) {
    32  			runGetSTH(cmd.Context())
    33  		},
    34  	})
    35  }
    36  
    37  // runGetSTH runs the get-sth command.
    38  func runGetSTH(ctx context.Context) {
    39  	logClient := connect(ctx)
    40  	sth, err := logClient.GetSTH(ctx)
    41  	if err != nil {
    42  		exitWithDetails(err)
    43  	}
    44  	// Display the STH.
    45  	when := ct.TimestampToTime(sth.Timestamp)
    46  	fmt.Printf("%v (timestamp %d): Got STH for %v log (size=%d) at %v, hash %x\n", when, sth.Timestamp, sth.Version, sth.TreeSize, logClient.BaseURI(), sth.SHA256RootHash)
    47  	fmt.Printf("%v\n", signatureToString(&sth.TreeHeadSignature))
    48  }
    49  

View as plain text