/**
 * UK Computer Misuse Act 1990 Compliance Pack
 *
 * Statute: Computer Misuse Act 1990 c.18, as amended by the Police and
 *   Justice Act 2006 ss.35-38, the Serious Crime Act 2015 s.41 + s.43
 *   (introducing s.3ZA serious-damage offence), and the Crime and Courts
 *   Act 2013 s.40 (renaming s.3A). Cyber Security and Resilience Bill
 *   (King's Speech 2024) is expected to update powers; CMA 1990 remains
 *   the foundational UK cyber-crime statute until and unless that Bill
 *   replaces sections.
 *
 * Jurisdiction: GB (United Kingdom — England + Wales + Scotland + NI)
 * Authority: Crown Prosecution Service (England + Wales) / Crown Office +
 *   Procurator Fiscal Service (Scotland) / Public Prosecution Service for
 *   Northern Ireland. National Crime Agency National Cyber Crime Unit
 *   (NCCU) investigates serious offences; Regional Organised Crime Units
 *   (ROCU) handle lower-tier; local police handle complaints.
 *
 * Why this pack:
 *   - CMA 1990 is the criminal-law surface for AI-agent behaviour in the
 *     UK. An agent that accesses third-party systems without authorisation
 *     (paywall bypass, credential stuffing, exploiting unpatched CVEs,
 *     scraping behind authentication, lateral movement through customer
 *     infrastructure) exposes the operator AND the deploying organisation
 *     to criminal liability under one or more of:
 *       s.1   Unauthorised access to computer material
 *       s.2   Unauthorised access with intent to commit further offences
 *       s.3   Unauthorised acts with intent to impair operation
 *       s.3ZA Unauthorised acts causing or creating risk of serious damage
 *       s.3A  Making, supplying or obtaining articles for use in offences
 *   - The "without authorisation" knowledge requirement is interpreted
 *     broadly post-DPP v Bignell and R v Bow Street Metropolitan
 *     Stipendiary Magistrate ex p Government of the USA. An agent that
 *     "knows" (via its prompt or tool description) that access exceeds the
 *     remit established by the system owner is on notice.
 *   - Penalty surface:
 *       s.1 — up to 2 years' imprisonment / unlimited fine.
 *       s.2 — up to 5 years' imprisonment / unlimited fine.
 *       s.3 — up to 10 years' imprisonment / unlimited fine.
 *       s.3ZA — up to 14 years' imprisonment (life if death / national-
 *               security risk).
 *       s.3A — up to 2 years' imprisonment / unlimited fine.
 *
 * Key behavioural requirements for AI agents:
 *   - Default-deny any tool invocation that would access a non-listed
 *     third-party system. Whitelist by operator; never derive authority
 *     from prompt context alone.
 *   - Block agents from chaining: credential discovery → external auth
 *     attempt; vulnerability identification → exploit invocation.
 *   - Evidence-preserve: a cooperator-incident audit chain that survives
 *     standard retention; the limitation period for indictable offences
 *     under the Magistrates' Courts Act 1980 / Criminal Procedure
 *     (Scotland) Act 1995 is six months from offence date for summary-
 *     only matters, but indictable matters under CMA have no statutory
 *     limitation.
 *   - Cooperate with NCA / NCCU / ROCU upon service of an information
 *     notice; preserve evidence pending warrant.
 *
 * Out of scope:
 *   - UK NIS Regs 2018 statutory cyber-resilience duty (separate pack:
 *     `uk-nis-regs`).
 *   - NCSC CAF assessment-evidence framework (separate pack: `ncsc-caf`).
 *   - Investigatory Powers Act 2016 (interception, equipment interference)
 *     — different statutory regime; a future pack if scope demands.
 *   - General Data Protection Regulation / UK GDPR (`uk-gdpr` pack).
 *
 * @connexum/ai-governance
 */
export const UK_CMA_1990_CATEGORY_CLASSIFIERS = {
    UNAUTHORISED_ACCESS_ATTEMPT: {
        references: [
            'CMA 1990 s.1 — unauthorised access to computer material',
            'CMA 1990 s.2 — unauthorised access with ulterior intent',
        ],
        classifier: (input) => {
            if (/\b(?:brute[\s-]?force|credential[\s-]?stuff|password[\s-]?spray)\b/i.test(input))
                return true;
            if (/\b(?:bypass\s+(?:authentication|authorisation|paywall|login|2fa|mfa|sso)|defeat\s+(?:rate[\s-]?limit|captcha))\b/i.test(input))
                return true;
            if (/\b(?:enumerat(?:e|ing)\s+(?:users?|accounts?|admin\s+endpoints?|hidden\s+routes?))\b/i.test(input))
                return true;
            if (/\b(?:access\s+(?:without\s+authorisation|exceeding\s+(?:authority|permission|scope))|unauthori[sz]ed\s+access)\b/i.test(input))
                return true;
            return false;
        },
    },
    IMPAIRMENT_INTENT: {
        references: [
            'CMA 1990 s.3 — unauthorised acts with intent to impair',
            'CMA 1990 s.3ZA — serious-damage offence',
        ],
        classifier: (input) => {
            if (/\b(?:denial[\s-]?of[\s-]?service|ddos|amplification\s+attack|slowloris|connection[\s-]?flood)\b/i.test(input))
                return true;
            if (/\b(?:ransomware\s+(?:payload|deploy|encrypt)|wiper\s+(?:malware|payload)|destructive\s+(?:script|payload))\b/i.test(input))
                return true;
            if (/\b(?:disable\s+(?:logging|audit\s+chain|edr|av|antivirus|backups?)|clear\s+(?:event\s+logs?|sysmon))\b/i.test(input))
                return true;
            if (/\b(?:tamper\s+with\s+(?:database|integrity|hash\s+chain)|impair\s+(?:operation|availability))\b/i.test(input))
                return true;
            return false;
        },
    },
    EXPLOIT_TOOLING: {
        references: [
            'CMA 1990 s.3A — making, supplying, or obtaining articles for use in offences',
        ],
        classifier: (input) => {
            if (/\b(?:cve[\s-]?\d{4}[\s-]?\d{4,}|exploit\s+(?:cve|kit|chain|module)|metasploit\s+module|msf\s+payload)\b/i.test(input))
                return true;
            if (/\b(?:weaponi[sz]e\s+(?:exploit|payload|poc)|payload\s+for\s+(?:rce|sqli|xxe|ssrf))\b/i.test(input))
                return true;
            if (/\b(?:shellcode|reverse\s+shell|bind\s+shell|c2\s+(?:beacon|implant)|cobalt\s+strike\s+beacon)\b/i.test(input))
                return true;
            if (/\b(?:obtain(?:ing)?\s+(?:0day|zeroday|n[\s-]?day)\s+(?:exploit|article))\b/i.test(input))
                return true;
            return false;
        },
    },
    EVIDENCE_TAMPERING: {
        references: [
            'CMA 1990 s.3 + Police and Criminal Evidence Act 1984 s.78 admissibility',
            'Criminal Justice and Public Order Act 1994 s.34 — drawing adverse inference',
        ],
        classifier: (input) => {
            if (/\b(?:wipe\s+(?:logs?|history|bash[\s_-]?history|prefetch|recent\s+files?)|securely\s+delete\s+(?:logs?|evidence))\b/i.test(input))
                return true;
            if (/\b(?:anti[\s-]?forensics?|timestomp|attribute\s+wipe|alter\s+(?:event\s+log|audit\s+entry))\b/i.test(input))
                return true;
            if (/\b(?:disable\s+(?:auditd|wevtutil|powershell\s+logging))\b/i.test(input))
                return true;
            return false;
        },
    },
    LAW_ENFORCEMENT_CORRESPONDENCE: {
        references: [
            'CMA 1990 enforcement — National Crime Agency / Crown Prosecution Service / Police Scotland / PSNI',
            'Police and Criminal Evidence Act 1984 s.9 — production orders',
        ],
        classifier: (input) => {
            if (/\b(?:nca\s+(?:notice|production\s+order|preservation\s+request|nccu)|national\s+crime\s+agency\s+notice)\b/i.test(input))
                return true;
            if (/\b(?:cps\s+(?:notice|charging\s+decision|file)|crown\s+(?:office|prosecution)\s+(?:notice|correspondence))\b/i.test(input))
                return true;
            if (/\b(?:pace\s+section\s+9\s+order|preservation\s+order\s+cma|warrant\s+(?:cma|cyber))\b/i.test(input))
                return true;
            return false;
        },
    },
    CREDENTIALS: {
        references: ['Cross-pack secrets safety; CMA-evidence artefacts must not embed credentials'],
        classifier: (input) => {
            if (/\b(?:api[_-]?key|apikey)\s*[=:]\s*["']?[A-Za-z0-9_\-\/+]{16,}["']?/i.test(input))
                return true;
            if (/\bpassword\s*[=:]\s*["']?[A-Za-z0-9!@#$%^&*_\-]{8,}["']?/i.test(input))
                return true;
            if (/-----BEGIN\s+(?:RSA\s+)?PRIVATE\s+KEY-----/.test(input))
                return true;
            return false;
        },
    },
};
export const UK_CMA_1990_PACK = {
    categoryClassifiers: UK_CMA_1990_CATEGORY_CLASSIFIERS,
    id: 'uk-cma-1990',
    aliases: [
        'uk-cma',
        'cma-1990',
        'computer-misuse-act',
        'computer-misuse-act-1990',
        'uk-computer-misuse-act',
        'uk-c18-1990',
    ],
    name: 'UK Computer Misuse Act 1990',
    version: '1.0.0',
    contentHash: '896aff0bac2e81858c535b96f2592099fe53a5da9ff73ba906a4fb8a0171c04d',
    description: 'Foundational UK cyber-crime statute (CMA 1990 c.18, as amended) covering s.1 unauthorised access, s.2 unauthorised access with intent, s.3 impairment, s.3ZA serious-damage offence (up to life imprisonment), and s.3A making/supplying/obtaining articles for use in offences. An AI agent that attempts to access third-party systems without explicit authorisation — credential stuffing, paywall bypass, CVE exploitation, lateral movement, evidence tampering — exposes the operator AND deploying organisation to criminal liability. Default-deny on tool invocations that would constitute an offence; whitelist by operator authority, never derive authority from prompt context.',
    authority: 'Crown Prosecution Service (England + Wales) / Crown Office + Procurator Fiscal Service (Scotland) / Public Prosecution Service for Northern Ireland; National Crime Agency NCCU investigates; ROCU + local police handle lower tier',
    industries: ['all-sectors', 'public-sector', 'financial-services', 'critical-national-infrastructure', 'healthcare', 'professional-services', 'software', 'managed-security-services'],
    requiredModules: [
        {
            name: 'governance-runtime',
            required: true,
            reason: 'Default-deny on any tool invocation that would access a non-whitelisted external system; agent operator authority is the source of truth, not the prompt.',
            reference: 'CMA 1990 s.1 — unauthorised access to computer material',
        },
        {
            name: 'data-classifier',
            required: true,
            reason: 'Surface CMA-offence-adjacent patterns (unauthorised access attempts, impairment intent, exploit tooling references, evidence tampering) for pre-tool inspection and audit-chain categorisation.',
            reference: 'CMA 1990 ss.1-3A behavioural categorisation',
        },
        {
            name: 'capability-bundle',
            required: true,
            reason: 'Capabilities tied to operator-issued authorisations; an agent cannot self-elevate to access systems outside the bundle without an explicit operator approval.',
            reference: 'CMA 1990 s.1 — knowledge of unauthorisation as legal threshold',
        },
        {
            name: 'approval-queue',
            required: true,
            reason: 'Any tool invocation flagged as potentially CMA-scope routed for human approval; on-call security review before the action runs.',
            reference: 'CMA 1990 ss.1-3 — pre-action approval as compliance gate',
        },
        {
            name: 'audit-integrity',
            required: true,
            reason: 'Tamper-evident audit chain capturing blocked attempts, approval decisions, and any executed actions; PACE 1984 s.78 admissibility for any subsequent prosecution.',
            reference: 'CMA 1990 enforcement; PACE 1984 s.78',
        },
        {
            name: 'session-persistence',
            required: true,
            reason: 'Evidence retained for the lifetime of any potential indictable proceeding (no statutory limit on CMA indictable offences); recommend 6 years floor and indefinite hold on incident-flagged artefacts.',
            reference: 'CMA 1990 — no statutory limitation on indictable offences',
        },
        {
            name: 'event-bus',
            required: true,
            reason: 'Routing to security / DPO / general counsel when a CMA-adjacent pattern is detected; mandatory NCA / NCCU correspondence when an offence is suspected.',
            reference: 'CMA 1990 cooperation with NCA NCCU + ROCU',
        },
        {
            name: 'attestation-manager',
            required: true,
            reason: 'Operator attestation of the authorised system list (which third-party systems the agent may touch); attestation must be current and reviewable.',
            reference: 'CMA 1990 s.1 — operator-defined authority',
        },
        {
            name: 'agent-auth',
            required: true,
            reason: 'Least privilege; no shared credentials between agent and operator; agent identity bound to a single authorisation scope.',
            reference: 'CMA 1990 s.1 — knowledge requirement; PACE evidence chain',
        },
        {
            name: 'encryption-layer',
            required: true,
            reason: 'Audit evidence and operator attestations encrypted at rest and in transit; admissibility preservation.',
            reference: 'CMA 1990 enforcement; PACE 1984 s.78 admissibility',
        },
    ],
    moduleConfig: {
        'governance-runtime': {
            defaultDenyOnUnknownExternalTarget: true,
            operatorAuthorityIsSourceOfTruth: true,
            promptDerivedAuthorityRejected: true,
        },
        'data-classifier': {
            enabledCategories: [
                'UNAUTHORISED_ACCESS_ATTEMPT',
                'IMPAIRMENT_INTENT',
                'EXPLOIT_TOOLING',
                'EVIDENCE_TAMPERING',
                'LAW_ENFORCEMENT_CORRESPONDENCE',
                'CREDENTIALS',
            ],
            credentialsAction: 'BLOCK',
            unauthorisedAccessAttemptAction: 'BLOCK',
            impairmentIntentAction: 'BLOCK',
            exploitToolingAction: 'BLOCK',
            evidenceTamperingAction: 'BLOCK',
        },
        'capability-bundle': {
            whitelistOnly: true,
            noPromptDerivedExpansion: true,
        },
        'approval-queue': {
            cmaAdjacentActionApprovalRequired: true,
            reviewTier: 'T2',
            emergencyApprovalRequiresCisoOrGeneralCounsel: true,
        },
        'audit-integrity': {
            tamperEvidentChainRequired: true,
            paceAdmissibilityFormatting: true,
        },
        'session-persistence': {
            retentionDaysMinimum: 2190, // 6 years floor; indefinite on incident flag
            indefiniteHoldOnIncidentFlag: true,
        },
        'event-bus': {
            ncaCorrespondenceRoutingRequired: true,
            generalCounselNotificationOnDetection: true,
        },
        'attestation-manager': {
            operatorAuthorisedSystemListAttested: true,
            attestationReviewPeriodDays: 90,
        },
        'agent-auth': {
            leastPrivilegeRequired: true,
            sharedCredentialsRejected: true,
        },
        'encryption-layer': {
            algorithm: 'aes-256-gcm',
            tlsMinVersion: '1.2',
        },
    },
    providerPolicy: {
        blockedProviders: [],
        requiredCapabilities: ['AUDIT-CHAIN-IMMUTABLE', 'TOOL-USE-GATED', 'OPERATOR-AUTHORITY-BINDING'],
        blockReasons: {},
    },
    dataPolicy: {
        scanCategories: [
            'UNAUTHORISED_ACCESS_ATTEMPT',
            'IMPAIRMENT_INTENT',
            'EXPLOIT_TOOLING',
            'EVIDENCE_TAMPERING',
            'LAW_ENFORCEMENT_CORRESPONDENCE',
            'CREDENTIALS',
        ],
        categoryActions: {
            UNAUTHORISED_ACCESS_ATTEMPT: 'BLOCK',
            IMPAIRMENT_INTENT: 'BLOCK',
            EXPLOIT_TOOLING: 'BLOCK',
            EVIDENCE_TAMPERING: 'BLOCK',
            LAW_ENFORCEMENT_CORRESPONDENCE: 'WARN',
            CREDENTIALS: 'BLOCK',
        },
        encryptionRequired: true,
        encryptionStandard: 'AES-256-GCM',
        minimumClassification: 'RESTRICTED',
    },
    retentionPolicy: {
        auditLogRetentionDays: 2190, // 6 years floor
        sessionRetentionDays: 2190,
        incidentRetentionDays: 2190,
        reference: 'CMA 1990 — no statutory limitation on indictable offences; PACE 1984 s.78 admissibility',
        forceDelete: false,
        requiresLegalHoldSupport: true,
        sovereignty: ['gb'],
    },
    incidentPolicy: {
        notificationDeadlineHours: 24,
        reference: 'CMA 1990 — internal security + general-counsel notification; NCA / NCCU when offence suspected',
        requiredRecipients: ['ciso', 'general-counsel', 'data-protection-officer', 'security-incident-response'],
        formalNotificationRequired: true,
    },
    validators: [
        {
            id: 'uk-cma-default-deny-active',
            description: 's.1 + s.3 default-deny on unauthorised external-target tool invocation; whitelist gate active.',
            reference: 'CMA 1990 ss.1 + 3',
            check: 'governance_active',
            failSeverity: 'CRITICAL',
        },
        {
            id: 'uk-cma-classifier-active',
            description: 'Data classifier surfacing CMA-offence-adjacent patterns before tool invocation; BLOCK action on unauthorised-access / impairment / exploit-tooling / evidence-tampering categories.',
            reference: 'CMA 1990 ss.1-3A',
            check: 'data_classifier_active',
            failSeverity: 'CRITICAL',
        },
        {
            id: 'uk-cma-capability-whitelist',
            description: 'Capability bundle is whitelist-only; no prompt-derived authority expansion.',
            reference: 'CMA 1990 s.1 — operator authority',
            check: 'capability_bundle_active',
            failSeverity: 'CRITICAL',
        },
        {
            id: 'uk-cma-approval-queue',
            description: 'CMA-adjacent actions routed for T2 approval before execution.',
            reference: 'CMA 1990 ss.1-3 — pre-action approval',
            check: 'approval_queue_active',
            failSeverity: 'CRITICAL',
        },
        {
            id: 'uk-cma-audit-chain-admissible',
            description: 'Tamper-evident audit chain captures blocked attempts + approvals + executed actions; PACE 1984 s.78 admissibility preserved.',
            reference: 'CMA 1990 enforcement; PACE 1984 s.78',
            check: 'audit_trail_exists',
            failSeverity: 'CRITICAL',
        },
        {
            id: 'uk-cma-evidence-retention',
            description: '6 years retention floor with indefinite hold on incident flag; no statutory limit on indictable CMA offences.',
            reference: 'CMA 1990 — indictable offences',
            check: 'retention_policy_active',
            failSeverity: 'HIGH',
        },
        {
            id: 'uk-cma-operator-attestation',
            description: 'Operator attestation of the authorised external-system list current; review period <= 90 days.',
            reference: 'CMA 1990 s.1 — operator-defined authority',
            check: 'attestation_active',
            failSeverity: 'HIGH',
        },
        {
            id: 'uk-cma-credential-block',
            description: 'Plaintext credentials blocked from prompts, tool inputs, and audit-chain entries.',
            reference: 'CMA 1990 s.2 + s.3A — credential-handling discipline',
            check: 'data_classifier_active',
            failSeverity: 'CRITICAL',
        },
        {
            id: 'uk-cma-encryption-active',
            description: 'Audit evidence and operator attestations encrypted at rest and in transit.',
            reference: 'CMA 1990 enforcement; PACE 1984 s.78',
            check: 'encryption_active',
            failSeverity: 'HIGH',
        },
    ],
};
//# sourceMappingURL=uk-cma-1990.js.map