Skip to content

Commit

Permalink
Merge pull request #2427 from shwethanidd/issue_2371
Browse files Browse the repository at this point in the history
Fixes issue#2371.
  • Loading branch information
craig8 authored Aug 7, 2020
2 parents 44ac2b5 + ea7bb0c commit 38a3d11
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 38a3d11

Please sign in to comment.