initDNSCryptConfig inits the DNSCrypt config. config must not be nil.
(config *proxy.Config)
| 342 | |
| 343 | // initDNSCryptConfig inits the DNSCrypt config. config must not be nil. |
| 344 | func (conf *configuration) initDNSCryptConfig(config *proxy.Config) (err error) { |
| 345 | if conf.DNSCryptConfigPath == "" { |
| 346 | return nil |
| 347 | } |
| 348 | |
| 349 | b, err := os.ReadFile(conf.DNSCryptConfigPath) |
| 350 | if err != nil { |
| 351 | return fmt.Errorf("reading dnscrypt config %q: %w", conf.DNSCryptConfigPath, err) |
| 352 | } |
| 353 | |
| 354 | rc := &dnscrypt.ResolverConfig{} |
| 355 | err = yaml.Unmarshal(b, rc) |
| 356 | if err != nil { |
| 357 | return fmt.Errorf("unmarshalling dnscrypt config: %w", err) |
| 358 | } |
| 359 | |
| 360 | err = rc.Validate() |
| 361 | if err != nil { |
| 362 | return fmt.Errorf("validating dnscrypt config: %w", err) |
| 363 | } |
| 364 | |
| 365 | cert, err := rc.NewCert() |
| 366 | if err != nil { |
| 367 | return fmt.Errorf("creating dnscrypt certificate: %w", err) |
| 368 | } |
| 369 | |
| 370 | err = cert.Validate() |
| 371 | if err != nil { |
| 372 | return fmt.Errorf("validating dnscrypt certificate: %w", err) |
| 373 | } |
| 374 | |
| 375 | config.DNSCryptResolverCert = cert |
| 376 | config.DNSCryptProviderName = rc.ProviderName |
| 377 | |
| 378 | return nil |
| 379 | } |
| 380 | |
| 381 | // parseListenAddrs returns a slice of listen IP addresses from the given |
| 382 | // options. In case no addresses are specified by options returns a slice with |
no test coverage detected