Skip to content

Commit

Permalink
Change key generation usernames
Browse files Browse the repository at this point in the history
  • Loading branch information
wussler committed Jun 3, 2019
1 parent 3bb600c commit 80afbce
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
14 changes: 12 additions & 2 deletions ProposalChanges.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,20 @@ Renamed.
```

### GenerateRSAKeyWithPrimes
No change.
`userName` and `domain` joined in `email`.
Added `name` parameter.
```
(pm *PmCrypto) GenerateRSAKeyWithPrimes(userName, domain, passphrase, keyType string, bits int, prime1, prime2, prime3, prime4 []byte) (string, error):
* (pgp *GopenPGP) GenerateRSAKeyWithPrimes(name, email, passphrase, keyType string, bits int, prime1, prime2, prime3, prime4 []byte) (string, error):
```

### GenerateKey
No change.
`userName` and `domain` joined in `email`.
Added `name` parameter.
```
(pm *PmCrypto) GenerateKey(userName, domain, passphrase, keyType string, bits int) (string, error) :
* (pgp *GopenPGP) GenerateKey(name, email, passphrase, keyType string, bits int) (string, error):
```

### UpdatePrivateKeyPassphrase
No change.
Expand Down
21 changes: 10 additions & 11 deletions crypto/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,16 @@ func (pgp *GopenPGP) IsArmoredKeyExpired(publicKey string) (bool, error) {
}

func (pgp *GopenPGP) generateKey(
userName, domain, passphrase, keyType string,
name, email, passphrase, keyType string,
bits int,
prime1, prime2, prime3, prime4 []byte,
) (string, error) {
if len(userName) <= 0 {
return "", errors.New("invalid user name format")
if len(email) <= 0 {
return "", errors.New("invalid email format")
}
var email = userName

if len(domain) > 0 {
email = email + "@" + domain
if len(name) <= 0 {
return "", errors.New("invalid name format")
}

comments := ""
Expand Down Expand Up @@ -120,7 +119,7 @@ func (pgp *GopenPGP) generateKey(
cfg.RSAPrimes = bigPrimes[:]
}

newEntity, err := openpgp.NewEntity(email, comments, email, cfg)
newEntity, err := openpgp.NewEntity(name, comments, email, cfg)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -154,18 +153,18 @@ func (pgp *GopenPGP) generateKey(

// GenerateRSAKeyWithPrimes generates a RSA key using the given primes.
func (pgp *GopenPGP) GenerateRSAKeyWithPrimes(
userName, domain, passphrase string,
name, email, passphrase string,
bits int,
primeone, primetwo, primethree, primefour []byte,
) (string, error) {
return pgp.generateKey(userName, domain, passphrase, "rsa", bits, primeone, primetwo, primethree, primefour)
return pgp.generateKey(name, email, passphrase, "rsa", bits, primeone, primetwo, primethree, primefour)
}

// GenerateKey generates a key of the given keyType ("rsa" or "x25519").
// If keyType is "rsa", bits is the RSA bitsize of the key.
// If keyType is "x25519" bits is unused.
func (pgp *GopenPGP) GenerateKey(userName, domain, passphrase, keyType string, bits int) (string, error) {
return pgp.generateKey(userName, domain, passphrase, keyType, bits, nil, nil, nil, nil)
func (pgp *GopenPGP) GenerateKey(name, email, passphrase, keyType string, bits int) (string, error) {
return pgp.generateKey(name, email, passphrase, keyType, bits, nil, nil, nil, nil)
}

// UpdatePrivateKeyPassphrase decrypts the given armored privateKey with oldPassphrase,
Expand Down
4 changes: 2 additions & 2 deletions crypto/key_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
"golang.org/x/crypto/rsa"
)

const name = "richard.stallman"
const domain = "protonmail.ch"
const name = "Richard M. Stallman"
const domain = "rms@protonmail.ch"

var passphrase = "I love GNU"
var rsaKey, ecKey, rsaPublicKey, ecPublicKey string
Expand Down

0 comments on commit 80afbce

Please sign in to comment.