-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Certificate compression is defined in RFC 8879: https://datatracker.ietf.org/doc/html/rfc8879 This implementation is client-side only, for server certificates.
- Loading branch information
Showing
13 changed files
with
374 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module github.com/refraction-networking/utls | ||
|
||
go 1.16 | ||
|
||
require ( | ||
github.com/andybalholm/brotli v1.0.4 | ||
github.com/klauspost/compress v1.13.6 | ||
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa | ||
golang.org/x/net v0.0.0-20211111160137-58aab5ef257a | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
github.com/andybalholm/brotli v1.0.4 h1:V7DdXeJtZscaqfNuAdSRuRFzuiKlHSC/Zh3zl9qY3JY= | ||
github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= | ||
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc= | ||
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= | ||
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa h1:idItI2DDfCokpg0N51B2VtiLdJ4vAuXC9fnCb2gACo4= | ||
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= | ||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= | ||
golang.org/x/net v0.0.0-20211111160137-58aab5ef257a h1:c83jeVQW0KGKNaKBRfelNYNHaev+qawl9yaA825s8XE= | ||
golang.org/x/net v0.0.0-20211111160137-58aab5ef257a/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= | ||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 h1:SrN+KX8Art/Sf4HNj6Zcz06G7VEz+7w9tdXTPOZ7+l4= | ||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= | ||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M= | ||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package tls | ||
|
||
import ( | ||
"golang.org/x/crypto/cryptobyte" | ||
) | ||
|
||
// Only implemented client-side, for server certificates. | ||
// Alternate certificate message formats (https://datatracker.ietf.org/doc/html/rfc7250) are not | ||
// supported. | ||
// https://datatracker.ietf.org/doc/html/rfc8879 | ||
type compressedCertificateMsg struct { | ||
raw []byte | ||
|
||
algorithm uint16 | ||
uncompressedLength uint32 // uint24 | ||
compressedCertificateMessage []byte | ||
} | ||
|
||
func (m *compressedCertificateMsg) marshal() []byte { | ||
if m.raw != nil { | ||
return m.raw | ||
} | ||
|
||
var b cryptobyte.Builder | ||
b.AddUint8(typeCompressedCertificate) | ||
b.AddUint24LengthPrefixed(func(b *cryptobyte.Builder) { | ||
b.AddUint16(m.algorithm) | ||
b.AddUint24(m.uncompressedLength) | ||
b.AddUint24LengthPrefixed(func(b *cryptobyte.Builder) { | ||
b.AddBytes(m.compressedCertificateMessage) | ||
}) | ||
}) | ||
|
||
m.raw = b.BytesOrPanic() | ||
return m.raw | ||
} | ||
|
||
func (m *compressedCertificateMsg) unmarshal(data []byte) bool { | ||
*m = compressedCertificateMsg{raw: data} | ||
s := cryptobyte.String(data) | ||
|
||
if !s.Skip(4) || // message type and uint24 length field | ||
!s.ReadUint16(&m.algorithm) || | ||
!s.ReadUint24(&m.uncompressedLength) || | ||
!readUint24LengthPrefixed(&s, &m.compressedCertificateMessage) { | ||
return false | ||
} | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package tls | ||
|
||
import ( | ||
"golang.org/x/crypto/cryptobyte" | ||
) | ||
|
||
// Only implemented client-side, for server certificates. | ||
// Alternate certificate message formats (https://datatracker.ietf.org/doc/html/rfc7250) are not | ||
// supported. | ||
// https://datatracker.ietf.org/doc/html/rfc8879 | ||
type compressedCertificateMsg struct { | ||
raw []byte | ||
|
||
algorithm uint16 | ||
uncompressedLength uint32 // uint24 | ||
compressedCertificateMessage []byte | ||
} | ||
|
||
func (m *compressedCertificateMsg) marshal() []byte { | ||
if m.raw != nil { | ||
return m.raw | ||
} | ||
|
||
var b cryptobyte.Builder | ||
b.AddUint8(typeCompressedCertificate) | ||
b.AddUint24LengthPrefixed(func(b *cryptobyte.Builder) { | ||
b.AddUint16(m.algorithm) | ||
b.AddUint24(m.uncompressedLength) | ||
b.AddUint24LengthPrefixed(func(b *cryptobyte.Builder) { | ||
b.AddBytes(m.compressedCertificateMessage) | ||
}) | ||
}) | ||
|
||
m.raw = b.BytesOrPanic() | ||
return m.raw | ||
} | ||
|
||
func (m *compressedCertificateMsg) unmarshal(data []byte) bool { | ||
*m = compressedCertificateMsg{raw: data} | ||
s := cryptobyte.String(data) | ||
|
||
if !s.Skip(4) || // message type and uint24 length field | ||
!s.ReadUint16(&m.algorithm) || | ||
!s.ReadUint24(&m.uncompressedLength) || | ||
!readUint24LengthPrefixed(&s, &m.compressedCertificateMessage) { | ||
return false | ||
} | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.