@@ -116,7 +116,7 @@ func (e *Entity) EncryptionKey(now time.Time, config *packet.Config) (Key, bool)
116
116
for i , subkey := range e .Subkeys {
117
117
subkeySelfSig , err := subkey .Verify (now , config ) // subkey has to be valid at time now
118
118
if err == nil &&
119
- isValidEncryptionKey (subkeySelfSig , subkey .PublicKey .PubKeyAlgo ) &&
119
+ isValidEncryptionKey (subkeySelfSig , subkey .PublicKey .PubKeyAlgo , config ) &&
120
120
checkKeyRequirements (subkey .PublicKey , config ) == nil &&
121
121
(maxTime .IsZero () || subkeySelfSig .CreationTime .Unix () >= maxTime .Unix ()) {
122
122
candidateSubkey = i
@@ -138,7 +138,7 @@ func (e *Entity) EncryptionKey(now time.Time, config *packet.Config) (Key, bool)
138
138
139
139
// If we don't have any subkeys for encryption and the primary key
140
140
// is marked as OK to encrypt with, then we can use it.
141
- if isValidEncryptionKey (primarySelfSignature , e .PrimaryKey .PubKeyAlgo ) {
141
+ if isValidEncryptionKey (primarySelfSignature , e .PrimaryKey .PubKeyAlgo , config ) {
142
142
return Key {
143
143
Entity : e ,
144
144
PrimarySelfSignature : primarySelfSignature ,
@@ -164,12 +164,12 @@ func (e *Entity) DecryptionKeys(id uint64, date time.Time, config *packet.Config
164
164
for _ , subkey := range e .Subkeys {
165
165
subkeySelfSig , err := subkey .LatestValidBindingSignature (date , config )
166
166
if err == nil &&
167
- (config .AllowDecryptionWithSigningKeys () || isValidEncryptionKey (subkeySelfSig , subkey .PublicKey .PubKeyAlgo )) &&
167
+ (config .AllowDecryptionWithSigningKeys () || isValidEncryptionKey (subkeySelfSig , subkey .PublicKey .PubKeyAlgo , config )) &&
168
168
(id == 0 || subkey .PublicKey .KeyId == id ) {
169
169
keys = append (keys , Key {subkey .Primary , primarySelfSignature , subkey .PublicKey , subkey .PrivateKey , subkeySelfSig })
170
170
}
171
171
}
172
- if config .AllowDecryptionWithSigningKeys () || isValidEncryptionKey (primarySelfSignature , e .PrimaryKey .PubKeyAlgo ) {
172
+ if config .AllowDecryptionWithSigningKeys () || isValidEncryptionKey (primarySelfSignature , e .PrimaryKey .PubKeyAlgo , config ) {
173
173
keys = append (keys , Key {e , primarySelfSignature , e .PrimaryKey , e .PrivateKey , primarySelfSignature })
174
174
}
175
175
return
@@ -219,8 +219,8 @@ func (e *Entity) signingKeyByIdUsage(now time.Time, id uint64, flags int, config
219
219
for idx , subkey := range e .Subkeys {
220
220
subkeySelfSig , err := subkey .Verify (now , config )
221
221
if err == nil &&
222
- (flags & packet .KeyFlagCertify == 0 || isValidCertificationKey (subkeySelfSig , subkey .PublicKey .PubKeyAlgo )) &&
223
- (flags & packet .KeyFlagSign == 0 || isValidSigningKey (subkeySelfSig , subkey .PublicKey .PubKeyAlgo )) &&
222
+ (flags & packet .KeyFlagCertify == 0 || isValidCertificationKey (subkeySelfSig , subkey .PublicKey .PubKeyAlgo , config )) &&
223
+ (flags & packet .KeyFlagSign == 0 || isValidSigningKey (subkeySelfSig , subkey .PublicKey .PubKeyAlgo , config )) &&
224
224
checkKeyRequirements (subkey .PublicKey , config ) == nil &&
225
225
(maxTime .IsZero () || subkeySelfSig .CreationTime .Unix () >= maxTime .Unix ()) &&
226
226
(id == 0 || subkey .PublicKey .KeyId == id ) {
@@ -243,8 +243,8 @@ func (e *Entity) signingKeyByIdUsage(now time.Time, id uint64, flags int, config
243
243
244
244
// If we don't have any subkeys for signing and the primary key
245
245
// is marked as OK to sign with, then we can use it.
246
- if (flags & packet .KeyFlagCertify == 0 || isValidCertificationKey (primarySelfSignature , e .PrimaryKey .PubKeyAlgo )) &&
247
- (flags & packet .KeyFlagSign == 0 || isValidSigningKey (primarySelfSignature , e .PrimaryKey .PubKeyAlgo )) &&
246
+ if (flags & packet .KeyFlagCertify == 0 || isValidCertificationKey (primarySelfSignature , e .PrimaryKey .PubKeyAlgo , config )) &&
247
+ (flags & packet .KeyFlagSign == 0 || isValidSigningKey (primarySelfSignature , e .PrimaryKey .PubKeyAlgo , config )) &&
248
248
(id == 0 || e .PrimaryKey .KeyId == id ) {
249
249
return Key {
250
250
Entity : e ,
@@ -770,20 +770,38 @@ func checkKeyRequirements(usedKey *packet.PublicKey, config *packet.Config) erro
770
770
return nil
771
771
}
772
772
773
- func isValidSigningKey (signature * packet.Signature , algo packet.PublicKeyAlgorithm ) bool {
774
- return algo .CanSign () &&
775
- signature .FlagsValid &&
776
- signature .FlagSign
773
+ func isValidSigningKey (signature * packet.Signature , algo packet.PublicKeyAlgorithm , config * packet.Config ) bool {
774
+ if ! algo .CanSign () {
775
+ return false
776
+ }
777
+
778
+ if signature .FlagsValid {
779
+ return signature .FlagSign
780
+ }
781
+
782
+ return config .AllowAllKeyFlagsWhenMissing ()
777
783
}
778
784
779
- func isValidCertificationKey (signature * packet.Signature , algo packet.PublicKeyAlgorithm ) bool {
780
- return algo .CanSign () &&
781
- signature .FlagsValid &&
782
- signature .FlagCertify
785
+ func isValidCertificationKey (signature * packet.Signature , algo packet.PublicKeyAlgorithm , config * packet.Config ) bool {
786
+ if ! algo .CanSign () {
787
+ return false
788
+ }
789
+
790
+ if signature .FlagsValid {
791
+ return signature .FlagCertify
792
+ }
793
+
794
+ return config .AllowAllKeyFlagsWhenMissing ()
783
795
}
784
796
785
- func isValidEncryptionKey (signature * packet.Signature , algo packet.PublicKeyAlgorithm ) bool {
786
- return algo .CanEncrypt () &&
787
- signature .FlagsValid &&
788
- (signature .FlagEncryptCommunications || signature .FlagEncryptStorage )
797
+ func isValidEncryptionKey (signature * packet.Signature , algo packet.PublicKeyAlgorithm , config * packet.Config ) bool {
798
+ if ! algo .CanEncrypt () {
799
+ return false
800
+ }
801
+
802
+ if signature .FlagsValid {
803
+ return signature .FlagEncryptCommunications || signature .FlagEncryptStorage
804
+ }
805
+
806
+ return config .AllowAllKeyFlagsWhenMissing ()
789
807
}
0 commit comments