github.com/zmap/zlint@v1.1.0/lints/lint_rsa_public_exponent_not_odd.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 "BRs: 6.1.6" 19 RSA: The CA SHALL confirm that the value of the public exponent is an odd number equal to 3 or more. Additionally, the public exponent SHOULD be in the range between 2^16+1 and 2^256-1. The modulus SHOULD also have the following characteristics: an odd number, not the power of a prime, and have no factors smaller than 752. [Citation: Section 5.3.3, NIST SP 800-89]. 20 *******************************************************************************************************/ 21 22 import ( 23 "crypto/rsa" 24 25 "github.com/zmap/zcrypto/x509" 26 "github.com/zmap/zlint/util" 27 ) 28 29 type rsaParsedTestsKeyExpOdd struct{} 30 31 func (l *rsaParsedTestsKeyExpOdd) Initialize() error { 32 return nil 33 } 34 35 func (l *rsaParsedTestsKeyExpOdd) CheckApplies(c *x509.Certificate) bool { 36 _, ok := c.PublicKey.(*rsa.PublicKey) 37 return ok && c.PublicKeyAlgorithm == x509.RSA 38 } 39 40 func (l *rsaParsedTestsKeyExpOdd) Execute(c *x509.Certificate) *LintResult { 41 key := c.PublicKey.(*rsa.PublicKey) 42 if key.E%2 == 1 { 43 return &LintResult{Status: Pass} 44 } else { 45 return &LintResult{Status: Error} 46 } 47 } 48 49 func init() { 50 RegisterLint(&Lint{ 51 Name: "e_rsa_public_exponent_not_odd", 52 Description: "RSA: Value of public exponent is an odd number equal to 3 or more.", 53 Citation: "BRs: 6.1.6", 54 Source: CABFBaselineRequirements, 55 EffectiveDate: util.CABV113Date, 56 Lint: &rsaParsedTestsKeyExpOdd{}, 57 }) 58 }