github.com/mre-fog/trillianxx@v1.1.2-0.20180615153820-ae375a99d36a/examples/ct/ctmapper/lookup/lookup.go (about) 1 // Copyright 2016 Google Inc. 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 // The lookup binary looks up a specific ID in a map. 16 package main 17 18 import ( 19 "context" 20 "flag" 21 22 "github.com/golang/glog" 23 pb "github.com/golang/protobuf/proto" 24 "github.com/google/trillian" 25 "github.com/google/trillian/examples/ct/ctmapper" 26 "github.com/google/trillian/examples/ct/ctmapper/ctmapperpb" 27 "google.golang.org/grpc" 28 ) 29 30 var mapServer = flag.String("map_server", "", "host:port for the map server") 31 var mapID = flag.Int("map_id", -1, "Map ID to write to") 32 33 func main() { 34 flag.Parse() 35 36 if flag.NArg() == 0 { 37 glog.Info("Usage: lookup [domain <domain> ...]") 38 return 39 } 40 41 conn, err := grpc.Dial(*mapServer, grpc.WithInsecure()) 42 if err != nil { 43 glog.Fatal(err) 44 } 45 defer conn.Close() 46 47 mapID := int64(*mapID) 48 vmap := trillian.NewTrillianMapClient(conn) 49 50 for i := 0; i < flag.NArg(); i++ { 51 domain := flag.Arg(i) 52 req := &trillian.GetMapLeavesRequest{ 53 MapId: mapID, 54 Index: [][]byte{ctmapper.HashDomain(domain)}, 55 } 56 resp, err := vmap.GetLeaves(context.Background(), req) 57 if err != nil { 58 glog.Warning("Failed to lookup domain %s: %v", domain, err) 59 continue 60 } 61 for _, kv := range resp.MapLeafInclusion { 62 el := ctmapperpb.EntryList{} 63 v := kv.Leaf.LeafValue 64 if len(v) == 0 { 65 continue 66 } 67 if err := pb.Unmarshal(v, &el); err != nil { 68 glog.Warning("Failed to unmarshal leaf %s: %v", kv.Leaf.LeafValue, err) 69 continue 70 } 71 glog.Infof("Found %s with certs at indices %v and pre-certs at indices %v", el.Domain, el.CertIndex, el.PrecertIndex) 72 } 73 } 74 }