1*d83a80eeSchristos#!/usr/bin/env python 2*d83a80eeSchristos# Copyright (c) 2007, Secure64 Software Corporation 3*d83a80eeSchristos# 4*d83a80eeSchristos# Permission is hereby granted, free of charge, to any person obtaining a copy 5*d83a80eeSchristos# of this software and associated documentation files (the "Software"), to deal 6*d83a80eeSchristos# in the Software without restriction, including without limitation the rights 7*d83a80eeSchristos# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8*d83a80eeSchristos# copies of the Software, and to permit persons to whom the Software is 9*d83a80eeSchristos# furnished to do so, subject to the following conditions: 10*d83a80eeSchristos# 11*d83a80eeSchristos# The above copyright notice and this permission notice shall be included in 12*d83a80eeSchristos# all copies or substantial portions of the Software. 13*d83a80eeSchristos# 14*d83a80eeSchristos# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15*d83a80eeSchristos# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16*d83a80eeSchristos# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17*d83a80eeSchristos# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18*d83a80eeSchristos# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19*d83a80eeSchristos# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20*d83a80eeSchristos# THE SOFTWARE. 21*d83a80eeSchristos# 22*d83a80eeSchristos# 23*d83a80eeSchristos# 24*d83a80eeSchristos# encrypt a passwd (very simplistic for now, using GPG or such-like 25*d83a80eeSchristos# key someday) 26*d83a80eeSchristos# 27*d83a80eeSchristos# 28*d83a80eeSchristos 29*d83a80eeSchristos#-- imports 30*d83a80eeSchristosimport os 31*d83a80eeSchristosimport os.path 32*d83a80eeSchristosimport sys 33*d83a80eeSchristosimport getpass 34*d83a80eeSchristosimport sys 35*d83a80eeSchristos 36*d83a80eeSchristosif os.path.exists('../bind2nsd/Config.py'): 37*d83a80eeSchristos sys.path.append('../bind2nsd') 38*d83a80eeSchristos from Config import * 39*d83a80eeSchristoselse: 40*d83a80eeSchristos from bind2nsd.Config import * 41*d83a80eeSchristos 42*d83a80eeSchristosif os.path.exists('../pyDes-1.2'): 43*d83a80eeSchristos sys.path.append('../pyDes-1.2') 44*d83a80eeSchristosimport pyDes 45*d83a80eeSchristos 46*d83a80eeSchristos#-- globals 47*d83a80eeSchristosconf = Config() 48*d83a80eeSchristos 49*d83a80eeSchristos#-- useful functions 50*d83a80eeSchristosdef usage(): 51*d83a80eeSchristos print 's64-mkpw %s, copyright(c) 2007, Secure64 Software Corporation' \ 52*d83a80eeSchristos % (conf.getValue('version')) 53*d83a80eeSchristos print 54*d83a80eeSchristos print 'usage: s64-mkpw' 55*d83a80eeSchristos return 56*d83a80eeSchristos 57*d83a80eeSchristosdef mkprintable(val): 58*d83a80eeSchristos cstr = '' 59*d83a80eeSchristos for ii in range(0, len(val)): 60*d83a80eeSchristos c = val[ii] 61*d83a80eeSchristos cstr += '%d ' % (ord(c)) 62*d83a80eeSchristos return cstr 63*d83a80eeSchristos 64*d83a80eeSchristos 65*d83a80eeSchristos#-- main --------------------------------------------------------------- 66*d83a80eeSchristosdef main(): 67*d83a80eeSchristos if len(sys.argv) > 1: 68*d83a80eeSchristos usage() 69*d83a80eeSchristos sys.exit(1) 70*d83a80eeSchristos 71*d83a80eeSchristos print 's64-mkpw %s, copyright(c) 2007, Secure64 Software Corporation' \ 72*d83a80eeSchristos % (conf.getValue('version')) 73*d83a80eeSchristos syspw = getpass.getpass('sysconfig password: ') 74*d83a80eeSchristos dnspw = getpass.getpass('dnsconfig password: ') 75*d83a80eeSchristos 76*d83a80eeSchristos fd = open(conf.getValue('password_file'), 'w+') 77*d83a80eeSchristos 78*d83a80eeSchristos obj = pyDes.triple_des('aBcDeFgHiJkLmNoP', pyDes.ECB) 79*d83a80eeSchristos fd.write(mkprintable(obj.encrypt(syspw, '#')) + '\n') 80*d83a80eeSchristos fd.write(mkprintable(obj.encrypt(dnspw, '#')) + '\n') 81*d83a80eeSchristos fd.close() 82*d83a80eeSchristos print '=> stored password in "%s"' % (conf.getValue('password_file')) 83*d83a80eeSchristos 84*d83a80eeSchristos return 85*d83a80eeSchristos 86*d83a80eeSchristosif __name__ == '__main__': 87*d83a80eeSchristos main() 88*d83a80eeSchristos 89