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

Bug Fix: Catch further encoding exception when verifying message #228

Closed
wants to merge 2 commits into from
Closed
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
3 changes: 2 additions & 1 deletion vanetza/geonet/router.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -502,13 +502,14 @@ void Router::indicate_secured(IndicationContextBasic& ctx, const BasicHeader& ba
case DecapReport::False_Signature:
case DecapReport::Invalid_Certificate:
case DecapReport::Revoked_Certificate:
case DecapReport::Inconsistant_Chain:
case DecapReport::Inconsistent_Chain:
case DecapReport::Invalid_Timestamp:
case DecapReport::Invalid_Mobility_Data:
case DecapReport::Unsigned_Message:
case DecapReport::Signer_Certificate_Not_Found:
case DecapReport::Unsupported_Signer_Identifier_Type:
case DecapReport::Unencrypted_Message:
case DecapReport::None:
// ok, continue
boost::apply_visitor(visitor, decap_confirm.plaintext_payload);
break;
Expand Down
31 changes: 16 additions & 15 deletions vanetza/security/decap_confirm.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,25 @@ namespace security

/**
* SN-DECAP.confirm report codes
* \see TS 102 723-8 v1.1.1 table 27
* \see TS 102 723-8 v1.1.1 table 27 or AUTOSAR SWS_V2xM_91000
*/
enum class DecapReport
{
Success,
False_Signature,
Invalid_Certificate,
Revoked_Certificate,
Inconsistant_Chain,
Invalid_Timestamp,
Duplicate_Message,
Invalid_Mobility_Data,
Unsigned_Message,
Signer_Certificate_Not_Found,
Unsupported_Signer_Identifier_Type,
Incompatible_Protocol,
Unencrypted_Message,
Decryption_Error,
Success = 0x00,
False_Signature = 0x01,
Invalid_Certificate = 0x02,
Revoked_Certificate = 0x03,
Inconsistent_Chain = 0x04,
Invalid_Timestamp = 0x05,
Duplicate_Message = 0x06,
Invalid_Mobility_Data = 0x07,
Unsigned_Message = 0x08,
Signer_Certificate_Not_Found = 0x09,
Unsupported_Signer_Identifier_Type = 0x0a,
Incompatible_Protocol = 0x0b,
Unencrypted_Message = 0x0c,
Decryption_Error = 0x0d,
None = 0xff,
};

/** \brief contains output of the verify process
Expand Down
10 changes: 9 additions & 1 deletion vanetza/security/straight_verify_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,14 @@ VerifyConfirm StraightVerifyService::verify(const v3::SecuredMessage& msg)
return confirm;
}

ByteBuffer encoded_signing_payload;
try {
encoded_signing_payload = msg.signing_payload();
} catch (...) {
confirm.report = VerificationReport::Decryption_Error;
return confirm;
}

ByteBuffer encoded_cert;
try {
encoded_cert = asn1::encode_oer(asn_DEF_CertificateBase, certificate);
Expand All @@ -439,7 +447,7 @@ VerifyConfirm StraightVerifyService::verify(const v3::SecuredMessage& msg)
return confirm;
}

ByteBuffer data_hash = m_backend.calculate_hash(public_key->type, msg.signing_payload());
ByteBuffer data_hash = m_backend.calculate_hash(public_key->type, encoded_signing_payload);
ByteBuffer cert_hash = m_backend.calculate_hash(public_key->type, encoded_cert);
ByteBuffer concat_hash = data_hash;
concat_hash.insert(concat_hash.end(), cert_hash.begin(), cert_hash.end());
Expand Down
8 changes: 6 additions & 2 deletions vanetza/security/v3/certificate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ boost::optional<HashedId8> calculate_hash(const EtsiTs103097Certificate_t& cert)
if (indicator.present != VerificationKeyIndicator_PR_verificationKey) {
return boost::none;
}

ByteBuffer buffer = asn1::encode_oer(asn_DEF_EtsiTs103097Certificate, &cert);
ByteBuffer buffer;
try {
buffer = asn1::encode_oer(asn_DEF_EtsiTs103097Certificate, &cert);
} catch (...) {
return boost::none;
}
switch (indicator.choice.verificationKey.present)
{
case PublicVerificationKey_PR_ecdsaNistP256:
Expand Down
29 changes: 16 additions & 13 deletions vanetza/security/verify_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,22 @@ namespace security

enum class VerificationReport
{
Success,
False_Signature,
Invalid_Certificate,
Revoked_Certificate,
Inconsistent_Chain,
Invalid_Timestamp,
Duplicate_Message,
Invalid_Mobility_Data,
Unsigned_Message,
Signer_Certificate_Not_Found,
Unsupported_Signer_Identifier_Type,
Incompatible_Protocol,
Configuration_Problem,
Success = 0x00,
False_Signature = 0x01,
Invalid_Certificate = 0x02,
Revoked_Certificate = 0x03,
Inconsistent_Chain = 0x04,
Invalid_Timestamp = 0x05,
Duplicate_Message = 0x06,
Invalid_Mobility_Data = 0x07,
Unsigned_Message = 0x08,
Signer_Certificate_Not_Found = 0x09,
Unsupported_Signer_Identifier_Type = 0x0a,
Incompatible_Protocol = 0x0b,
Unencrypted_Message = 0x0c,
Decryption_Error = 0x0d,
Configuration_Problem = 0x0e,
None = 0xff,
};

// mandatory parameters of SN-VERIFY.request (TS 102 723-8 V1.1.1)
Expand Down
Loading