feat: Tích hợp Bản quyền License AES-256 (OTH.Adapter), Biên bản giao ban A4, Biểu đồ tròn và Tài liệu triển khai demo

This commit is contained in:
ongtrieuhau
2026-10-27 02:04:23 -07:00
parent 6d54ca20f6
commit 358cfbfde1
13 changed files with 2149 additions and 32 deletions
+36
View File
@@ -46,15 +46,22 @@ type UpdaterConfig struct {
CurrentVersion string `json:"current_version"`
}
type LicenseConfig struct {
CryptoKey string `json:"crypto_key"` // stored as ENC(...)
Key string `json:"key"` // stored ciphertext U2FsdGVk...
}
type AppConfig struct {
Server ServerConfig `json:"server"`
Database DBConfig `json:"database"`
Updater UpdaterConfig `json:"updater"`
License LicenseConfig `json:"license"`
// runtime plaintext fields (not exported to JSON if needed)
DecryptedDBPassword string `json:"-"`
DecryptedUpdaterToken string `json:"-"`
DecryptedAdminPassword string `json:"-"`
DecryptedCryptoKey string `json:"-"`
}
var (
@@ -154,6 +161,10 @@ func DefaultConfig() *AppConfig {
Token: "",
CurrentVersion: "v1.0.2",
},
License: LicenseConfig{
CryptoKey: "BAD5A05F330D5B8CDDFCA9E7ECDC840B",
Key: "",
},
}
return cfg
}
@@ -171,15 +182,18 @@ func LoadConfig(path string) (*AppConfig, error) {
cfg.DecryptedAdminPassword = cfg.Server.AdminPassword
cfg.DecryptedDBPassword = cfg.Database.Password
cfg.DecryptedUpdaterToken = cfg.Updater.Token
cfg.DecryptedCryptoKey = cfg.License.CryptoKey
// Encrypt for disk save
encAdmin, _ := Encrypt(cfg.Server.AdminPassword)
encDB, _ := Encrypt(cfg.Database.Password)
encTok, _ := Encrypt(cfg.Updater.Token)
encCrypto, _ := Encrypt(cfg.License.CryptoKey)
cfg.Server.AdminPassword = encAdmin
cfg.Database.Password = encDB
cfg.Updater.Token = encTok
cfg.License.CryptoKey = encCrypto
data, _ := json.MarshalIndent(cfg, "", " ")
_ = os.MkdirAll(filepath.Dir(configPath), 0755)
@@ -203,10 +217,24 @@ func LoadConfig(path string) (*AppConfig, error) {
decAdmin, _ := Decrypt(cfg.Server.AdminPassword)
decDB, _ := Decrypt(cfg.Database.Password)
decTok, _ := Decrypt(cfg.Updater.Token)
if cfg.License.CryptoKey == "" {
cfg.License.CryptoKey = "BAD5A05F330D5B8CDDFCA9E7ECDC840B"
}
decCrypto, _ := Decrypt(cfg.License.CryptoKey)
if decCrypto == "" {
decCrypto = "BAD5A05F330D5B8CDDFCA9E7ECDC840B"
}
cfg.DecryptedAdminPassword = decAdmin
cfg.DecryptedDBPassword = decDB
cfg.DecryptedUpdaterToken = decTok
cfg.DecryptedCryptoKey = decCrypto
// Ensure crypto key is stored encrypted on disk
if !strings.HasPrefix(cfg.License.CryptoKey, "ENC(") {
encCrypto, _ := Encrypt(cfg.License.CryptoKey)
cfg.License.CryptoKey = encCrypto
}
// Auto-migrate legacy owner & repo
if cfg.Updater.Owner == "" || cfg.Updater.Owner == "hdhiswork" {
@@ -242,6 +270,14 @@ func SaveConfig(cfg *AppConfig) error {
enc, _ := Encrypt(clone.Updater.Token)
clone.Updater.Token = enc
}
if clone.License.CryptoKey == "" {
clone.License.CryptoKey = "BAD5A05F330D5B8CDDFCA9E7ECDC840B"
}
if !strings.HasPrefix(clone.License.CryptoKey, "ENC(") {
clone.DecryptedCryptoKey = clone.License.CryptoKey
enc, _ := Encrypt(clone.License.CryptoKey)
clone.License.CryptoKey = enc
}
data, err := json.MarshalIndent(&clone, "", " ")
if err != nil {