Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from glog to klog #962

Merged
merged 3 commits into from
Aug 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions client/ctclient/cmd/bisect.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import (
"fmt"
"sort"

"github.com/golang/glog"
ct "github.com/google/certificate-transparency-go"
"github.com/spf13/cobra"
"k8s.io/klog/v2"
)

func init() {
Expand All @@ -45,7 +45,7 @@ func init() {
func runBisect(ctx context.Context) {
logClient := connect(ctx)
if timestamp == 0 {
glog.Exit("No -timestamp option supplied")
klog.Exit("No -timestamp option supplied")
}
target := timestamp
sth, err := logClient.GetSTH(ctx)
Expand All @@ -58,18 +58,18 @@ func runBisect(ctx context.Context) {
exitWithDetails(err)
}
if l := len(entries.Entries); l != 1 {
glog.Exitf("Unexpected number (%d) of entries received requesting index %d", l, idx)
klog.Exitf("Unexpected number (%d) of entries received requesting index %d", l, idx)
}
logEntry, err := ct.RawLogEntryFromLeaf(idx, &entries.Entries[0])
if err != nil {
glog.Exitf("Failed to parse leaf %d: %v", idx, err)
klog.Exitf("Failed to parse leaf %d: %v", idx, err)
}
return logEntry
}
// Performing a binary search assumes that the timestamps are monotonically
// increasing.
idx := sort.Search(int(sth.TreeSize), func(idx int) bool {
glog.V(1).Infof("check timestamp at index %d", idx)
klog.V(1).Infof("check timestamp at index %d", idx)
entry := getEntry(int64(idx))
return entry.Leaf.TimestampedEntry.Timestamp >= uint64(target)
})
Expand Down
14 changes: 7 additions & 7 deletions client/ctclient/cmd/get_consistency_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ import (
"encoding/hex"
"fmt"

"github.com/golang/glog"
"github.com/google/certificate-transparency-go/client"
"github.com/spf13/cobra"
"github.com/transparency-dev/merkle/proof"
"github.com/transparency-dev/merkle/rfc6962"
"k8s.io/klog/v2"
)

var (
Expand Down Expand Up @@ -56,28 +56,28 @@ func init() {
func runGetConsistencyProof(ctx context.Context) {
logClient := connect(ctx)
if treeSize <= 0 {
glog.Exit("No valid --size supplied")
klog.Exit("No valid --size supplied")
}
if prevSize <= 0 {
glog.Exit("No valid --prev_size supplied")
klog.Exit("No valid --prev_size supplied")
}
var hash1, hash2 []byte
if prevHash != "" {
var err error
hash1, err = hashFromString(prevHash)
if err != nil {
glog.Exitf("Invalid --prev_hash: %v", err)
klog.Exitf("Invalid --prev_hash: %v", err)
}
}
if treeHash != "" {
var err error
hash2, err = hashFromString(treeHash)
if err != nil {
glog.Exitf("Invalid --tree_hash: %v", err)
klog.Exitf("Invalid --tree_hash: %v", err)
}
}
if (hash1 != nil) != (hash2 != nil) {
glog.Exitf("Need both --prev_hash and --tree_hash or neither")
klog.Exitf("Need both --prev_hash and --tree_hash or neither")
}
getConsistencyProofBetween(ctx, logClient, prevSize, treeSize, hash1, hash2)
}
Expand All @@ -96,7 +96,7 @@ func getConsistencyProofBetween(ctx context.Context, logClient client.CheckLogCl
}
// We have tree hashes so we can verify the proof.
if err := proof.VerifyConsistency(rfc6962.DefaultHasher, first, second, pf, prevHash, treeHash); err != nil {
glog.Exitf("Failed to VerifyConsistency(%x @size=%d, %x @size=%d): %v", prevHash, first, treeHash, second, err)
klog.Exitf("Failed to VerifyConsistency(%x @size=%d, %x @size=%d): %v", prevHash, first, treeHash, second, err)
}
fmt.Printf("Verified that hash %x @%d + proof = hash %x @%d\n", prevHash, first, treeHash, second)
}
Expand Down
8 changes: 4 additions & 4 deletions client/ctclient/cmd/get_entries.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ import (
"fmt"
"os"

"github.com/golang/glog"
ct "github.com/google/certificate-transparency-go"
"github.com/google/certificate-transparency-go/x509"
"github.com/google/certificate-transparency-go/x509util"
"github.com/spf13/cobra"
"k8s.io/klog/v2"
)

var (
Expand Down Expand Up @@ -55,7 +55,7 @@ func init() {
func runGetEntries(ctx context.Context) {
logClient := connect(ctx)
if getFirst == -1 {
glog.Exit("No -first option supplied")
klog.Exit("No -first option supplied")
}
if getLast == -1 {
getLast = getFirst
Expand Down Expand Up @@ -102,7 +102,7 @@ func showRawCert(cert ct.ASN1Cert) {
if textOut {
c, err := x509.ParseCertificate(cert.Data)
if err != nil {
glog.Errorf("Error parsing certificate: %q", err.Error())
klog.Errorf("Error parsing certificate: %q", err.Error())
}
if c == nil {
return
Expand All @@ -123,6 +123,6 @@ func showParsedCert(cert *x509.Certificate) {

func showPEMData(data []byte) {
if err := pem.Encode(os.Stdout, &pem.Block{Type: "CERTIFICATE", Bytes: data}); err != nil {
glog.Errorf("Failed to PEM encode cert: %q", err.Error())
klog.Errorf("Failed to PEM encode cert: %q", err.Error())
}
}
22 changes: 11 additions & 11 deletions client/ctclient/cmd/get_inclusion_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ import (
"strings"
"time"

"github.com/golang/glog"
ct "github.com/google/certificate-transparency-go"
"github.com/google/certificate-transparency-go/client"
"github.com/google/certificate-transparency-go/x509"
"github.com/spf13/cobra"
"github.com/transparency-dev/merkle/proof"
"github.com/transparency-dev/merkle/rfc6962"
"k8s.io/klog/v2"
)

var (
Expand Down Expand Up @@ -66,7 +66,7 @@ func runGetInclusionProof(ctx context.Context) {
var err error
hash, err = hashFromString(leafHash)
if err != nil {
glog.Exitf("Invalid --leaf_hash supplied: %v", err)
klog.Exitf("Invalid --leaf_hash supplied: %v", err)
}
} else if len(certChain) > 0 {
// Build a leaf hash from the chain and a timestamp.
Expand All @@ -75,37 +75,37 @@ func runGetInclusionProof(ctx context.Context) {
entryTimestamp = timestamp // Use user-specified timestamp.
}
if entryTimestamp == 0 {
glog.Exit("No timestamp available to accompany certificate")
klog.Exit("No timestamp available to accompany certificate")
}

var leafEntry *ct.MerkleTreeLeaf
cert, err := x509.ParseCertificate(chain[0].Data)
if x509.IsFatal(err) {
glog.Warningf("Failed to parse leaf certificate: %v", err)
klog.Warningf("Failed to parse leaf certificate: %v", err)
leafEntry = ct.CreateX509MerkleTreeLeaf(chain[0], uint64(entryTimestamp))
} else if cert.IsPrecertificate() {
leafEntry, err = ct.MerkleTreeLeafFromRawChain(chain, ct.PrecertLogEntryType, uint64(entryTimestamp))
if err != nil {
glog.Exitf("Failed to build pre-certificate leaf entry: %v", err)
klog.Exitf("Failed to build pre-certificate leaf entry: %v", err)
}
} else {
leafEntry = ct.CreateX509MerkleTreeLeaf(chain[0], uint64(entryTimestamp))
}

leafHash, err := ct.LeafHashForLeaf(leafEntry)
if err != nil {
glog.Exitf("Failed to create hash of leaf: %v", err)
klog.Exitf("Failed to create hash of leaf: %v", err)
}
hash = leafHash[:]

// Print a warning if this timestamp is still within the MMD window.
when := ct.TimestampToTime(uint64(entryTimestamp))
if age := time.Since(when); age < logMMD {
glog.Warningf("WARNING: Timestamp (%v) is with MMD window (%v), log may not have incorporated this entry yet.", when, logMMD)
klog.Warningf("WARNING: Timestamp (%v) is with MMD window (%v), log may not have incorporated this entry yet.", when, logMMD)
}
}
if len(hash) != sha256.Size {
glog.Exit("No leaf hash available")
klog.Exit("No leaf hash available")
}
getInclusionProofForHash(ctx, logClient, hash)
}
Expand Down Expand Up @@ -133,7 +133,7 @@ func getInclusionProofForHash(ctx context.Context, logClient client.CheckLogClie
if sth != nil {
// If we retrieved an STH we can verify the proof.
if err := proof.VerifyInclusion(rfc6962.DefaultHasher, uint64(rsp.LeafIndex), sth.TreeSize, hash, rsp.AuditPath, sth.SHA256RootHash[:]); err != nil {
glog.Exitf("Failed to VerifyInclusion(%d, %d)=%v", rsp.LeafIndex, sth.TreeSize, err)
klog.Exitf("Failed to VerifyInclusion(%d, %d)=%v", rsp.LeafIndex, sth.TreeSize, err)
}
fmt.Printf("Verified that hash %x + proof = root hash %x\n", hash, sth.SHA256RootHash)
}
Expand All @@ -142,7 +142,7 @@ func getInclusionProofForHash(ctx context.Context, logClient client.CheckLogClie
func chainFromFile(filename string) ([]ct.ASN1Cert, int64) {
contents, err := os.ReadFile(filename)
if err != nil {
glog.Exitf("Failed to read certificate file: %v", err)
klog.Exitf("Failed to read certificate file: %v", err)
}
rest := contents
var chain []ct.ASN1Cert
Expand All @@ -157,7 +157,7 @@ func chainFromFile(filename string) ([]ct.ASN1Cert, int64) {
}
}
if len(chain) == 0 {
glog.Exitf("No certificates found in %s", certChain)
klog.Exitf("No certificates found in %s", certChain)
}

// Also look for something like a text timestamp for convenience.
Expand Down
26 changes: 13 additions & 13 deletions client/ctclient/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ import (
"strings"
"time"

"github.com/golang/glog"
ct "github.com/google/certificate-transparency-go"
"github.com/google/certificate-transparency-go/client"
"github.com/google/certificate-transparency-go/jsonclient"
"github.com/google/certificate-transparency-go/loglist"
"github.com/google/certificate-transparency-go/x509util"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"k8s.io/klog/v2"
)

const connectionFlags = "{--log_uri uri | --log_name name [--log_list {file|uri}]} [--pub_key file]"
Expand All @@ -47,7 +47,7 @@ var (
)

func init() {
// Add flags added with "flag" package, including glog, to Cobra flag set.
// Add flags added with "flag" package, including klog, to Cobra flag set.
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)

flags := rootCmd.PersistentFlags()
Expand All @@ -72,7 +72,7 @@ var rootCmd = &cobra.Command{
// appropriately. It needs to be called exactly once by main().
func Execute() {
if err := rootCmd.Execute(); err != nil {
glog.Fatal(err)
klog.Fatal(err)
}
}

Expand All @@ -82,15 +82,15 @@ func signatureToString(signed *ct.DigitallySigned) string {

func exitWithDetails(err error) {
if err, ok := err.(client.RspError); ok {
glog.Infof("HTTP details: status=%d, body:\n%s", err.StatusCode, err.Body)
klog.Infof("HTTP details: status=%d, body:\n%s", err.StatusCode, err.Body)
}
glog.Exit(err.Error())
klog.Exit(err.Error())
}

func connect(ctx context.Context) *client.LogClient {
var tlsCfg *tls.Config
if skipHTTPSVerify {
glog.Warning("Skipping HTTPS connection verification")
klog.Warning("Skipping HTTPS connection verification")
tlsCfg = &tls.Config{InsecureSkipVerify: skipHTTPSVerify}
}
httpClient := &http.Client{
Expand All @@ -110,7 +110,7 @@ func connect(ctx context.Context) *client.LogClient {
if pubKey != "" {
pubkey, err := os.ReadFile(pubKey)
if err != nil {
glog.Exit(err)
klog.Exit(err)
}
opts.PublicKey = string(pubkey)
}
Expand All @@ -119,34 +119,34 @@ func connect(ctx context.Context) *client.LogClient {
if logName != "" {
llData, err := x509util.ReadFileOrURL(logList, httpClient)
if err != nil {
glog.Exitf("Failed to read log list: %v", err)
klog.Exitf("Failed to read log list: %v", err)
}
ll, err := loglist.NewFromJSON(llData)
if err != nil {
glog.Exitf("Failed to build log list: %v", err)
klog.Exitf("Failed to build log list: %v", err)
}

logs := ll.FindLogByName(logName)
if len(logs) == 0 {
glog.Exitf("No log with name like %q found in loglist %q", logName, logList)
klog.Exitf("No log with name like %q found in loglist %q", logName, logList)
}
if len(logs) > 1 {
logNames := make([]string, len(logs))
for i, log := range logs {
logNames[i] = fmt.Sprintf("%q", log.Description)
}
glog.Exitf("Multiple logs with name like %q found in loglist: %s", logName, strings.Join(logNames, ","))
klog.Exitf("Multiple logs with name like %q found in loglist: %s", logName, strings.Join(logNames, ","))
}
uri = "https://" + logs[0].URL
if opts.PublicKey == "" {
opts.PublicKeyDER = logs[0].Key
}
}

glog.V(1).Infof("Use CT log at %s", uri)
klog.V(1).Infof("Use CT log at %s", uri)
logClient, err := client.New(uri, httpClient, opts)
if err != nil {
glog.Exit(err)
klog.Exit(err)
}

return logClient
Expand Down
6 changes: 3 additions & 3 deletions client/ctclient/cmd/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ import (
"fmt"
"time"

"github.com/golang/glog"
ct "github.com/google/certificate-transparency-go"
"github.com/google/certificate-transparency-go/x509"
"github.com/google/certificate-transparency-go/x509util"
"github.com/spf13/cobra"
"k8s.io/klog/v2"
)

var logMMD time.Duration
Expand All @@ -48,7 +48,7 @@ func init() {
func runUpload(ctx context.Context) {
logClient := connect(ctx)
if certChain == "" {
glog.Exitf("No certificate chain file specified with -cert_chain")
klog.Exitf("No certificate chain file specified with -cert_chain")
}
chain, _ := chainFromFile(certChain)

Expand Down Expand Up @@ -76,7 +76,7 @@ func runUpload(ctx context.Context) {
leafEntry := ct.CreateX509MerkleTreeLeaf(chain[0], sct.Timestamp)
leafHash, err := ct.LeafHashForLeaf(leafEntry)
if err != nil {
glog.Exitf("Failed to create hash of leaf: %v", err)
klog.Exitf("Failed to create hash of leaf: %v", err)
}

// Display the SCT.
Expand Down
6 changes: 5 additions & 1 deletion client/ctclient/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
// ctclient is a command-line utility for interacting with CT logs.
package main

import "github.com/google/certificate-transparency-go/client/ctclient/cmd"
import (
"github.com/google/certificate-transparency-go/client/ctclient/cmd"
"k8s.io/klog/v2"
)

func main() {
klog.InitFlags(nil)
cmd.Execute()
}
Loading