第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何使用 Python 解碼“X-ARR-ClientCert”標(biāo)頭?

如何使用 Python 解碼“X-ARR-ClientCert”標(biāo)頭?

夢(mèng)里花落0921 2023-10-31 14:17:49
如何解碼X-ARR-ClientCertAzure 應(yīng)用服務(wù)傳遞到我的 Azure Function 代碼的標(biāo)頭?例子:HTTP 觸發(fā)的 Python Azure FunctionAzure 應(yīng)用服務(wù)配置為接受客戶端證書請(qǐng)求者通過 GET 請(qǐng)求發(fā)送客戶端證書(按照此處的 Postman 說明)X-ARR-ClientCertAzure 應(yīng)用服務(wù)通過標(biāo)頭將客戶端證書傳遞給函數(shù)代碼問題:我找不到有關(guān)如何編碼此標(biāo)頭的文檔我找不到如何使用 Python 解碼此標(biāo)頭的示例我得到的最接近的是這段代碼:import loggingimport base64import azure.functions as funcdef main(req: func.HttpRequest) -> func.HttpResponse:        logging.info('####### Python HTTP trigger certificate validation function processing a request. #######')    # Retrieve client cert from headers    req_cert_str = req.headers.get("X-ARR-ClientCert")        req_cert_bytes = base64.b64decode(req_cert_str)        decoded_string = req_cert_bytes.decode('cp1252')    return func.HttpResponse(        decoded_string    )結(jié)果是Status 500 Internal server error:Exception while executing function: Functions.certiFunc <--- Result: Failure Exception: UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 403: character maps to <undefined> Stack: File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 343, in _handle__invocation_request call_result = await self._loop.run_in_executor( File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run result = self.fn(*self.args, **self.kwargs) File "/azure-functions-host/workers/python/3.8/LINUX/X64/azure_functions_worker/dispatcher.py", line 480, in __run_sync_func return func(**params) File "/home/site/wwwroot/certiFunc/__init__.py", line 14, in main decoded_string = req_cert_bytes.decode('cp1252') File "/usr/local/lib/python3.8/encodings/cp1252.py", line 15, in decode return codecs.charmap_decode(input,errors,decoding_table) 當(dāng)替換 時(shí)decoded_string = req_cert_bytes.decode('utf-8'),我得到:運(yùn)行以下命令時(shí)(直接解碼標(biāo)頭)...req_cert_str = req.headers.get("X-ARR-ClientCert")decoded_string = base64.b64decode(req_cert_str) ...我得到一個(gè)Status 200 Success,但響應(yīng)是二進(jìn)制(?)字符和純文本的混搭:
查看完整描述

1 回答

?
犯罪嫌疑人X

TA貢獻(xiàn)2080條經(jīng)驗(yàn) 獲得超4個(gè)贊

由于您要從 Postman 添加客戶端證書,因此它采用 DER(二進(jìn)制)格式。您可以使用 Python加密技術(shù)從字節(jié)本身解碼 x509 證書。


from cryptography import x509


# header is base64 encoded string, so extract the bytes first

req_cert_str = req.headers.get("X-ARR-ClientCert")?

req_cert_bytes = base64.b64decode(req_cert_str)


cert = x509.load_der_x509_certificate(req_cert_bytes)


# do stuffs with cert

logging.info(f'Received client cert with serial number: {cert.serial_number}')


查看完整回答
反對(duì) 回復(fù) 2023-10-31
  • 1 回答
  • 0 關(guān)注
  • 142 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)