github.com/zmap/zlint@v1.1.0/lints/lint_spki_rsa_encryption_parameter_not_null.go (about) 1 package lints 2 3 /* 4 * ZLint Copyright 2019 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 "RFC5280: RFC 4055, Section 1.2" 19 RSA: Encoded algorithm identifier MUST have NULL parameters. 20 *******************************************************************************************************/ 21 22 import ( 23 "fmt" 24 25 "github.com/zmap/zcrypto/x509" 26 "github.com/zmap/zlint/util" 27 "golang.org/x/crypto/cryptobyte" 28 cryptobyte_asn1 "golang.org/x/crypto/cryptobyte/asn1" 29 ) 30 31 type rsaSPKIEncryptionParamNotNULL struct{} 32 33 func (l *rsaSPKIEncryptionParamNotNULL) Initialize() error { 34 return nil 35 } 36 37 func (l *rsaSPKIEncryptionParamNotNULL) CheckApplies(c *x509.Certificate) bool { 38 // explicitly check for util.OidRSAEncryption, as RSA-PSS or RSA-OAEP certificates might be classified with c.PublicKeyAlgorithm = RSA 39 return c.PublicKeyAlgorithmOID.Equal(util.OidRSAEncryption) 40 } 41 42 func (l *rsaSPKIEncryptionParamNotNULL) Execute(c *x509.Certificate) *LintResult { 43 input := cryptobyte.String(c.RawSubjectPublicKeyInfo) 44 45 var publicKeyInfo cryptobyte.String 46 if !input.ReadASN1(&publicKeyInfo, cryptobyte_asn1.SEQUENCE) { 47 return &LintResult{Status: Fatal, Details: "error reading pkixPublicKey"} 48 } 49 50 var algorithm cryptobyte.String 51 var tag cryptobyte_asn1.Tag 52 // use ReadAnyElement to preserve tag and length octets 53 if !publicKeyInfo.ReadAnyASN1Element(&algorithm, &tag) { 54 return &LintResult{Status: Fatal, Details: "error reading pkixPublicKey"} 55 } 56 57 if err := util.CheckAlgorithmIDParamNotNULL(algorithm, util.OidRSAEncryption); err != nil { 58 return &LintResult{Status: Error, Details: fmt.Sprintf("certificate pkixPublicKey %s", err.Error())} 59 } 60 61 return &LintResult{Status: Pass} 62 } 63 64 func init() { 65 RegisterLint(&Lint{ 66 Name: "e_spki_rsa_encryption_parameter_not_null", 67 Description: "RSA: Encoded public key algorithm identifier MUST have NULL parameters", 68 Citation: "RFC 4055, Section 1.2", 69 Source: RFC5280, // RFC4055 is referenced in RFC5280, Section 1 70 EffectiveDate: util.RFC5280Date, 71 Lint: &rsaSPKIEncryptionParamNotNULL{}, 72 }) 73 }