前提
PythonのOCSPライブラリを使って、OCSPレスポンダを作ろうとしております。
バイト列から OCSP Requestに変換する関数、ocsp.load_der_ocsp_request()が出すエラーメッセージに悩んでおります。
ぜひ、お力を貸していただきたく存じます。
Pythonのライブラリ
https://cryptography.io/en/latest/x509/ocsp/
ocsp.load_der_ocsp_request()のソースコード
https://github.com/pyca/cryptography/blob/0f2d8303383aa0ec1717ea20685b5d158248df8a/src/rust/src/x509/ocsp_req.rs#L21
実現したいこと
エラーを解決する
発生している問題・エラーメッセージ
error parsing asn1 value: ParseError { kind: UnexpectedTag { actual: Tag { value: 13, constructed: false, class: Application } } }
該当のソースコード
サーバー側 エラーを吐くコード
Python3.9
1 try: 2 print(request.get_data()) 3 print(type(request.get_data())) 4 ocsp_req = ocsp.load_der_ocsp_request(request.get_data()) 5 except Exception as e: 6 ###error parsing asn1 value: ParseError { kind: UnexpectedTag { actual: Tag { value: 13, constructed: false, class: Application } } } 7 print(e) 8 return make_response("malformed ocspRequest", 400)
クライアント側 OCSP Requestをバイト列で送っているコード
Python3.9
1 try: 2 cert = load_pem_x509_certificate(pem_cert) 3 issuer = load_pem_x509_certificate(pem_issuer) 4 except Exception as e: 5 exit(e) 6 7 try: 8 builder = ocsp.OCSPRequestBuilder() 9 builder = builder.add_certificate(cert, issuer, SHA256()) 10 req = builder.build() 11 print(req) 12 req_data = base64.b64encode(req.public_bytes(serialization.Encoding.DER)) 13 except Exception as e: 14 exit(e) 15 16 headers = { 17 'Content-Type': 'application/ocsp-request' 18 } 19 20 url = 'http://localhost:8000/ocsp' 21 try: 22 r = requests.post(url, data=req_data,headers=headers) 23 print(r.text) 24 except requests.HTTPError as e: 25 print(e.status_code) 26 print(e.text) 27 exit(e)
試したこと
証明書自体に不備があるのかと思い、いくつかの証明書でOCSPRequestのバイト列を作って試してみましたが、どれも結果は同じでした。
補足情報
Name: cryptography
Version: 39.0.0
Summary: cryptography is a package which provides cryptographic recipes and primitives to Python developers.
Home-page: https://github.com/pyca/cryptography

バッドをするには、ログインかつ
こちらの条件を満たす必要があります。