def create_tra(service=None, ttl=2400, cert=None): "Create a Access Request Ticket (TRA)" # Base TRA squeleton (Ticket de Requerimiento de Acceso) tra = SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?>' '<loginTicketRequest version="1.0">' '</loginTicketRequest>') tra.add_child('header') # get the source from the certificate subject, ie "CN=empresa, O=dna, C=py" if cert: crt = xmlsec.x509_parse_cert(cert) tra.header.add_child('source', crt.get_subject().as_text()) tra.header.add_child('destination', 'C=py, O=dna, OU=sofia, CN=wsaatest') d = int(time.mktime(datetime.datetime.now().timetuple())) tra.header.add_child('uniqueId', str(d)) date = lambda ts: datetime.datetime.fromtimestamp(ts).isoformat() tra.header.add_child('generationTime', str(date(d - ttl))) tra.header.add_child('expirationTime', str(date(d + ttl))) tra.add_child('service', service) return tra.as_xml()
def create_tra(service=None, ttl=2400, cert=None): "Create a Access Request Ticket (TRA)" # Base TRA squeleton (Ticket de Requerimiento de Acceso) tra = SimpleXMLElement( '<?xml version="1.0" encoding="UTF-8"?>' '<loginTicketRequest version="1.0">' '</loginTicketRequest>') tra.add_child('header') # get the source from the certificate subject, ie "CN=empresa, O=dna, C=py" if cert: crt = xmlsec.x509_parse_cert(cert) tra.header.add_child('source', crt.get_subject().as_text()) tra.header.add_child('destination', 'C=py, O=dna, OU=sofia, CN=wsaatest') d = int(time.mktime(datetime.datetime.now().timetuple())) tra.header.add_child('uniqueId', str(d)) date = lambda ts: datetime.datetime.fromtimestamp(ts).isoformat() tra.header.add_child('generationTime', str(date(d-ttl))) tra.header.add_child('expirationTime', str(date(d+ttl))) tra.add_child('service', service) return tra.as_xml()
def x509(self): if not self._x509: self._x509 = xmlsec.x509_parse_cert(self.cert) return self._x509