Skip to content
Snippets Groups Projects
Unverified Commit c4b0c12d authored by Ben Adida's avatar Ben Adida Committed by GitHub
Browse files

Merge pull request #216 from McCio/mccio/minor-changes

Various minor changes
parents 151d2fdb 388891c9
No related branches found
No related tags found
No related merge requests found
......@@ -7,3 +7,4 @@ venv
celerybeat-*
env.sh
.cache
.idea/
\ No newline at end of file
"""
Crypto Utils
"""
import hashlib
import hmac, base64, json
from hashlib import sha256
......@@ -21,3 +21,11 @@ def to_json(d):
def from_json(json_str):
if not json_str: return None
return json.loads(json_str)
def do_hmac(k,s):
"""
HMAC a value with a key, hex output
"""
mac = hmac.new(k, s, hashlib.sha1)
return mac.hexdigest()
\ No newline at end of file
# -*- coding: utf-8 -*-
from django.conf.urls import *
from django.conf import settings
from django.conf.urls import patterns, include
from views import *
urlpatterns = None
urlpatterns = patterns('',
(r'^autologin$', admin_autologin),
(r'^testcookie$', test_cookie),
......
......@@ -5,9 +5,7 @@ Ben Adida - ben@adida.net
2005-04-11
"""
import urllib, re, sys, datetime, urlparse, string
import boto.ses
import urllib, re, datetime, string
# utils from helios_auth, too
from helios_auth.utils import *
......@@ -15,14 +13,6 @@ from helios_auth.utils import *
from django.conf import settings
import random, logging
import hashlib, hmac, base64
def do_hmac(k,s):
"""
HMAC a value with a key, hex output
"""
mac = hmac.new(k, s, hashlib.sha1)
return mac.hexdigest()
def split_by_length(str, length, rejoin_with=None):
......@@ -167,7 +157,7 @@ def one_val_raw_sql(raw_sql, values=[]):
"""
for a simple aggregate
"""
from django.db import connection, transaction
from django.db import connection
cursor = connection.cursor()
cursor.execute(raw_sql, values)
......
......@@ -6,41 +6,41 @@ Ben Adida (ben@adida.net)
"""
from django.core.urlresolvers import reverse
from django.core.mail import send_mail
from django.core.paginator import Paginator
from django.core.exceptions import PermissionDenied
from django.http import *
from django.http import HttpResponse, Http404, HttpResponseRedirect, HttpResponseForbidden
from django.db import transaction, IntegrityError
from mimetypes import guess_type
from validate_email import validate_email
import csv, urllib, os, base64
import urllib, os, base64
from crypto import algs, electionalgs, elgamal
from crypto import utils as cryptoutils
from workflows import homomorphic
from helios import utils as helios_utils
from view_utils import *
from helios import utils, VOTERS_EMAIL, VOTERS_UPLOAD
from view_utils import SUCCESS, FAILURE, return_json, render_template, render_template_raw
from helios_auth.security import *
from helios_auth.security import check_csrf, login_required, get_user, save_in_session_across_logouts
from helios_auth.auth_systems import AUTH_SYSTEMS, can_list_categories
from helios_auth.models import AuthenticationExpired
from helios import security
from helios_auth import views as auth_views
import tasks
from security import *
from helios_auth.security import get_user, save_in_session_across_logouts
from security import (election_view, election_admin,
trustee_check, set_logged_in_trustee,
can_create_election, user_can_see_election, get_voter,
user_can_admin_election, user_can_feature_election)
import uuid, datetime
import logging
from models import *
from models import User, Election, CastVote, Voter, VoterFile, Trustee, AuditedBallot
import datatypes
import forms, signals
import forms
# Parameters for everything
ELGAMAL_PARAMS = elgamal.Cryptosystem()
......@@ -196,7 +196,7 @@ def election_new(request):
election_params = dict(election_form.cleaned_data)
# is the short name valid
if helios_utils.urlencode(election_params['short_name']) == election_params['short_name']:
if utils.urlencode(election_params['short_name']) == election_params['short_name']:
election_params['uuid'] = str(uuid.uuid1())
election_params['cast_url'] = settings.SECURE_URL_HOST + reverse(one_election_cast, args=[election_params['uuid']])
......@@ -293,8 +293,8 @@ def election_badge(request, election):
@election_view()
def one_election_view(request, election):
user = get_user(request)
admin_p = security.user_can_admin_election(user, election)
can_feature_p = security.user_can_feature_election(user, election)
admin_p = user_can_admin_election(user, election)
can_feature_p = user_can_feature_election(user, election)
notregistered = False
eligible_p = True
......@@ -383,7 +383,7 @@ def list_trustees(request, election):
def list_trustees_view(request, election):
trustees = Trustee.get_by_election(election)
user = get_user(request)
admin_p = security.user_can_admin_election(user, election)
admin_p = user_can_admin_election(user, election)
return render_template(request, 'list_trustees', {'election': election, 'trustees': trustees, 'admin_p':admin_p})
......@@ -446,7 +446,7 @@ Your trustee dashboard is at
Helios
""" % (election.name, url)
helios_utils.send_email(settings.SERVER_EMAIL, ["%s <%s>" % (trustee.name, trustee.email)], 'your trustee homepage for %s' % election.name, body)
utils.send_email(settings.SERVER_EMAIL, ["%s <%s>" % (trustee.name, trustee.email)], 'your trustee homepage for %s' % election.name, body)
logging.info("URL %s " % url)
return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(list_trustees_view, args = [election.uuid]))
......@@ -471,7 +471,7 @@ def trustee_upload_pk(request, election, trustee):
if not trustee.public_key.verify_sk_proof(trustee.pok, algs.DLog_challenge_generator):
raise Exception("bad pok for this public key")
trustee.public_key_hash = utils.hash_b64(utils.to_json(trustee.public_key.toJSONDict()))
trustee.public_key_hash = cryptoutils.hash_b64(utils.to_json(trustee.public_key.toJSONDict()))
trustee.save()
......@@ -923,7 +923,7 @@ def one_election_set_featured(request, election):
"""
user = get_user(request)
if not security.user_can_feature_election(user, election):
if not user_can_feature_election(user, election):
raise PermissionDenied()
featured_p = bool(int(request.GET['featured_p']))
......@@ -987,7 +987,7 @@ def one_election_copy(request, election):
def one_election_questions(request, election):
questions_json = utils.to_json(election.questions)
user = get_user(request)
admin_p = security.user_can_admin_election(user, election)
admin_p = user_can_admin_election(user, election)
return render_template(request, 'election_questions', {'election': election, 'questions_json' : questions_json, 'admin_p': admin_p})
......@@ -1191,7 +1191,7 @@ def voters_list_pretty(request, election):
order_by = 'alias'
user = get_user(request)
admin_p = security.user_can_admin_election(user, election)
admin_p = user_can_admin_election(user, election)
categories = None
eligibility_category_id = None
......@@ -1224,9 +1224,9 @@ def voters_list_pretty(request, election):
return render_template(request, 'voters_list',
{'election': election, 'voters_page': voters_page,
'voters': voters_page.object_list, 'admin_p': admin_p,
'email_voters': helios.VOTERS_EMAIL,
'email_voters': VOTERS_EMAIL,
'limit': limit, 'total_voters': total_voters,
'upload_p': helios.VOTERS_UPLOAD, 'q' : q,
'upload_p': VOTERS_UPLOAD, 'q' : q,
'voter_files': voter_files,
'categories': categories,
'eligibility_category_id' : eligibility_category_id})
......@@ -1330,7 +1330,7 @@ def voters_upload_cancel(request, election):
@election_admin(frozen=True)
def voters_email(request, election):
if not helios.VOTERS_EMAIL:
if not VOTERS_EMAIL:
return HttpResponseRedirect(settings.SECURE_URL_HOST + reverse(one_election_view, args=[election.uuid]))
TEMPLATES = [
('vote', 'Time to Vote'),
......
......@@ -10,6 +10,7 @@ from functools import update_wrapper
from django.http import HttpResponse, Http404, HttpResponseRedirect
from django.core.exceptions import *
from django.conf import settings
from django.http import HttpResponseNotAllowed
import oauth
......
......@@ -49,12 +49,16 @@ function do_encrypt(message) {
// receive either
// a) an election and an integer position of the question
// that this worker will be used to encrypt
// {'type': 'setup', 'question_num' : 2, 'election' : election_json}
// {'type': 'setup', 'election': election_json}
//
// b) an answer that needs encrypting
// {'type': 'encrypt', 'answer' : answer_json}
// {'type': 'encrypt', 'q_num': 2, 'id': id, 'answer': answer_json}
//
self.onmessage = function(event) {
// dispatch to method
self['do_' + event.data.type](event.data);
if (event.data.type === "setup") {
do_setup(event.data);
} else if (event.data.type === "encrypt") {
do_encrypt(event.data);
}
};
#!/bin/bash
set -e # Exit immediately if a command exits with a non-zero status.
dropdb helios
createdb helios
python manage.py syncdb
......
# -*- coding: utf-8 -*-
from django.conf.urls import *
from django.conf.urls import patterns
from views import *
from views import home, about, docs, faq, privacy
urlpatterns = patterns('',
(r'^$', home),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment