+
    $iC  c                   sD   ^ RI t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHtH	t	 ^ RI
t
^ RIt
^ RItR ]n        RtRtRtRtRsRsRsRsRsRsR tRR	 ltR
 tR tR tR tR tR tR t R t!R t"R t#R t$RR lt% ! R R4      t&R t'RR lt(R t)]*R8X  d
   ])! 4        R# R# )    N)mkdtempmkstempc                 s    VP                    R \        V 4      R,          P                  4       \        V 4      R,          ,            R2# )z: :N   Nr   NN
)__name__strupper)ZmsgZcategoryZ	_unused_aZ_unused_kwas   &&*,;/usr/share/crypto-policies/python/update-crypto-policies.py<lambda>r
      s8    CHRL..03s8B<?@C    z/usr/share/crypto-policiesz/etc/crypto-policieszreload-cmds.shz/proc/sys/crypto/fips_enabledc                  s<    \        V R \        P                  /VB  R# )ZfileN)printsysZstderr)ZargsZkwargss   *,r	   eprintr   &   s    	4+cjj+F+r   c                 s\    \         P                  R ,          s\        \        P                  n        V e   V sM1 \         P                  R,          s\        \        P                  n	        \         P                  P                  \        R4      s\         P                  P                  \        R4      s\         P                  P                  \        R4      s\         P                  P                  \        \         4      sR#   \         d
    \        s Li ; i  \         d
    \        s Li ; i)profile_dirNbase_dirzlocal.d	back-endsZstate)osZenvironr   cryptopoliciesUnscopedCryptoPolicyZ	SHARE_DIRZKeyErrorDEFAULT_PROFILE_DIRr   Z
CONFIG_DIRDEFAULT_BASE_DIRpathjoin	local_dirbackend_config_dir	state_dirRELOAD_CMD_NAMEreload_cmd_pathalt_base   &r	   	dir_pathsr!   *   s    *jj/8C++5 	(zz*-H=EN//: Xy1Ih<Xw/Iggll;@O!  *)*  	('H	(s"   0D  0D  DDD+*D+c                 s    \         P                  ! 4       p\         P                  ! V 4       \         P                  ! R 4      pR V 4       p\	        V4      p\         P                  ! V4       V# )Z.c              3   sT   "   T F  w  rq1\        V4      \        V4      3x  K   	  R # 5iN)sorted)Z.0ZrootZdirsZfiless   &   r	   Z	<genexpr>Zget_walk.<locals>.<genexpr>P   s"     N4ED6$</s   &()r   ZgetcwdZchdirwalkr#   )r   Zold_cwdr$      &  r	   get_walkr&   I   sK     iikGHHTN773<DNND$<DHHWKr   c                 s   \         P                  ! RR7      p V P                  4       pVP                  RRRRRR7       VP                  R	R
RR7       VP                  RR
RR7       VP                  RR
RR7       V P                  RR
\         P                  R7       V P                  RR
RR7       V P                  4       # )zParse the command lineF)Zallow_abbrevz--setZ? ZPOLICYzset the policy POLICY)ZnargsZdefaultZmetavarhelpz--showZ
store_truez.show the current policy from the configuration)Zactionr(   z--is-appliedz+check whether the current policy is appliedz--checkzAcheck whether the generated policy files match the current policyz
--no-checkz--no-reloadz3do not run the reload scripts when setting a policy)argparseZArgumentParserZadd_mutually_exclusive_groupZadd_argumentZSUPPRESS
parse_args)ZparserZgroup     r	   r*   r*   V   s    $$%8F//1E	wc2x3  5	xL  N	~lI  K	y7  8 \%..  0
l5  6 r   c                  s    \         P                  ! \         P                  P                  \        R 4      4      P
                  p \         P                  ! \         P                  P                  \        R4      4      P
                  p\        \         P                  P                  \        R 4      RR7      ;_uu_ 4       pVP                  4       pRRR4       \        \         P                  P                  \        R4      RR7      ;_uu_ 4       pVP                  4       pRRR4       X X8  d9   XX8X  d2   \        4       '       g"   \        R4       \        P                  ! ^ 4       \        R4       \        P                  ! ^4       R#   + '       g   i     L; i  + '       g   i     L; i  \         d    \        P                  ! ^M4        Li ; i)currentconfigutf-8ZencodingNz The configured policy is appliedz$The configured policy is NOT applied)r   Zstatr   r   r   Zst_mtimer   openreadOSErrorr   exitis_fips_auto_bind_mountedr   )Ztime1Ztime2fZ	contents1Z	contents2s        r	   
is_appliedr6   k   s   Y	:;DDXx89BB"'',,y)4wGG1I H"'',,x2WEEI F
 	Y&-//01	
01HHQK HGEE sH   B;F. =F?F. FF. F	F. F+	&F. +F. .!GGc                  s"   \         p \        p\        p\        p\	        4       p\        VR 7       \        P                  ! V\        R7       \        P                  ! \        P                  P                  V R4      \        P                  P                  \         R4      R7       \        4        \        4       p\        VRRR7       \        V4      p\        \        4      p\        V4      p\        \        4      p	Rp
Wg8w  d   Rp
W8w  d   Rp
V\        V3pV\        V	3pW3 F  w  rpV F  w  pppV F  pV
'       d    K  \        P                  P                  VVV4      p\        P                  P                  VVV4      p\!        VR4      ;_uu_ 4       p\!        VR4      ;_uu_ 4       pV
'       g7   VP#                  R4      pVP#                  R4      pVV8w  d   Rp
V'       d   K=   RRR4       RRR4       K  	  K  	  K  	  \        P$                  ! V4       V
'       d$   \'        R	4       \(        P*                  ! ^4       R# \-        R
4       \(        P*                  ! ^ 4       R#   + '       g   i     L; i  + '       g   i     EK]  ; i)r   )ZsrcZdstr-   F)print_enabledallow_symlinkingTZrbi    Nz9The configured policy does NOT match the generated policyz2The configured policy matches the generated policy)r   r   r   r   r   r!   shutilZcopytreeZcopyr   r   r   setup_directoriesparse_pconfigapply_policyr&   r0   r1   Zrmtreer   r   r3   r   )Zorig_base_dirZorig_local_dirZorig_backend_config_dirZorig_state_dirr   pconfigZwalk_orig_backendZwalk_backendZwalk_orig_stateZ
walk_stateerrZ_backendZ_stateZorig_prefixZ
tmp_prefixr$   Zd_Zflr5   Zf_origZf_tmpZfp1Zfp2Zb1Zb2s                             r	   checkr@      s   MN0NyHx  OOI6
KKBGGLL9GGLL846
 oGF !89./L~.O)$J
C($&(:LHHY
2F)1)9%HAq"k1a8ZA6&$''3UD0A0AS! XXd^ XXd^8"&C!r! 1B''   *:" MM(
JKBC! 1B0A'''s0   I<*I)30I)(I))I<)I94I<<Jc                  s     \         P                  ! \        R RR7       \         P                  ! \        R RR7       R#   \         d     R# i ; i)i  T)ZmodeZexist_okN)r   Zmakedirsr   r   r2    r   r	   r:   r:      s:    
&UTB
IED9 s   :> AAc                  s     \        \        R R7      ;_uu_ 4       p \        V P                  4       4      ^ 8  uuRRR4       #   + '       g   i     R# ; i  \         d     R# i ; i)Zasciir/   NF)r0   FIPS_MODE_FLAGZintr1   r2   )r5       r	   	fips_moderD      sH    .733qqvvx=1$ 4333 s-   A A
A A	A A A%$A%c           	      sV   V P                  4       VP                  4       r\        R R4      ;_uu_ 4       p\        VP                  4       4       F;  pVP	                  R4      v  rErdW8X  g   K   VP                  V 4      u uuRRR4       # 	  RRR4       R#   + '       g   i     R# ; i)z/proc/self/mountinfoZbrrC   NF)Zencoder0   ZreversedZ	readlinessplitZendswith)Z
whatsuffixZwherer5   liner?   Zwhat_Zwhere_s   &&     r	   
is_mountedrG      s    "))+U\\^	$d	+	+qQ[[]+D)-D)9&Aq!F~~j11	 
,	++ 
,
  
,	+
 s   5B.BBB(	c                  s    \         P                  P                  \        R 4      p \         P                  P                  \        R4      p\	        RV 4      ;'       d    \	        RV4      # )r-   r   z$/crypto-policies/default-fips-configz/crypto-policies/back-ends/FIPS)r   r   r   r   rG   Zpolicy_fileZbackendsr+   r	   r4   r4      sR    '',,x2Kww||Hk2H={K H H<hGIr   c                  s    \         P                  P                  \        R 4      p \         P                  P                  \        R4      p\        P
                  ! RV .4       \        P
                  ! RV.4       R# )r-   r   z/bin/umountN)r   r   r   r   
subprocessZ
check_callrH   r+   r	   umount_fips_auto_bindrJ      sP    '',,x2Kww||Hk2H=+67=(34r   c                 s   \        WR 7      w  r4\        P                  ! V\        VR4      4       \        P                  ! V4       \        P
                  ! VR4        \        P                  ! V\        P                  P                  W4      4        \        P                  ! T4       R#   \         d/    \        P                  ! T4       \        P                  ! T4       h i ; i  \        P                  ! T4       i ; i)Zprefixdirr.   i  N)r   r   writeZbytesZfsyncZfchmodrenamer   r   r2   unlinkclose)	directoryfilenameZcontentsfdr      &&&  r	   
safe_writerU      s    8JRHHRx)*HHRLIIb%
		$Y9: 	  
		$

 	s   4B+ +9C$$C' 'C?c                 s\   \        WR 7      w  r4\        P                  ! V4       \        P                  ! V4       \        P                  ! W$4        \        P
                  ! V\        P                  P                  W4      4       R#   \         d    \        P                  ! T4       h i ; i)rK   N)	r   r   rP   rO   ZsymlinkrN   r   r   r2   )rQ   rR   ZtargetrS   r   rT   r	   safe_symlinkrV      sm    8JRHHRLIIdOJJv
		$Y9: 
		$s   4B #B+c           
      s4   \         P                  P                  WAR ,           4      p\        \        P                  ! V4      4      p	Rp
V	 F,  p\         P                  P                  V4      '       g   K*  Rp
 M	  \         P                  P                  V\        V 4      VR,           4      p\         P                  ! V\         P                  4      pV
'       g&   V'       d   V'       d   \        W1R,           V4       R# V'       dI   V P                  '       g7   V'       d/   \        VRR7      ;_uu_ 4       pVP                  4       pRRR4       \        W1R,           V4       V
'       d   \         P                  P                  W1R,           4      p \        VRRR7      ;_uu_ 4       pV	 FD  p \        VRR7      ;_uu_ 4       pVP                  4       pRRR4        TP!                  X4       KF  	  RRR4       R# R#   + '       g   i     L; i  + '       g   i     LE; i  \         d    \        R	T 24        K  i ; i  \         d    \        R
T RT 24        K  i ; i  + '       g   i     R# ; i  \         d    \        RT R24        R# i ; i)z	-*.configFTz.txtz.configNr.   r/   ZazCannot read local policy file z$Error appending local configuration z to zError opening configuration z" for appending local configuration)r   r   r   r#   globexistsr   accessR_OKrV   subpoliciesr0   r1   rU   r2   r   rM   )r=   ZcfgnameZcfgdataZcfgdirZlocaldirZ
profiledirpolicy_was_emptyr8   Zlocal_cfg_pathZ
local_cfgsZlocal_cfg_presentZlcfgZprofilepathZprofilepath_existsZf_preZcfgfileZcfZlfZ
local_datas   &&&&&&&&           r	   save_configr]      s   WW\\(k,ABN		.12J77>>$ $ 
 '',,z3w<69IJK;8!38HVy0+>'"5"5"5:J +00EjjlG 1 v*G4'',,v':;	8gsW55&D!!$99R)+J :7, ' 65  10 :9" !!?vFG ! # 7E"&tG9 6 77 655  	81' ;7 7 8	8s   4G<I9 %I%,H"HH"I,I%0I9 <H	HH"I%H""H?	;I%>H?	?I%I"	I%!I"	"I%%I6	0I9 6I9 9JJc                   sH   a  ] tR tRt o R tR
R ltR tR tR tR t	Rt
V tR	# )ProfileConfigi1  c                s"    R V n         . V n        R# )r'   Npolicyr[   selfr    r	   __init__ZProfileConfig.__init__2  s    r   c                s4   VP                  4       P                  R 4      pV^ ,          '       d    V'       g   V^ ,          V n        VR,          pV Uu. uF  qC'       g   K  VNK  	  ppV'       d   V P                  P	                  V4       R# W0n        R# u upi ):r   N)r   rE   r`   r[   Zextend)rb   s	subpolicylirT   r	   parse_stringZProfileConfig.parse_string6  so    GGIOOC Q44	A$DK"A1QQQ##A& 	  s   	B Bc                s   R p\        VRR7      ;_uu_ 4       pV FI  pVP                  R^4      ^ ,          pVP                  4       pV'       g   K6  V P                  WB4       RpKK  	  RRR4       R#   + '       g   i     R# ; i)Fr.   r/   Z#TN)r0   rE   Zstripri   )rb   rR   rf   r5   rF   s   &&   r	   
parse_fileZProfileConfig.parse_fileA  sg    	(W--zz#q)!,zz|4%%d6 $I  .---s   4A2A22B	c                s    VP                  4       P                  R 4      pV P                   Uu. uF  q3V9  g   K  VNK  	  upV n        R# u upi )rd   N)r   rE   r[   )rb   re   rg   rh   s   &&  r	   remove_subpoliciesZ ProfileConfig.remove_subpoliciesK  s>    GGIOOC '+'7'7F'7!A:AA'7FFs
   AAc                s    V P                   pR P                  V P                  4      pV'       d   VR ,           V,           pV# )rd   )r`   r   r[   )rb   re   Zsubsr%   r	   __str__ZProfileConfig.__str__O  s4    KKxx(()C$Ar   c                s.    \        \        V 4      4       R # r"   )r   r   ra   r    r	   showZProfileConfig.showV  s    c$ir   r_   NF)r   Z
__module__Z__qualname__Z__firstlineno__rc   ri   rj   rk   rl   rm   Z__static_attributes__Z__classdictcell__)Z__classdict__s   @r	   r^   r^   1  s)     	!%G r   r^   c                  s   \        4       p \        P                  P                  \        R 4      p\        P
                  ! V\        P                  4      '       d   V P                  V4       V # \        4       '       d   V P                  R4       V # V P                  \        P                  P                  \        R4      4       V # )r-   FIPSzdefault-config)r^   r   r   r   r   rY   rZ   rj   rD   ri   r   )r=   Z
configfiler+   r	   r;   r;   Z  s    oGh1J	yyRWW%%:& N 
V$ N 	277<<5EFGNr   c                 s	   ^ pRpV'       d   V P                   pV P                  V4       Rp\        P                  P	                  R4      p\        4       pV P                   V8w  d   V'       d   V P                   R8X  d3   V'       g*   V'       g"   \        R4       \        R4       \        R4       M?V'       d8   \        R4       \        R	4       \        R
4       \        R4       \        R4       \        \        8X  d<   \        P                  ! 4       ^ 8w  d"   \        R4       \        P                  ! ^4        \        P                  ! V P                   .V P                  O5!  p	\%        4       '       d   \        R4       \        R\&         R24       V'       d   \)        R4       \+        4        Mo\,        P,                  ! \        P                  P/                  \0        R4      4      '       d   \        R\0         R24       V# \)        R\&         R\0         R24       V# V'       d   \)        R\3        V 4      ,           4       \5        \6        4       Uu. uF  pRV9   g   K  VNK  	  ppV Fj  p\6        P8                  V,          pV! 4       p VP;                  X	4      p \A        WP>                  X\B        \0        \D        X	PG                  4       VR7       Kl  	  V'       d#    \K        \        R \3        V 4      R!,           4        \K        \&        R#\3        V 4      R!,           4        \K        \&        R%\3        X	4      4       V'       d"   \)        R'4       \)        R(4       \)        R)4       V#   \        P                  P                    d-   p
\        T
4       \        P                  ! ^4        Rp
?
ELMRp
?
i\        P                  P"                   d0   p
\        RT
 24       \        P                  ! ^4        Rp
?
ELRp
?
ii ; iu upi   \<         d.    \        RTP>                  ,           4       \        R4       ^p ELi ; i  \H         d/    \        RTP>                  ,           4       \        R4       ^p EK  i ; i  \H         d    \        R"4       ^p ELi ; i  \H         d    \        R$4       ^p ELi ; i  \H         d    \        R&4       ^p ELi ; i)*r    FTz/usr/bin/bootcro   zHWarning: Using 'update-crypto-policies --set FIPS' is not sufficient forz         FIPS compliance.zF         The kernel must be started with `fips=1` for FIPS compliance.zOWarning: Using 'update-crypto-policies --set' in FIPS mode will make the systemz!         non-compliant with FIPS.z4         It can also break ssh access to the system.zJ         Reboot without `fips=1` on the kernel command line to disable thez         system FIPS mode.z/You must be root to run update-crypto-policies.Nz%Errors found in policy, first one:  
zDThere's an automatic FIPS policy bind-mount from booting with fips=1zThe information under z might not be accurate.z)Removing automatic FIPS policy bind-mountz
*-*.configzThere are drop-in files under z that will beignored in an automatic FIPS policy. To make them effective, manually switch to a FIPS policy by running `update-crypto-policies --set FIPS`.ztConsider switching to a permanent FIPS policy with update-crypto-policies --set FIPS, so that the information under z. is accurate and files that might be added to z! in the future will be in effect.zSetting system policy to Z	GeneratorzError generating config for zKeeping original configuration)r\   r8   zError saving config for r-   r   z.Error setting the current policy configurationr,   z$Error updating current policy markerzCURRENT.polz"Error updating current policy dumpzFNote: System-wide crypto policies are applied on application start-up.zBIt is recommended to restart the system for the change of policieszto fully take place.)&r`   ri   r   r   rX   rD   r   r   r   Zgeteuidr   r3   r   r   r[   Z
validationZPolicyFileNotFoundErrorZPolicySyntaxErrorr4   r   r   rJ   rW   r   r   r   rL   policygeneratorsZ__dict__Zgenerate_configZLookupErrorZCONFIG_NAMEr]   r   r   Zis_emptyr2   rU   )r=   profiler7   r8   r>   Z
set_configZ	oldpolicyZbootcZis_in_fips_modeZucpZexZgZ
generatorsZclsZgenr-   s   &&&&            r	   r<   r<   h  s   
CJNN	W%
/0#+ >>Y&=~~'_ 4 567 3 4  ; <:;MN . /34##

(9@A11'.. H3:3F3FH !"" 	 * 	+'	{2IJK=>!#YYrww||I|<==3I; ?E E F
 J ++4+ 666?[ A55 6 J)CL89 !12G2kQ6F!!2JG''*e	((-F	&*I{),)9; ( 	x3w<$+>?
9iW)<=
9mSX6
  5 	6 + 	,$%Jq $$<< r
$$66 7t<=J H  	1COOCD34C	  	-?@34C	  	CDC	  56  34s   ;,M. 	P$PP"6Q%!R !R# )S .P!N44 PP$P  P4QQ4R RR R #R?>R?SSc                 sD   \        4        \        4       p V P                  '       d!   \        4        \        P                  ! ^ 4       V P
                  '       d!   \        4        \        P                  ! ^ 4       \        4        \        4       pV P                  '       d'   VP                  4        \        P                  ! ^ 4       V P                  p\        W4      pV P                  '       g   \        P                  ! R\        .4       \        P                  ! V4       R# )z!The actual command implementationz	/bin/bashN)r!   r*   r6   r   r3   r@   r:   r;   rm   Zsetr<   Z	no_reloadrI   Zcallr   )Zcmdliner=   rq   r>   s       r	   mainrr     s    KlG}}}oG|||kkG
w
(Co67HHSMr   Z__main__r"   rn   )NTT)+r)   rW   r   r9   rI   r   ZwarningsZtempfiler   r   r   Zcryptopolicies.validationrp   Zformatwarningr   r   r   rB   r   r   r   r   r   r   r   r!   r&   r*   r6   r@   r:   rD   rG   r4   rJ   rU   rV   r]   r^   r;   r<   rr   r   rA   r   r	   <module>rs      s      	   
  %    D  3 ) "0	 	,A>
*(7tI5	.8f& &R}@B zF r   