Feature: Implement HTTPS-Only Communication with Certificate Pinning (NF.S21) #113
Labels
No labels
Epic 5
MCP
P1
PR-0
PR-1
api
api-layer
architecture
area:backend
area:frontend
arrow
authentication
backend
bug
chat
client
clipboard
common-module
compose
cross-cutting
cross-cutting-requirement
data-layer
data-models
database
desktop-client
documentation
duplicate
enhancement
epic
epic-1
epic-2
epic-3
epic-4
epic-5
epic-6
epic-7
epic-llm-config
error-handling
feature
frontend
good first issue
help wanted
implementation
infrastructure
installer
invalid
kotlin
ktor
llm
medium-priority
message
multiplatform
needs-review
needs-triage
packaging
performance
phase-1
phase-2
phase-3
phase-4
phase-5
phase3
phase:3
priority: high
question
refactor
refactoring
resource-sharing
security
server
server-module
services
session
session-management
settings
setup
shutdown
state
storage
streaming
sub-issue
tests
tooling
type:task
ui
ui/ux
user-accounts
user-management
ux
viewmodel
websocket
windows
windows-integration
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Torvian.eu/chatbot#113
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Executive Summary
This issue details the implementation plan for enabling HTTPS-only communication between the client and server, as specified in user story NF.S21 - Secure Communication with Server. The revised approach leverages a
CustomTrustManagerfor certificate pinning on the client, eliminating the need for server-side certificate distribution and enhancing security.User Story
Current State
http://localhost:8080Required Changes Overview
The implementation requires changes across server, client (app), and common modules, spanning approximately 13-18 files with new files to be created and existing files to be modified.
Implementation Plan (Phases)
Phase 1: Server SSL/TLS Infrastructure (Estimated: 3-4 days)
This phase focuses on configuring the server to serve content over HTTPS and managing server certificates.
SslConfigdata class (server/src/main/kotlin/eu/torvian/chatbot/server/domain/config/SslConfig.kt).CertificateServiceandDefaultCertificateServicefromtemp/files, updating package names.CertificateManagerinterface andDefaultCertificateManagerimplementation.ServerControlServiceImpl:CertificateManager.loadKeystorehelper method.startSuspendto generate self-signed certificates ifsslConfig.generateSelfSignedis true and no keystore exists.createEmbeddedServerto use theconfigurelambda forsslConnectorsetup.server/build.gradle.kts.configModule,serviceModule,mainModule) forSslConfig,CertificateService,CertificateManager, andServerControlServiceImplinjection.ServerConfigandServerMainto includeSslConfigand use HTTPS defaults.CertificateServiceTest,CertificateManagerTest,ServerHttpsTest).Phase 2: Client SSL/TLS Configuration (Estimated: 3-4 days)
This phase focuses on configuring the client's HTTP client to use HTTPS and implement certificate pinning.
CertificateStorageinterface and platform-specific implementations (FileSystemCertificateStorage,AndroidCertificateStorage,BrowserCertificateStorage).CustomTrustManagerfor Desktop and Android platforms. This manager will handle certificate pinning by verifying the server certificate obtained during the TLS handshake against a stored certificate.createHttpClientto configure SSL/TLS, injectingCertificateStorageand usingCustomTrustManagerfor JVM/Android.serverUrlinAppMain.kt,MainActivity.kt, and WASMAppMain.ktto usehttps://localhost:8443(or appropriate platform-specific HTTPS URL).CertificateStorageindesktopModule,androidModule, andwasmJsModule.CertificateStorageTest).Phase 3: Certificate Verification UI (Estimated: 2-3 days)
This phase focuses on providing a user interface for handling self-signed or changed certificates.
CertificateWarningDialogcomposable to display certificate details (fingerprint, issuer, validity) and allow the user to accept or reject the certificate.CertificateWarningDialoginto the client's connection flow, triggered by theCustomTrustManageron first connection to a server with a self-signed certificate, or if a pinned certificate changes.CertificateStorageand handle rejections.Phase 4: Testing and Documentation (Estimated: 2-3 days)
READMEwith HTTPS setup instructions.Key Components and Files
Server
SslConfig.kt(server/src/main/kotlin/eu/torvian/chatbot/server/domain/config/SslConfig)CertificateManager.kt(server/src/main/kotlin/eu/torvian/chatbot/server/service/security/CertificateManager)DefaultCertificateManager.kt(server/src/main/kotlin/eu/torvian/chatbot/server/service/security/DefaultCertificateManager)CertificateServiceTest.kt(server/src/test/kotlin/eu/torvian/chatbot/server/service/security/CertificateServiceTest.kt)CertificateManagerTest.kt(server/src/test/kotlin/eu/torvian/chatbot/server/service/security/CertificateManagerTest.kt)ServerHttpsTest.kt(server/src/test/kotlin/eu/torvian/chatbot/server/ktor/ServerHttpsTest.kt)ServerConfig.ktServerMain.ktServerControlServiceImpl.ktchatBotServerModule.ktconfigModule.ktserviceModule.ktbuild.gradle.ktsClient
CertificateStorage.kt(app/src/commonMain/kotlin/eu/torvian/chatbot/app/service/security/CertificateStorage.kt)FileSystemCertificateStorage.kt(app/src/desktopMain/kotlin/eu/torvian/chatbot/app/service/security/FileSystemCertificateStorage.kt)CustomTrustManager.kt(Desktop) (app/src/desktopMain/kotlin/eu/torvian/chatbot/app/service/security/CustomTrustManager.kt)AndroidCertificateStorage.kt(app/src/androidMain/kotlin/eu/torvian/chatbot/app/service/security/AndroidCertificateStorage.kt)CustomTrustManager.kt(Android) (app/src/androidMain/kotlin/eu/torvian/chatbot/app/service/security/CustomTrustManager.kt)BrowserCertificateStorage.kt(app/src/wasmJsMain/kotlin/eu/torvian/chatbot/app/service/security/BrowserCertificateStorage.kt)CertificateWarningDialog.kt(app/src/commonMain/kotlin/eu/torvian/chatbot/app/compose/dialogs/CertificateWarningDialog.kt)CertificateStorageTest.kt(app/src/desktopTest/kotlin/eu/torvian/chatbot/app/service/security/CertificateStorageTest.kt)createHttpClient.ktappModule.ktAppMain.kt(desktop)desktopModule.ktMainActivity.kt(android)androidModule.ktAppMain.kt(wasm)Configuration Management
application.conffor SSL settings (e.g.,server.ssl.enabled,server.ssl.port,server.ssl.keystore.path,server.ssl.keystore.password,server.ssl.keyAlias,server.ssl.keyPassword,server.ssl.generateSelfSigned).AppConfigto use HTTPS URLs (e.g.,https://localhost:8443).Security Considerations
Acceptance Criteria Mapping
CertificateManager.CustomTrustManager.CertificateWarningDialogon first connection or certificate change.CertificateStorageimplementations.Estimated Effort
Total Estimated Effort: 10-14 days