Skip to content

Platform Services

James Daley edited this page Jun 20, 2026 · 2 revisions

Platform Services

ForsettiPlatform adapts core service interfaces to native Windows behavior. It depends on ForsettiCore and Windows SDK libraries; ForsettiCore does not depend on ForsettiPlatform.

Adapter Map

flowchart LR
    Container["ServiceContainer"]
    Register["DefaultForsettiPlatformServices::registerAll"]
    Networking["INetworkingService\nWinHttpNetworkingService"]
    Storage["IStorageService\nRegistryStorageService"]
    Secure["ISecureStorageService\nDpapiSecureStorageService"]
    Export["IFileExportService\nLocalFileExportService"]
    Telemetry["ITelemetryService\nNoopTelemetryService"]
    Registration["IModuleRegistrationStore\nRegistryModuleRegistrationStore"]
    Digest["IManifestDigestProvider\nCngSha256ManifestDigestProvider"]
    Views["IWindowsViewFactoryRegistry\nForsettiViewFactoryRegistry"]

    Register --> Container
    Container --> Networking
    Container --> Storage
    Container --> Secure
    Container --> Export
    Container --> Telemetry
    Register --> Registration
    Register --> Digest
    Register --> Views
Loading

Service Implementations

Core Interface Platform Implementation Native Backing Capability
INetworkingService WinHttpNetworkingService WinHTTP networking
IStorageService RegistryStorageService HKCU Registry values storage
ISecureStorageService DpapiSecureStorageService Windows DPAPI plus HKCU storage secure_storage
IFileExportService LocalFileExportService Local filesystem file_export
ITelemetryService NoopTelemetryService No-op implementation telemetry
IModuleRegistrationStore RegistryModuleRegistrationStore HKCU Registry records registration confirmation
IManifestDigestProvider CngSha256ManifestDigestProvider Windows CNG SHA-256 canonical manifest hashing
IWindowsViewFactoryRegistry ForsettiViewFactoryRegistry In-process registry plus dispatcher declared view ownership

WinHttpNetworkingService

WinHttpNetworkingService performs HTTP/HTTPS GET requests through WinHTTP and returns response bytes through std::future<std::vector<uint8_t>>.

Important behavior:

  • Accepts http and https URLs.
  • Rejects unsupported schemes.
  • Rejects header values containing line breaks to prevent header injection.
  • Uses native WinHTTP session, connection, request, send, receive, and read APIs.
sequenceDiagram
    participant Module
    participant Context
    participant Provider as CapabilityScopedServiceProvider
    participant Net as WinHttpNetworkingService
    participant WinHTTP

    Module->>Context: services()->resolve<INetworkingService>()
    Context->>Provider: resolve governed service
    Provider-->>Module: service when networking is granted
    Module->>Net: data(url, headers)
    Net->>WinHTTP: open session, connect, request, send
    WinHTTP-->>Net: response bytes
    Net-->>Module: future<vector<uint8_t>>
Loading

RegistryStorageService

RegistryStorageService persists strings under HKCU. It supports custom root subkeys for tests and host-specific isolation.

Protection points:

  • Rejects empty keys.
  • Rejects path-like keys.
  • Serializes access with a mutex.
  • Uses Windows Registry value operations rather than process-only memory.

DpapiSecureStorageService

DpapiSecureStorageService protects byte arrays with Windows DPAPI and stores protected blobs under HKCU.

Protection points:

  • Rejects unsafe keys using the same value-name constraints as registry storage.
  • Uses DPAPI protection before persistence.
  • Unprotects bytes on read.
  • Stores data in a testable root subkey.

LocalFileExportService

LocalFileExportService writes bytes to a configured export directory.

Protection points:

  • Sanitizes filenames.
  • Handles empty and path-only inputs with a safe fallback.
  • Handles reserved Windows device names.
  • Prevents path traversal by writing only beneath the configured export directory.
flowchart TD
    Input["requested filename"]
    Sanitize["sanitize filename"]
    Reserved{"reserved or empty?"}
    Fallback["apply safe fallback"]
    Join["join with export directory"]
    Write["write bytes"]
    Result["true or false"]

    Input --> Sanitize --> Reserved
    Reserved -- yes --> Fallback --> Join
    Reserved -- no --> Join
    Join --> Write --> Result
Loading

NoopTelemetryService

Telemetry is intentionally a no-op implementation in the current platform layer. It satisfies the core ITelemetryService interface without transmitting or persisting telemetry events.

Module Registration Platform

RegistryModuleRegistrationStore stores ModuleRegistrationRecord values in HKCU-backed storage. CngSha256ManifestDigestProvider produces canonical manifest hashes using Windows CNG. Together they support activation-time confirmation that the manifest being activated is the manifest the framework recorded.

Windows View Factory Registry

ForsettiViewFactoryRegistry binds a module ID and view ID to an IWindowsViewFactory. Registration requires the view ID to appear in the module's manifest-declared view IDs. Duplicate factories fail, undeclared view IDs fail, and view creation runs through an IWindowsDispatcher.

Test Coverage

tests/ForsettiPlatformTests/PlatformServicesTests.cpp covers:

  • Registry set/get/overwrite/remove/multiple-key behavior.
  • Registry persistence across service instances.
  • Registry unsafe-key rejection.
  • DPAPI secure storage persistence across service instances.
  • DPAPI unsafe-key rejection.
  • WinHTTP unsupported scheme rejection.
  • WinHTTP unsafe header rejection.
  • Local file export write behavior.
  • Local file export filename sanitization and traversal protection.
  • Default service registration.
  • Module registration persistence and canonical digest behavior.
  • View factory declaration enforcement, duplicate detection, factory resolution, and dispatcher-backed view creation.

Clone this wiki locally