Esempio n. 1
0
File: user.py Progetto: Hexagon/Oden
    def new(self, username, password, email):

        try:
            _user = username
            _pass = password
            _email = email
            _salt = "%s%s" % (_user[1], _email[0])
            _enc_pass = crypt.crypt(_pass, _salt)

        except:
            self.debug = "Data preparation failed ..."
            return False

        _diaspora_handle = _user + "@" + config.pod_domain
        _pod_url = config.pod_url

        # Generate RSA key pair, 4096 bit
        keys = rsa_helper.generate_rsa(4096)
        if keys != None:
            _priv_key = keys[1]
            _pub_key = keys[0]
        else:
            self.debug = "Key generation failed ..."
            return False

        # Construct user document
        user = {
            "username": _user,
            "email": _email,
            "encrypted_password": _enc_pass,
            "password_salt": "",
            "pending_request_ids": [],
            "visible_person_ids": [],
            "visible_post_ids": [],
            "current_sign_in_ip": "",
            "current_sign_in_at": datetime.datetime.utcnow(),
            "last_sign_in_ip": "",
            "last_sign_in_at": datetime.datetime.utcnow(),
            "sign_in_count": 0,
            "serialized_private_key": _priv_key,
            "getting_started": True,
        }

        # Try inserting object
        try:

            self.object_id = self.collection.insert(user)

            # Populate self.data
            self.get_by_id(self.object_id)

            # Force creation of a corresponding people object
            people_obj = people.People().new(self.object_id, _diaspora_handle, _pub_key, _pod_url)
            if people_obj:
                return True
            else:
                # No profile could be created
                # TODO: Delete the newly created user object ( with id - self.object_id )
                self.debug = "People object could not be created ..."
                return False
        except:
            # User could not be created
            self.debug = "Could not insert object in  ..."
            return False
Esempio n. 2
0
File: test.py Progetto: Hexagon/Oden
test_aes                = True
test_salmon             = True
test_new_people         = True
test_new_user           = True
test_new_aspect         = True
test_get_user_by_user   = True
test_get_user_by_id     = True
test_get_people_by_id   = True


# Run selected tests
# ------------------------------------
if test_rsa or test_salmon:
    print "Generating 4096 bit RSA key pair..."
    try:
        res = rsa_helper.generate_rsa(4096)
        if res:
            print " - Success"
            success += 1
        else:
            print " - Fail"
            fail +=1
    except:
        print " - Epic fail"
        fail +=1

if test_rsa or test_salmon:
    print "Encrypting message with public key using rsa_helper..."
    try:
        plain = "Testing encryption"
        cipher = rsa_helper.encrypt(plain,res[0])