git.prognetwork.ru/x0r/utls@v1.3.3/u_fingerprinter.go (about) 1 // Copyright 2017 Google Inc. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package tls 6 7 // Fingerprinter is a struct largely for holding options for the FingerprintClientHello func 8 type Fingerprinter struct { 9 // AllowBluntMimicry will ensure that unknown extensions are 10 // passed along into the resulting ClientHelloSpec as-is 11 // It will not ensure that the PSK is passed along, if you require that, use KeepPSK 12 // WARNING: there could be numerous subtle issues with ClientHelloSpecs 13 // that are generated with this flag which could compromise security and/or mimicry 14 AllowBluntMimicry bool 15 // AlwaysAddPadding will always add a UtlsPaddingExtension with BoringPaddingStyle 16 // at the end of the extensions list if it isn't found in the fingerprinted hello. 17 // This could be useful in scenarios where the hello you are fingerprinting does not 18 // have any padding, but you suspect that other changes you make to the final hello 19 // (including things like different SNI lengths) would cause padding to be necessary 20 AlwaysAddPadding bool 21 } 22 23 // FingerprintClientHello returns a ClientHelloSpec which is based on the 24 // ClientHello that is passed in as the data argument 25 // 26 // If the ClientHello passed in has extensions that are not recognized or cannot be handled 27 // it will return a non-nil error and a nil *ClientHelloSpec value 28 // 29 // The data should be the full tls record, including the record type/version/length header 30 // as well as the handshake type/length/version header 31 // https://tools.ietf.org/html/rfc5246#section-6.2 32 // https://tools.ietf.org/html/rfc5246#section-7.4 33 // 34 // It calls UnmarshalClientHello internally, and is kept for backwards compatibility 35 func (f *Fingerprinter) FingerprintClientHello(data []byte) (clientHelloSpec *ClientHelloSpec, err error) { 36 return f.RawClientHello(data) 37 } 38 39 // RawClientHello returns a ClientHelloSpec which is based on the 40 // ClientHello raw bytes that is passed in as the raw argument. 41 // 42 // It was renamed from FingerprintClientHello in v1.3.1 and earlier versions 43 // as a more precise name for the function 44 func (f *Fingerprinter) RawClientHello(raw []byte) (clientHelloSpec *ClientHelloSpec, err error) { 45 clientHelloSpec = &ClientHelloSpec{} 46 err = clientHelloSpec.FromRaw(raw, f.AllowBluntMimicry) 47 if err != nil { 48 return nil, err 49 } 50 51 if f.AlwaysAddPadding { 52 clientHelloSpec.AlwaysAddPadding() 53 } 54 55 return clientHelloSpec, nil 56 } 57 58 // UnmarshalJSONClientHello returns a ClientHelloSpec which is based on the 59 // ClientHello JSON bytes that is passed in as the json argument. 60 func (f *Fingerprinter) UnmarshalJSONClientHello(json []byte) (clientHelloSpec *ClientHelloSpec, err error) { 61 clientHelloSpec = &ClientHelloSpec{} 62 err = clientHelloSpec.UnmarshalJSON(json) 63 if err != nil { 64 return nil, err 65 } 66 67 if f.AlwaysAddPadding { 68 clientHelloSpec.AlwaysAddPadding() 69 } 70 71 return clientHelloSpec, nil 72 }