github.com/zmap/zlint@v1.1.0/lints/lint_ext_san_uri_relative.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 subjectAltName 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 extSANURIRelative struct{} 37 38 func (l *extSANURIRelative) Initialize() error { 39 return nil 40 } 41 42 func (l *extSANURIRelative) CheckApplies(c *x509.Certificate) bool { 43 return util.IsExtInCert(c, util.SubjectAlternateNameOID) 44 } 45 46 func (l *extSANURIRelative) Execute(c *x509.Certificate) *LintResult { 47 for _, uri := range c.URIs { 48 parsed_uri, err := url.Parse(uri) 49 50 if err != nil { 51 return &LintResult{Status: Error} 52 } 53 54 if !parsed_uri.IsAbs() { 55 return &LintResult{Status: Error} 56 } 57 } 58 return &LintResult{Status: Pass} 59 } 60 61 func init() { 62 RegisterLint(&Lint{ 63 Name: "e_ext_san_uri_relative", 64 Description: "When the subjectAlternateName extension is present and a URI is used, the name MUST NOT be a relative URI", 65 Citation: "RFC 5280: 4.2.1.6", 66 Source: RFC5280, 67 EffectiveDate: util.RFC5280Date, 68 Lint: &extSANURIRelative{}, 69 }) 70 }