Beispiel #1
0
	def to_kirbi(self):
		filename = '%s@%s_%s' % (self.client.to_string() , self.server.to_string(), hashlib.sha1(self.ticket.to_asn1()).hexdigest()[:8])
		krbcredinfo = {}
		krbcredinfo['key'] = EncryptionKey(self.key.to_asn1())
		krbcredinfo['prealm'] = self.client.realm.to_string()
		krbcredinfo['pname'] = self.client.to_asn1()[0]
		krbcredinfo['flags'] = core.IntegerBitString(self.tktflags).cast(TicketFlags)
		if self.time.authtime != 0: #this parameter is not mandatory, and most of the time not present
			krbcredinfo['authtime'] = datetime.datetime.fromtimestamp(self.time.authtime)
		krbcredinfo['starttime'] = datetime.datetime.fromtimestamp(self.time.starttime)
		krbcredinfo['endtime'] = datetime.datetime.fromtimestamp(self.time.endtime)
		if self.time.renew_till != 0: #this parameter is not mandatory, and sometimes it's not present
			krbcredinfo['renew-till'] = datetime.datetime.fromtimestamp(self.time.authtime)
		krbcredinfo['srealm'] = self.server.realm.to_string()
		krbcredinfo['sname'] = self.server.to_asn1()[0]
		
		enc_krbcred = {}
		enc_krbcred['ticket-info'] = [KrbCredInfo(krbcredinfo)]
		
		krbcred = {}
		krbcred['pvno'] = krb5_pvno
		krbcred['msg-type'] = MESSAGE_TYPE.KRB_CRED.value
		krbcred['tickets'] = [Ticket.load(self.ticket.to_asn1())]
		krbcred['enc-part'] = EncryptedData({'etype': EncryptionType.NULL.value, 'cipher': EncKrbCredPart(enc_krbcred).dump()})
	
	
	
		kirbi = KRBCRED(krbcred)
		return kirbi, filename
Beispiel #2
0
	def from_kirbidir(directory_path):
		"""
		Iterates trough all .kirbi files in a given directory and converts all of them into one CCACHE object
		"""
		cc = CCACHE()
		dir_path = os.path.join(os.path.abspath(directory_path), '*.kirbi')
		for filename in glob.glob(dir_path):
			with open(filename, 'rb') as f:
				kirbidata = f.read()
				kirbi = KRBCRED.load(kirbidata).native
				cc.add_kirbi(kirbi)
		
		return cc
Beispiel #3
0
    def to_asn1(self):
        krbcredinfo = {}
        krbcredinfo['key'] = EncryptionKey({
            'keytype': self.KeyType,
            'keyvalue': self.Key
        })
        krbcredinfo['prealm'] = self.AltTargetDomainName
        krbcredinfo['pname'] = PrincipalName({
            'name-type': self.EClientName_type,
            'name-string': self.EClientName
        })
        krbcredinfo['flags'] = core.IntegerBitString(
            self.TicketFlags).cast(TicketFlags)
        krbcredinfo['starttime'] = self.StartTime
        krbcredinfo['endtime'] = self.EndTime
        krbcredinfo['renew-till'] = self.RenewUntil
        krbcredinfo['srealm'] = self.DomainName
        krbcredinfo['sname'] = PrincipalName({
            'name-type': self.ServiceName_type,
            'name-string': self.ServiceName
        })

        enc_krbcred = {}
        enc_krbcred['ticket-info'] = [KrbCredInfo(krbcredinfo)]

        ticket = {}
        ticket['tkt-vno'] = krb5_pvno
        ticket['realm'] = self.DomainName
        ticket['sname'] = PrincipalName({
            'name-type': NAME_TYPE.SRV_INST.value,
            'name-string': self.ServiceName
        })
        ticket['enc-part'] = EncryptedData({
            'etype': self.TicketEncType,
            'kvno': self.TicketKvno,
            'cipher': self.Ticket
        })

        krbcred = {}
        krbcred['pvno'] = krb5_pvno
        krbcred['msg-type'] = MESSAGE_TYPE.KRB_CRED.value
        krbcred['tickets'] = [Ticket(ticket)]
        krbcred['enc-part'] = EncryptedData({
            'etype':
            EncryptionType.NULL.value,
            'cipher':
            EncKrbCredPart(enc_krbcred).dump()
        })

        return KRBCRED(krbcred)
Beispiel #4
0
	def from_kirbi(kirbidata):
		kirbi = KRBCRED.load(kirbidata).native
		cc = CCACHE()
		cc.add_kirbi(kirbi)		
		return cc