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_box_open_afternm(self):
m = b"howdy"
pk, sk = pysodium.crypto_box_keypair()
k = pysodium.crypto_box_beforenm(pk, sk)
n = pysodium.randombytes(pysodium.crypto_box_NONCEBYTES)
c = pysodium.crypto_box_afternm(m, n, k)
self.assertEqual(c, c)
plaintext = pysodium.crypto_box_open_afternm(c, n, k)
self.assertEqual(m, plaintext)
def initialize():
"""
Create a ~/.zkm directory with a config file inside.
The config file will hold our public key, secret key, and since value.
"""
if os.path.exists(ZKMDIR) is False:
print('[+] Creating ZKM configuration directory.')
os.mkdir(ZKMDIR, 0o750)
print('[+] Creating new keypair.')
our_public, our_secret = pysodium.crypto_box_keypair()
print('[+] Creating configuration file.')
config = {b'public': base64.b64encode(our_public),
b'secret': base64.b64encode(our_secret),
b'since': b'1',
b'channel': b'default'}
save_data(CONFIG, config)
os.chmod(CONFIG, 0o600)
print('[+] Creating contacts file.')
save_data(CONTACT, {})
os.chmod(CONTACT, 0o600)
else:
print('[-] ZKM configuration directory already exists.')
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 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 register(team_name, countries):
team_name = to_unicode(team_name)
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