Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new ClientHellos #122

Merged
merged 2 commits into from Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion common.go
Expand Up @@ -96,7 +96,6 @@ const (
extensionSignatureAlgorithmsCert uint16 = 50
extensionKeyShare uint16 = 51
extensionNextProtoNeg uint16 = 13172 // not IANA assigned
extensionALPS uint16 = 17513
gaukas marked this conversation as resolved.
Show resolved Hide resolved
extensionRenegotiationInfo uint16 = 0xff01
)

Expand Down
2 changes: 1 addition & 1 deletion u_fingerprinter.go
Expand Up @@ -350,7 +350,7 @@ func (f *Fingerprinter) FingerprintClientHello(data []byte) (*ClientHelloSpec, e
}
supportedProtocols = append(supportedProtocols, string(proto))
}
clientHelloSpec.Extensions = append(clientHelloSpec.Extensions, &FakeALPSExtension{supportedProtocols})
clientHelloSpec.Extensions = append(clientHelloSpec.Extensions, &ApplicationSettingsExtension{supportedProtocols})

case fakeRecordSizeLimit:
recordSizeExt := new(FakeRecordSizeLimitExtension)
Expand Down
4 changes: 2 additions & 2 deletions u_parrots.go
Expand Up @@ -1499,7 +1499,7 @@ func utlsIdToSpec(id ClientHelloID) (ClientHelloSpec, error) {
CertCompressionBrotli,
},
},
&FakeALPSExtension{
&ApplicationSettingsExtension{
SupportedProtocols: []string{
"h2",
},
Expand Down Expand Up @@ -1901,7 +1901,7 @@ func utlsIdToSpec(id ClientHelloID) (ClientHelloSpec, error) {
CertCompressionBrotli,
},
},
&FakeALPSExtension{
&ApplicationSettingsExtension{
SupportedProtocols: []string{
"h2",
},
Expand Down
59 changes: 13 additions & 46 deletions u_tls_extensions.go
Expand Up @@ -356,6 +356,17 @@ func (e *ALPNExtension) Read(b []byte) (int, error) {
return e.Len(), io.EOF
}

// ApplicationSettingsExtension represents the TLS ALPS extension. At the time
// of this writing, this extension is currently a draft:
// https://datatracker.ietf.org/doc/html/draft-vvv-tls-alps-01
//
// This library does not offer actual support for ALPS. This extension is
// "faked" - it is advertised by the client, but not respected if the server
// responds with support.
//
// In the normal convention of this library, this type name would be prefixed
// with 'Fake'. The existing name is retained for backwards compatibility
// reasons.
type ApplicationSettingsExtension struct {
SupportedProtocols []string
}
Expand All @@ -378,8 +389,8 @@ func (e *ApplicationSettingsExtension) Read(b []byte) (int, error) {
}

// Read Type.
b[0] = byte(extensionALPS >> 8) // hex: 44 dec: 68
b[1] = byte(extensionALPS & 0xff) // hex: 69 dec: 105
b[0] = byte(fakeExtensionALPS >> 8) // hex: 44 dec: 68
b[1] = byte(fakeExtensionALPS & 0xff) // hex: 69 dec: 105

lengths := b[2:] // get the remaining buffer without Type
b = b[6:] // set the buffer to the buffer without Type, Length and ALPS Extension Length (so only the Supported ALPN list remains)
Expand Down Expand Up @@ -952,50 +963,6 @@ func (e *FakeTokenBindingExtension) Read(b []byte) (int, error) {
return e.Len(), io.EOF
}

type FakeALPSExtension struct {
SupportedProtocols []string
}

func (e *FakeALPSExtension) writeToUConn(uc *UConn) error {
return nil
}

func (e *FakeALPSExtension) Len() int {
bLen := 2 + 2 + 2
for _, s := range e.SupportedProtocols {
bLen += 1 + len(s)
}
return bLen
}

func (e *FakeALPSExtension) Read(b []byte) (int, error) {
if len(b) < e.Len() {
return 0, io.ErrShortBuffer
}

b[0] = byte(fakeExtensionALPS >> 8)
b[1] = byte(fakeExtensionALPS & 0xff)
lengths := b[2:]
b = b[6:]

stringsLength := 0
for _, s := range e.SupportedProtocols {
l := len(s)
b[0] = byte(l)
copy(b[1:], s)
b = b[1+l:]
stringsLength += 1 + l
}

lengths[2] = byte(stringsLength >> 8)
lengths[3] = byte(stringsLength)
stringsLength += 2
lengths[0] = byte(stringsLength >> 8)
lengths[1] = byte(stringsLength)

return e.Len(), io.EOF
}

// https://datatracker.ietf.org/doc/html/draft-ietf-tls-subcerts-15#section-4.1.1

type FakeDelegatedCredentialsExtension struct {
Expand Down