-
Notifications
You must be signed in to change notification settings - Fork 22
/
printkeys.py
executable file
·93 lines (78 loc) · 2.66 KB
/
printkeys.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/python
# This file is part of Piper.
#
# Piper is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Piper is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Piper. If not, see <http://www.gnu.org/licenses/>.
#
# Piper Copyright (C) 2013 Christopher Cassano
import Image
import ImageDraw
import ImageFont
import qrcode
import sys
from Adafruit_Thermal import *
import piper as Piper
import random
import sqlite3
#define function to print usage and exit
def printUsageAndExit():
print "Usage: printkeys.py [-r | -f] [numCopies]"
print "Options explained: "
print "\t[-r | -f]\tSelect -r or -f to remember or forget the generated keys, respectively.";
print "\t[numCopies]\tThe number of copies of the paper wallet that you want to print. A value of 1 would print 1 paper wallet, A value of 4 would print 4 identical paper wallets, etc."
sys.exit(0)
#check for proper number of arguments
if len(sys.argv) != 3:
printUsageAndExit()
#check for remember or forget flag
if sys.argv[1] == "-r":
rememberKeys = True
elif sys.argv[1] == "-f":
rememberKeys = False
else:
printUsageAndExit()
#try to parse the number of copies
try:
numCopies = int(sys.argv[2])
except ValueError:
printUsageAndExit()
#make sure the number of copies to print is valid
if numCopies <= 0:
print "The number of copies must be >= 0"
sys.exit(0);
#check on the setting to automatically encrypt the private key
#load settings from DB
con = None
try:
con = sqlite3.connect('/home/pi/Printer/settings.db3')
cur = con.cursor()
cur.execute("SELECT key, value FROM Settings;")
# heatTime, coinType, addrPrefix, encType FROM piper_settings LIMIT 1;")
rows = cur.fetchall()
settings = {}
for row in rows:
settings[row[0]] = row[1]
except sqlite3.Error, e:
print("Error %s:" % e.args[0])
sys.exit(1)
finally:
if con:
con.commit()
con.close()
coinType = settings["cointype"]
pw = ""
if settings["headlessEnc"] == "1" and settings["keyGenType"] != "bip0032":
pw = Piper.getRandPass(int(settings['randomPasswordLength']))
Piper.genAndPrintKeysAndPass(rememberKeys, rememberKeys, numCopies, pw, coinType, rememberKeys)
else:
Piper.genAndPrintKeys(rememberKeys, rememberKeys, numCopies, pw, coinType, rememberKeys, settings["keyGenType"])