certificate.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package option
  2. import (
  3. C "github.com/sagernet/sing-box/constant"
  4. "github.com/sagernet/sing/common/json"
  5. "github.com/sagernet/sing/common/json/badoption"
  6. )
  7. type _CertificateOptions struct {
  8. Store string `json:"store,omitempty"`
  9. Certificate badoption.Listable[string] `json:"certificate,omitempty"`
  10. CertificatePath badoption.Listable[string] `json:"certificate_path,omitempty"`
  11. CertificateDirectoryPath badoption.Listable[string] `json:"certificate_directory_path,omitempty"`
  12. TLSDecryption *TLSDecryptionOptions `json:"tls_decryption,omitempty"`
  13. }
  14. type TLSDecryptionOptions struct {
  15. Enabled bool `json:"enabled,omitempty"`
  16. KeyPair string `json:"key_pair_p12,omitempty"`
  17. KeyPairPassword string `json:"key_pair_p12_password,omitempty"`
  18. }
  19. type CertificateOptions _CertificateOptions
  20. func (o CertificateOptions) MarshalJSON() ([]byte, error) {
  21. switch o.Store {
  22. case C.CertificateStoreSystem:
  23. o.Store = ""
  24. }
  25. return json.Marshal((*_CertificateOptions)(&o))
  26. }
  27. func (o *CertificateOptions) UnmarshalJSON(data []byte) error {
  28. err := json.Unmarshal(data, (*_CertificateOptions)(o))
  29. if err != nil {
  30. return err
  31. }
  32. switch o.Store {
  33. case C.CertificateStoreSystem, "":
  34. o.Store = C.CertificateStoreSystem
  35. }
  36. return nil
  37. }