From ea8eb9cc2a8cfb04e4d8e56ea8f9b20f09484aee Mon Sep 17 00:00:00 2001 From: yeyuning Date: Tue, 30 Jan 2024 16:43:54 +0800 Subject: [PATCH] =?UTF-8?q?fixed=201e27fa9=20from=20https://gitee.com/yeyu?= =?UTF-8?q?ning/security=5Fcode=5Fsignature/pulls/90=20=E5=A4=9A=E5=AD=97?= =?UTF-8?q?=E8=8A=82=E5=AD=97=E7=AC=A6=E5=88=87=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yeyuning Change-Id: I97eb04f787d20a303eefa7811afa6ff46ee79c29 --- services/key_enable/src/cert_path_utils.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/services/key_enable/src/cert_path_utils.rs b/services/key_enable/src/cert_path_utils.rs index 8bc658f..bcab701 100644 --- a/services/key_enable/src/cert_path_utils.rs +++ b/services/key_enable/src/cert_path_utils.rs @@ -30,6 +30,7 @@ const TYPE_KEY: &str = "type"; const SUBJECT_KEY: &str = "subject"; const ISSUER_KEY: &str = "issuer"; const MAX_CERT_PATH: &str = "max-certs-path"; +const COMMON_NAME_CHAR_LIMIT: usize = 7; /// profile cert path error pub enum CertPathError { /// cert path add remove error @@ -365,11 +366,15 @@ pub fn common_format_fabricate_name(common_name: &str, organization: &str, email if common_name.len() >= organization.len() && common_name.starts_with(organization) { return common_name.to_string(); } - if common_name.len() >= 7 && organization.len() >= 7 && common_name[0..7] == organization[0..7] { - ret = common_name.to_string(); - } else { - ret = format!("{}: {}", organization, common_name); + if common_name.len() >= COMMON_NAME_CHAR_LIMIT && organization.len() >= COMMON_NAME_CHAR_LIMIT { + let common_name_prefix = &common_name.as_bytes()[..COMMON_NAME_CHAR_LIMIT]; + let organization_prefix = &organization.as_bytes()[..COMMON_NAME_CHAR_LIMIT]; + if common_name_prefix == organization_prefix { + ret = common_name.to_string(); + return ret; + } } + ret = format!("{}: {}", organization, common_name); } else if !common_name.is_empty() { ret = common_name.to_string(); } else if !organization.is_empty() { -- Gitee