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