2024-09-22 00:29:36 +09:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
2025-02-19 00:25:00 +09:00
|
|
|
"fmt"
|
2024-09-22 00:29:36 +09:00
|
|
|
"sync"
|
2024-10-23 21:46:21 +09:00
|
|
|
|
2024-12-20 00:20:02 +09:00
|
|
|
"git.gensokyo.uk/security/fortify/fst"
|
2025-02-16 16:28:46 +09:00
|
|
|
"git.gensokyo.uk/security/fortify/internal/app/shim"
|
2025-02-18 18:47:48 +09:00
|
|
|
"git.gensokyo.uk/security/fortify/internal/sys"
|
2024-09-22 00:29:36 +09:00
|
|
|
)
|
|
|
|
|
2025-02-18 23:05:37 +09:00
|
|
|
func New(os sys.State) (fst.App, error) {
|
|
|
|
a := new(app)
|
|
|
|
a.os = os
|
2025-02-19 00:25:00 +09:00
|
|
|
|
|
|
|
id := new(fst.ID)
|
|
|
|
err := fst.NewAppID(id)
|
|
|
|
a.id = newID(id)
|
|
|
|
|
|
|
|
return a, err
|
2025-01-15 23:39:51 +09:00
|
|
|
}
|
|
|
|
|
2024-09-22 00:29:36 +09:00
|
|
|
type app struct {
|
2024-10-20 00:07:48 +09:00
|
|
|
// application unique identifier
|
2025-02-19 00:25:00 +09:00
|
|
|
id *stringPair[fst.ID]
|
2024-10-23 21:46:21 +09:00
|
|
|
// operating system interface
|
2025-02-18 18:47:48 +09:00
|
|
|
os sys.State
|
2024-10-27 00:46:15 +09:00
|
|
|
// shim process manager
|
|
|
|
shim *shim.Shim
|
2024-09-22 00:29:36 +09:00
|
|
|
// child process related information
|
|
|
|
seal *appSeal
|
|
|
|
|
|
|
|
lock sync.RWMutex
|
|
|
|
}
|
|
|
|
|
2025-02-19 00:25:00 +09:00
|
|
|
func (a *app) ID() fst.ID { return a.id.unwrap() }
|
2024-10-20 00:07:48 +09:00
|
|
|
|
2024-09-22 00:29:36 +09:00
|
|
|
func (a *app) String() string {
|
|
|
|
if a == nil {
|
2025-02-19 00:25:00 +09:00
|
|
|
return "(invalid app)"
|
2024-09-22 00:29:36 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
a.lock.RLock()
|
|
|
|
defer a.lock.RUnlock()
|
|
|
|
|
2024-10-27 00:46:15 +09:00
|
|
|
if a.shim != nil {
|
|
|
|
return a.shim.String()
|
2024-09-22 00:29:36 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
if a.seal != nil {
|
2025-02-19 00:25:00 +09:00
|
|
|
if a.seal.sys.user.uid == nil {
|
|
|
|
return fmt.Sprintf("(sealed app %s with invalid uid)", a.id)
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("(sealed app %s as uid %s)", a.id, a.seal.sys.user.uid)
|
2024-09-22 00:29:36 +09:00
|
|
|
}
|
|
|
|
|
2025-02-19 00:25:00 +09:00
|
|
|
return fmt.Sprintf("(unsealed app %s)", a.id)
|
2024-09-22 00:29:36 +09:00
|
|
|
}
|