github.com/zmap/zlint@v1.1.0/lints/lint_ext_ian_uri_host_not_fqdn_or_ip.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 When the issuerAltName extension contains a URI, the name MUST be 19 stored in the uniformResourceIdentifier (an IA5String). The name 20 MUST NOT be a relative URI, and it MUST follow the URI syntax and 21 encoding rules specified in [RFC3986]. The name MUST include both a 22 scheme (e.g., "http" or "ftp") and a scheme-specific-part. URIs that 23 include an authority ([RFC3986], Section 3.2) MUST include a fully 24 qualified domain name or IP address as the host. Rules for encoding 25 Internationalized Resource Identifiers (IRIs) are specified in 26 Section 7.4. 27 *********************************************************************/ 28 29 import ( 30 "net/url" 31 32 "github.com/zmap/zcrypto/x509" 33 "github.com/zmap/zlint/util" 34 ) 35 36 type IANURIFQDNOrIP struct{} 37 38 func (l *IANURIFQDNOrIP) Initialize() error { 39 return nil 40 } 41 42 func (l *IANURIFQDNOrIP) CheckApplies(c *x509.Certificate) bool { 43 return util.IsExtInCert(c, util.IssuerAlternateNameOID) 44 } 45 46 func (l *IANURIFQDNOrIP) Execute(c *x509.Certificate) *LintResult { 47 for _, uri := range c.IANURIs { 48 if uri != "" { 49 parsedUrl, err := url.Parse(uri) 50 if err != nil { 51 return &LintResult{Status: Error} 52 } 53 host := parsedUrl.Host 54 if !util.AuthIsFQDNOrIP(host) { 55 return &LintResult{Status: Error} 56 } 57 } 58 } 59 return &LintResult{Status: Pass} 60 } 61 62 func init() { 63 RegisterLint(&Lint{ 64 Name: "e_ext_ian_uri_host_not_fqdn_or_ip", 65 Description: "URIs that include an authority ([RFC3986], Section 3.2) MUST include a fully qualified domain name or IP address as the host", 66 Citation: "RFC 5280: 4.2.1.6", 67 Source: RFC5280, 68 EffectiveDate: util.RFC5280Date, 69 Lint: &IANURIFQDNOrIP{}, 70 }) 71 }