Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add REST endpoints for OCSP responses #62

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion VERSION.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.11
0.10.0
17 changes: 16 additions & 1 deletion pkilint/rest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from fastapi import FastAPI, HTTPException

from pkilint.rest import cabf_serverauth, cabf_smime
from pkilint.rest import cabf_serverauth, cabf_smime, ocsp
from pkilint.rest import model

_PKILINT_VERSION = version('pkilint')
Expand All @@ -20,6 +20,7 @@
cabf_smime.create_linter_group_instance(),
cabf_serverauth.create_linter_group_instance(),
]
_OCSP_PKIX_LINTER = ocsp.create_ocsp_response_linter()


@app.get('/version')
Expand Down Expand Up @@ -94,3 +95,17 @@ def certificate_lint(linter_group_name: str, linter_name: str, doc: model.Certif
parsed_doc = doc.parsed_document

return linter_instance.lint(parsed_doc)

@app.get('/ocsp/pkix')
def ocsp_linter_validations() -> List[model.Validation]:
"""Returns the set of validations performed by the OCSP response linter"""

return _OCSP_PKIX_LINTER.validations

@app.post('/ocsp/pkix')
def ocsp_response_lint(doc: model.OcspResponseModel) -> model.LintResultList:
"""Lints the specified OCSP response"""

parsed_doc = doc.parsed_document

return _OCSP_PKIX_LINTER.lint(parsed_doc)
23 changes: 23 additions & 0 deletions pkilint/rest/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,29 @@ def validate(self) -> 'CertificateModel':
def parsed_document(self):
return self._parsed_document

class OcspResponseModel(DocumentModel):
_parsed_document = None

@model_validator(mode='after')
def validate(self) -> 'OcspResponseModel':
super()._validate()

if self.pem is not None:
try:
self._parsed_document = loader.load_ocsp_response(self.pem, 'request', 'request')
except PyAsn1Error as e:
raise ValueError('Invalid PEM text specified') from e
else:
ocsp_der_response = base64.b64decode(self.b64)
try:
self._parsed_document = loader.load_ocsp_response(ocsp_der_response, 'request', 'request')
except PyAsn1Error as e:
raise ValueError('Invalid Base-64 encoding specified') from e
return self

@property
def parsed_document(self):
return self._parsed_document

def create_unprocessable_entity_error_detail(message: str, error_type: str = 'value_error'):
return [
Expand Down
12 changes: 12 additions & 0 deletions pkilint/rest/ocsp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from pkilint.pkix import ocsp, create_attribute_decoder, create_extension_decoder, extension, name
from pkilint.rest import model

def create_ocsp_response_linter():
return model.Linter(
validator=ocsp.create_pkix_ocsp_response_validator_container(
[
ocsp.create_response_decoder(),
create_attribute_decoder(name.ATTRIBUTE_TYPE_MAPPINGS),
create_extension_decoder(extension.EXTENSION_MAPPINGS),
], []), name='ocsp_linter'
)
Loading