...

Source file src/github.com/google/certificate-transparency-go/preload/dumpscts/dumpscts.go

Documentation: github.com/google/certificate-transparency-go/preload/dumpscts

     1  // Copyright 2015 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  // Dumpscts prints out SCTs written to a file by the preloader command in
    16  // the ../preloader directory.
    17  package main
    18  
    19  import (
    20  	"compress/zlib"
    21  	"encoding/gob"
    22  	"flag"
    23  	"io"
    24  	"log"
    25  	"os"
    26  
    27  	"github.com/google/certificate-transparency-go/preload"
    28  )
    29  
    30  var sctFile = flag.String("sct_file", "", "File to load SCTs & leaf data from")
    31  
    32  func main() {
    33  	flag.Parse()
    34  	var sctReader io.ReadCloser
    35  	if *sctFile == "" {
    36  		log.Fatal("Must specify --sct_file")
    37  	}
    38  
    39  	sctFileReader, err := os.Open(*sctFile)
    40  	if err != nil {
    41  		log.Fatal(err)
    42  	}
    43  	sctReader, err = zlib.NewReader(sctFileReader)
    44  	if err != nil {
    45  		log.Fatal(err)
    46  	}
    47  	defer func() {
    48  		err := sctReader.Close()
    49  		if err != nil && err != io.EOF {
    50  			log.Fatalf("Error closing file: %s", err)
    51  		}
    52  	}()
    53  
    54  	// TODO(alcutter) should probably store this stuff in a protobuf really.
    55  	decoder := gob.NewDecoder(sctReader)
    56  	var addedCert preload.AddedCert
    57  	numAdded := 0
    58  	numFailed := 0
    59  	for {
    60  		err = decoder.Decode(&addedCert)
    61  		if err != nil {
    62  			break
    63  		}
    64  		if addedCert.AddedOk {
    65  			log.Println(addedCert.SignedCertificateTimestamp)
    66  			numAdded++
    67  		} else {
    68  			log.Printf("Cert was not added: %s", addedCert.ErrorMessage)
    69  			numFailed++
    70  		}
    71  	}
    72  	log.Printf("Num certs added: %d, num failed: %d\n", numAdded, numFailed)
    73  }
    74  

View as plain text