Skip to content

Commit 9c9b9ce

Browse files
lubuxtwiss
authored andcommitted
feat: Add a preset proton profile and replace default
1 parent 25ad89a commit 9c9b9ce

File tree

2 files changed

+42
-19
lines changed

2 files changed

+42
-19
lines changed

profile/preset.go

+32-18
Original file line numberDiff line numberDiff line change
@@ -11,24 +11,7 @@ import (
1111
// Default returns a custom profile that support features
1212
// that are widely implemented.
1313
func Default() *Custom {
14-
setKeyAlgorithm := func(cfg *packet.Config, securityLevel int8) {
15-
cfg.Algorithm = packet.PubKeyAlgoEdDSA
16-
switch securityLevel {
17-
case constants.HighSecurity:
18-
cfg.Curve = packet.Curve25519
19-
default:
20-
cfg.Curve = packet.Curve25519
21-
}
22-
}
23-
return &Custom{
24-
SetKeyAlgorithm: setKeyAlgorithm,
25-
Hash: crypto.SHA256,
26-
CipherEncryption: packet.CipherAES256,
27-
CompressionAlgorithm: packet.CompressionZLIB,
28-
CompressionConfiguration: &packet.CompressionConfig{
29-
Level: 6,
30-
},
31-
}
14+
return ProtonV1()
3215
}
3316

3417
// RFC4880 returns a custom profile for this library
@@ -142,3 +125,34 @@ func Symmetric() *Custom {
142125
V6: true,
143126
}
144127
}
128+
129+
// ProtonV1 is the version 1 profile used in proton clients.
130+
func ProtonV1() *Custom {
131+
setKeyAlgorithm := func(cfg *packet.Config, securityLevel int8) {
132+
cfg.Algorithm = packet.PubKeyAlgoEdDSA
133+
switch securityLevel {
134+
case constants.HighSecurity:
135+
cfg.Curve = packet.Curve25519
136+
default:
137+
cfg.Curve = packet.Curve25519
138+
}
139+
}
140+
return &Custom{
141+
SetKeyAlgorithm: setKeyAlgorithm,
142+
Hash: crypto.SHA512,
143+
CipherEncryption: packet.CipherAES256,
144+
CipherKeyEncryption: packet.CipherAES256,
145+
CompressionAlgorithm: packet.CompressionZLIB,
146+
CompressionConfiguration: &packet.CompressionConfig{
147+
Level: 6,
148+
},
149+
S2kKeyEncryption: &s2k.Config{
150+
S2KMode: s2k.IteratedSaltedS2K,
151+
Hash: crypto.SHA256,
152+
S2KCount: 65536,
153+
},
154+
DisableIntendedRecipients: true,
155+
AllowAllPublicKeyAlgorithms: true,
156+
AllowWeakRSA: true,
157+
}
158+
}

profile/profile.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ type Custom struct {
2424
// S2kKeyEncryption defines the s2k algorithm for key encryption.
2525
S2kKeyEncryption *s2k.Config
2626
// AeadEncryption defines the aead encryption algorithm for pgp encryption.
27+
// If nil, aead is disabled even if the key supports it.
2728
AeadEncryption *packet.AEADConfig
29+
// KeyGenAeadEncryption defines if the output key in key generation
30+
// advertises SEIPDv2 and aead algorithms in its key preferences.
31+
// If nil, uses AeadEncryption as key preferences.
32+
KeyGenAeadEncryption *packet.AEADConfig
2833
// S2kEncryption defines the s2k algorithm for pgp encryption.
2934
S2kEncryption *s2k.Config
3035
// CompressionConfiguration defines the compression configuration to be used if any.
@@ -54,10 +59,14 @@ type Custom struct {
5459
// KeyGenerationProfile, KeyEncryptionProfile, EncryptionProfile, and SignProfile
5560

5661
func (p *Custom) KeyGenerationConfig(securityLevel int8) *packet.Config {
62+
aeadConfig := p.AeadEncryption
63+
if p.KeyGenAeadEncryption != nil {
64+
aeadConfig = p.KeyGenAeadEncryption
65+
}
5766
cfg := &packet.Config{
5867
DefaultHash: p.Hash,
5968
DefaultCipher: p.CipherEncryption,
60-
AEADConfig: p.AeadEncryption,
69+
AEADConfig: aeadConfig,
6170
DefaultCompressionAlgo: p.CompressionAlgorithm,
6271
CompressionConfig: p.CompressionConfiguration,
6372
V6Keys: p.V6,

0 commit comments

Comments
 (0)