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