Commit 018f6172 authored by hark's avatar hark
Browse files
parents
#!/usr/bin/python
GLADE_DIR = './glade'
__appname__ = 'tails-group-installer'
__version__ = '0.1.1'
\ No newline at end of file
'''
Created on 15/06/2015
@author: noid
'''
import subprocess
import logging
class CloneTools(object):
'''
classdocs
'''
def __init__(self):
'''
Constructor
'''
pass
def clone_tails(self):
proc = subprocess.Popen(
[
"liveusb-creator", "-u", "-n",
"--clone", "-P", "-m", "-x"
],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
logging.debug("subprocess clone open")
out, err = proc.communicate()
logging.debug("out: "+out)
logging.debug("err: "+err)
\ No newline at end of file
'''
Created on 19/06/2015
@author: noid
'''
ROOT_PASSWORD = "1234"
PASSPHRASE_LENGTH_REQUIRED = 5
'''
Created on 22/06/2015
@author: noid
'''
class DsaTools(object):
'''
Tools for create DSA Keys related to Pidgin OTR
'''
def __init__(self):
'''
Constructor
'''
def gen_param(self, user):
'''
openssl genpkey -genparam -algorithm DSA out tfctestdsap.pem -pkeyopt dsa_paramgen_bits: 1024
'''
pass
def gen_key_text(self, user, params):
'''
Generates key with params created with gen_param
openssl genpkey -paramfile tfctestdsap.pem out tfctestdsak.pem -text
'''
pass
def get_fingerprint(self,user):
'''
ssh-keygen -l -f testsshkeygen.pub
'''
pass
\ No newline at end of file
'''
Created on 22/06/2015
@author: noid
'''
import tailsgroupinstaller
import os
from gi.repository import Gtk
class GoodbyeWindow(object):
'''
Window to say goodbye to users and close application
'''
def __init__(self, groupinstaller):
'''
Constructor
'''
self.groupinstaller = groupinstaller
builder = Gtk.Builder()
builder.add_from_file(os.path.join(tailsgroupinstaller.GLADE_DIR, "goodbye.glade"))
builder.connect_signals(self)
self.window = builder.get_object("goodbye")
self.window.move(500,100)
self.window.resize(500,600)
def delete_event(self, *args):
Gtk.main_quit(*args)
\ No newline at end of file
'''
Created on 15/06/2015
@author: noid
'''
import threading
import gnupg
import tailsgroupinstaller
class GpgThread(threading.Thread):
'''
classdocs
'''
def run(self, groupinstaller, user):
self.groupinstaller = groupinstaller
self.user = user
gpg = gnupg.GPG(gnupghome=user.user_alias)
user_data = {'name_real' : user.user_alias,
'name_email' : user.account,
'expire_date' : 0,
'key_type' : 'RSA',
'key_length' : 4096,
'subkey_type' : 'RSA',
'subkey_length' : 4096,
'subkey_usage' : 'encrypt,sign,auth',
'passphrase' : user.password
}
batch_data = gpg.gen_key_input(**user_data)
user.gpg_key = gpg.gen_key(batch_data)
user.keyid = gpg.list_keys()[0]['keyid']
user.pub_key_armored = gpg.export_keys(user.keyid)
'''
Constructor
'''
terminate = False
twitter_username = None
twitter_text = ''
def set_buffer(self, buffer):
self.buffer = buffer
def run(self):
while(not self.terminate):
api = twitter.Api()
self.twitter_text = ''
if self.twitter_username != None:
try:
for status in api.GetUserTimeline(self.twitter_username):
self.twitter_text += status.text + "\n"
except:
pass
Gdk.threads_enter()
self.buffer.set_text(self.twitter_text)
Gdk.threads_leave()
time.sleep(5)
\ No newline at end of file
'''
Created on 15/06/2015
@author: noid
'''
import tailsgroupinstaller
from tailsgroupinstaller import user
import gnupg
import threading
import shutil
import os
import subprocess
import logging
class GpgTools(object):
'''
classdocs
'''
def __init__(self):
'''
Constructor
'''
pass
def create_gpg_batch(self,user):
gpg = gnupg.GPG(gnupghome=user.path_home+"/.gnupg")
user_data = {'name_real' : user.name,
'name_email' : user.account,
'expire_date' : 0,
'key_type' : 'RSA',
'key_length' : 4096,
'subkey_type' : 'RSA',
'subkey_length' : 4096,
'subkey_usage' : 'encrypt,sign,auth',
'passphrase' : user.passphrase
}
batch_data = gpg.gen_key_input(**user_data)
return batch_data
def create_gpg_keys(self,user):
""" Create gpg_keys openning a thread in order to not block applicacion.
"""
self.user = user
self.create_gpg_profile(user)
def create_gpg_group_pubring(self, users):
"""
Modify users gpg pubring and trust keys
"""
# Import pubkeys to pubring already existent in Tails
gpg = gnupg.GPG(gnupghome='/home/amnesia/.gnupg')
for user in users:
gpg.import_keys(user.pub_key_armored)
logging.debug("Group pubring created")
def create_gpg_profile(self, user):
"""
Create gpg keyring for user
"""
#self.groupinstaller.userwindow.window.infoprofiles_label.set_label("Testing label")
self.user = user
gpg = gnupg.GPG(gnupghome=user.path_home+"/gnupg", verbose=True)
logging.debug('Imported gnupg')
batch_data = self.create_gpg_batch(user)
logging.debug('Created batch data')
user.gpg_key = gpg.gen_key(batch_data)
user.keyid = gpg.list_keys()[0]['keyid']
logging.debug("User keyid: "+user.keyid)
user.pub_key_armored = gpg.export_keys(user.keyid)
user.fingerprint = gpg.list_keys()[0]['fingerprint']
logging.debug(user.fingerprint)
logging.debug(user.name+" gpg profile created")
def create_trustdb(self,users):
with open('/home/amnesia/.gnupg/ownertrust.txt', 'w') as f:
for user in users:
f.write(user.fingerprint+":6:\n")
os.remove("/home/amnesia/.gnupg/trustdb.gpg")
proc = subprocess.Popen(
[
"gpg", "--import-ownertrust",
"/home/amnesia/.gnupg/ownertrust.txt"
]
)
\ No newline at end of file
'''
Created on 15/06/2015
@author: noid
'''
import tailsgroupinstaller
from tailsgroupinstaller import user
import subprocess
import os
class GpgTools2(object):
'''
classdocs
'''
def __init__(self):
'''
Constructor
'''
def create_batch_file(self,user):
self.user = user
sti ="Key-Type: RSA\n"
sti = sti + "Key-Length:4096\n"
#sti = sti + "Key-Length: "+str(bits)+"\n"
sti = sti + "Passphrase: "+self.user.password+"\n"
sti = sti + "Expire-Date: 0\n"
sti = sti + "Subkey-Length: 4096\n"
sti = sti + "Subkey-Type: RSA\n"
sti = sti + "Name-Real: "+self.user.name+"\n"
sti = sti + "Name-Email: "+self.user.account+"\n"
sti = sti + "%pubring "+self.user.name+"_pubring\n"
sti = sti + "%secring "+self.user.name+"_secring\n"
sti = sti + "%commit\n"
sti = sti + "%save\n"
sti = sti + "%echo done\n"
sti = sti + "\031\n\032\n"
batch=open(user.name,"w")
batch.write(sti)
batch.close()
pass
def create_gpg_keys(self,user):
self.user = user
self.create_batch_file(user)
path = "/home/noid/workspace/tails-group-installer/"
batch = path+self.user.name
print batch
cmd = [
"gpg --homedir ",
path,
"--batch",
"--gen-key",
batch
]
print cmd
p = subprocess.Popen(cmd,shell=True,stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
def create_trustdb(self):
pass
def create_pubring(self):
pass
def create_gpg_group_pubring(self, users):
pass
def create_gpg_subprocess(self, user):
self.user = user
cmd = "gpg --batch --gen-key --yes"
sti ="Key-Type: RSA\n"
sti = sti + "Key-Length:4096\n"
#sti = sti + "Key-Length: "+str(bits)+"\n"
sti = sti + "Passphrase: "+self.user.password+"\n"
sti = sti + "Expire-Date: 0\n"
sti = sti + "Subkey-Length: 4096\n"
sti = sti + "Subkey-Type: RSA\n"
sti = sti + "Name-Real: "+self.user.name+"\n"
sti = sti + "Name-Email: "+self.user.account+"\n"
sti = sti + "%commit\n"
sti = sti + "%save\n"
sti = sti + "%echo done\n"
sti = sti + "\031\n\032\n"
p = subprocess.Popen(cmd,shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE)
p.stdin.write(sti)
p.stdin.close() #Whi pgp don't create a key in debian?
return p.wait()
\ No newline at end of file
'''
Created on 15/06/2015
@author: noid
'''
import string
import random
import os
import shutil
import fileinput
import re
import logging
class IcedoveTools(object):
'''
classdocs
'''
def __init__(self):
'''
Constructor
'''
self.icedove_profile = "defaults/icedove_profile"
pass
def create_icedove_folders(self, _users):
for user in _users:
self.create_icedove_folder(user)
def create_icedove_folder(self,user):
self.user = user
logging.info("Start creation of icedove folder for user: "+self.user.name)
self.create_profile_folder(user)
logging.info("profile folder created")
self.create_ini_file(user)
logging.info("ini file created")
self.modify_prefs(user)
logging.info("prefs modified")
def create_profile_folder(self,user):
shutil.copytree(self.icedove_profile, user.path_home + "/dotfiles/.icedove/"
+ user.icedove_folder_name)
def create_ini_file(self,user):
f = open(user.path_home + "/dotfiles/.icedove/profiles.ini","w")
t = """[General]
StartWithLastProfile=1
[Profile0]
Name=default
IsRelative=1
Path="""+user.icedove_folder_name+"\n"
f.write(t)
f.close()
def modify_prefs2(self,user):
self.replacements = {"riseup_mail_account":user.account.split("@")[0],
"icedove_folder_name":user.icedove_folder_name
}
prefs = user.path_home + "/dotfiles/.icedove/" + user.icedove_folder_name + "/prefs.js"
lines = []
with open(prefs) as infile:
for line in infile:
for src, target in self.replacements.iteritems():
line = line.replace(src,target)
lines.append(line)
with open(prefs,"w") as outfile:
for line in lines:
outfile.write(line)
def modify_prefs(self,user):
prefs = user.path_home + "/dotfiles/.icedove/" + user.icedove_folder_name + "/prefs.js"
for line in fileinput.input(prefs,1):
print line.replace("riseup_mail_account",user.account.split("@")[0]),
for line in fileinput.input(prefs,1):
print line.replace("icedove_folder_name",user.icedove_folder_name)
'''
Created on 16/06/2015
@author: noid
'''
import tailsgroupinstaller
import os
from gi.repository import Gtk
from time import sleep
import logging
from tailsgroupinstaller.goodbyewindow import GoodbyeWindow
class PersistCloneWindow(object):
'''
classdocs
'''
def __init__(self, groupinstaller):
'''
Constructor
'''
self.groupinstaller = groupinstaller
builder = Gtk.Builder()
builder.add_from_file(os.path.join(tailsgroupinstaller.GLADE_DIR, "persistclone.glade"))
builder.connect_signals(self)
self.window = builder.get_object("persistclone")
self.window.move(500,100)
self.window.btn_clone = builder.get_object("btn_clone")
self.window.btn_persistence = builder.get_object("btn_persistence")
self.window.btn_configure_accounts = builder.get_object("btn_configure_accounts")
self.window.clonebox = builder.get_object("clonebox")
self.window.persistencebox = builder.get_object("persistencebox")
self.window.configureaccountsbox = builder.get_object("configureaccountsbox")
self.window.profiles_created_ok_dialog = builder.get_object("profiles_created_ok_dialog")
self.afterclone_dialog = builder.get_object("afterclone_dialog")
self.afterpersistence_dialog = builder.get_object("afterpersistence_dialog")
self.window.user_label = builder.get_object("user_label")
self.window.creatingusb_label = builder.get_object("creatingusb_label")
self.last_user = False
self.nusers = self.groupinstaller.nusers
self.window.persistencebox.set_sensitive(False)
self.window.configureaccountsbox.set_sensitive(False)
self.actual_user = 0
self.load_user()
def delete_event(self, *args):
Gtk.main_quit(*args)
def load_user(self):
self.window.creatingusb_label.set_label("Creating device "+str((self.actual_user+1))+" of "
+ str(int(self.nusers)))
self.user = self.groupinstaller._users[self.actual_user]
self.window.user_label.set_label("User: "+self.user.name)
self.window.clonebox.set_sensitive(True)
self.window.btn_clone.set_sensitive(True)
self.window.persistencebox.set_sensitive(False)
self.window.configureaccountsbox.set_sensitive(False)
def btn_clone_clicked(self,widget):
#self.afterclone_dialog.show()
self.window.btn_clone.set_sensitive(False)
self.groupinstaller.clonetools.clone_tails()
self.window.persistencebox.set_sensitive(True)
self.window.btn_persistence.set_sensitive(True)
def btn_persistence_clicked(self,widget):
#self.afterpersistence_dialog.show()
self.window.btn_persistence.set_sensitive(False)
self.groupinstaller.persistencetools.create_partition()
self.window.configureaccountsbox.set_sensitive(True)
self.window.btn_configure_accounts.set_sensitive(True)
def btn_configure_accounts_clicked(self,widget):
self.actual_user +=1
self.window.btn_configure_accounts.set_sensitive(False)
self.groupinstaller.persistencetools.configure_partition(self.user)
if self.actual_user != self.groupinstaller.nusers:
self.load_user()
else:
logging.debug("Users completed")
self.groupinstaller.goodbyewindow = GoodbyeWindow(self.groupinstaller)
self.groupinstaller.persistclonewindow.window.hide()
self.groupinstaller.goodbyewindow.window.show()
pass
def profiles_created_ok_dialog_btn_clicked(self,widget):
self.window.profiles_created_ok_dialog.hide()
\ No newline at end of file
'''
Created on 15/06/2015
@author: noid
'''
import subprocess
import os,shutil