github.com/zmap/zlint@v1.1.0/lints/lint_rsa_public_exponent_not_in_range.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 rsaParsedTestsExpInRange struct { 31 upperBound *big.Int 32 } 33 34 func (l *rsaParsedTestsExpInRange) Initialize() error { 35 l.upperBound = &big.Int{} 36 l.upperBound.Exp(big.NewInt(2), big.NewInt(256), nil) 37 return nil 38 } 39 40 func (l *rsaParsedTestsExpInRange) CheckApplies(c *x509.Certificate) bool { 41 _, ok := c.PublicKey.(*rsa.PublicKey) 42 return ok && c.PublicKeyAlgorithm == x509.RSA 43 } 44 45 func (l *rsaParsedTestsExpInRange) Execute(c *x509.Certificate) *LintResult { 46 key := c.PublicKey.(*rsa.PublicKey) 47 exponent := key.E 48 const lowerBound = 65536 // 2^16 + 1 49 if exponent > lowerBound && l.upperBound.Cmp(big.NewInt(int64(exponent))) == 1 { 50 return &LintResult{Status: Pass} 51 } 52 return &LintResult{Status: Warn} 53 } 54 55 func init() { 56 RegisterLint(&Lint{ 57 Name: "w_rsa_public_exponent_not_in_range", 58 Description: "RSA: Public exponent SHOULD be in the range between 2^16 + 1 and 2^256 - 1", 59 Citation: "BRs: 6.1.6", 60 Source: CABFBaselineRequirements, 61 EffectiveDate: util.CABV113Date, 62 Lint: &rsaParsedTestsExpInRange{}, 63 }) 64 }