github.com/sagernet/sing-box@v1.9.0-rc.20/option/tls_acme.go (about) 1 package option 2 3 import ( 4 C "github.com/sagernet/sing-box/constant" 5 E "github.com/sagernet/sing/common/exceptions" 6 "github.com/sagernet/sing/common/json" 7 ) 8 9 type InboundACMEOptions struct { 10 Domain Listable[string] `json:"domain,omitempty"` 11 DataDirectory string `json:"data_directory,omitempty"` 12 DefaultServerName string `json:"default_server_name,omitempty"` 13 Email string `json:"email,omitempty"` 14 Provider string `json:"provider,omitempty"` 15 DisableHTTPChallenge bool `json:"disable_http_challenge,omitempty"` 16 DisableTLSALPNChallenge bool `json:"disable_tls_alpn_challenge,omitempty"` 17 AlternativeHTTPPort uint16 `json:"alternative_http_port,omitempty"` 18 AlternativeTLSPort uint16 `json:"alternative_tls_port,omitempty"` 19 ExternalAccount *ACMEExternalAccountOptions `json:"external_account,omitempty"` 20 DNS01Challenge *ACMEDNS01ChallengeOptions `json:"dns01_challenge,omitempty"` 21 } 22 23 type ACMEExternalAccountOptions struct { 24 KeyID string `json:"key_id,omitempty"` 25 MACKey string `json:"mac_key,omitempty"` 26 } 27 28 type _ACMEDNS01ChallengeOptions struct { 29 Provider string `json:"provider,omitempty"` 30 AliDNSOptions ACMEDNS01AliDNSOptions `json:"-"` 31 CloudflareOptions ACMEDNS01CloudflareOptions `json:"-"` 32 } 33 34 type ACMEDNS01ChallengeOptions _ACMEDNS01ChallengeOptions 35 36 func (o ACMEDNS01ChallengeOptions) MarshalJSON() ([]byte, error) { 37 var v any 38 switch o.Provider { 39 case C.DNSProviderAliDNS: 40 v = o.AliDNSOptions 41 case C.DNSProviderCloudflare: 42 v = o.CloudflareOptions 43 case "": 44 return nil, E.New("missing provider type") 45 default: 46 return nil, E.New("unknown provider type: " + o.Provider) 47 } 48 return MarshallObjects((_ACMEDNS01ChallengeOptions)(o), v) 49 } 50 51 func (o *ACMEDNS01ChallengeOptions) UnmarshalJSON(bytes []byte) error { 52 err := json.Unmarshal(bytes, (*_ACMEDNS01ChallengeOptions)(o)) 53 if err != nil { 54 return err 55 } 56 var v any 57 switch o.Provider { 58 case C.DNSProviderAliDNS: 59 v = &o.AliDNSOptions 60 case C.DNSProviderCloudflare: 61 v = &o.CloudflareOptions 62 default: 63 return E.New("unknown provider type: " + o.Provider) 64 } 65 err = UnmarshallExcluded(bytes, (*_ACMEDNS01ChallengeOptions)(o), v) 66 if err != nil { 67 return err 68 } 69 return nil 70 } 71 72 type ACMEDNS01AliDNSOptions struct { 73 AccessKeyID string `json:"access_key_id,omitempty"` 74 AccessKeySecret string `json:"access_key_secret,omitempty"` 75 RegionID string `json:"region_id,omitempty"` 76 } 77 78 type ACMEDNS01CloudflareOptions struct { 79 APIToken string `json:"api_token,omitempty"` 80 }