newFakeClientHello picks an SNI per the randomizer, builds a ClientHello with randomized extra padding, and returns both the bytes and the SNI used (for logging).
()
| 319 | // with randomized extra padding, and returns both the bytes and the SNI used |
| 320 | // (for logging). |
| 321 | func (e *Engine) newFakeClientHello() ([]byte, string, error) { |
| 322 | sni := e.rnd.PickSNI(e.cfg.SNIPool) |
| 323 | if sni == "" { |
| 324 | return nil, "", errors.New("engine: empty SNI pool") |
| 325 | } |
| 326 | var rnd, sess, ks [32]byte |
| 327 | if _, err := rand.Read(rnd[:]); err != nil { |
| 328 | return nil, "", err |
| 329 | } |
| 330 | if _, err := rand.Read(sess[:]); err != nil { |
| 331 | return nil, "", err |
| 332 | } |
| 333 | if _, err := rand.Read(ks[:]); err != nil { |
| 334 | return nil, "", err |
| 335 | } |
| 336 | extra := e.rnd.ExtraPad() |
| 337 | buf, err := injector.BuildClientHelloPadded(rnd[:], sess[:], []byte(sni), ks[:], extra) |
| 338 | if err != nil { |
| 339 | return nil, "", err |
| 340 | } |
| 341 | return buf, sni, nil |
| 342 | } |
| 343 | |
| 344 | func (e *Engine) infof(format string, args ...any) { |
| 345 | if e.cfg.Log != nil { |
no test coverage detected