github.com/zmap/zlint@v1.1.0/lints/lint_rsa_mod_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 "math/big" 25 26 "github.com/zmap/zcrypto/x509" 27 "github.com/zmap/zlint/util" 28 ) 29 30 type rsaParsedTestsKeyModOdd struct{} 31 32 func (l *rsaParsedTestsKeyModOdd) Initialize() error { 33 return nil 34 } 35 36 func (l *rsaParsedTestsKeyModOdd) CheckApplies(c *x509.Certificate) bool { 37 _, ok := c.PublicKey.(*rsa.PublicKey) 38 return ok && c.PublicKeyAlgorithm == x509.RSA 39 } 40 41 func (l *rsaParsedTestsKeyModOdd) Execute(c *x509.Certificate) *LintResult { 42 key := c.PublicKey.(*rsa.PublicKey) 43 z := big.NewInt(0) 44 if (z.Mod(key.N, big.NewInt(2)).Cmp(big.NewInt(1))) == 0 { 45 return &LintResult{Status: Pass} 46 } else { 47 return &LintResult{Status: Warn} 48 } 49 } 50 51 func init() { 52 RegisterLint(&Lint{ 53 Name: "w_rsa_mod_not_odd", 54 Description: "RSA: Modulus SHOULD also have the following characteristics: an odd number", 55 Citation: "BRs: 6.1.6", 56 Source: CABFBaselineRequirements, 57 EffectiveDate: util.CABV113Date, 58 Lint: &rsaParsedTestsKeyModOdd{}, 59 }) 60 }