Beispiel #1
0
    def test_crypto_pwhash_scryptsalsa208sha256_str(self):
        passwd = b'Correct Horse Battery Staple'

        # Use very small limits to avoid burning resources in CI
        mem_limit = 16777216
        ops_limit = 32768

        storage_string = pysodium.crypto_pwhash_scryptsalsa208sha256_str(passwd, ops_limit, mem_limit)
        self.assertTrue(storage_string.startswith(pysodium.crypto_pwhash_scryptsalsa208sha256_STRPREFIX))

        self.assertNotEqual(storage_string, pysodium.crypto_pwhash_scryptsalsa208sha256_str(passwd, ops_limit, mem_limit), "Each call should compute a new random salt.")
Beispiel #2
0
    def test_crypto_pwhash_scryptsalsa208sha256_str(self):
        passwd = b'Correct Horse Battery Staple'

        # Use very small limits to avoid burning resources in CI
        mem_limit = 16777216
        ops_limit = 32768

        storage_string = pysodium.crypto_pwhash_scryptsalsa208sha256_str(passwd, ops_limit, mem_limit)
        self.assertTrue(storage_string.startswith(pysodium.crypto_pwhash_scryptsalsa208sha256_STRPREFIX))

        self.assertNotEqual(storage_string, pysodium.crypto_pwhash_scryptsalsa208sha256_str(passwd, ops_limit, mem_limit), "Each call should compute a new random salt.")
Beispiel #3
0
 def test_crypto_pwhash_salsa208sha256_str(self):
     password = '******'
     pwhash = pysodium.crypto_pwhash_scryptsalsa208sha256_str(password)
     self.assertEqual(
         pysodium.crypto_pwhash_scryptsalsa208sha256_str_verify(
             pwhash, password), None)
     with self.assertRaises(ValueError):
         pysodium.crypto_pwhash_scryptsalsa208sha256_str_verify(
             pwhash, 'wrongpassword')
Beispiel #4
0
    def test_crypto_pwhash_scryptsalsa208sha256_str_verify(self):
        passwd = b'Correct Horse Battery Staple'
        other_passwd = b'correct horse battery staple'
        
        # Use very small limits to avoid burning resources in CI
        mem_limit = 32 * 1024
        ops_limit = 1024

        storage_string = pysodium.crypto_pwhash_scryptsalsa208sha256_str(passwd, ops_limit, mem_limit)

        pysodium.crypto_pwhash_scryptsalsa208sha256_str_verify(storage_string, passwd)

        self.assertRaises(ValueError, pysodium.crypto_pwhash_scryptsalsa208sha256_str_verify, storage_string, other_passwd)
        self.assertRaises(ValueError, pysodium.crypto_pwhash_scryptsalsa208sha256_str_verify, storage_string[:-1], passwd)
        self.assertRaises(ValueError, pysodium.crypto_pwhash_scryptsalsa208sha256_str_verify, storage_string + b'a', passwd)
Beispiel #5
0
    def test_crypto_pwhash_scryptsalsa208sha256_str_verify(self):
        passwd = b'Correct Horse Battery Staple'
        other_passwd = b'correct horse battery staple'

        # Use very small limits to avoid burning resources in CI
        mem_limit = 16777216
        ops_limit = 32768

        storage_string = pysodium.crypto_pwhash_scryptsalsa208sha256_str(passwd, ops_limit, mem_limit)

        pysodium.crypto_pwhash_scryptsalsa208sha256_str_verify(storage_string, passwd)

        self.assertRaises(ValueError, pysodium.crypto_pwhash_scryptsalsa208sha256_str_verify, storage_string, other_passwd)
        self.assertRaises(ValueError, pysodium.crypto_pwhash_scryptsalsa208sha256_str_verify, storage_string[:-1], passwd)
        self.assertRaises(ValueError, pysodium.crypto_pwhash_scryptsalsa208sha256_str_verify, storage_string + b'a', passwd)
Beispiel #6
0
def main():
    parser = argparse.ArgumentParser()

    parser.add_argument('-u',
                        '--username',
                        action='store',
                        dest='username',
                        required=True)
    parser.add_argument('-m',
                        '--homedir',
                        action='store',
                        dest='directory',
                        required=True)
    parser.add_argument('-d', '--domain', action='store', dest='domain')
    parser.add_argument('-i',
                        '--inactive',
                        action='store_true',
                        dest='inactive',
                        help='Removes authentication privileges')
    args = parser.parse_args()

    cleartext = randomize_password()
    password = pysodium.crypto_pwhash_scryptsalsa208sha256_str(cleartext, 1, 1)

    if args.inactive is True:
        sql_insert(args.username, password, '0', args.directory)
        print('New FTP/TLS user created without authentication privileges.\n' +
              '%s %s' %
              ('See details for more information:', args.username + '.txt'))
    else:
        sql_insert(args.username, password, '1', args.directory)
        print('New FTP/TLS user created.\n' + '%s %s' %
              ('See details for more information:', args.username + '.txt'))

    if args.domain is not None:
        check_directory(args.directory, args.domain)

    create_file(args.username, cleartext)
Beispiel #7
0
 def test_crypto_pwhash_salsa208sha256_str(self):
     password = '******'
     pwhash = pysodium.crypto_pwhash_scryptsalsa208sha256_str(password)
     self.assertEqual(pysodium.crypto_pwhash_scryptsalsa208sha256_str_verify(pwhash, password), None)
     with self.assertRaises(ValueError):
         pysodium.crypto_pwhash_scryptsalsa208sha256_str_verify(pwhash, 'wrongpassword')