def _send_signed_request(url, payload, hostname, nonce, headers={'Content-Type': 'application/json'}): info = db.recallHost(hostname) priv=OpenSSL.crypto.load_privatekey(OpenSSL.crypto.FILETYPE_PEM, base64.b64decode(info['acct_privkey'])) key=serialization.load_pem_private_key(base64.b64decode(info['acct_privkey']), password=None, backend=default_backend()) header = { "alg": "RS256", "jwk": jose.JWKRSA(key=jose.ComparableRSAKey(key.public_key())).to_partial_json(), } payload64 = _b64(json.dumps(payload).encode('utf8')) protected64 = _b64(json.dumps({"nonce":nonce})) signature64 = _b64(OpenSSL.crypto.sign(priv, str(protected64) + '.' + str(payload64), 'sha256')) message=json.dumps({"header":header,"protected":protected64, "payload":payload64, "signature":signature64}) resp = requests.post(url, data=message, headers=headers) return resp
ipaddress = jwt[1]['ipaddr'] hostname = jwt[1]['hostname'] alg = jwt[1]['alg'] secret = jwt[1]['secret'] privkey = jwt[1]['privkey'] #to be used with LE except KeyError, e: return 'KeyError', 400 code, resp=ddns.addDDNSHost(hostname, ipaddress, secret, alg) if code!=0: return resp, 400 code, resp=ddns.updateDDNSHost(hostname,ipaddress,secret) if code!=0: return resp, 400 info = db.recallHost(hostname) if info == None: logger.debug('Host not found in DB. Creating new entry') db.storeKeypair(hostname, privkey, db.generateKeypair()) info = db.recallHost(hostname) if info['reg_json']==None: if not le.Register(info):#201 updateDB return 'Error in LetsEncrypt Registration', 400 info=db.recallHost(hostname) if info['authz_json']==None: authzStatus='' else: authzStatus = json.loads(info['authz_json']).get('body').get('status') or None