...

Source file src/github.com/google/certificate-transparency-go/ctpolicy/chromepolicy.go

Documentation: github.com/google/certificate-transparency-go/ctpolicy

     1  // Copyright 2018 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 ctpolicy
    16  
    17  import (
    18  	"github.com/google/certificate-transparency-go/loglist3"
    19  	"github.com/google/certificate-transparency-go/x509"
    20  )
    21  
    22  // ChromeCTPolicy implements logic for complying with Chrome's CT log policy
    23  type ChromeCTPolicy struct {
    24  }
    25  
    26  // LogsByGroup describes submission requirements for embedded SCTs according to
    27  // https://github.com/chromium/ct-policy/blob/master/ct_policy.md#qualifying-certificate.
    28  // Returns an error if it's not possible to satisfy the policy with the provided loglist.
    29  func (chromeP ChromeCTPolicy) LogsByGroup(cert *x509.Certificate, approved *loglist3.LogList) (LogPolicyData, error) {
    30  	googGroup := LogGroupInfo{Name: "Google-operated", IsBase: false}
    31  	googGroup.populate(approved, func(op *loglist3.Operator) bool { return op.GoogleOperated() })
    32  	if err := googGroup.setMinInclusions(1); err != nil {
    33  		return nil, err
    34  	}
    35  
    36  	nonGoogGroup := LogGroupInfo{Name: "Non-Google-operated", IsBase: false}
    37  	nonGoogGroup.populate(approved, func(op *loglist3.Operator) bool { return !op.GoogleOperated() })
    38  	if err := nonGoogGroup.setMinInclusions(1); err != nil {
    39  		return nil, err
    40  	}
    41  	var incCount int
    42  	switch m := lifetimeInMonths(cert); {
    43  	case m < 15:
    44  		incCount = 2
    45  	case m <= 27:
    46  		incCount = 3
    47  	case m <= 39:
    48  		incCount = 4
    49  	default:
    50  		incCount = 5
    51  	}
    52  	baseGroup, err := BaseGroupFor(approved, incCount)
    53  	if err != nil {
    54  		return nil, err
    55  	}
    56  	groups := LogPolicyData{
    57  		googGroup.Name:    &googGroup,
    58  		nonGoogGroup.Name: &nonGoogGroup,
    59  		baseGroup.Name:    baseGroup,
    60  	}
    61  	return groups, nil
    62  }
    63  
    64  // Name returns label for the submission policy.
    65  func (chromeP ChromeCTPolicy) Name() string {
    66  	return "Chrome"
    67  }
    68  

View as plain text