Skip to content
Permalink
Browse files

asn1: generate security-related code by asn1c

Change-Id: I9f068b549131c1aafde39f28632170d4a43289cd
  • Loading branch information...
riebl committed Sep 19, 2019
1 parent 3733deb commit e57dff2dde15327b2ddf9bc8f7cf99b39ed16a09
Showing 700 changed files with 21,387 additions and 412 deletions.
@@ -126,7 +126,7 @@ install(EXPORT ${PROJECT_NAME} NAMESPACE Vanetza:: FILE VanetzaTargets.cmake DES

install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/vanetza
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
FILES_MATCHING PATTERN "*.hpp" PATTERN "asn1/its/*.h" PATTERN "/tests/*.hpp" EXCLUDE)
FILES_MATCHING PATTERN "*.hpp" PATTERN "/tests/*.hpp" EXCLUDE)

# export build tree (allows import by outside projects)
export(EXPORT ${PROJECT_NAME} NAMESPACE Vanetza:: FILE VanetzaExports.cmake)
@@ -2,12 +2,18 @@ find_program(ASN1C_EXECUTABLE NAMES asn1c DOC "ASN.1 compiler")
if(ASN1C_EXECUTABLE)
execute_process(COMMAND ${ASN1C_EXECUTABLE} -version ERROR_VARIABLE _asn1c_version)
string(REGEX MATCH "[0-9]\\.[0-9]\\.[0-9]+" ASN1C_VERSION ${_asn1c_version})
get_filename_component(_asn1c_executable_path ${ASN1C_EXECUTABLE} DIRECTORY)
endif()

find_path(ASN1C_SKELETON_DIR NAMES asn_application.c
HINTS "${_asn1c_executable_path}/.."
PATH_SUFFIXES share/asn1c skeletons
DOC "Directory containing generic asn1c skeleton files")

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(asn1c
REQUIRED_VARS ASN1C_EXECUTABLE
REQUIRED_VARS ASN1C_EXECUTABLE ASN1C_SKELETON_DIR
FOUND_VAR ASN1C_FOUND
VERSION_VAR ASN1C_VERSION)

mark_as_advanced(ASN1C_EXECUTABLE)
mark_as_advanced(ASN1C_EXECUTABLE ASN1C_SKELETON_DIR)
@@ -1,4 +1,10 @@
set(_its_asn1_source_file "asn1c_its_sources.txt")
set(_sec_asn1_source_file "asn1c_security_sources.txt")
set(_support_asn1_source_file "asn1c_support_sources.txt")

set(_its_asn1_dir "${CMAKE_CURRENT_SOURCE_DIR}/its")
set(_sec_asn1_dir "${CMAKE_CURRENT_SOURCE_DIR}/security")
set(_support_asn1_dir "${CMAKE_CURRENT_SOURCE_DIR}/support")

option(VANETZA_ASN1_WITH_ASN1C "Enable asn1c targets" OFF)
if(VANETZA_ASN1_WITH_ASN1C)
@@ -12,38 +18,120 @@ if(VANETZA_ASN1_WITH_ASN1C)
${PROJECT_SOURCE_DIR}/asn1/EN302637-2v141-CAM.asn
${PROJECT_SOURCE_DIR}/asn1/EN302637-3v131-DENM.asn
)
set(_its_asn1_dir "${CMAKE_CURRENT_SOURCE_DIR}/its")
set(_sec_asn1_files
${PROJECT_SOURCE_DIR}/asn1/TS103097v131.asn
${PROJECT_SOURCE_DIR}/asn1/IEEE1609dot2.asn
${PROJECT_SOURCE_DIR}/asn1/IEEE1609dot2BaseTypes.asn
)

add_custom_command(OUTPUT ${_support_asn1_dir}
DEPENDS "${ASN1C_SKELETON_DIR}"
COMMAND ${CMAKE_COMMAND} -E make_directory ${_support_asn1_dir}
COMMAND ${CMAKE_COMMAND} -DDESTINATION=${_support_asn1_dir}
-P ${CMAKE_CURRENT_SOURCE_DIR}/copy_asn1c_skeleton.cmake
COMMENT "Copying generic asn1c support code" VERBATIM
WORKING_DIRECTORY ${ASN1C_SKELETON_DIR})
add_custom_command(OUTPUT "${_support_asn1_source_file}"
DEPENDS ${_support_asn1_dir}
COMMAND ${CMAKE_COMMAND} -DASN1C_OUTPUT_DIR=support -DASN1C_SOURCE_FILE=${_support_asn1_source_file}
-P collect_asn1c_sources.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} VERBATIM)

add_custom_target(clean_asn1c
COMMAND ${CMAKE_COMMAND} -DASN1C_OUTPUT_DIR=its -DASN1C_SOURCE_FILE=${_its_asn1_source_file} -P clean_asn1c.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_custom_command(OUTPUT ${_its_asn1_dir}
DEPENDS ${_its_asn1_name}/${_its_asn1_files}
DEPENDS ${_its_asn1_files}
COMMAND ${CMAKE_COMMAND} -E make_directory ${_its_asn1_dir}
COMMAND ${ASN1C_EXECUTABLE} ${_asn1c_flags} -D ${_its_asn1_dir} ${_its_asn1_files} ${CMAKE_CURRENT_SOURCE_DIR}/test.asn
COMMENT "Generating code from ITS ASN.1 modules" VERBATIM
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${_its_asn1_name})
COMMAND ${ASN1C_EXECUTABLE} ${_asn1c_flags} -R -D ${_its_asn1_dir} ${_its_asn1_files} test.asn
COMMENT "Generating code from ITS application ASN.1 modules (CDD, CA, DEN)" VERBATIM
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_custom_command(OUTPUT "${_its_asn1_source_file}"
DEPENDS ${_its_asn1_dir}
COMMAND ${CMAKE_COMMAND} -DASN1C_OUTPUT_DIR=its -DASN1C_SOURCE_FILE=${_its_asn1_source_file} -P collect_asn1c_sources.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
add_custom_target(generate_asn1c DEPENDS ${_its_asn1_dir} ${_its_asn1_source_file})
COMMAND ${CMAKE_COMMAND} -DASN1C_OUTPUT_DIR=its -DASN1C_SOURCE_FILE=${_its_asn1_source_file}
-P collect_asn1c_sources.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} VERBATIM)

add_custom_command(OUTPUT "${_sec_asn1_dir}"
DEPENDS ${_sec_asn1_files}
COMMAND ${CMAKE_COMMAND} -E make_directory ${_sec_asn1_dir}
COMMAND ${ASN1C_EXECUTABLE} ${_asn1c_flags} -R -D ${_sec_asn1_dir} ${_sec_asn1_files}
COMMENT "Generating code from Security (1609.2 and TS 103 097) ASN.1 modules" VERBATIM)
add_custom_command(OUTPUT "${_sec_asn1_source_file}"
DEPENDS ${_sec_asn1_dir}
COMMAND ${CMAKE_COMMAND} -DASN1C_OUTPUT_DIR=security -DASN1C_SOURCE_FILE=${_sec_asn1_source_file}
-P collect_asn1c_sources.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} VERBATIM)

add_custom_target(generate_asn1c DEPENDS
"${_support_asn1_dir}" "${_support_asn1_source_file}"
"${_its_asn1_dir}" "${_its_asn1_source_file}"
"${_sec_asn1_dir}" "${_sec_asn1_source_file}"
VERBATIM)
add_custom_command(TARGET generate_asn1c POST_BUILD
COMMAND ${CMAKE_COMMAND} -DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}
-P ${CMAKE_CURRENT_SOURCE_DIR}/patch_asn1c_skeleton.cmake
COMMENT "Patching asn1c support files"
WORKING_DIRECTORY ${_support_asn1_dir} VERBATIM)
add_custom_command(TARGET generate_asn1c POST_BUILD
COMMAND ${CMAKE_COMMAND} -DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR} -P ${CMAKE_CURRENT_SOURCE_DIR}/patch_asn1c_sources.cmake
COMMENT "Patching ITS asn1c files"
WORKING_DIRECTORY ${_its_asn1_dir})
COMMAND ${CMAKE_COMMAND} -DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}
-P ${CMAKE_CURRENT_SOURCE_DIR}/patch_asn1c_generated.cmake
COMMENT "Patching generated ITS application asn1c files"
WORKING_DIRECTORY ${_its_asn1_dir} VERBATIM)
add_custom_command(TARGET generate_asn1c POST_BUILD
COMMAND ${CMAKE_COMMAND} -DPROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}
-P ${CMAKE_CURRENT_SOURCE_DIR}/patch_asn1c_generated.cmake
COMMENT "Patching generated security asn1c files"
WORKING_DIRECTORY ${_sec_asn1_dir} VERBATIM)

# wipe directory with generated files before generating
add_custom_target(clean_asn1c
COMMAND ${CMAKE_COMMAND}
-DASN1C_OUTPUT_DIR=${_support_asn1_dir}
-DASN1C_SOURCE_FILE=${_support_asn1_source_file}
-P clean_asn1c.cmake
COMMAND ${CMAKE_COMMAND}
-DASN1C_OUTPUT_DIR=${_its_asn1_dir}
-DASN1C_SOURCE_FILE=${_its_asn1_source_file}
-P clean_asn1c.cmake
COMMAND ${CMAKE_COMMAND}
-DASN1C_OUTPUT_DIR=${_sec_asn1_dir}
-DASN1C_SOURCE_FILE=${_sec_asn1_source_file}
-P clean_asn1c.cmake
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} VERBATIM)
add_dependencies(generate_asn1c clean_asn1c)
endif()


set(CXX_SOURCES asn1c_wrapper.cpp)
file(STRINGS "${_its_asn1_source_file}" ASN1C_SOURCES REGEX "^[^#]+")
add_vanetza_component(asn1 ${CXX_SOURCES} ${ASN1C_SOURCES})
file(STRINGS "${_its_asn1_source_file}" ITS_ASN1C_SOURCES REGEX "^[^#]+")
file(STRINGS "${_support_asn1_source_file}" SUPPORT_ASN1C_SOURCES REGEX "^[^#]+")

add_vanetza_component(asn1 ${CXX_SOURCES} ${ITS_ASN1C_SOURCES} ${SUPPORT_ASN1C_SOURCES})
target_include_directories(asn1 PUBLIC
$<BUILD_INTERFACE:${_support_asn1_dir}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/vanetza/asn1/support}>)
target_link_libraries(asn1 PUBLIC Boost::boost)
set_target_properties(asn1 PROPERTIES C_STANDARD 11)

install(DIRECTORY ${_support_asn1_dir} ${_its_asn1_dir}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/vanetza/asn1
FILES_MATCHING PATTERN "*.h")


file(STRINGS "${_sec_asn1_source_file}" SEC_ASN1C_SOURCES REGEX "^[^#]+")
if (SEC_ASN1C_SOURCES)
add_library(asn1_security OBJECT ${SEC_ASN1C_SOURCES})
target_include_directories(asn1_security PUBLIC
$<BUILD_INTERFACE:${_support_asn1_dir}>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/vanetza/asn1/support}>)
set_target_properties(asn1_security PROPERTIES POSITION_INDEPENDENT_CODE ON C_STANDARD 11)
else()
message(AUTHOR_WARNING "source file ${_sec_asn1_source_file} is empty, fix this now!")
endif()


# Silence warnings in code generated by asn1c
if (CMAKE_C_COMPILER_ID STREQUAL "Clang")
set_property(SOURCE ${ASN1C_SOURCES} APPEND PROPERTY COMPILE_OPTIONS "-Wno-parentheses-equality")
set_property(SOURCE ${SUPPORT_ASN1C_SOURCES} ${ITS_ASN1C_SOURCES} ${SEC_ASN1C_SOURCES}
APPEND PROPERTY COMPILE_OPTIONS "-Wno-parentheses-equality")
endif()

add_test_subdirectory(tests)
@@ -1,5 +1,4 @@
# generated file
its/ANY.c
its/AccelerationConfidence.c
its/AccelerationControl.c
its/AccidentSubCauseCode.c
@@ -12,9 +11,6 @@ its/AlacarteContainer.c
its/Altitude.c
its/AltitudeConfidence.c
its/AltitudeValue.c
its/BIT_STRING.c
its/BIT_STRING_oer.c
its/BOOLEAN.c
its/BasicContainer.c
its/BasicVehicleContainerHighFrequency.c
its/BasicVehicleContainerLowFrequency.c
@@ -45,7 +41,6 @@ its/DeltaReferencePosition.c
its/DigitalMap.c
its/DriveDirection.c
its/DrivingLaneStatus.c
its/EXTERNAL.c
its/EmbarkationStatus.c
its/EmergencyContainer.c
its/EmergencyPriority.c
@@ -55,7 +50,6 @@ its/EventHistory.c
its/EventPoint.c
its/ExteriorLights.c
its/GenerationDeltaTime.c
its/GraphicString.c
its/HardShoulderStatus.c
its/HazardousLocation-AnimalOnTheRoadSubCauseCode.c
its/HazardousLocation-DangerousCurveSubCauseCode.c
@@ -68,9 +62,6 @@ its/HeightLonCarr.c
its/HighFrequencyContainer.c
its/HumanPresenceOnTheRoadSubCauseCode.c
its/HumanProblemSubCauseCode.c
its/IA5String.c
its/INTEGER.c
its/INTEGER_oer.c
its/ImpactReductionContainer.c
its/InformationQuality.c
its/ItineraryPath.c
@@ -86,18 +77,7 @@ its/LongitudinalAcceleration.c
its/LongitudinalAccelerationValue.c
its/LowFrequencyContainer.c
its/ManagementContainer.c
its/NativeEnumerated.c
its/NativeEnumerated_oer.c
its/NativeInteger.c
its/NativeInteger_oer.c
its/NumberOfOccupants.c
its/NumericString.c
its/OBJECT_IDENTIFIER.c
its/OCTET_STRING.c
its/OCTET_STRING_oer.c
its/OPEN_TYPE.c
its/OPEN_TYPE_oer.c
its/ObjectDescriptor.c
its/OpeningDaysHours.c
its/PathDeltaTime.c
its/PathHistory.c
@@ -165,7 +145,6 @@ its/TrafficConditionSubCauseCode.c
its/TrafficRule.c
its/TransmissionInterval.c
its/TurningRadius.c
its/UTF8String.c
its/VDS.c
its/ValidityDuration.c
its/VanetzaTest.c
@@ -185,33 +164,3 @@ its/WrongWayDrivingSubCauseCode.c
its/YawRate.c
its/YawRateConfidence.c
its/YawRateValue.c
its/asn_SEQUENCE_OF.c
its/asn_SET_OF.c
its/asn_application.c
its/asn_bit_data.c
its/asn_codecs_prim.c
its/asn_internal.c
its/asn_random_fill.c
its/ber_decoder.c
its/ber_tlv_length.c
its/ber_tlv_tag.c
its/constr_CHOICE.c
its/constr_CHOICE_oer.c
its/constr_SEQUENCE.c
its/constr_SEQUENCE_OF.c
its/constr_SEQUENCE_oer.c
its/constr_SET_OF.c
its/constr_SET_OF_oer.c
its/constr_TYPE.c
its/constraints.c
its/der_encoder.c
its/oer_decoder.c
its/oer_encoder.c
its/oer_support.c
its/per_decoder.c
its/per_encoder.c
its/per_opentype.c
its/per_support.c
its/xer_decoder.c
its/xer_encoder.c
its/xer_support.c
@@ -0,0 +1,114 @@
# generated file
security/AesCcmCiphertext.c
security/BasePublicEncryptionKey.c
security/BitmapSsp.c
security/BitmapSspRange.c
security/Certificate.c
security/CertificateBase.c
security/CertificateId.c
security/CertificateType.c
security/CircularRegion.c
security/Countersignature.c
security/CountryAndRegions.c
security/CountryAndSubregions.c
security/CountryOnly.c
security/CrlSeries.c
security/Duration.c
security/EccP256CurvePoint.c
security/EccP384CurvePoint.c
security/EcdsaP256Signature.c
security/EcdsaP384Signature.c
security/EciesP256EncryptedKey.c
security/ElevInt.c
security/Elevation.c
security/EncryptedData.c
security/EncryptedDataEncryptionKey.c
security/EncryptionKey.c
security/EndEntityType.c
security/EtsiTs103097Certificate.c
security/EtsiTs103097Data-Encrypted.c
security/EtsiTs103097Data-Signed.c
security/EtsiTs103097Data-SignedAndEncrypted.c
security/EtsiTs103097Data-SignedExternalPayload.c
security/EtsiTs103097Data.c
security/ExplicitCertificate.c
security/GeographicRegion.c
security/GroupLinkageValue.c
security/HashAlgorithm.c
security/HashedData.c
security/HashedId10.c
security/HashedId3.c
security/HashedId8.c
security/HeaderInfo.c
security/Hostname.c
security/IValue.c
security/IdentifiedRegion.c
security/Ieee1609Dot2Content.c
security/Ieee1609Dot2Data.c
security/ImplicitCertificate.c
security/IssuerIdentifier.c
security/KnownLatitude.c
security/KnownLongitude.c
security/LaId.c
security/Latitude.c
security/LinkageData.c
security/LinkageSeed.c
security/LinkageValue.c
security/Longitude.c
security/MissingCrlIdentifier.c
security/NinetyDegreeInt.c
security/OneEightyDegreeInt.c
security/Opaque.c
security/PKRecipientInfo.c
security/PolygonalRegion.c
security/PreSharedKeyRecipientInfo.c
security/Psid.c
security/PsidGroupPermissions.c
security/PsidSsp.c
security/PsidSspRange.c
security/PublicEncryptionKey.c
security/PublicVerificationKey.c
security/RecipientInfo.c
security/RectangularRegion.c
security/RegionAndSubregions.c
security/SequenceOfCertificate.c
security/SequenceOfHashedId3.c
security/SequenceOfIdentifiedRegion.c
security/SequenceOfOctetString.c
security/SequenceOfPsid.c
security/SequenceOfPsidGroupPermissions.c
security/SequenceOfPsidSsp.c
security/SequenceOfPsidSspRange.c
security/SequenceOfRecipientInfo.c
security/SequenceOfRectangularRegion.c
security/SequenceOfRegionAndSubregions.c
security/SequenceOfUint16.c
security/SequenceOfUint8.c
security/ServiceSpecificPermissions.c
security/Signature.c
security/SignedData.c
security/SignedDataPayload.c
security/SignerIdentifier.c
security/SingleEtsiTs103097Certificate.c
security/SspRange.c
security/SubjectAssurance.c
security/SubjectPermissions.c
security/SymmAlgorithm.c
security/SymmRecipientInfo.c
security/SymmetricCiphertext.c
security/SymmetricEncryptionKey.c
security/ThreeDLocation.c
security/Time32.c
security/Time64.c
security/ToBeSignedCertificate.c
security/ToBeSignedData.c
security/TwoDLocation.c
security/Uint16.c
security/Uint3.c
security/Uint32.c
security/Uint64.c
security/Uint8.c
security/UnknownLatitude.c
security/UnknownLongitude.c
security/ValidityPeriod.c
security/VerificationKeyIndicator.c

0 comments on commit e57dff2

Please sign in to comment.
You can’t perform that action at this time.