github.com/zmap/zlint@v1.1.0/util/time.go (about)

     1  /*
     2   * ZLint Copyright 2018 Regents of the University of Michigan
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License"); you may not
     5   * use this file except in compliance with the License. You may obtain a copy
     6   * of the License at http://www.apache.org/licenses/LICENSE-2.0
     7   *
     8   * Unless required by applicable law or agreed to in writing, software
     9   * distributed under the License is distributed on an "AS IS" BASIS,
    10   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
    11   * implied. See the License for the specific language governing
    12   * permissions and limitations under the License.
    13   */
    14  
    15  package util
    16  
    17  import (
    18  	"encoding/asn1"
    19  	"time"
    20  
    21  	"github.com/zmap/zcrypto/x509"
    22  )
    23  
    24  var (
    25  	ZeroDate                    = time.Date(0000, time.January, 1, 0, 0, 0, 0, time.UTC)
    26  	RFC1035Date                 = time.Date(1987, time.January, 1, 0, 0, 0, 0, time.UTC)
    27  	RFC2459Date                 = time.Date(1999, time.January, 1, 0, 0, 0, 0, time.UTC)
    28  	RFC3280Date                 = time.Date(2002, time.April, 1, 0, 0, 0, 0, time.UTC)
    29  	RFC3490Date                 = time.Date(2003, time.March, 1, 0, 0, 0, 0, time.UTC)
    30  	RFC8399Date                 = time.Date(2018, time.May, 1, 0, 0, 0, 0, time.UTC)
    31  	RFC4325Date                 = time.Date(2005, time.December, 1, 0, 0, 0, 0, time.UTC)
    32  	RFC4630Date                 = time.Date(2006, time.August, 1, 0, 0, 0, 0, time.UTC)
    33  	RFC5280Date                 = time.Date(2008, time.May, 1, 0, 0, 0, 0, time.UTC)
    34  	RFC6818Date                 = time.Date(2013, time.January, 1, 0, 0, 0, 0, time.UTC)
    35  	CABEffectiveDate            = time.Date(2012, time.July, 1, 0, 0, 0, 0, time.UTC)
    36  	CABReservedIPDate           = time.Date(2016, time.October, 1, 0, 0, 0, 0, time.UTC)
    37  	CABGivenNameDate            = time.Date(2016, time.September, 7, 0, 0, 0, 0, time.UTC)
    38  	CABSerialNumberEntropyDate  = time.Date(2016, time.September, 30, 0, 0, 0, 0, time.UTC)
    39  	CABV102Date                 = time.Date(2012, time.June, 8, 0, 0, 0, 0, time.UTC)
    40  	CABV113Date                 = time.Date(2013, time.February, 21, 0, 0, 0, 0, time.UTC)
    41  	CABV114Date                 = time.Date(2013, time.May, 3, 0, 0, 0, 0, time.UTC)
    42  	CABV116Date                 = time.Date(2013, time.July, 29, 0, 0, 0, 0, time.UTC)
    43  	CABV130Date                 = time.Date(2015, time.April, 16, 0, 0, 0, 0, time.UTC)
    44  	CABV131Date                 = time.Date(2015, time.September, 28, 0, 0, 0, 0, time.UTC)
    45  	NO_SHA1                     = time.Date(2016, time.January, 1, 0, 0, 0, 0, time.UTC)
    46  	NoRSA1024RootDate           = time.Date(2011, time.January, 1, 0, 0, 0, 0, time.UTC)
    47  	NoRSA1024Date               = time.Date(2014, time.January, 1, 0, 0, 0, 0, time.UTC)
    48  	GeneralizedDate             = time.Date(2050, time.January, 1, 0, 0, 0, 0, time.UTC)
    49  	NoReservedIP                = time.Date(2015, time.November, 1, 0, 0, 0, 0, time.UTC)
    50  	SubCert39Month              = time.Date(2016, time.July, 2, 0, 0, 0, 0, time.UTC)
    51  	SubCert825Days              = time.Date(2018, time.March, 2, 0, 0, 0, 0, time.UTC)
    52  	CABV148Date                 = time.Date(2017, time.June, 8, 0, 0, 0, 0, time.UTC)
    53  	EtsiEn319_412_5_V2_2_1_Date = time.Date(2017, time.November, 1, 0, 0, 0, 0, time.UTC)
    54  	OnionOnlyEVDate             = time.Date(2015, time.May, 1, 0, 0, 0, 0, time.UTC)
    55  	CABV201Date                 = time.Date(2017, time.July, 28, 0, 0, 0, 0, time.UTC)
    56  	AppleCTPolicyDate           = time.Date(2018, time.October, 15, 0, 0, 0, 0, time.UTC)
    57  )
    58  
    59  func FindTimeType(firstDate, secondDate asn1.RawValue) (int, int) {
    60  	return firstDate.Tag, secondDate.Tag
    61  }
    62  
    63  func GetTimes(cert *x509.Certificate) (asn1.RawValue, asn1.RawValue) {
    64  	var outSeq, firstDate, secondDate asn1.RawValue
    65  	// Unmarshal into the sequence
    66  	rest, err := asn1.Unmarshal(cert.RawTBSCertificate, &outSeq)
    67  	// Start unmarshalling the bytes
    68  	rest, err = asn1.Unmarshal(outSeq.Bytes, &outSeq)
    69  	// This is here to account for if version is not included
    70  	if outSeq.Tag == 0 {
    71  		rest, err = asn1.Unmarshal(rest, &outSeq)
    72  	}
    73  	rest, err = asn1.Unmarshal(rest, &outSeq)
    74  	rest, err = asn1.Unmarshal(rest, &outSeq)
    75  	rest, err = asn1.Unmarshal(rest, &outSeq)
    76  	// Finally at the validity date, load them into a different RawValue
    77  	rest, err = asn1.Unmarshal(outSeq.Bytes, &firstDate)
    78  	_, err = asn1.Unmarshal(rest, &secondDate)
    79  	if err != nil {
    80  		return asn1.RawValue{}, asn1.RawValue{}
    81  	}
    82  	return firstDate, secondDate
    83  }