55import re
66import git
77
8- FIPS_PROTECTED_DIRECTORIES = [b'arch/x86/crypto/' , b'cypto /asymmetric_keys/' , b'crypto/' , b'drivers/crypto/' ,
8+ FIPS_PROTECTED_DIRECTORIES = [b'arch/x86/crypto/' , b'crypto /asymmetric_keys/' , b'crypto/' , b'drivers/crypto/' ,
99 b'drivers/char/random.c' , b'include/crypto' ]
1010
11+ DEBUG = False
12+
1113def find_common_tag (old_tags , new_tags ):
1214 for tag in old_tags :
1315 if tag in new_tags :
@@ -43,13 +45,17 @@ def check_for_fips_protected_changes(repo, branch, common_tag):
4345
4446 num_commits = len (results .stdout .split (b'\n ' ))
4547 print ('[rolling release update] Number of commits to check: ' , num_commits )
46- shas_to_check = []
48+ shas_to_check = {}
4749 commits_checked = 0
4850
51+ progress_interval = max (1 , num_commits // 10 )
52+
4953 print ('[rolling release update] Checking modifications of shas' )
54+ if DEBUG :
55+ print (results .stdout .split (b'\n ' ))
5056 for sha in results .stdout .split (b'\n ' ):
5157 commits_checked += 1
52- if commits_checked % ( num_commits // 10 ) == 0 :
58+ if commits_checked % progress_interval == 0 :
5359 print (f'[rolling release update] Checked { commits_checked } of { num_commits } commits' )
5460 if sha == b'' :
5561 continue
@@ -61,19 +67,38 @@ def check_for_fips_protected_changes(repo, branch, common_tag):
6167 exit (1 )
6268
6369 sha_hash_and_subject = b''
70+ touched_fips_files = set ()
71+ is_rebuild = False
72+
6473 for line in res .stdout .split (b'\n ' ):
6574 if sha_hash_and_subject == b'' :
6675 sha_hash_and_subject = line
76+ if b'Rebuild rocky' in line :
77+ is_rebuild = True
6778 continue
6879 if line == b'' :
6980 continue
7081
82+ add_to_check = False
83+
7184 for dir in FIPS_PROTECTED_DIRECTORIES :
7285 if line .startswith (dir ):
73- print (f'FIPS protected directory change found in commit { sha } ' )
74- print (sha_hash_and_subject )
75- shas_to_check .append (sha_hash_and_subject .split (b' ' )[0 ])
76- sha_hash_and_subject = b''
86+ if DEBUG :
87+ print (f'FIPS protected directory { dir } change found in commit { sha } ' )
88+ print (sha_hash_and_subject )
89+ add_to_check = True
90+ if dir not in touched_fips_files :
91+ touched_fips_files .add (dir )
92+
93+ if add_to_check :
94+ shas_to_check [sha_hash_and_subject .split (b' ' )[0 ]] = touched_fips_files
95+
96+ if touched_fips_files :
97+ print (f'[rolling release update] Checked commit { sha } touched { len (touched_fips_files )} FIPS protected files' )
98+ for f in touched_fips_files :
99+ print (f' - { f } ' )
100+ sha_hash_and_subject = b''
101+
77102 print (f'[rolling release update] { len (shas_to_check )} of { num_commits } commits have FIPS protected changes' )
78103
79104 return shas_to_check
@@ -91,13 +116,20 @@ def check_for_fips_protected_changes(repo, branch, common_tag):
91116 action = 'store_true' )
92117 parser .add_argument ('--demo' , help = 'DEMO mode, will make a new set of branches with demo_ prepended' ,
93118 action = 'store_true' )
119+ parser .add_argument ('--debug' , help = 'Enable debug output' , action = 'store_true' )
94120 args = parser .parse_args ()
95121
96122 if args .demo :
97123 print ('======================== DEMO MODE ENABLED ==========================' )
98124 print ('[rolling release update] DEMO mode enabled YOU SHOULD NOT COMMIT THIS' )
99125 print ('======================== DEMO MODE ENABLED ==========================' )
100126
127+ if args .debug :
128+ DEBUG = True
129+ print ('======================== DEBUG MODE ENABLED ==========================' )
130+ print ('[rolling release update] Debug mode enabled' )
131+ print ('======================== DEBUG MODE ENABLED ==========================' )
132+
101133 repo = git .Repo (args .repo )
102134
103135 rolling_product = args .old_rolling_branch .split ('/' )[0 ]
@@ -117,8 +149,14 @@ def check_for_fips_protected_changes(repo, branch, common_tag):
117149 print ('[rolling release update] Checking for FIPS protected changes between the common tag and HEAD' )
118150 shas_to_check = check_for_fips_protected_changes (repo , args .new_base_branch , latest_resf_sha )
119151 if shas_to_check and args .fips_override is False :
120- for sha in shas_to_check :
121- print (repo .git .show (sha .decode ()))
152+ for sha ,dir in shas_to_check .items ():
153+ print (f"## Commit { sha .decode ()} " )
154+ print ('\' \' \' ' )
155+ dir_list = []
156+ for d in dir :
157+ dir_list .append (d .decode ())
158+ print (repo .git .show (sha .decode (), dir_list ))
159+ print ('\' \' \' ' )
122160 print ('[rolling release update] FIPS protected changes found between the common tag and HEAD' )
123161 print ('[rolling release update] Please Contact the CIQ FIPS / Security team for further instructions' )
124162 print ('[rolling release update] Exiting' )
0 commit comments