Skip to content

Commit 8faf8e2

Browse files
committed
feat: Add a preset proton profile and replace default
1 parent 280d7e4 commit 8faf8e2

File tree

2 files changed

+45
-19
lines changed

2 files changed

+45
-19
lines changed

profile/preset.go

Lines changed: 35 additions & 18 deletions
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,37 @@ 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+
s2kConfig := s2k.Config{
141+
S2KMode: s2k.IteratedSaltedS2K,
142+
Hash: crypto.SHA256,
143+
S2KCount: 65536,
144+
}
145+
return &Custom{
146+
SetKeyAlgorithm: setKeyAlgorithm,
147+
Hash: crypto.SHA512,
148+
CipherEncryption: packet.CipherAES256,
149+
CipherKeyEncryption: packet.CipherAES256,
150+
CompressionAlgorithm: packet.CompressionZLIB,
151+
CompressionConfiguration: &packet.CompressionConfig{
152+
Level: 6,
153+
},
154+
S2kKeyEncryption: &s2kConfig,
155+
S2kEncryption: &s2kConfig,
156+
DisableIntendedRecipients: true,
157+
AllowAllPublicKeyAlgorithms: true,
158+
InsecureAllowWeakRSA: true,
159+
InsecureAllowDecryptionWithSigningKeys: true,
160+
}
161+
}

profile/profile.go

Lines changed: 10 additions & 1 deletion
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.
@@ -56,10 +61,14 @@ type Custom struct {
5661
// KeyGenerationProfile, KeyEncryptionProfile, EncryptionProfile, and SignProfile
5762

5863
func (p *Custom) KeyGenerationConfig(securityLevel int8) *packet.Config {
64+
aeadConfig := p.AeadEncryption
65+
if p.KeyGenAeadEncryption != nil {
66+
aeadConfig = p.KeyGenAeadEncryption
67+
}
5968
cfg := &packet.Config{
6069
DefaultHash: p.Hash,
6170
DefaultCipher: p.CipherEncryption,
62-
AEADConfig: p.AeadEncryption,
71+
AEADConfig: aeadConfig,
6372
DefaultCompressionAlgo: p.CompressionAlgorithm,
6473
CompressionConfig: p.CompressionConfiguration,
6574
V6Keys: p.V6,

0 commit comments

Comments
 (0)