Skip to content

Commit

Permalink
Use forwardee idenitity in forwarding key generation
Browse files Browse the repository at this point in the history
  • Loading branch information
wussler committed Mar 7, 2023
1 parent efbd7f8 commit bb8710b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 31 deletions.
5 changes: 2 additions & 3 deletions openpgp/forwarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/ProtonMail/go-crypto/openpgp/packet"
)

func (e *Entity) NewForwardingEntity(config *packet.Config) (forwardeeKey *Entity, proxyParam []byte, err error) {
func (e *Entity) NewForwardingEntity(name, comment, email string, config *packet.Config) (forwardeeKey *Entity, proxyParam []byte, err error) {
encryptionSubKey, ok := e.EncryptionKey(config.Now())
if !ok {
return nil, nil, errors.InvalidArgumentError("no valid encryption key found")
Expand All @@ -32,9 +32,8 @@ func (e *Entity) NewForwardingEntity(config *packet.Config) (forwardeeKey *Entit

config.Algorithm = packet.PubKeyAlgoEdDSA
config.Curve = packet.Curve25519
id := e.PrimaryIdentity().UserId

forwardeeKey, err = NewEntity(id.Name, id.Comment, id.Email, config)
forwardeeKey, err = NewEntity(name, comment, email, config)
if err != nil {
return nil, nil, err
}
Expand Down
38 changes: 19 additions & 19 deletions openpgp/forwarding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,30 @@ import (

const forwardeeKey = `-----BEGIN PGP PRIVATE KEY BLOCK-----
xVgEY/ikABYJKwYBBAHaRw8BAQdAzz/nPfhJnoAYwg43AFYzxX1v6UwGmfN9jPiI
/MOFxFgAAQDTqvO94jZPb9brhpwayNI9QlqqTlvDP6AH8CpXUfoVmxDczRNib2Ig
PGJvYkBwcm90b24ubWU+wooEExYIADwFAmP4pAAJkIdp9lyYAlNMFiEEzW5s1IvY
GXCwcJkZh2n2XJgCU0wCGwMCHgECGQECCwcCFQgCFgACIgEAAPmGAQDxysrSwxQO
27X/eg7xSE5JVXT7bt8cEZOE+iC2IDS02QEA2CvXnZJK4AOmPsFWKzn3HkFxCybc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= `-----BEGIN PGP MESSAGE-----
wV4Dwkk3ytpHrqASAQdAzPWbm24Uj6OYSDaauOuFMRPPLr5zWKXgvC1eHPD78ykw
YkvxNCwD6hfzjLoASVv9jhHJoXY+Pag6QHvoFuMn+hdG90yFh5HMFyileY/CTrT7
0kcBAPalcAq/OH/pBtIhGT/TKS88IIkz2aSukjbQRf+JNyh7bF+uXVDGmD8zOGa8
mM9TmGOf8Vi3sjgVAQ5rZQzh36HrBDloBA==
=PotS
wV4DB27Wn97eACkSAQdA62TlMU2QoGmf5iBLnIm4dlFRkLIg+6MbaatghwxK+Ccw
yGZuVVMAK/ypFfebDf4D/rlEw3cysv213m8aoK8nAUO8xQX3XQq3Sg+EGm0BNV8E
0kABEPyCWARoo5klT1rHPEhelnz8+RQXiOIX3G685XCWdCmaV+tzW082D0xGXSlC
7lM8r1DumNnO8srssko2qIja
=pVRa
-----END PGP MESSAGE-----`

const forwardedPlaintext = "Hello Bob, hello world"
const forwardedPlaintext = "Message for Bob"

func TestForwardingStatic(t *testing.T) {
charlesKey, err := ReadArmoredKeyRing(bytes.NewBufferString(forwardeeKey))
Expand Down Expand Up @@ -78,7 +78,7 @@ func TestForwardingFull(t *testing.T) {
t.Fatal(err)
}

charlesEntity, proxyParam, err := bobEntity.NewForwardingEntity(keyConfig)
charlesEntity, proxyParam, err := bobEntity.NewForwardingEntity("charles", "", "[email protected]", keyConfig)
if err != nil {
t.Fatal(err)
}
Expand Down
16 changes: 7 additions & 9 deletions openpgp/internal/ecc/curve25519/curve25519.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,14 @@ func DeriveProxyParam(recipientSecretByte, forwardeeSecretByte []byte) (proxyPar
curveGroup,
)

proxyParam = proxyTransform.Bytes()
rawProxyParam := proxyTransform.Bytes()

// convert to small endian
reverse(proxyParam)
// pad and convert to small endian
proxyParam = make([]byte, x25519lib.Size)
l := len(rawProxyParam)
for i := 0; i < l; i++ {
proxyParam[i] = rawProxyParam[l-i-1]
}

return proxyParam, nil
}
Expand Down Expand Up @@ -116,9 +120,3 @@ func scalarMult(dst, scalar, point *[32]byte) {
x2.Multiply(&x2, &z2)
copy(dst[:], x2.Bytes())
}

func reverse(in []byte) {
for i, j := 0, len(in)-1; i < j; i, j = i+1, j-1 {
in[i], in[j] = in[j], in[i]
}
}

0 comments on commit bb8710b

Please sign in to comment.