a
    «õj©D  ã                   @  s$  d dl mZ d dlZd dlZd dlZd dlZd dlZd dlm	Z	 d dl
mZ e	dƒZe	dƒZe	dƒZdd	d
dddddœZddœdd„Zdddœdd„Zdddœdd„Zddœdd „Zdddd!œd"d#„Zdddd$œd%d&„Zddddd'dd(œd)d*„Zddœd+d,„Zd-dœd.d/„Zed0k�r eeƒ ƒ‚dS )1é    )ÚannotationsN)ÚPath)ÚAnyzsite/regulatory.htmlzbuild_site.pyz&regulatory/regulatory_hub_content.jsonz3https://eur-lex.europa.eu/eli/reg/2025/5/oj/eng/pdfznhttps://unece.org/transport/documents/2021/03/standards/un-regulation-no-155-cyber-security-and-cyber-securityzphttps://unece.org/transport/documents/2021/03/standards/un-regulation-no-156-software-update-and-software-updatezAhttps://unece.org/sites/default/files/2024-03/R156e%20%282%29.pdfz2https://eur-lex.europa.eu/eli/reg/2024/2847/oj/nldz2https://eur-lex.europa.eu/eli/reg/2024/2847/oj/engzRhttps://eur-lex.europa.eu/legal-content/EN/TXT/HTML/?uri=CELEX:02024R2847-20241120)Úr155_eurlexÚ
r155_uneceÚ
r156_uneceÚr156_pdfÚcra_nlÚcra_enÚcra_consolidatedzargparse.Namespace)Úreturnc                  C  sD   t jdd�} | jdttd� | jdttd� | jdttd� |  ¡ S )NzBuild the NCRC Regulatory hub)Zdescriptionz--output)ÚtypeÚdefaultz--site-builderz	--content)ÚargparseÚArgumentParserÚadd_argumentr   ÚDEFAULT_OUTPUTÚDEFAULT_SITE_BUILDERÚDEFAULT_CONTENTÚ
parse_args)Úp© r   úbuild_regulatory_page.pyr      s
    r   r   Ústr)Úvr   c                 C  s   t jt| pdƒdd�S )NÚ T)Zquote)ÚhtmlÚescaper   )r   r   r   r   Úe   s    r   r   zdict[str, Any])Úpathr   c                 C  sR   | j dd��}t |¡}W d   ƒ n1 s,0    Y  t|tƒsNtd| › �ƒ‚|S )Núutf-8©ÚencodingzExpected object in )ÚopenÚjsonÚloadÚ
isinstanceÚdictÚ
ValueError)r   ÚfÚdatar   r   r   Ú	load_json   s
    (
r+   )r   c                 C  sB   t j d| ¡}|r|js&td| › �ƒ‚t j |¡}|j |¡ |S )NZncrc_build_sitezCannot load )Ú	importlibÚutilÚspec_from_file_locationÚloaderÚRuntimeErrorÚmodule_from_specÚexec_module)r   ÚspecÚmodr   r   r   Úload_site_builder&   s    
r5   )ÚlabelÚurlr   c                 C  s   dt |ƒ› dt | ƒ› d�S )Nz<a class="reg-source" href="z!" target="_blank" rel="noopener">u    â†—</a>©r   )r6   r7   r   r   r   Úsource_button.   s    r9   )r6   Úkindr   c                 C  s   dt |ƒ› dt | ƒ› d�S )Nz<span class="reg-authority z">z</span>r8   )r6   r:   r   r   r   Ú	authority1   s    r;   zlist[tuple[str, str]])ÚfidÚtitleÚsubtitleÚbodyÚlinksr   c                 C  s^   d  dd„ |D ƒ¡}dt| ƒ› dtddƒ› dt|  ¡ ƒ› d	t|ƒ› d
t|ƒ› d|› d|› d�S )Nr   c                 s  s   | ]\}}t ||ƒV  qd S )N)r9   ©Ú.0ÚaÚbr   r   r   Ú	<genexpr>5   ó    z!framework_card.<locals>.<genexpr>z#<article class="reg-framework" id="z">
<div class="reg-card-top">zOFFICIAL REGULATIONÚofficialz<span class="reg-code">z</span></div>
<h2>z</h2><p class="reg-lead">z</p>z<div class="reg-sources">z</div></article>)Újoinr   r;   Úupper)r<   r=   r>   r?   r@   Zbuttonsr   r   r   Úframework_card4   s    ÿ
ÿþþþþrJ   c                  C  s†  t dddddtd fdtd fd	gƒ} t d
ddddtd fdtd fgƒ}t dddddtd fdtd fdtd fgƒ}dtddƒ d }g d¢}d  d!d"„ |D ƒ¡}d#td$dƒ› d%|› d&�}g d'¢}d  d(d"„ |D ƒ¡}d)td*d+ƒ d,|› d&� }	d-td.d/ƒ d0 }
d1td2d3ƒ d4 td5td ƒ d6 td7td ƒ d8 td9td ƒ td:td ƒ d; }d<| › |› |› d=|› |› |	› |
› |› d>�S )?NÚr155zUN Regulation No. 155zBVehicle cybersecurity and Cyber Security Management System (CSMS).uâ  
<p>R155 addresses vehicle cybersecurity through approval requirements, a manufacturer CSMS and vehicle-type cybersecurity measures across development, production and post-production.</p>
<div class="reg-mini-grid"><div><strong>Main regulation</strong><span>Scope, approval, CSMS certification and specifications</span></div><div><strong>Annexes 1â€“4</strong><span>Information, communication, approval mark and CSMS certificate</span></div><div><strong>Annex 5</strong><span>Threats, vulnerabilities, attack methods and corresponding mitigations</span></div></div>
<p class="reg-note">NCRC threat pages contain the promoted R155 review-baseline traceability. The hub explains the framework and does not duplicate every T-xxx mapping.</p>zOfficial publicationr   zUNECE sourcer   )zThreat Registerz
index.htmlÚr156zUN Regulation No. 156z>Software updates and Software Update Management System (SUMS).uª  
<p>R156 addresses approval of vehicles with regard to software updates and the organisational processes used to manage those updates.</p>
<div class="reg-mini-grid"><div><strong>SUMS</strong><span>Systematic organisational processes and procedures for software updates</span></div><div><strong>Vehicle requirements</strong><span>Software-update process, integrity, identification and safe execution</span></div><div><strong>Annexes 1â€“4</strong><span>Information, communication, approval mark and SUMS certificate</span></div></div>
<p class="reg-note">R156 is presented here as a framework overview. Threat-specific R156 traceability is not yet part of the promoted baseline.</p>r   zOfficial PDFr   ÚcrazEU Cyber Resilience ActzIHorizontal cybersecurity requirements for products with digital elements.aù  
<p>Regulation (EU) 2024/2847 addresses products with digital elements, essential cybersecurity requirements, vulnerability handling, economic-operator obligations, conformity assessment and market surveillance.</p>
<div class="reg-mini-grid"><div><strong>Product security</strong><span>Design, development and production requirements</span></div><div><strong>Vulnerability handling</strong><span>Processes during the expected period of product use</span></div><div><strong>Scope boundaries</strong><span>Sector-specific exclusions and interaction with other Union rules</span></div></div>
<p class="reg-note">Automotive applicability must be assessed for the specific product and legal context. Expert Views below identify questions, not legal conclusions.</p>zOfficial text (NL)r	   zOfficial text (EN)r
   zConsolidated textr   zW<section class="card reg-section" id="scope-interaction"><div class="reg-section-head">zEXPERT VIEWZexperta   <div><p class="section-kicker">Scope interaction</p><h2>Type approval, CRA and the grey zone</h2></div></div>
<p class="muted">This analytical model separates three practical discussion zones. It is not an official legal classification.</p>
<div class="reg-zone-grid">
<article class="reg-zone type"><h3>Type Approved Zone</h3><p>Vehicles and products clearly handled through the applicable type-approval framework and automotive cybersecurity or software-update requirements.</p></article>
<article class="reg-zone cra"><h3>CRA Zone</h3><p>Products with digital elements placed on the EU market that are not covered by an applicable sector-specific exclusion.</p></article>
<article class="reg-zone grey"><h3>Grey Zone</h3><p>Software, hardware, embedded devices and tools whose position between type approval, separate market placement and CRA applicability requires product-specific assessment.</p></article>
</div></section>))z+Passenger, commercial vehicles and trailerszaComplete vehicles, systems, components and separate technical units in the type-approval context.)z
L-categoryzcTwo- and three-wheel vehicles and quadricycles, with category- and timing-specific scope questions.)úOff-highway and NRMMzsAgricultural, forestry and non-road machinery with connected ECUs, telematics, cloud services and software updates.)úAutomotive supply chainz~Tier II+, off-the-shelf and out-of-context software and hardware may have less visible assurance in vehicle-level assessments.)zSoftware componentsz]Operating systems, middleware, communication stacks, cryptographic libraries and bootloaders.)zHardware and embedded unitszbMCUs, HSMs, secure elements, modems, Wi-Fi/Bluetooth modules, GNSS receivers and advanced sensors.)úTools and toolchainszeDevelopment, production, diagnostic, calibration, flashing, testing and vulnerability-analysis tools.)zOutside type approvalzbEV charging, workshop equipment, aftermarket devices, apps, cloud services and mobility platforms.r   c                 s  s,   | ]$\}}d t |ƒ› dt |ƒ› d�V  qdS )z<article class="reg-eco"><h3>ú</h3><p>z</p></article>Nr8   rA   r   r   r   rE   Z   rF   zbuild_body.<locals>.<genexpr>zO<section class="card reg-section" id="ecosystem"><div class="reg-section-head">zEXPERT ANALYSISa*  <div><p class="section-kicker">Automotive ecosystem</p><h2>Where scope questions emerge</h2></div></div><p class="muted">The following areas are retained as structured expert-analysis topics. Each requires verification against the applicable legal and product context.</p><div class="reg-eco-grid">z</div></section>))rO   z¯When does a separately supplied software or hardware component require its own CRA applicability assessment rather than being treated only through vehicle-level type approval?)zType-approval boundaryzŒWhere is the practical boundary between a product covered through vehicle type approval and a product placed independently on the EU market?)rP   zsWhich development, production, diagnostic and service tools should be assessed independently for CRA applicability?)zEmbedded connectivityz—How should reusable Wi-Fi, Bluetooth, cellular and GNSS products be treated when the same product is supplied to automotive and non-automotive markets?)rN   zwHow should product-oriented CRA assessment interact with existing vehicle and machinery regulatory regimes in practice?)zAssurance depthz’How can cybersecurity assurance remain demonstrable for relevant components originating deeper than the directly assessed automotive supply chain?c                 s  s,   | ]$\}}d t |ƒ› dt |ƒ› d�V  qdS )z"<article class="reg-question"><h3>rQ   z:</p><span class="reg-question-state">OPEN</span></article>Nr8   )rB   r=   Úquestionr   r   r   rE   x   s   ûÿþzT<section class="card reg-section" id="open-questions"><div class="reg-section-head">zOPEN REGULATORY QUESTIONrR   aˆ  <div><p class="section-kicker">Open questions</p><h2>Questions requiring further validation</h2></div></div><p class="muted">These questions are retained deliberately as unresolved. They are not presented as legal conclusions and may later be closed, refined or reclassified when authoritative interpretation or sufficient review evidence becomes available.</p><div class="reg-question-grid">zL<section class="card reg-section" id="method"><div class="reg-section-head">zNCRC EXPLANATIONZncrca.  <div><p class="section-kicker">Method</p><h2>How to read this hub</h2></div></div>
<div class="reg-method-grid"><div><strong>Official regulation</strong><p>Primary or authoritative legal and regulatory sources.</p></div><div><strong>NCRC explanation</strong><p>Neutral orientation and navigation through the frameworks.</p></div><div><strong>Expert View</strong><p>Structured analysis and discussion input, not statutory text or an official interpretation.</p></div><div><strong>Open regulatory question</strong><p>A scope or responsibility question that requires further validation.</p></div></div>
<p class="reg-privacy"><strong>Attribution rule:</strong> individual expert names and affiliations are withheld on the public site. Internal provenance retains the source file, version and authorship.</p></section>zM<section class="card reg-section" id="sources"><div class="reg-section-head">zOFFICIAL SOURCESrG   u½   <div><p class="section-kicker">Source access</p><h2>Regulations and annexes</h2></div></div>
<div class="reg-source-list"><div><h3>UN R155</h3><p>Official regulation plus Annexes 1â€“5.</p>z	Open R155uI   </div><div><h3>UN R156</h3><p>Official regulation plus Annexes 1â€“4.</p>z	Open R156zl</div><div><h3>Cyber Resilience Act</h3><p>Official Journal text and consolidated documentation version.</p>zOpen CRA (NL)zOpen consolidated textz</div></div></section>a–  <section class="reg-hero"><p class="section-kicker">Regulatory knowledge hub</p><h1>Automotive cybersecurity regulation</h1><p class="reg-intro">Official regulations, NCRC explanations, expert analysis and open scope questions are kept visibly separate. The hub connects vehicle type approval, software updates and horizontal product cybersecurity without presenting analysis as legal fact.</p><div class="reg-jumps"><a href="#r155">R155</a><a href="#r156">R156</a><a href="#cra">CRA</a><a href="#scope-interaction">Scope interaction</a><a href="#ecosystem">Ecosystem</a><a href="#sources">Official sources</a></div></section><section class="reg-framework-grid">z
</section>u]   <div class="footer">Regulatory Hub Baseline 1.0 Â· Expert attribution withheld publicly</div>)rJ   ÚSOURCESr;   rH   r9   )rK   rL   rM   ZzonesZecosystem_itemsZecoZ	ecosystemZquestions_itemsZqhtmlZ	questionsZrulesZsourcesr   r   r   Ú
build_body:   sT    
ý
ý
 ý

ú
þøýÿÿÿÿÿÿÿÿrT   Úintc                  C  sŠ   t ƒ } t| jƒ t| jƒ}|j dd¡ dd¡}d}|jd|j| d�t	ƒ  |j
 }| jjjddd	� | jj|d
d� td| j› �ƒ dS )Nz.class="site-nav-link active" href="index.html"z'class="site-nav-link" href="index.html"z,class="site-nav-link" href="regulatory.html"z3class="site-nav-link active" href="regulatory.html"a÷  
.reg-hero{padding:28px 0 18px}.reg-hero h1{margin:3px 0 8px}.reg-intro{max-width:900px;color:var(--muted);font-size:1.02rem}.reg-jumps{display:flex;gap:7px;flex-wrap:wrap;margin-top:16px}.reg-jumps a,.reg-source{display:inline-flex;padding:7px 10px;border:1px solid var(--line);border-radius:6px;background:var(--surface-alt);color:var(--accent);text-decoration:none;font-size:.78rem;font-weight:700}.reg-jumps a:hover,.reg-source:hover{background:var(--surface-hover);border-color:var(--accent);text-decoration:none}.reg-framework-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:14px;margin-bottom:16px}.reg-framework{padding:18px;border:1px solid var(--line);border-top:4px solid #325d88;border-radius:8px;background:var(--surface)}.reg-framework h2{margin:10px 0 4px}.reg-lead{color:var(--muted);min-height:42px}.reg-card-top,.reg-section-head{display:flex;justify-content:space-between;gap:12px;align-items:flex-start}.reg-code{font-size:.72rem;color:var(--muted);font-weight:800}.reg-authority{display:inline-flex;padding:4px 7px;border-radius:5px;font-size:.67rem;font-weight:800;letter-spacing:.04em}.reg-authority.official{background:#dce9f5;color:#234b70}.reg-authority.ncrc{background:#e5efe9;color:#285c42}.reg-authority.expert{background:#f3e7d6;color:#7c4d13}.reg-authority.question{background:#eceeef;color:#51565c}.reg-mini-grid{display:grid;gap:7px;margin:12px 0}.reg-mini-grid>div{padding:9px;border:1px solid var(--line);border-radius:6px;background:var(--surface-alt)}.reg-mini-grid strong,.reg-mini-grid span{display:block}.reg-mini-grid span{margin-top:3px;color:var(--muted);font-size:.78rem}.reg-note{font-size:.8rem;color:var(--muted)}.reg-sources{display:flex;gap:6px;flex-wrap:wrap;margin-top:14px}.reg-section{margin-top:16px}.reg-section-head{justify-content:flex-start}.reg-section-head h2{margin:2px 0 0}.reg-zone-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:10px}.reg-zone{padding:15px;border:1px solid var(--line);border-radius:7px}.reg-zone.type{border-top:4px solid #8b4c4c}.reg-zone.cra{border-top:4px solid #2c7f9e}.reg-zone.grey{border-top:4px solid #777}.reg-eco-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:9px}.reg-eco{padding:13px;border:1px solid var(--line);border-radius:6px;background:var(--surface-alt)}.reg-eco h3{margin:0 0 5px}.reg-eco p{margin:0;color:var(--muted);font-size:.82rem}.reg-method-grid,.reg-source-list{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:9px}.reg-method-grid>div,.reg-source-list>div{padding:13px;border:1px solid var(--line);border-radius:6px;background:var(--surface-alt)}.reg-method-grid p,.reg-source-list p{color:var(--muted);font-size:.8rem}.reg-question-grid{display:grid;grid-template-columns:repeat(2,minmax(0,1fr));gap:9px}.reg-question{position:relative;padding:14px 60px 14px 14px;border:1px solid var(--line);border-left:4px solid #777;border-radius:6px;background:var(--surface-alt)}.reg-question h3{margin:0 0 5px}.reg-question p{margin:0;color:var(--muted);font-size:.82rem}.reg-question-state{position:absolute;right:10px;top:10px;padding:3px 6px;border:1px solid #777;border-radius:5px;color:#555;font-size:.64rem;font-weight:800}.reg-privacy{padding:12px;border-left:4px solid #7c4d13;background:var(--surface-alt)}@media(max-width:900px){.reg-framework-grid,.reg-zone-grid{grid-template-columns:1fr}.reg-method-grid,.reg-source-list,.reg-eco-grid{grid-template-columns:1fr 1fr}}@media(max-width:600px){.reg-method-grid,.reg-source-list,.reg-eco-grid,.reg-question-grid{grid-template-columns:1fr}}
z/Regulatory | Automotive Cybersecurity Dashboard)r=   ZcssT)ÚparentsÚexist_okr    r!   zWrote r   )r   r+   Zcontentr5   Zsite_builderZHEADÚreplaceÚformatZCSSrT   ZTAILÚoutputÚparentÚmkdirZ
write_textÚprint)ÚargsZsiteÚheadZ	extra_cssZpager   r   r   Úmainš   s    

 r`   Ú__main__)Z
__future__r   r   Zhashlibr   Úimportlib.utilr,   r$   Úpathlibr   Útypingr   r   r   r   rS   r   r   r+   r5   r9   r;   rJ   rT   r`   Ú__name__Ú
SystemExitr   r   r   r   Ú<module>   s0   (ù
`