PyFoam.Infrastructure.Authentication module

Simple public key authentication with RSA based on the implementation http://code.activestate.com/recipes/578797-public-key-encryption-rsa/

class PyFoam.Infrastructure.Authentication.Key(exponent, modulus)

Bases: tuple

exponent

Alias for field number 0

modulus

Alias for field number 1

class PyFoam.Infrastructure.Authentication.KeyPair(public, private)

Bases: tuple

private

Alias for field number 1

public

Alias for field number 0

PyFoam.Infrastructure.Authentication.authenticatedKeys()[source]
PyFoam.Infrastructure.Authentication.checkAuthentication(userName, challenge)[source]
PyFoam.Infrastructure.Authentication.checkChallenge(challenge, pubKey)[source]
PyFoam.Infrastructure.Authentication.createChallengeString(msg)[source]
PyFoam.Infrastructure.Authentication.decode(bcipher, privkey, verbose=False)[source]
PyFoam.Infrastructure.Authentication.encode(msg, pubkey, verbose=False)[source]
PyFoam.Infrastructure.Authentication.ensureKeyPair()[source]
PyFoam.Infrastructure.Authentication.is_prime(n, k=30)[source]
PyFoam.Infrastructure.Authentication.key_to_str(key)[source]

Convert Key to string representation >>> key_to_str(Key(50476910741469568741791652650587163073, 95419691922573224706255222482923256353)) ‘25f97fd801214cdc163796f8a43289c1:47c92a08bc374e96c7af66eb141d7a21’

PyFoam.Infrastructure.Authentication.keygen(n, public=None)[source]

Generate public and private keys from primes up to N.

Optionally, specify the public key exponent (65537 is popular choice).

>>> pubkey, privkey = keygen(2**64)
>>> msg = 123456789012345
>>> coded = pow(msg, *pubkey)
>>> plain = pow(coded, *privkey)
>>> assert msg == plain
PyFoam.Infrastructure.Authentication.multinv(modulus, value)[source]

Multiplicative inverse in a given modulus

>>> multinv(191, 138)
18
>>> multinv(191, 38)
186
>>> multinv(120, 23)
47
PyFoam.Infrastructure.Authentication.myAuthenticatedKeysFile()[source]
PyFoam.Infrastructure.Authentication.myPrivateKey()[source]
PyFoam.Infrastructure.Authentication.myPrivateKeyFile()[source]
PyFoam.Infrastructure.Authentication.myPublicKey()[source]
PyFoam.Infrastructure.Authentication.myPublicKeyFile()[source]
PyFoam.Infrastructure.Authentication.myPublicKeyText()[source]
PyFoam.Infrastructure.Authentication.randprime(n=100000000)[source]
PyFoam.Infrastructure.Authentication.str_to_key(key_str)[source]

Convert string representation to Key (assuming valid input) >>> (str_to_key(‘25f97fd801214cdc163796f8a43289c1:47c92a08bc374e96c7af66eb141d7a21’) == … Key(exponent=50476910741469568741791652650587163073, modulus=95419691922573224706255222482923256353)) True