Skip to content

Commit

Permalink
Fixes issue#2371. Added retry logic if generated keys startswith -
Browse files Browse the repository at this point in the history
  • Loading branch information
shwethanidd committed Aug 6, 2020
1 parent 255be58 commit ea7bb0c
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions volttron/platform/keystore.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,24 @@ def get_agent_keystore_path(identity=None):
def generate_keypair_dict():
"""Generate and return new keypair as dictionary"""
public, secret = curve_keypair()
return {'public': encode_key(public),
'secret': encode_key(secret)}
encoded_public = encode_key(public)
encoded_secret = encode_key(secret)
attempts = 0
max_attempts = 3

done = False
while not done and attempts < max_attempts:
# Keys that start with '-' are hard to use and cause issues with the platform
if encoded_secret.startswith('-') or encoded_public.startswith('-'):
# try generating public and secret key again
public, secret = curve_keypair()
encoded_public = encode_key(public)
encoded_secret = encode_key(secret)
else:
done = True

return {'public': encoded_public,
'secret': encoded_secret}

def generate(self):
"""Generate and store new key pair"""
Expand Down

0 comments on commit ea7bb0c

Please sign in to comment.