Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_crypto_sign_open(self):
pk, sk = pysodium.crypto_sign_keypair()
signed = pysodium.crypto_sign(b'howdy', sk)
changed = signed[:pysodium.crypto_sign_BYTES] + b'0' + signed[pysodium.crypto_sign_BYTES + 1:]
pysodium.crypto_sign_open(signed, pk)
self.assertRaises(ValueError, pysodium.crypto_sign_open, changed, pk)
def test_crypto_sign_sk_to_pk(self):
pk, sk = pysodium.crypto_sign_keypair()
pk2 = pysodium.crypto_sign_sk_to_pk(sk)
self.assertEqual(pk, pk2)
log.info('updating subrepo')
SubRepo.pull()
log.info('registering new team: %s' % team_name)
team = Team(name=team_name)
if team.exists():
log.fail('team is already registered')
return False
log.info('generating encryption keypair')
crypt_pk, crypt_sk = pysodium.crypto_box_keypair()
log.info('generating signature keypair')
sign_pk, sign_sk = pysodium.crypto_sign_keypair()
team.update({'countries': countries,
'crypt_pk': crypt_pk,
'sign_pk': sign_pk})
team.validate()
team.save()
SubRepo.push(commit_message='Register team %s' % team_name)
log.success('team %s added successfully' % team_name)
write_team_secrets(team.id, crypt_sk, sign_sk)
return True
def getkey(keydir):
datadir = os.path.expanduser(keydir)
try:
with open(datadir+'server-key', 'rb') as fd:
key = fd.read()
return key
except FileNotFoundError:
print("no server key found, generating...")
if not os.path.exists(datadir):
os.mkdir(datadir,0o700)
pk, sk = pysodium.crypto_sign_keypair()
with open(datadir+'server-key','wb') as fd:
os.fchmod(fd.fileno(),0o600)
fd.write(sk)
with open(datadir+'server-key.pub','wb') as fd:
fd.write(pk)
print("please share `%s` with all clients" % (datadir+'server-key.pub'))
return sk
def getkey(datadir):
datadir = os.path.expanduser(datadir)
try:
fd = open(datadir+'key', 'rb')
key = fd.read()
fd.close()
return key
except FileNotFoundError:
if not os.path.exists(datadir):
os.mkdir(datadir,0o700)
pk, sk = pysodium.crypto_sign_keypair()
with open(datadir+'key','wb') as fd:
os.fchmod(fd.fileno(),0o600)
fd.write(sk)
return sk
def create(self):
self.created = datetime.datetime.utcnow()
self.valid = datetime.datetime.utcnow() + datetime.timedelta(days=365)
self.mp, self.ms = nacl.crypto_sign_keypair()
self.sp, self.ss = nacl.crypto_sign_keypair()
self.cp, self.cs = nacl.crypto_box_keypair()
self.save()
def getkey(self):
datadir = os.path.expanduser(self.datadir)
try:
fd = open(datadir+'key', 'rb')
key = fd.read()
fd.close()
return key
except FileNotFoundError:
if not os.path.exists(datadir):
os.mkdir(datadir,0o700)
pk, sk = pysodium.crypto_sign_keypair()
with open(datadir+'key','wb') as fd:
os.fchmod(fd.fileno(),0o600)
fd.write(sk)
return sk