Changeset 36f642f for fedd/federation


Ignore:
Timestamp:
Sep 16, 2011 5:26:57 PM (13 years ago)
Author:
Ted Faber <faber@…>
Branches:
compt_changes, info-ops, master
Children:
cbe0570
Parents:
6031c9d
Message:

Save split keys in abac_authorizers fixes #12

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fedd/federation/authorizer.py

    r6031c9d r36f642f  
    213213        self.me = me
    214214        self.save_dir = load or save
     215        self.local_files = False
    215216        if self.save_dir:
    216217            self.save_dir = os.path.abspath(self.save_dir)
     
    228229
    229230                self.key, self.me = abac_split_cert(self.me, keyfile, certfile)
     231                self.local_files = True
    230232            else:
    231233                raise abac_authorizer.bad_cert_error("Combination " + \
     
    444446        return rv
    445447
     448    def copy_file(self, src, dest, mode=0600):
     449        '''
     450        Copy src to dest with file mode mode.  May raise exceptions on file ops
     451        '''
     452        d = open(dest, 'w')
     453        s = open(src, 'r')
     454        d.write(s.read())
     455        s.close()
     456        d.close()
     457        os.chmod(dest, mode)
     458
     459
     460
    446461    def save(self, dir=None):
    447462        self.lock.acquire()
     
    457472                os.mkdir(dir)
    458473
     474            # if self.key and self.me were split, copy the split files into the
     475            # new directory.
     476            if self.local_files:
     477                self.copy_file(self.key, '%s/key.pem' % dir)
     478                self.copy_file(self.me, '%s/cert.pem' % dir)
     479                # Point the key and me members to the new locations for
     480                # pickling
     481                hold_key = self.key
     482                hold_me = self.me
     483                self.key = '%s/key.pem' % dir
     484                self.me = '%s/cert.pem' % dir
     485
    459486            f = open("%s/state" % dir, "w")
    460487            pickle.dump(self, f)
    461488            f.close()
     489
     490            if self.local_files:
     491                self.key = hold_key
     492                self.me = hold_me
    462493
    463494            if not os.access("%s/certs" %dir, os.F_OK):
Note: See TracChangeset for help on using the changeset viewer.