Skip to content

Commit 9aee2e2

Browse files
authored
Update go-crypto to 1.3.0 (#341)
Additionally, it introduces the option to specify a limit on the amount of data that can be extracted from compressed input.
1 parent 6fc90ca commit 9aee2e2

File tree

8 files changed

+43
-4
lines changed

8 files changed

+43
-4
lines changed

crypto/decryption_core.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,11 @@ func (dh *decryptionHandle) decryptionConfig(configTime int64) *packet.Config {
352352
// Should the session key be returned.
353353
config.CacheSessionKey = dh.RetrieveSessionKey
354354

355+
// Set max decompression size if set.
356+
if dh.MaxDecompressedSize != 0 {
357+
config.MaxDecompressedMessageSize = &dh.MaxDecompressedSize
358+
}
359+
355360
// Set time.
356361
config.Time = NewConstantClock(configTime)
357362
return config

crypto/decryption_handle.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ type decryptionHandle struct {
3030
// VerificationContext provides a verification context for the signature of the pgp message, if any.
3131
// Only considered if VerifyKeyRing is not nil.
3232
VerificationContext *VerificationContext
33+
// MaxDecompressedSize defines the maximum number of bytes allowed for a message
34+
// after decompression. An error is thrown if the decompressed data exceeds this limit.
35+
MaxDecompressedSize int64
3336
// PlainDetachedSignature indicates that all provided detached signatures are not encrypted.
3437
PlainDetachedSignature bool
3538
// DisableIntendedRecipients indicates if the signature verification should not check if

crypto/decryption_handle_builder.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ func (dpb *DecryptionHandleBuilder) PlainDetachedSignature() *DecryptionHandleBu
123123
return dpb
124124
}
125125

126+
// MaxDecompressedMessageSize defines the maximum number of bytes allowed for a message
127+
// after decompression. An error is thrown if the decompressed data exceeds this limit.
128+
func (dpb *DecryptionHandleBuilder) MaxDecompressedMessageSize(size int64) *DecryptionHandleBuilder {
129+
dpb.handle.MaxDecompressedSize = size
130+
return dpb
131+
}
132+
126133
// DisableVerifyTimeCheck disables the check for comparing the signature creation time
127134
// against the verification time.
128135
func (dpb *DecryptionHandleBuilder) DisableVerifyTimeCheck() *DecryptionHandleBuilder {

crypto/verify_handle.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
type verifyHandle struct {
1818
VerifyKeyRing *KeyRing
1919
VerificationContext *VerificationContext
20+
MaxDecompressedSize int64
2021
DisableVerifyTimeCheck bool
2122
DisableStrictMessageParsing bool
2223
DisableAutomaticTextSanitize bool
@@ -161,6 +162,9 @@ func (vh *verifyHandle) verifyingReader(
161162
config.CheckPacketSequence = &checkPacketSequence
162163
verifyTime := vh.clock().Unix()
163164
config.Time = NewConstantClock(verifyTime)
165+
if vh.MaxDecompressedSize != 0 {
166+
config.MaxDecompressedMessageSize = &vh.MaxDecompressedSize
167+
}
164168
if vh.VerificationContext != nil {
165169
config.KnownNotations = map[string]bool{constants.SignatureContextName: true}
166170
}

crypto/verify_handle_builder.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,14 @@ func (vhb *VerifyHandleBuilder) DisableAutomaticTextSanitize() *VerifyHandleBuil
8080
return vhb
8181
}
8282

83+
// MaxDecompressedMessageSize specifies the maximum allowed size, in bytes,
84+
// for a message after decompression within an inline-signed message.
85+
// If the decompressed message exceeds this limit, an error is returned.
86+
func (vhb *VerifyHandleBuilder) MaxDecompressedMessageSize(size int64) *VerifyHandleBuilder {
87+
vhb.handle.MaxDecompressedSize = size
88+
return vhb
89+
}
90+
8391
// New creates a VerifyHandle and checks that the given
8492
// combination of parameters is valid. If the parameters are invalid,
8593
// an error is returned.

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/ProtonMail/gopenpgp/v3
33
go 1.22.0
44

55
require (
6-
github.com/ProtonMail/go-crypto v1.2.0
6+
github.com/ProtonMail/go-crypto v1.3.0
77
github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f
88
github.com/stretchr/testify v1.10.0
99
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
github.com/ProtonMail/go-crypto v1.2.0 h1:+PhXXn4SPGd+qk76TlEePBfOfivE0zkWFenhGhFLzWs=
2-
github.com/ProtonMail/go-crypto v1.2.0/go.mod h1:9whxjD8Rbs29b4XWbB8irEcE8KHMqaR2e7GWU1R+/PE=
1+
github.com/ProtonMail/go-crypto v1.3.0 h1:ILq8+Sf5If5DCpHQp4PbZdS1J7HDFRXz/+xKBiRGFrw=
2+
github.com/ProtonMail/go-crypto v1.3.0/go.mod h1:9whxjD8Rbs29b4XWbB8irEcE8KHMqaR2e7GWU1R+/PE=
33
github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f h1:tCbYj7/299ekTTXpdwKYF8eBlsYsDVoggDAuAjoK66k=
44
github.com/ProtonMail/go-mime v0.0.0-20230322103455-7d82a3887f2f/go.mod h1:gcr0kNtGBqin9zDW9GOHcVntrwnjrK+qdJ06mWYBybw=
55
github.com/cloudflare/circl v1.6.0 h1:cr5JKic4HI+LkINy2lg3W2jF8sHCVTBncJr5gIIq7qk=

profile/profile.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ type Custom struct {
5050
InsecureAllowWeakRSA bool
5151
// InsecureAllowDecryptionWithSigningKeys is a flag to enable to decrypt with signing keys for compatibility reasons.
5252
InsecureAllowDecryptionWithSigningKeys bool
53+
// MaxDecompressedMessageSize sets the maximum decompressed messages size that can be read
54+
// before throwing an error.
55+
MaxDecompressedMessageSize int64
5356
}
5457

5558
// Custom implements the profile interfaces:
@@ -75,6 +78,7 @@ func (p *Custom) EncryptionConfig() *packet.Config {
7578
AEADConfig: p.AeadEncryption,
7679
S2KConfig: p.S2kEncryption,
7780
InsecureAllowDecryptionWithSigningKeys: p.InsecureAllowDecryptionWithSigningKeys,
81+
MaxDecompressedMessageSize: p.maxDecompressedMessageSize(),
7882
}
7983
if p.DisableIntendedRecipients {
8084
intendedRecipients := false
@@ -100,7 +104,8 @@ func (p *Custom) KeyEncryptionConfig() *packet.Config {
100104

101105
func (p *Custom) SignConfig() *packet.Config {
102106
config := &packet.Config{
103-
DefaultHash: p.Hash,
107+
DefaultHash: p.Hash,
108+
MaxDecompressedMessageSize: p.maxDecompressedMessageSize(),
104109
}
105110
if p.SignHash != nil {
106111
config.DefaultHash = *p.SignHash
@@ -124,3 +129,10 @@ func (p *Custom) CompressionConfig() *packet.Config {
124129
DefaultCompressionAlgo: p.CompressionAlgorithm,
125130
}
126131
}
132+
133+
func (p *Custom) maxDecompressedMessageSize() *int64 {
134+
if p.MaxDecompressedMessageSize == 0 {
135+
return nil
136+
}
137+
return &p.MaxDecompressedMessageSize
138+
}

0 commit comments

Comments
 (0)