-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Consistent secret key from a seed #11
Comments
Or generate a shared secret from the issuer and the account user's public and secret key using Diffie–Hellman key exchange. |
Currently, this implementation is redundant for a simple usage and takes time. Let's implement generating a secret via BLAKE3 hash from a private key file first. |
We got a very useful information on DH key exchange to create a common secret.
$ # Create a publicly agreed parameter to share
$ openssl genpkey -genparam -algorithm DH -out param.pem
$ # Alice creates her public/private key pair
$ openssl genpkey -paramfile param.pem -out alice_priv.pem
$ openssl pkey -in alice_priv.pem -pubout -out alice_pub.pem
$ # Bob creates his public/private key pair
$ openssl genpkey -paramfile param.pem -out bob_priv.pem
$ openssl pkey -in bob_priv.pem -pubout -out bob_pub.pem
$ # Alice and Bob download each other's public key.
$ curl **snip**
$ # Alice generates common secret from her private key and Bob's public key
$ openssl pkeyutl -derive -inkey alice_priv.pem -peerkey bob_pub.pem -out shared_alice_bob.bin
$ base64 shared_alice_bob.bin > shared_alice_bob.txt
$ # Bob generates common secret from his private key and Alice's public key
$ openssl pkeyutl -derive -inkey bob_priv.pem -peerkey alice_pub.pem -out shared_bob_alice.bin
$ base64 shared_bob_alice.bin > shared_bob_alice.txt
$ # At this time, 'shared_alice_bob.txt' and 'shared_bob_alice.txt' are equivalent. |
We decided not implement this. But consider ECDH to generate common secret as a secret key for TOTP. |
JFYI I you want a consistent secret key, just create a byte slice and overwrite the key. totpKey, err := totp.GenerateKey("example.com", "Alice")
if err != nil {
log.Fatal(err)
}
totpKey.Secret = totp.Secret(yourConsistentKey) package main
import (
"fmt"
"log"
"github.com/KEINOS/go-totp/totp"
)
func main() {
// Generate TOTP key (with rand secret)
Issuer := "Example.com"
AccountName := "[email protected]"
myKey, err := totp.GenerateKey(Issuer, AccountName)
if err != nil {
log.Fatal(err)
}
// Ensure the key size
myConstKey := make([]byte, int(myKey.Options.SecretSize))
myConstValue := []byte("foobar")
copy(myConstKey, myConstValue)
// Re-assign consistent value as TOTP secret
myKey.Secret = totp.Secret(myConstKey[:])
// Generate 6 digits passcode (valid for 30 seconds)
passcode, err := myKey.PassCode()
if err != nil {
log.Fatal(err)
}
// Validate the passcode
if myKey.Validate(passcode) {
fmt.Println("Passcode is valid")
}
}
|
Feature request
An option to generate a consistent secret key from a specified
Seed
.Reason
First of all, this feature request is not intended for those who have lost their TOTP secret key.
TOTP may have greater potential than simply being used for 2FA.
Current workaround
Overwrite the secret after generation.
Ideas to implement
The text was updated successfully, but these errors were encountered: