github.com/zmap/zlint@v1.1.0/lints/lint_wrong_time_format_pre2050.go (about) 1 package lints 2 3 /* 4 * ZLint Copyright 2018 Regents of the University of Michigan 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 7 * use this file except in compliance with the License. You may obtain a copy 8 * of the License at http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 13 * implied. See the License for the specific language governing 14 * permissions and limitations under the License. 15 */ 16 17 /********************************************************************* 18 CAs conforming to this profile MUST always encode certificate 19 validity dates through the year 2049 as UTCTime; certificate validity 20 dates in 2050 or later MUST be encoded as GeneralizedTime. 21 Conforming applications MUST be able to process validity dates that 22 are encoded in either UTCTime or GeneralizedTime. 23 *********************************************************************/ 24 25 import ( 26 "encoding/asn1" 27 "time" 28 29 "github.com/zmap/zcrypto/x509" 30 "github.com/zmap/zlint/util" 31 ) 32 33 type generalizedPre2050 struct{} 34 35 func (l *generalizedPre2050) Initialize() error { 36 return nil 37 } 38 39 func (l *generalizedPre2050) CheckApplies(c *x509.Certificate) bool { 40 return true 41 } 42 43 func (l *generalizedPre2050) Execute(c *x509.Certificate) *LintResult { 44 date1, date2 := util.GetTimes(c) 45 var t time.Time 46 type1, type2 := util.FindTimeType(date1, date2) 47 if type1 == 24 { 48 temp, err := asn1.Marshal(date1) 49 if err != nil { 50 return &LintResult{Status: Fatal} 51 } 52 _, err = asn1.Unmarshal(temp, &t) 53 if err != nil { 54 return &LintResult{Status: Fatal} 55 } 56 if t.Before(util.GeneralizedDate) { 57 return &LintResult{Status: Error} 58 } 59 } 60 if type2 == 24 { 61 temp, err := asn1.Marshal(date2) 62 if err != nil { 63 return &LintResult{Status: Fatal} 64 } 65 _, err = asn1.Unmarshal(temp, &t) 66 if err != nil { 67 return &LintResult{Status: Fatal} 68 } 69 if t.Before(util.GeneralizedDate) { 70 return &LintResult{Status: Error} 71 } 72 } 73 return &LintResult{Status: Pass} 74 } 75 76 func init() { 77 RegisterLint(&Lint{ 78 Name: "e_wrong_time_format_pre2050", 79 Description: "Certificates valid through the year 2049 MUST be encoded in UTC time", 80 Citation: "RFC 5280: 4.1.2.5", 81 Source: RFC5280, 82 EffectiveDate: util.RFC2459Date, 83 Lint: &generalizedPre2050{}, 84 }) 85 }