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

Fix/genchallange invalid #154

Merged
merged 2 commits into from
Oct 31, 2022
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
26 changes: 14 additions & 12 deletions iso15118/secc/states/iso15118_2_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -1017,18 +1017,6 @@ async def process_message(

authorization_req: AuthorizationReq = msg.body.authorization_req

# [V2G2-475] The message 'AuthorizationRes' shall contain the ResponseCode
# 'FAILED_ChallengeInvalid' if the challenge response contained in the
# AuthorizationReq message in attribute GenChallenge is not valid versus
# the provided GenChallenge in PaymentDetailsRes.
if authorization_req.gen_challenge != self.comm_session.gen_challenge:
self.stop_state_machine(
"[V2G2-475] GenChallenge is not the same in PaymentDetailsRes",
message,
ResponseCode.FAILED_CHALLENGE_INVALID,
)
return

if self.comm_session.selected_auth_option == AuthEnum.PNC_V2:
if not self.comm_session.contract_cert_chain:
self.stop_state_machine(
Expand All @@ -1041,6 +1029,20 @@ async def process_message(

if not self.signature_verified_once:
self.signature_verified_once = True

# [V2G2-475] The message 'AuthorizationRes' shall contain
# the ResponseCode 'FAILED_ChallengeInvalid' if the challenge
# response contained in the AuthorizationReq message in attribute
# GenChallenge is not valid versus the provided GenChallenge
# in PaymentDetailsRes.
if authorization_req.gen_challenge != self.comm_session.gen_challenge:
self.stop_state_machine(
"[V2G2-475] GenChallenge is not the same in PaymentDetailsRes",
message,
ResponseCode.FAILED_CHALLENGE_INVALID,
)
return

if not verify_signature(
signature=msg.header.signature,
elements_to_sign=[
Expand Down
3 changes: 2 additions & 1 deletion tests/secc/states/test_iso15118_2_states.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,8 @@ async def test_authorization_next_state_on_authorization_request(
async def test_authorization_req_gen_challenge_invalid(self):
self.comm_session.writer = Mock()
self.comm_session.writer.get_extra_info = Mock()

self.comm_session.selected_auth_option = AuthEnum.PNC_V2
self.comm_session.contract_cert_chain = Mock()
self.comm_session.gen_challenge = get_random_bytes(16)
id = "aReq"
gen_challenge = get_random_bytes(16)
Expand Down