Exemplo n.º 1
0
    def run(self, intr, kap_path):
        client_conf = intr.client_conf

        if not intr.client_conf:
            sys.stderr.write("No client selected.\n")
            return 1

        # Check if the client license has been set.
        if not intr.client_conf.lim_seats or not intr.client_conf.max_seats:
            input_license_info(intr)

        # Prepare the client upgrade KAP.
        try:
            kap_data = intr.client_conf.new_upgrade_kap()

            if kap_data:
                print "The following data will be generated and encrypted:"
                print KAP.show_KAP(kap_data)

                if get_confirm("Do you want to save this KAP?", intr.assume_answer):
                    kap_id = intr.client_conf.save_kap(kap_data)
                    intr.client_conf.encrypt_kap(kap_id, kap_path)
                    print "Saved and encrypted KAP %s to %s" % (kap_id, kap_path)

            return 0

        except Exception, e:
            if intr.debug: raise
            else: raise Exception("cannot generate KAP: %s" % str(e))
Exemplo n.º 2
0
    def run(self, intr, kap_path):
        if intr.client_conf == None:
            sys.stderr.write("No client selected.\n"); return 1
        if not intr.client_conf.kar_open:
            sys.stderr.write("The KAR has not been opened.\n"); return 1
        if not intr.client_conf.kar_verified:
            sys.stderr.write("The KAR has not been verified.\n"); return 1
        if not intr.client_conf.best_before or not intr.client_conf.best_after:
            sys.stderr.write("The license validity dates have not been set.\n"); return 1
        if not intr.client_conf.lim_seats or not intr.client_conf.max_seats:
            sys.stderr.write("The license seats counts have not been set.\n"); return 1

        try:
            kap_data = intr.client_conf.new_license_kap()

            if kap_data:
                print "The following data will be generated and encrypted:"
                print KAP.show_KAP(kap_data)

                if get_confirm("Do you want to save this KAP?", intr.assume_answer):
                    kap_id = intr.client_conf.save_kap(kap_data)
                    intr.client_conf.encrypt_kap(kap_id, kap_path)
                    print "Saved and encrypted KAP %s to %s" % (kap_id, kap_path)

            return 0

        except Exception, e:
            if intr.debug: raise
            else: raise Exception("cannot generate license KAP: %s" % str(e))
Exemplo n.º 3
0
 def encrypt(self, kap_id, enc_kap_path, sig_key):
     """Encrypt a KAP for the client and signs it with a key."""
     kdata = self.get(kap_id)
     if not kdata:
         raise Exception("KAP %s doesn't exists" % kap_id)
     KAP.write_KAP(kdata, enc_kap_path,
                   do_encrypt = True,
                   teambox_email_skey = sig_key,
                   encrypt_pkey = self.client_conf.get_enc_pkey().key_path)
Exemplo n.º 4
0
 def get(self, kap_id):
     """Return store KAP data."""
     kf = os.path.join(self._kap_dir, kap_id) + ".tar.gz"
     if os.path.exists(kf):
         return KAP.read_KAP(kf)
     else:
         return None
Exemplo n.º 5
0
 def add(self, kdata):
     """Add a KAP to the client configuration."""
     # Get an unique name for the KAP file.
     s = time.strftime("%Y%m%d")
     kn = ""
     kp = ""
     d = 1
     while True:
         kn = "kap_%s_%s_%d" % (kdata.kap_type, s, d)
         kp = os.path.join(self._kap_dir, kn) + ".tar.gz"
         if not os.path.exists(kp):
             break
         else:
             d = d + 1
     # Write the raw KAP.
     KAP.write_KAP(kdata, kp, do_encrypt = False)
     return kn
Exemplo n.º 6
0
    def run(self, intr, kap_id):
        if intr.client_conf == None:
            sys.stderr.write("No client selected.\n"); return 1
        if not intr.client_conf.KapManager.exists(kap_id):
            sys.stderr.write("KAP %s doesn't exists for this client.\n" % kap_id); return 1

        kap_data = intr.client_conf.KapManager.get(kap_id)
        sys.stdout.write(KAP.show_KAP(kap_data))
        return 0
Exemplo n.º 7
0
    def run(self, intr, kap_id, kap_path):
        if intr.client_conf == None:
            sys.stderr.write("No client selected.\n"); return 1
        if not intr.client_conf.KapManager.exists(kap_id):
            sys.stderr.write("KAP %s doesn't exists for this client.\n" % kap_id); return 1

        try:
            kap_data = intr.client_conf.KapManager.get(kap_id)

            if kap_data:
                if not intr.assume_answer:
                    sys.stdout.write("The following data will be encrypted:")
                    sys.stdout.write(KAP.show_KAP(kap_data))

                if get_confirm("Do you want to save this KAP?", intr.assume_answer):
                    intr.client_conf.encrypt_kap(kap_id, kap_path)
                    sys.stdout.write("Saved KAP %s to %s" % (kap_id, kap_path))
            return 0

        except Exception, e:
            if intr.debug: raise
            else: raise Exception("Cannot encrypt KAP: %s" % str(e))