github.com/zmap/zlint@v1.1.0/lints/lint_utc_time_does_not_include_seconds.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 4.1.2.5.1. UTCTime 19 The universal time type, UTCTime, is a standard ASN.1 type intended 20 for representation of dates and time. UTCTime specifies the year 21 through the two low-order digits and time is specified to the 22 precision of one minute or one second. UTCTime includes either Z 23 (for Zulu, or Greenwich Mean Time) or a time differential. 24 For the purposes of this profile, UTCTime values MUST be expressed in 25 Greenwich Mean Time (Zulu) and MUST include seconds (i.e., times are 26 YYMMDDHHMMSSZ), even where the number of seconds is zero. Conforming 27 systems MUST interpret the year field (YY) as follows: 28 29 Where YY is greater than or equal to 50, the year SHALL be 30 interpreted as 19YY; and 31 32 Where YY is less than 50, the year SHALL be interpreted as 20YY. 33 ************************************************************************/ 34 35 import ( 36 "github.com/zmap/zcrypto/x509" 37 "github.com/zmap/zlint/util" 38 ) 39 40 type utcNoSecond struct { 41 } 42 43 func (l *utcNoSecond) Initialize() error { 44 return nil 45 } 46 47 func (l *utcNoSecond) CheckApplies(c *x509.Certificate) bool { 48 firstDate, secondDate := util.GetTimes(c) 49 beforeTag, afterTag := util.FindTimeType(firstDate, secondDate) 50 date1Utc := beforeTag == 23 51 date2Utc := afterTag == 23 52 return date1Utc || date2Utc 53 } 54 55 func (l *utcNoSecond) Execute(c *x509.Certificate) *LintResult { 56 date1, date2 := util.GetTimes(c) 57 beforeTag, afterTag := util.FindTimeType(date1, date2) 58 date1Utc := beforeTag == 23 59 date2Utc := afterTag == 23 60 if date1Utc { 61 if len(date1.Bytes) != 13 && len(date1.Bytes) != 17 { 62 return &LintResult{Status: Error} 63 } 64 } 65 if date2Utc { 66 if len(date2.Bytes) != 13 && len(date2.Bytes) != 17 { 67 return &LintResult{Status: Error} 68 } 69 } 70 return &LintResult{Status: Pass} 71 } 72 73 func init() { 74 RegisterLint(&Lint{ 75 Name: "e_utc_time_does_not_include_seconds", 76 Description: "UTCTime values MUST include seconds", 77 Citation: "RFC 5280: 4.1.2.5.1", 78 Source: RFC5280, 79 EffectiveDate: util.RFC2459Date, 80 Lint: &utcNoSecond{}, 81 }) 82 }