-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Randomize v4 and v5 signatures via custom notation
- Loading branch information
Showing
7 changed files
with
99 additions
and
9 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 |
---|---|---|
|
@@ -35,6 +35,8 @@ const ( | |
KeyFlagGroupKey | ||
) | ||
|
||
const SaltNotationName = "[email protected]" | ||
|
||
// Signature represents a signature. See RFC 4880, section 5.2. | ||
type Signature struct { | ||
Version int | ||
|
@@ -878,6 +880,19 @@ func (sig *Signature) Sign(h hash.Hash, priv *PrivateKey, config *Config) (err e | |
} | ||
sig.Version = priv.PublicKey.Version | ||
sig.IssuerFingerprint = priv.PublicKey.Fingerprint | ||
if priv.Version != 6 && config.RandomizeSignaturesViaNotation() { | ||
salt, err := SignatureSaltForHash(sig.Hash, config.Random()) | ||
if err != nil { | ||
return err | ||
} | ||
notation := Notation{ | ||
Name: SaltNotationName, | ||
Value: salt, | ||
IsCritical: false, | ||
IsHumanReadable: false, | ||
} | ||
sig.Notations = append(sig.Notations, ¬ation) | ||
} | ||
sig.outSubpackets, err = sig.buildSubpackets(priv.PublicKey) | ||
if err != nil { | ||
return err | ||
|
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 |
---|---|---|
|
@@ -86,6 +86,7 @@ func TestSignDetachedWithNotation(t *testing.T) { | |
IsHumanReadable: true, | ||
}, | ||
}, | ||
NonDeterministicSignaturesViaNotation: packet.BoolPointer(false), | ||
} | ||
err := DetachSign(signature, kring[0], message, config) | ||
if err != nil { | ||
|
@@ -137,6 +138,7 @@ func TestSignDetachedWithCriticalNotation(t *testing.T) { | |
IsCritical: true, | ||
}, | ||
}, | ||
NonDeterministicSignaturesViaNotation: packet.BoolPointer(false), | ||
} | ||
err := DetachSign(signature, kring[0], message, config) | ||
if err != nil { | ||
|
@@ -180,7 +182,6 @@ func TestSignDetachedWithCriticalNotation(t *testing.T) { | |
} | ||
|
||
func TestNewEntity(t *testing.T) { | ||
|
||
// Check bit-length with no config. | ||
e, err := NewEntity("Test User", "test", "[email protected]", nil) | ||
if err != nil { | ||
|
@@ -211,8 +212,11 @@ func TestNewEntity(t *testing.T) { | |
t.Errorf("BitLength %v, expected %v", bl, cfg.RSABits) | ||
} | ||
|
||
keySerializeConfig := &packet.Config{ | ||
NonDeterministicSignaturesViaNotation: packet.BoolPointer(false), | ||
} | ||
w := bytes.NewBuffer(nil) | ||
if err := e.SerializePrivate(w, nil); err != nil { | ||
if err := e.SerializePrivate(w, keySerializeConfig); err != nil { | ||
t.Errorf("failed to serialize entity: %s", err) | ||
return | ||
} | ||
|
@@ -229,7 +233,7 @@ func TestNewEntity(t *testing.T) { | |
} | ||
|
||
w = bytes.NewBuffer(nil) | ||
if err := e.SerializePrivate(w, nil); err != nil { | ||
if err := e.SerializePrivate(w, keySerializeConfig); err != nil { | ||
t.Errorf("failed to serialize entity second time: %s", err) | ||
return | ||
} | ||
|
@@ -247,7 +251,7 @@ func TestNewEntity(t *testing.T) { | |
} | ||
|
||
w = bytes.NewBuffer(nil) | ||
if err := e.SerializePrivate(w, nil); err != nil { | ||
if err := e.SerializePrivate(w, keySerializeConfig); err != nil { | ||
t.Errorf("failed to serialize after encryption round: %s", err) | ||
return | ||
} | ||
|