| 1 |
// Copyright 2019 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 |
// The submission_server runs (pre-)certs multi-Log submission complying with |
| 16 |
// CT-policy provided. |
| 17 |
package main |
| 18 |
|
| 19 |
import ( |
| 20 |
"context" |
| 21 |
"flag" |
| 22 |
"log" |
| 23 |
"net/http" |
| 24 |
"time" |
| 25 |
|
| 26 |
"github.com/google/certificate-transparency-go/submission" |
| 27 |
"github.com/google/trillian/monitoring/prometheus" |
| 28 |
"github.com/prometheus/client_golang/prometheus/promhttp" |
| 29 |
"k8s.io/klog/v2" |
| 30 |
) |
| 31 |
|
| 32 |
// Flags. |
| 33 |
var ( |
| 34 |
httpEndpoint = flag.String("http_endpoint", "localhost:5951", "Endpoint for HTTP (host:port)") |
| 35 |
logListPath = flag.String("loglist_path", "https://www.gstatic.com/ct/log_list/v3/log_list.json", "Path for list of CT Logs in JSON format") |
| 36 |
logListRefreshInterval = flag.Duration("loglist_refresh_interval", 24*time.Hour, "Interval between consecutive reads of Log-list") |
| 37 |
rootsRefreshInterval = flag.Duration("roots_refresh_interval", 24*time.Hour, "Interval between consecutive get-roots calls") |
| 38 |
policyType = flag.String("policy_type", "chrome", "CT-policy <chrome|apple>") |
| 39 |
dryRun = flag.Bool("dry_run", false, "No real submissions done") |
| 40 |
addPreChainTimeout = flag.Duration("add_prechain_timeout", 10*time.Second, "Timeout for each add-prechain call") |
| 41 |
loadPendingQualifiedLogs = flag.Bool("load_pending_qualified_logs", true, "Whether to submit cert to one of Pending+Qualified Logs along main submission") |
| 42 |
) |
| 43 |
|
| 44 |
func parsePolicyType() submission.CTPolicyType { |
| 45 |
switch *policyType { |
| 46 |
case "chrome": |
| 47 |
return submission.ChromeCTPolicy |
| 48 |
case "apple": |
| 49 |
return submission.AppleCTPolicy |
| 50 |
} |
| 51 |
klog.Fatalf("flag policyType does not support value %q", *policyType) |
| 52 |
return submission.ChromeCTPolicy |
| 53 |
} |
| 54 |
|
| 55 |
func main() { |
| 56 |
klog.InitFlags(nil) |
| 57 |
flag.Parse() |
| 58 |
|
| 59 |
plc := parsePolicyType() |
| 60 |
|
| 61 |
lcb := submission.BuildLogClient |
| 62 |
if *dryRun { |
| 63 |
lcb = submission.NewStubLogClient |
| 64 |
} |
| 65 |
mf := prometheus.MetricFactory{} |
| 66 |
|
| 67 |
s := submission.NewProxyServer(*logListPath, submission.GetDistributorBuilder(plc, lcb, mf), *addPreChainTimeout, mf) |
| 68 |
s.Run(context.Background(), *logListRefreshInterval, *rootsRefreshInterval, *loadPendingQualifiedLogs) |
| 69 |
http.HandleFunc("/ct/v1/proxy/add-pre-chain/", s.HandleAddPreChain) |
| 70 |
http.HandleFunc("/ct/v1/proxy/add-chain/", s.HandleAddChain) |
| 71 |
http.Handle("/metrics", promhttp.Handler()) |
| 72 |
http.HandleFunc("/", s.HandleInfo) |
| 73 |
srv := &http.Server{ |
| 74 |
Addr: *httpEndpoint, |
| 75 |
Handler: nil, |
| 76 |
ReadHeaderTimeout: 10 * time.Second, |
| 77 |
ReadTimeout: 2 * time.Minute, |
| 78 |
WriteTimeout: 2 * time.Minute, |
| 79 |
IdleTimeout: 2 * time.Minute, |
| 80 |
} |
| 81 |
log.Fatal(srv.ListenAndServe()) |
| 82 |
} |