forked from refraction-networking/utls
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement certificate compression (refraction-networking#95)
Certificate compression is defined in RFC 8879: https://datatracker.ietf.org/doc/html/rfc8879 This implementation is client-side only, for server certificates. - Fixes refraction-networking#104.
- Loading branch information
Showing
6 changed files
with
131 additions
and
49 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
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
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