From c7ee673e7c31bae2d74870fd9a3cd2c748af0dd9 Mon Sep 17 00:00:00 2001 From: Martin Regen Date: Fri, 14 May 2021 10:02:04 +0200 Subject: [PATCH] enable .NET analyzer, fix security warnings (#1175) - fix security warnings and some low hanging fruit refactoring --- .editorconfig | 358 ++++++++++-------- common.props | 7 + .../src/Extensions/ByteArrayEx.cs | 3 + .../src/Extensions/StreamEx.cs | 7 +- .../src/Messaging/Default/EventBusHost.cs | 4 +- .../src/Utils/HostAutoStart.cs | 2 +- .../src/Services/SignalRHubClientHost.cs | 2 +- .../src/Default/IoTSdkFactory.cs | 3 + .../src/Hosting/ModuleHost.cs | 8 +- .../src/Hosting/SettingsRouter.cs | 6 +- .../src/EventHub/EventProcessorHost.cs | 2 +- .../src/Clients/ServiceBusClientFactory.cs | 6 +- .../src/Services/ServiceBusEventBus.cs | 2 +- .../src/Services/SignalRServiceHost.cs | 2 +- .../src/Storage/CdmFileStorageAdapter.cs | 8 +- .../src/Extensions/EndpointServicesEx.cs | 10 +- .../src/Extensions/FilterEncoderEx.cs | 16 +- .../src/Extensions/OperationResultEx.cs | 2 +- .../src/Extensions/VariantEncoderEx.cs | 12 +- .../src/IClientSession.cs | 2 +- .../src/Services/ClientServices.cs | 55 ++- .../src/Services/ClientSession.cs | 14 +- .../src/Stack/Design/Model.cs | 4 +- .../src/Stack/Encoders/ModelDecoder.cs | 2 +- .../src/Stack/Encoders/ModelEncoder.cs | 2 +- .../Stack/Extensions/EndpointDescriptionEx.cs | 2 +- .../src/Stack/Nodeset/NodeSet2.cs | 10 +- .../src/Transport/Probe/ServerProbe.cs | 2 +- .../src/Services/EndpointRegistry.cs | 6 +- .../Servers/TestData/TestDataObjectState.cs | 4 +- .../src/Startup.cs | 2 +- tools/templates/sdl.yml | 5 +- 32 files changed, 304 insertions(+), 266 deletions(-) diff --git a/.editorconfig b/.editorconfig index 0571aaaf2a..4340cab740 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,7 +5,7 @@ root = true [*.{json,sh}] # New line preferences -end_of_line = lf +end_of_line = lf insert_final_newline = true # C# files @@ -14,270 +14,292 @@ insert_final_newline = true #### Core EditorConfig Options #### # Indentation and spacing -indent_size = 4 -indent_style = space -tab_width = 4 +indent_size = 4 +indent_style = space +tab_width = 4 # New line preferences -end_of_line = crlf -insert_final_newline = false +end_of_line = crlf +insert_final_newline = false #### .NET Coding Conventions #### # Organize usings -dotnet_separate_import_directive_groups = false -dotnet_sort_system_directives_first = false +dotnet_separate_import_directive_groups = false +dotnet_sort_system_directives_first = false # this. and Me. preferences -dotnet_style_qualification_for_event = false:suggestion -dotnet_style_qualification_for_field = false:suggestion -dotnet_style_qualification_for_method = false:suggestion -dotnet_style_qualification_for_property = false:suggestion +dotnet_style_qualification_for_event = false : suggestion +dotnet_style_qualification_for_field = false : suggestion +dotnet_style_qualification_for_method = false : suggestion +dotnet_style_qualification_for_property = false : suggestion # Language keywords vs BCL types preferences -dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion -dotnet_style_predefined_type_for_member_access = true:suggestion +dotnet_style_predefined_type_for_locals_parameters_members = true : suggestion +dotnet_style_predefined_type_for_member_access = true : suggestion # Parentheses preferences -dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:suggestion -dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:suggestion -dotnet_style_parentheses_in_other_operators = never_if_unnecessary:suggestion -dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:suggestion +dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity : suggestion +dotnet_style_parentheses_in_other_binary_operators = always_for_clarity : suggestion +dotnet_style_parentheses_in_other_operators = never_if_unnecessary : suggestion +dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity : suggestion # Modifier preferences -dotnet_style_require_accessibility_modifiers = for_non_interface_members:silent +dotnet_style_require_accessibility_modifiers = for_non_interface_members : silent # Expression-level preferences -csharp_style_deconstructed_variable_declaration = true:suggestion -csharp_style_inlined_variable_declaration = false:suggestion -csharp_style_throw_expression = true:suggestion -dotnet_style_coalesce_expression = true:suggestion -dotnet_style_collection_initializer = true:suggestion -dotnet_style_explicit_tuple_names = true:suggestion -dotnet_style_null_propagation = true:suggestion -dotnet_style_object_initializer = true:suggestion -dotnet_style_prefer_auto_properties = true:suggestion -dotnet_style_prefer_compound_assignment = true:suggestion -dotnet_style_prefer_conditional_expression_over_assignment = true:silent -dotnet_style_prefer_conditional_expression_over_return = true:silent -dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion -dotnet_style_prefer_inferred_tuple_names = true:suggestion -dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion +csharp_style_deconstructed_variable_declaration = true : suggestion +csharp_style_inlined_variable_declaration = false : suggestion +csharp_style_throw_expression = true : suggestion +dotnet_style_coalesce_expression = true : suggestion +dotnet_style_collection_initializer = true : suggestion +dotnet_style_explicit_tuple_names = true : suggestion +dotnet_style_null_propagation = true : suggestion +dotnet_style_object_initializer = true : suggestion +dotnet_style_prefer_auto_properties = true : suggestion +dotnet_style_prefer_compound_assignment = true : suggestion +dotnet_style_prefer_conditional_expression_over_assignment = true : silent +dotnet_style_prefer_conditional_expression_over_return = true : silent +dotnet_style_prefer_inferred_anonymous_type_member_names = true : suggestion +dotnet_style_prefer_inferred_tuple_names = true : suggestion +dotnet_style_prefer_is_null_check_over_reference_equality_method = true : suggestion # Field preferences -dotnet_style_readonly_field = true:warning +dotnet_style_readonly_field = true : warning # Parameter preferences -dotnet_code_quality_unused_parameters = all:suggestion +dotnet_code_quality_unused_parameters = all : suggestion #### C# Coding Conventions #### # var preferences -csharp_style_var_elsewhere = true:suggestion -csharp_style_var_for_built_in_types = true:suggestion -csharp_style_var_when_type_is_apparent = true:suggestion +csharp_style_var_elsewhere = true : suggestion +csharp_style_var_for_built_in_types = true : suggestion +csharp_style_var_when_type_is_apparent = true : suggestion # Expression-bodied members -csharp_style_expression_bodied_accessors = when_on_single_line:silent -csharp_style_expression_bodied_constructors = false:suggestion -csharp_style_expression_bodied_indexers = when_on_single_line:silent -csharp_style_expression_bodied_lambdas = when_on_single_line:silent -csharp_style_expression_bodied_local_functions = when_on_single_line:silent -csharp_style_expression_bodied_methods = false:suggestion -csharp_style_expression_bodied_operators = when_on_single_line:silent -csharp_style_expression_bodied_properties = when_on_single_line:silent +csharp_style_expression_bodied_accessors = when_on_single_line : silent +csharp_style_expression_bodied_constructors = false : suggestion +csharp_style_expression_bodied_indexers = when_on_single_line : silent +csharp_style_expression_bodied_lambdas = when_on_single_line : silent +csharp_style_expression_bodied_local_functions = when_on_single_line : silent +csharp_style_expression_bodied_methods = false : suggestion +csharp_style_expression_bodied_operators = when_on_single_line : silent +csharp_style_expression_bodied_properties = when_on_single_line : silent # Pattern matching preferences -csharp_style_pattern_matching_over_as_with_null_check = true:suggestion -csharp_style_pattern_matching_over_is_with_cast_check = true:suggestion -csharp_style_prefer_switch_expression = false:suggestion +csharp_style_pattern_matching_over_as_with_null_check = true : suggestion +csharp_style_pattern_matching_over_is_with_cast_check = true : suggestion +csharp_style_prefer_switch_expression = false : suggestion # Null-checking preferences -csharp_style_conditional_delegate_call = true:suggestion +csharp_style_conditional_delegate_call = true : suggestion # Modifier preferences -csharp_prefer_static_local_function = true:warning -csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async +csharp_prefer_static_local_function = true : warning +csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async # Code-block preferences -csharp_prefer_braces = true:suggestion -csharp_prefer_simple_using_statement = false:suggestion +csharp_prefer_braces = true : suggestion +csharp_prefer_simple_using_statement = false : suggestion # Expression-level preferences -csharp_prefer_simple_default_expression = true:suggestion -csharp_style_pattern_local_over_anonymous_function = true:suggestion -csharp_style_prefer_index_operator = true:suggestion -csharp_style_prefer_range_operator = true:suggestion -csharp_style_unused_value_assignment_preference = discard_variable:silent -csharp_style_unused_value_expression_statement_preference = discard_variable:silent +csharp_prefer_simple_default_expression = true : suggestion +csharp_style_pattern_local_over_anonymous_function = true : suggestion +csharp_style_prefer_index_operator = true : suggestion +csharp_style_prefer_range_operator = true : suggestion +csharp_style_unused_value_assignment_preference = discard_variable : silent +csharp_style_unused_value_expression_statement_preference = discard_variable : silent # 'using' directive preferences -csharp_using_directive_placement = inside_namespace:suggestion +csharp_using_directive_placement = inside_namespace : suggestion #### C# Formatting Rules #### # New line preferences -csharp_new_line_before_catch = true -csharp_new_line_before_else = true -csharp_new_line_before_finally = true -csharp_new_line_before_members_in_anonymous_types = true -csharp_new_line_before_members_in_object_initializers = true -csharp_new_line_before_open_brace = none -csharp_new_line_between_query_expression_clauses = true +csharp_new_line_before_catch = true +csharp_new_line_before_else = true +csharp_new_line_before_finally = true +csharp_new_line_before_members_in_anonymous_types = true +csharp_new_line_before_members_in_object_initializers = true +csharp_new_line_before_open_brace = none +csharp_new_line_between_query_expression_clauses = true # Indentation preferences -csharp_indent_block_contents = true -csharp_indent_braces = false -csharp_indent_case_contents = true -csharp_indent_case_contents_when_block = true -csharp_indent_labels = one_less_than_current -csharp_indent_switch_labels = true +csharp_indent_block_contents = true +csharp_indent_braces = false +csharp_indent_case_contents = true +csharp_indent_case_contents_when_block = true +csharp_indent_labels = one_less_than_current +csharp_indent_switch_labels = true # Space preferences -csharp_space_after_cast = false -csharp_space_after_colon_in_inheritance_clause = true -csharp_space_after_comma = true -csharp_space_after_dot = false -csharp_space_after_keywords_in_control_flow_statements = true -csharp_space_after_semicolon_in_for_statement = true -csharp_space_around_binary_operators = before_and_after -csharp_space_around_declaration_statements = false -csharp_space_before_colon_in_inheritance_clause = true -csharp_space_before_comma = false -csharp_space_before_dot = false -csharp_space_before_open_square_brackets = false -csharp_space_before_semicolon_in_for_statement = false -csharp_space_between_empty_square_brackets = false -csharp_space_between_method_call_empty_parameter_list_parentheses = false -csharp_space_between_method_call_name_and_opening_parenthesis = false -csharp_space_between_method_call_parameter_list_parentheses = false -csharp_space_between_method_declaration_empty_parameter_list_parentheses = false -csharp_space_between_method_declaration_name_and_open_parenthesis = false -csharp_space_between_method_declaration_parameter_list_parentheses = false -csharp_space_between_parentheses = false -csharp_space_between_square_brackets = false +csharp_space_after_cast = false +csharp_space_after_colon_in_inheritance_clause = true +csharp_space_after_comma = true +csharp_space_after_dot = false +csharp_space_after_keywords_in_control_flow_statements = true +csharp_space_after_semicolon_in_for_statement = true +csharp_space_around_binary_operators = before_and_after +csharp_space_around_declaration_statements = false +csharp_space_before_colon_in_inheritance_clause = true +csharp_space_before_comma = false +csharp_space_before_dot = false +csharp_space_before_open_square_brackets = false +csharp_space_before_semicolon_in_for_statement = false +csharp_space_between_empty_square_brackets = false +csharp_space_between_method_call_empty_parameter_list_parentheses = false +csharp_space_between_method_call_name_and_opening_parenthesis = false +csharp_space_between_method_call_parameter_list_parentheses = false +csharp_space_between_method_declaration_empty_parameter_list_parentheses = false +csharp_space_between_method_declaration_name_and_open_parenthesis = false +csharp_space_between_method_declaration_parameter_list_parentheses = false +csharp_space_between_parentheses = false +csharp_space_between_square_brackets = false # Wrapping preferences -csharp_preserve_single_line_blocks = true -csharp_preserve_single_line_statements = true +csharp_preserve_single_line_blocks = true +csharp_preserve_single_line_statements = true #### Naming styles #### # Naming rules -dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion -dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface -dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i +dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion +dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface +dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i -dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion -dotnet_naming_rule.types_should_be_pascal_case.symbols = types -dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case +dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.types_should_be_pascal_case.symbols = types +dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case -dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion -dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members -dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case +dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members +dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case -dotnet_naming_rule.async_method_should_be_ends_in_async.severity = suggestion -dotnet_naming_rule.async_method_should_be_ends_in_async.symbols = async_method -dotnet_naming_rule.async_method_should_be_ends_in_async.style = ends_in_async +dotnet_naming_rule.async_method_should_be_ends_in_async.severity = suggestion +dotnet_naming_rule.async_method_should_be_ends_in_async.symbols = async_method +dotnet_naming_rule.async_method_should_be_ends_in_async.style = ends_in_async -dotnet_naming_rule.public_const_field_should_be_pascal_case.severity = suggestion -dotnet_naming_rule.public_const_field_should_be_pascal_case.symbols = public_const_field -dotnet_naming_rule.public_const_field_should_be_pascal_case.style = pascal_case +dotnet_naming_rule.public_const_field_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.public_const_field_should_be_pascal_case.symbols = public_const_field +dotnet_naming_rule.public_const_field_should_be_pascal_case.style = pascal_case -dotnet_naming_rule.public_static_readonly_field_should_be_pascal_case.severity = suggestion -dotnet_naming_rule.public_static_readonly_field_should_be_pascal_case.symbols = public_static_readonly_field -dotnet_naming_rule.public_static_readonly_field_should_be_pascal_case.style = pascal_case +dotnet_naming_rule.public_static_readonly_field_should_be_pascal_case.severity = suggestion +dotnet_naming_rule.public_static_readonly_field_should_be_pascal_case.symbols = public_static_readonly_field +dotnet_naming_rule.public_static_readonly_field_should_be_pascal_case.style = pascal_case -dotnet_naming_rule.private_or_protected_const_field_should_be_begins_with_k.severity = suggestion -dotnet_naming_rule.private_or_protected_const_field_should_be_begins_with_k.symbols = private_or_protected_const_field -dotnet_naming_rule.private_or_protected_const_field_should_be_begins_with_k.style = begins_with_k +dotnet_naming_rule.private_or_protected_const_field_should_be_begins_with_k.severity = suggestion +dotnet_naming_rule.private_or_protected_const_field_should_be_begins_with_k.symbols = private_or_protected_const_field +dotnet_naming_rule.private_or_protected_const_field_should_be_begins_with_k.style = begins_with_k dotnet_naming_rule.private_or_protected_static_readonly_field_should_be_begins_with_k.severity = suggestion -dotnet_naming_rule.private_or_protected_static_readonly_field_should_be_begins_with_k.symbols = private_or_protected_static_readonly_field -dotnet_naming_rule.private_or_protected_static_readonly_field_should_be_begins_with_k.style = begins_with_k +dotnet_naming_rule.private_or_protected_static_readonly_field_should_be_begins_with_k.symbols = private_or_protected_static_readonly_field +dotnet_naming_rule.private_or_protected_static_readonly_field_should_be_begins_with_k.style = begins_with_k -dotnet_naming_rule.public_or_protected_field_should_be_begins_with__.severity = suggestion -dotnet_naming_rule.public_or_protected_field_should_be_begins_with__.symbols = public_or_protected_field -dotnet_naming_rule.public_or_protected_field_should_be_begins_with__.style = begins_with__ +dotnet_naming_rule.public_or_protected_field_should_be_begins_with__.severity = suggestion +dotnet_naming_rule.public_or_protected_field_should_be_begins_with__.symbols = public_or_protected_field +dotnet_naming_rule.public_or_protected_field_should_be_begins_with__.style = begins_with__ -dotnet_naming_rule.private_or_internal_field_should_be_begins_with__.severity = suggestion -dotnet_naming_rule.private_or_internal_field_should_be_begins_with__.symbols = private_or_internal_field -dotnet_naming_rule.private_or_internal_field_should_be_begins_with__.style = begins_with__ +dotnet_naming_rule.private_or_internal_field_should_be_begins_with__.severity = suggestion +dotnet_naming_rule.private_or_internal_field_should_be_begins_with__.symbols = private_or_internal_field +dotnet_naming_rule.private_or_internal_field_should_be_begins_with__.style = begins_with__ -dotnet_naming_rule.private_or_internal_static_field_should_be_begins_with__.severity = suggestion -dotnet_naming_rule.private_or_internal_static_field_should_be_begins_with__.symbols = private_or_internal_static_field -dotnet_naming_rule.private_or_internal_static_field_should_be_begins_with__.style = begins_with__ +dotnet_naming_rule.private_or_internal_static_field_should_be_begins_with__.severity = suggestion +dotnet_naming_rule.private_or_internal_static_field_should_be_begins_with__.symbols = private_or_internal_static_field +dotnet_naming_rule.private_or_internal_static_field_should_be_begins_with__.style = begins_with__ # Symbol specifications -dotnet_naming_symbols.interface.applicable_kinds = interface -dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal +dotnet_naming_symbols.interface.applicable_kinds = interface +dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal dotnet_naming_symbols.interface.required_modifiers = -dotnet_naming_symbols.public_or_protected_field.applicable_kinds = field -dotnet_naming_symbols.public_or_protected_field.applicable_accessibilities = public, protected +dotnet_naming_symbols.public_or_protected_field.applicable_kinds = field +dotnet_naming_symbols.public_or_protected_field.applicable_accessibilities = public, protected dotnet_naming_symbols.public_or_protected_field.required_modifiers = -dotnet_naming_symbols.private_or_internal_field.applicable_kinds = field -dotnet_naming_symbols.private_or_internal_field.applicable_accessibilities = internal, private +dotnet_naming_symbols.private_or_internal_field.applicable_kinds = field +dotnet_naming_symbols.private_or_internal_field.applicable_accessibilities = internal, private dotnet_naming_symbols.private_or_internal_field.required_modifiers = -dotnet_naming_symbols.private_or_internal_static_field.applicable_kinds = field -dotnet_naming_symbols.private_or_internal_static_field.applicable_accessibilities = internal, private -dotnet_naming_symbols.private_or_internal_static_field.required_modifiers = static +dotnet_naming_symbols.private_or_internal_static_field.applicable_kinds = field +dotnet_naming_symbols.private_or_internal_static_field.applicable_accessibilities = internal, private +dotnet_naming_symbols.private_or_internal_static_field.required_modifiers = static -dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum -dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal +dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum +dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal dotnet_naming_symbols.types.required_modifiers = -dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method -dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal +dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method +dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal dotnet_naming_symbols.non_field_members.required_modifiers = -dotnet_naming_symbols.async_method.applicable_kinds = method -dotnet_naming_symbols.async_method.applicable_accessibilities = * -dotnet_naming_symbols.async_method.required_modifiers = async +dotnet_naming_symbols.async_method.applicable_kinds = method +dotnet_naming_symbols.async_method.applicable_accessibilities = * +dotnet_naming_symbols.async_method.required_modifiers = async -dotnet_naming_symbols.private_or_protected_const_field.applicable_kinds = field -dotnet_naming_symbols.private_or_protected_const_field.applicable_accessibilities = private, protected, protected_internal, private_protected, local -dotnet_naming_symbols.private_or_protected_const_field.required_modifiers = const +dotnet_naming_symbols.private_or_protected_const_field.applicable_kinds = field +dotnet_naming_symbols.private_or_protected_const_field.applicable_accessibilities = private, protected, protected_internal, private_protected, local +dotnet_naming_symbols.private_or_protected_const_field.required_modifiers = const -dotnet_naming_symbols.private_or_protected_static_readonly_field.applicable_kinds = field -dotnet_naming_symbols.private_or_protected_static_readonly_field.applicable_accessibilities = private, protected, protected_internal, private_protected, local -dotnet_naming_symbols.private_or_protected_static_readonly_field.required_modifiers = readonly, static +dotnet_naming_symbols.private_or_protected_static_readonly_field.applicable_kinds = field +dotnet_naming_symbols.private_or_protected_static_readonly_field.applicable_accessibilities = private, protected, protected_internal, private_protected, local +dotnet_naming_symbols.private_or_protected_static_readonly_field.required_modifiers = readonly, static -dotnet_naming_symbols.public_const_field.applicable_kinds = field -dotnet_naming_symbols.public_const_field.applicable_accessibilities = public, internal -dotnet_naming_symbols.public_const_field.required_modifiers = const +dotnet_naming_symbols.public_const_field.applicable_kinds = field +dotnet_naming_symbols.public_const_field.applicable_accessibilities = public, internal +dotnet_naming_symbols.public_const_field.required_modifiers = const -dotnet_naming_symbols.public_static_readonly_field.applicable_kinds = field -dotnet_naming_symbols.public_static_readonly_field.applicable_accessibilities = public, internal -dotnet_naming_symbols.public_static_readonly_field.required_modifiers = readonly +dotnet_naming_symbols.public_static_readonly_field.applicable_kinds = field +dotnet_naming_symbols.public_static_readonly_field.applicable_accessibilities = public, internal +dotnet_naming_symbols.public_static_readonly_field.required_modifiers = readonly # Naming styles dotnet_naming_style.pascal_case.required_prefix = dotnet_naming_style.pascal_case.required_suffix = dotnet_naming_style.pascal_case.word_separator = -dotnet_naming_style.pascal_case.capitalization = pascal_case +dotnet_naming_style.pascal_case.capitalization = pascal_case -dotnet_naming_style.begins_with_i.required_prefix = I +dotnet_naming_style.begins_with_i.required_prefix = I dotnet_naming_style.begins_with_i.required_suffix = dotnet_naming_style.begins_with_i.word_separator = -dotnet_naming_style.begins_with_i.capitalization = pascal_case +dotnet_naming_style.begins_with_i.capitalization = pascal_case -dotnet_naming_style.begins_with__.required_prefix = _ +dotnet_naming_style.begins_with__.required_prefix = _ dotnet_naming_style.begins_with__.required_suffix = dotnet_naming_style.begins_with__.word_separator = -dotnet_naming_style.begins_with__.capitalization = camel_case +dotnet_naming_style.begins_with__.capitalization = camel_case dotnet_naming_style.ends_in_async.required_prefix = -dotnet_naming_style.ends_in_async.required_suffix = Async +dotnet_naming_style.ends_in_async.required_suffix = Async dotnet_naming_style.ends_in_async.word_separator = -dotnet_naming_style.ends_in_async.capitalization = pascal_case +dotnet_naming_style.ends_in_async.capitalization = pascal_case -dotnet_naming_style.begins_with_k.required_prefix = k +dotnet_naming_style.begins_with_k.required_prefix = k dotnet_naming_style.begins_with_k.required_suffix = dotnet_naming_style.begins_with_k.word_separator = -dotnet_naming_style.begins_with_k.capitalization = pascal_case +dotnet_naming_style.begins_with_k.capitalization = pascal_case + +# Diagnostic settings (windows only) +dotnet_analyzer_diagnostic.severity = silent +# TODO: reliability, perf and RCS1090 as warning +dotnet_analyzer_diagnostic.category-reliability.severity = suggestion +dotnet_analyzer_diagnostic.category-performance.severity = suggestion +dotnet_analyzer_diagnostic.category-security.severity = warning + +# CA1805: Do not initialize unnecessarily. +dotnet_diagnostic.CA1805.severity = suggestion +dotnet_code_quality.CA1805.api_surface = private, internal + +# CA1822: Mark members as static. +dotnet_diagnostic.CA1822.severity = suggestion +dotnet_code_quality.CA1822.api_surface = private, internal + +# CA3075: Insecure DTD processing in XML +dotnet_diagnostic.CA3075.severity = warning + +# RCS1090: Add call to 'ConfigureAwait' (or vice versa) +dotnet_diagnostic.RCS1090.severity = suggestion + diff --git a/common.props b/common.props index 6eaa28a4d3..d1dae52941 100644 --- a/common.props +++ b/common.props @@ -13,6 +13,7 @@ true Industrial;Industrial IoT;Manufacturing;Azure;IoT;.NET true + true true en-US 8.0 @@ -40,6 +41,12 @@ false + + + + + false + $(PrereleaseVersionNoLeadingHyphen)-$(GitCommitIdShort) [$(NuGetPackageVersion)] diff --git a/common/src/Microsoft.Azure.IIoT.Core/src/Extensions/ByteArrayEx.cs b/common/src/Microsoft.Azure.IIoT.Core/src/Extensions/ByteArrayEx.cs index 0c5cebbc1a..169a006998 100644 --- a/common/src/Microsoft.Azure.IIoT.Core/src/Extensions/ByteArrayEx.cs +++ b/common/src/Microsoft.Azure.IIoT.Core/src/Extensions/ByteArrayEx.cs @@ -69,11 +69,14 @@ public static class ByteArrayEx { return Convert.ToBase64String(value); } + /// /// Hashes the string /// /// string to hash /// + [Diagnostics.CodeAnalysis.SuppressMessage("Security", "CA5350:Do Not Use Weak Cryptographic Algorithms", + Justification = "SHA1 not used for crypto operation.")] public static string ToSha1Hash(this byte[] bytestr) { if (bytestr == null) { return null; diff --git a/common/src/Microsoft.Azure.IIoT.Core/src/Extensions/StreamEx.cs b/common/src/Microsoft.Azure.IIoT.Core/src/Extensions/StreamEx.cs index fcdb530366..60f3dbd419 100644 --- a/common/src/Microsoft.Azure.IIoT.Core/src/Extensions/StreamEx.cs +++ b/common/src/Microsoft.Azure.IIoT.Core/src/Extensions/StreamEx.cs @@ -8,6 +8,7 @@ namespace System.IO { using System.Text; using System.Threading; using System.Threading.Tasks; + using System.Xml; /// /// Stream extensions @@ -51,7 +52,11 @@ public static class StreamEx { var reader = new StreamReader(stream); try { var serializer = new Xml.Serialization.XmlSerializer(typeof(T)); - return (T)serializer.Deserialize(reader); + var xmlReader = new XmlTextReader(reader) { + DtdProcessing = DtdProcessing.Prohibit, + XmlResolver = null + }; + return (T)serializer.Deserialize(xmlReader); } finally { reader.Close(); diff --git a/common/src/Microsoft.Azure.IIoT.Core/src/Messaging/Default/EventBusHost.cs b/common/src/Microsoft.Azure.IIoT.Core/src/Messaging/Default/EventBusHost.cs index a09eacb5d1..8075f2c2d3 100644 --- a/common/src/Microsoft.Azure.IIoT.Core/src/Messaging/Default/EventBusHost.cs +++ b/common/src/Microsoft.Azure.IIoT.Core/src/Messaging/Default/EventBusHost.cs @@ -58,7 +58,7 @@ public class EventBusHost : IHostProcess { catch (Exception ex) { _logger.Error(ex, "Failed to start Event bus host for {type}.", type.Name); - throw ex; + throw; } } } @@ -82,7 +82,7 @@ public class EventBusHost : IHostProcess { catch (Exception ex) { _logger.Error(ex, "Failed to stop Event bus host using token {token}.", token); - throw ex; + throw; } } _handlers.Clear(); diff --git a/common/src/Microsoft.Azure.IIoT.Core/src/Utils/HostAutoStart.cs b/common/src/Microsoft.Azure.IIoT.Core/src/Utils/HostAutoStart.cs index f755adfc5c..716fa750bd 100644 --- a/common/src/Microsoft.Azure.IIoT.Core/src/Utils/HostAutoStart.cs +++ b/common/src/Microsoft.Azure.IIoT.Core/src/Utils/HostAutoStart.cs @@ -35,7 +35,7 @@ public class HostAutoStart : IDisposable, IStartable { } catch (Exception ex) { _logger.Error(ex, "Failed to start some hosts."); - throw ex; + throw; } } diff --git a/common/src/Microsoft.Azure.IIoT.Http.SignalR/src/Services/SignalRHubClientHost.cs b/common/src/Microsoft.Azure.IIoT.Http.SignalR/src/Services/SignalRHubClientHost.cs index 2c090c6a0a..56f65ea025 100644 --- a/common/src/Microsoft.Azure.IIoT.Http.SignalR/src/Services/SignalRHubClientHost.cs +++ b/common/src/Microsoft.Azure.IIoT.Http.SignalR/src/Services/SignalRHubClientHost.cs @@ -81,7 +81,7 @@ public class SignalRHubClientHost : ICallbackRegistrar, IHostProcess { catch (Exception ex) { _started = false; _logger.Error(ex, "Error starting SignalR client host."); - throw ex; + throw; } finally { _lock.Release(); diff --git a/common/src/Microsoft.Azure.IIoT.Hub.Module.Client/src/Default/IoTSdkFactory.cs b/common/src/Microsoft.Azure.IIoT.Hub.Module.Client/src/Default/IoTSdkFactory.cs index ce59684a7e..1e8354a188 100644 --- a/common/src/Microsoft.Azure.IIoT.Hub.Module.Client/src/Default/IoTSdkFactory.cs +++ b/common/src/Microsoft.Azure.IIoT.Hub.Module.Client/src/Default/IoTSdkFactory.cs @@ -140,7 +140,10 @@ public sealed class IoTSdkFactory : IClientFactory, IDisposable { _logHook?.Dispose(); } + /// + [System.Diagnostics.CodeAnalysis.SuppressMessage("Security", "CA5359:Do Not Disable Certificate Validation", + Justification = "")] public async Task CreateAsync(string product, IProcessControl ctrl) { if (_bypassCertValidation) { diff --git a/common/src/Microsoft.Azure.IIoT.Hub.Module.Framework/src/Hosting/ModuleHost.cs b/common/src/Microsoft.Azure.IIoT.Hub.Module.Framework/src/Hosting/ModuleHost.cs index 39ac0c1dfd..360e759fbf 100644 --- a/common/src/Microsoft.Azure.IIoT.Hub.Module.Framework/src/Hosting/ModuleHost.cs +++ b/common/src/Microsoft.Azure.IIoT.Hub.Module.Framework/src/Hosting/ModuleHost.cs @@ -92,7 +92,7 @@ public sealed class ModuleHost : IModuleHost, ITwinProperties, IEventEmitter, } finally { kModuleStart.WithLabels(DeviceId ?? "", ModuleId ?? "", _moduleGuid, "", - DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss.FFFFFFFK", + DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss.FFFFFFFK", CultureInfo.InvariantCulture)).Set(0); Client?.Dispose(); Client = null; @@ -153,7 +153,7 @@ public sealed class ModuleHost : IModuleHost, ITwinProperties, IEventEmitter, return; } } - catch (Exception ex) { + catch (Exception) { kModuleStart.WithLabels(DeviceId ?? "", ModuleId ?? "", _moduleGuid, version, DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss.FFFFFFFK", @@ -166,7 +166,7 @@ public sealed class ModuleHost : IModuleHost, ITwinProperties, IEventEmitter, ModuleId = null; SiteId = null; Gateway = null; - throw ex; + throw; } finally { _lock.Release(); @@ -544,7 +544,7 @@ public sealed class ModuleHost : IModuleHost, ITwinProperties, IEventEmitter, private static readonly Gauge kModuleStart = Metrics .CreateGauge("iiot_edge_module_start", "starting module", new GaugeConfiguration { - LabelNames = new[] {"deviceid", "module", "runid", "version", "timestamp_utc" } + LabelNames = new[] { "deviceid", "module", "runid", "version", "timestamp_utc" } }); } } diff --git a/common/src/Microsoft.Azure.IIoT.Hub.Module.Framework/src/Hosting/SettingsRouter.cs b/common/src/Microsoft.Azure.IIoT.Hub.Module.Framework/src/Hosting/SettingsRouter.cs index 3aed64f3b8..d8c9c51051 100644 --- a/common/src/Microsoft.Azure.IIoT.Hub.Module.Framework/src/Hosting/SettingsRouter.cs +++ b/common/src/Microsoft.Azure.IIoT.Hub.Module.Framework/src/Hosting/SettingsRouter.cs @@ -444,7 +444,7 @@ private class PropertyInvoker { _logger.Warning(e, "Exception during setter {controller} {name} invocation", _controller.Target.GetType().Name, _property.Name); - throw e; + throw; } } @@ -475,7 +475,7 @@ private class PropertyInvoker { _logger.Warning(e, "Exception during getter {controller} {name} invocation", _controller.Target.GetType().Name, _property.Name); - throw e; + throw; } } @@ -508,7 +508,7 @@ private class PropertyInvoker { _logger.Warning(e, "Exception collecting all indexed values on {controller}.", _controller.Target.GetType().Name); - throw e; + throw; } } diff --git a/common/src/Microsoft.Azure.IIoT.Hub.Processor/src/EventHub/EventProcessorHost.cs b/common/src/Microsoft.Azure.IIoT.Hub.Processor/src/EventHub/EventProcessorHost.cs index fb92d1ba6c..999228e3ea 100644 --- a/common/src/Microsoft.Azure.IIoT.Hub.Processor/src/EventHub/EventProcessorHost.cs +++ b/common/src/Microsoft.Azure.IIoT.Hub.Processor/src/EventHub/EventProcessorHost.cs @@ -103,7 +103,7 @@ public sealed class EventProcessorHost : IDisposable, IEventProcessingHost, IHos catch (Exception ex) { _logger.Error(ex, "Error starting event processor host."); _host = null; - throw ex; + throw; } finally { _lock.Release(); diff --git a/common/src/Microsoft.Azure.IIoT.Messaging.ServiceBus/src/Clients/ServiceBusClientFactory.cs b/common/src/Microsoft.Azure.IIoT.Messaging.ServiceBus/src/Clients/ServiceBusClientFactory.cs index b46532d7d8..50ac490994 100644 --- a/common/src/Microsoft.Azure.IIoT.Messaging.ServiceBus/src/Clients/ServiceBusClientFactory.cs +++ b/common/src/Microsoft.Azure.IIoT.Messaging.ServiceBus/src/Clients/ServiceBusClientFactory.cs @@ -141,7 +141,7 @@ public class ServiceBusClientFactory : IServiceBusClientFactory { continue; } _logger.Error(ex, "Failed to create subscription client."); - throw ex; + throw; } } } @@ -172,7 +172,7 @@ public class ServiceBusClientFactory : IServiceBusClientFactory { continue; // 429 } _logger.Error(ex, "Failed to create queue client."); - throw ex; + throw; } } } @@ -202,7 +202,7 @@ public class ServiceBusClientFactory : IServiceBusClientFactory { continue; // 429 } _logger.Error(ex, "Failed to create topic client."); - throw ex; + throw; } } } diff --git a/common/src/Microsoft.Azure.IIoT.Messaging.ServiceBus/src/Services/ServiceBusEventBus.cs b/common/src/Microsoft.Azure.IIoT.Messaging.ServiceBus/src/Services/ServiceBusEventBus.cs index cd2272dc82..0e42cc9c40 100644 --- a/common/src/Microsoft.Azure.IIoT.Messaging.ServiceBus/src/Services/ServiceBusEventBus.cs +++ b/common/src/Microsoft.Azure.IIoT.Messaging.ServiceBus/src/Services/ServiceBusEventBus.cs @@ -112,7 +112,7 @@ public class ServiceBusEventBus : IEventBus { eventName); } else { - throw ex; + throw; } } handlers = new Dictionary(); diff --git a/common/src/Microsoft.Azure.IIoT.Messaging.SignalR/src/Services/SignalRServiceHost.cs b/common/src/Microsoft.Azure.IIoT.Messaging.SignalR/src/Services/SignalRServiceHost.cs index 81458d44eb..363fc71ea9 100644 --- a/common/src/Microsoft.Azure.IIoT.Messaging.SignalR/src/Services/SignalRServiceHost.cs +++ b/common/src/Microsoft.Azure.IIoT.Messaging.SignalR/src/Services/SignalRServiceHost.cs @@ -84,7 +84,7 @@ public SignalRServiceHost(ISignalRServiceConfig config, ILogger logger) } catch (Exception ex) { _logger.Error(ex, "Failed to start SignalR service host."); - throw ex; + throw; } } diff --git a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Cdm/src/Storage/CdmFileStorageAdapter.cs b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Cdm/src/Storage/CdmFileStorageAdapter.cs index 4e6ab0daa0..5d23235b4f 100644 --- a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Cdm/src/Storage/CdmFileStorageAdapter.cs +++ b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Cdm/src/Storage/CdmFileStorageAdapter.cs @@ -70,7 +70,7 @@ public class CdmFileStorageAdapter : NetworkAdapter, IStorageAdapter, IDisposabl } catch (Exception ex) { _logger.Error(ex, "Failed to read data from {corpus}", corpusPath); - throw ex; + throw; } } @@ -89,7 +89,7 @@ public class CdmFileStorageAdapter : NetworkAdapter, IStorageAdapter, IDisposabl } catch (Exception ex) { _logger.Error(ex, "Failed to write data to {corpus}", corpusPath); - throw ex; + throw; } } @@ -111,7 +111,7 @@ public class CdmFileStorageAdapter : NetworkAdapter, IStorageAdapter, IDisposabl } catch (Exception ex) { _logger.Error(ex, "Failed to write data to {corpus}", corpusPath); - throw ex; + throw; } } @@ -124,7 +124,7 @@ public class CdmFileStorageAdapter : NetworkAdapter, IStorageAdapter, IDisposabl } catch (Exception ex) { _logger.Error(ex, "Failed to get files in {corpus}", folderCorpusPath); - throw ex; + throw; } } diff --git a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Extensions/EndpointServicesEx.cs b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Extensions/EndpointServicesEx.cs index 29d470a30d..4d8d182eab 100644 --- a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Extensions/EndpointServicesEx.cs +++ b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Extensions/EndpointServicesEx.cs @@ -20,8 +20,8 @@ public static class EndpointServicesEx { /// /// /// - /// /// + /// /// /// public static Task ExecuteServiceAsync(this IEndpointServices client, @@ -34,8 +34,8 @@ public static class EndpointServicesEx { /// /// /// - /// /// + /// /// /// /// @@ -73,8 +73,8 @@ public static class EndpointServicesEx { /// /// /// - /// /// + /// /// /// /// @@ -107,8 +107,8 @@ public static class EndpointServicesEx { /// /// /// - /// /// + /// /// /// /// @@ -125,8 +125,8 @@ public static class EndpointServicesEx { /// /// /// - /// /// + /// /// /// /// diff --git a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Extensions/FilterEncoderEx.cs b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Extensions/FilterEncoderEx.cs index 89f9fdf9bf..cebcb386ee 100644 --- a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Extensions/FilterEncoderEx.cs +++ b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Extensions/FilterEncoderEx.cs @@ -36,8 +36,8 @@ public static class FilterEncoderEx { /// /// Convert to stack model /// - /// /// + /// /// /// public static EventFilter Decode(this IVariantEncoder encoder, EventFilterModel model, @@ -60,8 +60,8 @@ public static class FilterEncoderEx { /// /// Convert to stack model /// - /// /// + /// /// public static EventFilterModel Encode(this IVariantEncoder encoder, EventFilter model) { if (model == null) { @@ -78,8 +78,8 @@ public static class FilterEncoderEx { /// /// Convert to stack model /// - /// /// + /// /// /// public static ContentFilter Decode(this IVariantEncoder encoder, ContentFilterModel model, @@ -97,8 +97,8 @@ public static class FilterEncoderEx { /// /// Convert to service model /// - /// /// + /// /// public static ContentFilterModel Encode(this IVariantEncoder encoder, ContentFilter model) { if (model == null) { @@ -114,8 +114,8 @@ public static class FilterEncoderEx { /// /// Convert to stack model /// - /// /// + /// /// /// public static ContentFilterElement Decode(this IVariantEncoder encoder, @@ -135,8 +135,8 @@ public static class FilterEncoderEx { /// /// Convert to service model /// - /// /// + /// /// public static ContentFilterElementModel Encode(this IVariantEncoder encoder, ContentFilterElement model) { @@ -156,8 +156,8 @@ public static class FilterEncoderEx { /// /// Convert to stack model /// - /// /// + /// /// /// public static FilterOperand Decode(this IVariantEncoder encoder, @@ -197,8 +197,8 @@ public static class FilterEncoderEx { /// /// Convert to service model /// - /// /// + /// /// public static FilterOperandModel Encode(this IVariantEncoder encoder, FilterOperand model) { diff --git a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Extensions/OperationResultEx.cs b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Extensions/OperationResultEx.cs index 05607591bc..411a21f63d 100644 --- a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Extensions/OperationResultEx.cs +++ b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Extensions/OperationResultEx.cs @@ -34,8 +34,8 @@ public static class OperationResultEx { /// /// /// - /// /// + /// /// /// public static void Validate(string operation, diff --git a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Extensions/VariantEncoderEx.cs b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Extensions/VariantEncoderEx.cs index a84ac4abdd..6c87bfa0ac 100644 --- a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Extensions/VariantEncoderEx.cs +++ b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Extensions/VariantEncoderEx.cs @@ -58,8 +58,8 @@ public static class VariantEncoderEx { /// /// /// - /// /// + /// /// public static ServiceResultModel Encode(this IVariantEncoder codec, DiagnosticInfo diagnostics, @@ -80,8 +80,8 @@ public static class VariantEncoderEx { /// Convert from service result to diagnostics info /// /// - /// /// + /// /// /// public static DiagnosticInfo Decode(this IVariantEncoder codec, @@ -99,8 +99,8 @@ public static class VariantEncoderEx { /// Convert from service result to diagnostics info /// /// - /// /// + /// /// public static List Decode( this IVariantEncoder codec, ServiceResultModel result, DiagnosticsModel config) { @@ -137,8 +137,8 @@ public static class VariantEncoderEx { /// Convert to service model /// /// - /// /// + /// /// public static ServiceResultModel Encode(this IVariantEncoder codec, List diagnostics, DiagnosticsModel config) { @@ -161,8 +161,8 @@ public static class VariantEncoderEx { /// /// /// - /// /// + /// /// public static ServiceResultModel Encode(this IVariantEncoder codec, StatusCode? statusCode, DiagnosticInfo diagnosticsInfo = null, @@ -189,8 +189,8 @@ public static class VariantEncoderEx { /// Convert operation results to json /// /// - /// /// + /// /// private static VariantValue Write(this IVariantEncoder codec, List results, DiagnosticsModel config) { diff --git a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/IClientSession.cs b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/IClientSession.cs index 255b92fd18..73c33f8d5c 100644 --- a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/IClientSession.cs +++ b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/IClientSession.cs @@ -32,8 +32,8 @@ public interface IClientSession : IDisposable { /// /// /// - /// /// + /// /// /// /// diff --git a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Services/ClientServices.cs b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Services/ClientServices.cs index 1a0740579d..1d619ea653 100644 --- a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Services/ClientServices.cs +++ b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Services/ClientServices.cs @@ -29,17 +29,15 @@ namespace Microsoft.Azure.IIoT.OpcUa.Protocol.Services { /// public class ClientServices : IClientHost, IEndpointServices, IEndpointDiscovery, ICertificateServices, IDisposable { - /// /// Create client host services /// - /// /// + /// /// /// public ClientServices(ILogger logger, IClientServicesConfig clientConfig, IIdentity identity = null, TimeSpan? maxOpTimeout = null) { - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _clientConfig = clientConfig ?? @@ -56,20 +54,19 @@ public class ClientServices : IClientHost, IEndpointServices, IEndpointDiscovery public async Task InitializeAsync() { if (_appConfig == null) { _appConfig = await _clientConfig.ToApplicationConfigurationAsync( - _identity, true, VerifyCertificate); + _identity, true, VerifyCertificate).ConfigureAwait(false); } } /// - public Task AddTrustedPeerAsync(byte[] certificates) { - InitializeAsync().ConfigureAwait(false); + public async Task AddTrustedPeerAsync(byte[] certificates) { + await InitializeAsync().ConfigureAwait(false); var chain = Utils.ParseCertificateChainBlob(certificates)? .Cast() .Reverse() .ToList(); if (chain == null || chain.Count == 0) { - return Task.FromException( - new ArgumentNullException(nameof(certificates))); + throw new ArgumentNullException(nameof(certificates)); } var certificate = chain.First(); try { @@ -83,13 +80,13 @@ public class ClientServices : IClientHost, IEndpointServices, IEndpointDiscovery _appConfig.SecurityConfiguration.TrustedIssuerCertificates .Add(chain); } - return Task.CompletedTask; + return; } catch (Exception ex) { _logger.Error(ex, "Failed to add Certificate {Thumbprint}, " + "{Subject} to trust list.", certificate.Thumbprint, certificate.Subject); - return Task.FromException(ex); + throw; } finally { chain?.ForEach(c => c?.Dispose()); @@ -97,15 +94,14 @@ public class ClientServices : IClientHost, IEndpointServices, IEndpointDiscovery } /// - public Task RemoveTrustedPeerAsync(byte[] certificates) { - InitializeAsync().ConfigureAwait(false); + public async Task RemoveTrustedPeerAsync(byte[] certificates) { + await InitializeAsync().ConfigureAwait(false); var chain = Utils.ParseCertificateChainBlob(certificates)? .Cast() .Reverse() .ToList(); if (chain == null || chain.Count == 0) { - return Task.FromException( - new ArgumentNullException(nameof(certificates))); + throw new ArgumentNullException(nameof(certificates)); } var certificate = chain.First(); try { @@ -116,13 +112,13 @@ public class ClientServices : IClientHost, IEndpointServices, IEndpointDiscovery .Remove(certificate.YieldReturn()); // Remove only from trusted peers - return Task.CompletedTask; + return; } catch (Exception ex) { _logger.Error(ex, "Failed to remove Certificate {Thumbprint}, " + "{Subject} from trust list.", certificate.Thumbprint, certificate.Subject); - return Task.FromException(ex); + throw; } finally { chain?.ForEach(c => c?.Dispose()); @@ -182,7 +178,7 @@ public class ClientServices : IClientHost, IEndpointServices, IEndpointDiscovery /// public async Task> FindEndpointsAsync( Uri discoveryUrl, List locales, CancellationToken ct) { - await InitializeAsync(); + await InitializeAsync().ConfigureAwait(false); var results = new HashSet(); var visitedUris = new HashSet { CreateDiscoveryUri(discoveryUrl.ToString(), 4840) @@ -191,7 +187,7 @@ public class ClientServices : IClientHost, IEndpointServices, IEndpointDiscovery var localeIds = locales != null ? new StringCollection(locales) : null; queue.Enqueue(Tuple.Create(discoveryUrl, new List())); ct.ThrowIfCancellationRequested(); - while (queue.Any()) { + while (queue.Count > 0) { var nextServer = queue.Dequeue(); discoveryUrl = nextServer.Item1; var sw = Stopwatch.StartNew(); @@ -224,14 +220,14 @@ public class ClientServices : IClientHost, IEndpointServices, IEndpointDiscovery if (string.IsNullOrEmpty(endpoint?.Url)) { throw new ArgumentNullException(nameof(endpoint.Url)); } - await InitializeAsync(); + await InitializeAsync().ConfigureAwait(false); var configuration = EndpointConfiguration.Create(_appConfig); configuration.OperationTimeout = 20000; var discoveryUrl = new Uri(endpoint.Url); using (var client = DiscoveryClient.Create(discoveryUrl, configuration)) { // Get endpoint descriptions from endpoint url var endpoints = await client.GetEndpointsAsync(null, - client.Endpoint.EndpointUrl, null, null); + client.Endpoint.EndpointUrl, null, null).ConfigureAwait(false); // Match to provided endpoint info var ep = endpoints.Endpoints?.FirstOrDefault(e => e.IsSameAs(endpoint)); @@ -254,7 +250,7 @@ public class ClientServices : IClientHost, IEndpointServices, IEndpointDiscovery if (string.IsNullOrEmpty(connection.Endpoint?.Url)) { throw new ArgumentNullException(nameof(connection.Endpoint.Url)); } - await InitializeAsync(); + await InitializeAsync().ConfigureAwait(false); var key = new ConnectionIdentifier(connection); while (true) { _cts.Token.ThrowIfCancellationRequested(); @@ -264,7 +260,7 @@ public class ClientServices : IClientHost, IEndpointServices, IEndpointDiscovery service, handler, timeout, ct, out var result); if (scheduled) { // Session is owning the task to completion now. - return await result; + return await result.ConfigureAwait(false); } } // Create new session next go around @@ -285,7 +281,6 @@ public class ClientServices : IClientHost, IEndpointServices, IEndpointDiscovery private async Task DiscoverAsync(Uri discoveryUrl, StringCollection localeIds, IEnumerable caps, int timeout, HashSet visitedUris, Queue>> queue, HashSet result) { - var configuration = EndpointConfiguration.Create(_appConfig); configuration.OperationTimeout = timeout; using (var client = DiscoveryClient.Create(discoveryUrl, configuration)) { @@ -293,7 +288,7 @@ public class ClientServices : IClientHost, IEndpointServices, IEndpointDiscovery // Get endpoints from current discovery server // var endpoints = await client.GetEndpointsAsync(null, - client.Endpoint.EndpointUrl, localeIds, null); + client.Endpoint.EndpointUrl, localeIds, null).ConfigureAwait(false); if (!(endpoints?.Endpoints?.Any() ?? false)) { _logger.Debug("No endpoints at {discoveryUrl}...", discoveryUrl); return; @@ -317,7 +312,7 @@ public class ClientServices : IClientHost, IEndpointServices, IEndpointDiscovery // try { var response = await client.FindServersOnNetworkAsync(null, 0, 1000, - new StringCollection()); + new StringCollection()).ConfigureAwait(false); var servers = response?.Servers ?? new ServerOnNetworkCollection(); foreach (var server in servers) { var url = CreateDiscoveryUri(server.DiscoveryUrl, discoveryUrl.Port); @@ -339,7 +334,7 @@ public class ClientServices : IClientHost, IEndpointServices, IEndpointDiscovery // into the discovery queue // var found = await client.FindServersAsync(null, - client.Endpoint.EndpointUrl, localeIds, null); + client.Endpoint.EndpointUrl, localeIds, null).ConfigureAwait(false); if (found?.Servers != null) { var servers = found.Servers.SelectMany(s => s.DiscoveryUrls); foreach (var server in servers) { @@ -357,7 +352,6 @@ public class ClientServices : IClientHost, IEndpointServices, IEndpointDiscovery /// Create session /// /// - /// private IClientSession GetOrCreateSession(ConnectionIdentifier id) { _lock.Wait(); try { @@ -378,7 +372,6 @@ public class ClientServices : IClientHost, IEndpointServices, IEndpointDiscovery /// /// Called when timer fired evicting inactive / timedout sessions /// - /// private void OnTimer() { if (_cts.IsCancellationRequested) { return; @@ -410,7 +403,6 @@ public class ClientServices : IClientHost, IEndpointServices, IEndpointDiscovery /// Handle inactive /// /// - /// private void EvictIfInactive(ConnectionIdentifier id) { _lock.Wait(); try { @@ -433,7 +425,7 @@ public class ClientServices : IClientHost, IEndpointServices, IEndpointDiscovery /// private void VerifyCertificate(CertificateValidator validator, CertificateValidationEventArgs e) { - if (e.Accept == true) { + if (e.Accept) { return; } if (e.Error.StatusCode == StatusCodes.BadCertificateUntrusted) { @@ -456,7 +448,6 @@ public class ClientServices : IClientHost, IEndpointServices, IEndpointDiscovery /// /// /// - /// private static string CreateDiscoveryUri(string uri, int defaultPort) { var url = new UriBuilder(uri); if (url.Port == 0 || url.Port == -1) { @@ -472,7 +463,6 @@ public class ClientServices : IClientHost, IEndpointServices, IEndpointDiscovery /// /// /// - /// private Task NotifyStateChangeAsync(ConnectionModel connection, EndpointConnectivityState state) { var id = new ConnectionIdentifier(connection); @@ -491,7 +481,6 @@ public class ClientServices : IClientHost, IEndpointServices, IEndpointDiscovery /// Disposable callback handle /// private class CallbackHandle : IDisposable { - /// /// Callback /// diff --git a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Services/ClientSession.cs b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Services/ClientSession.cs index 3f6989237d..16e41ac734 100644 --- a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Services/ClientSession.cs +++ b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Services/ClientSession.cs @@ -62,7 +62,7 @@ internal sealed class ClientSession : IClientSession { _urlQueue = new ConcurrentQueue(_connection.Endpoint.GetAllUrls()); _queue = new PriorityQueue(); _enqueueEvent = new TaskCompletionSource( - TaskContinuationOptions.RunContinuationsAsynchronously); + TaskCreationOptions.RunContinuationsAsynchronously); #pragma warning disable RECS0002 // Convert anonymous method to method group _processor = Task.Factory.StartNew(() => RunAsync(), _cts.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default).Unwrap(); @@ -75,11 +75,11 @@ internal sealed class ClientSession : IClientSession { /// /// Application configuration /// Endpoint to connect to - /// Session timeout + /// Logger /// Status callback for reporting /// - /// Logger /// Optional session name + /// Session timeout /// Keep alive interval public static IClientSession Create(ApplicationConfiguration config, ConnectionModel connection, ILogger logger, Func /// Application configuration /// Endpoint to connect to - /// Session timeout + /// Logger /// Status callback for reporting /// - /// Logger /// Optional session name + /// Session timeout /// Keep alive interval public static (IClientSession, ISessionHandle) CreateWithHandle( ApplicationConfiguration config, ConnectionModel connection, @@ -495,7 +495,7 @@ internal sealed class ClientSession : IClientSession { // Wait on a fresh task or on the not yet completed on if (tcs.Task.IsCompleted) { var newEvent = new TaskCompletionSource( - TaskContinuationOptions.RunContinuationsAsynchronously); + TaskCreationOptions.RunContinuationsAsynchronously); if (Interlocked.CompareExchange(ref _enqueueEvent, newEvent, tcs) == tcs) { // Exchanged safely now we can wait for it. tcs = newEvent; @@ -657,7 +657,7 @@ internal sealed class ClientSession : IClientSession { var complexTypeSystem = new ComplexTypeSystem(session); await complexTypeSystem.Load(); } - catch (Exception ex){ + catch (Exception ex) { _logger.Error(ex, "Failed to load complex type system"); } return session; diff --git a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Stack/Design/Model.cs b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Stack/Design/Model.cs index 935753156e..ee7315baf0 100644 --- a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Stack/Design/Model.cs +++ b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Stack/Design/Model.cs @@ -62,14 +62,16 @@ public static class Model { // Try to load as type dictionary if (!design.CanSeek) { // Stream is already partitially read - need to reset - if we cannot throw - throw ex; + throw; } try { design.Seek(0, SeekOrigin.Begin); return LoadTypeDictionary(design, assigner, resolver); } catch { +#pragma warning disable CA2200 // Rethrow to preserve stack details throw ex; +#pragma warning restore CA2200 // Rethrow to preserve stack details } } } diff --git a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Stack/Encoders/ModelDecoder.cs b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Stack/Encoders/ModelDecoder.cs index 09922bbcda..d8cafc60df 100644 --- a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Stack/Encoders/ModelDecoder.cs +++ b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Stack/Encoders/ModelDecoder.cs @@ -23,8 +23,8 @@ public class ModelDecoder : IDecoder, IDisposable { /// /// Create wrapper /// - /// /// + /// /// public ModelDecoder(Stream stream, string contentType, ServiceMessageContext context = null) : diff --git a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Stack/Encoders/ModelEncoder.cs b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Stack/Encoders/ModelEncoder.cs index 9773aa3ecb..f332aea03f 100644 --- a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Stack/Encoders/ModelEncoder.cs +++ b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Stack/Encoders/ModelEncoder.cs @@ -20,8 +20,8 @@ public class ModelEncoder : IEncoder, IDisposable { /// Create wrapper /// /// - /// /// + /// /// public ModelEncoder(Stream stream, string contentType, Action callback = null, diff --git a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Stack/Extensions/EndpointDescriptionEx.cs b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Stack/Extensions/EndpointDescriptionEx.cs index 48f3611f29..9c4e5fc5dc 100644 --- a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Stack/Extensions/EndpointDescriptionEx.cs +++ b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Stack/Extensions/EndpointDescriptionEx.cs @@ -15,8 +15,8 @@ public static class EndpointDescriptionEx { /// /// Matches model /// - /// /// + /// /// public static bool IsSameAs(this EndpointDescription endpoint, EndpointModel model) { diff --git a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Stack/Nodeset/NodeSet2.cs b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Stack/Nodeset/NodeSet2.cs index 59645a1b5f..cca6283a6f 100644 --- a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Stack/Nodeset/NodeSet2.cs +++ b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Stack/Nodeset/NodeSet2.cs @@ -23,8 +23,8 @@ public class NodeSet2 { /// Creates a nodeset from node state collection /// /// - /// /// + /// /// /// public static NodeSet2 CreateFromNodeStateCollection(NodeStateCollection collection, @@ -48,8 +48,8 @@ public class NodeSet2 { /// Creates a nodeset from node state collection /// /// - /// /// + /// /// /// public static NodeSet2 Create(IEnumerable nodes, @@ -77,7 +77,11 @@ public class NodeSet2 { var reader = new StreamReader(stream); try { var serializer = new XmlSerializer(typeof(UANodeSet)); - return new NodeSet2(serializer.Deserialize(reader) as UANodeSet); + var xmlReader = new XmlTextReader(reader) { + DtdProcessing = DtdProcessing.Prohibit, + XmlResolver = null + }; + return new NodeSet2(serializer.Deserialize(xmlReader) as UANodeSet); } finally { reader.Dispose(); diff --git a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Transport/Probe/ServerProbe.cs b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Transport/Probe/ServerProbe.cs index 74bd93818e..1260c5169b 100644 --- a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Transport/Probe/ServerProbe.cs +++ b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Protocol/src/Transport/Probe/ServerProbe.cs @@ -74,8 +74,8 @@ private class ServerHelloAsyncProbe : IAsyncProbe { /// /// Called whenever socket operation completes /// - /// /// + /// /// /// /// true if completed, false to be called again diff --git a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Registry/src/Services/EndpointRegistry.cs b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Registry/src/Services/EndpointRegistry.cs index 44c805052a..4d5c7e399d 100644 --- a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Registry/src/Services/EndpointRegistry.cs +++ b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Registry/src/Services/EndpointRegistry.cs @@ -240,10 +240,10 @@ public sealed class EndpointRegistry : IEndpointRegistry, IApplicationEndpointRe } await ActivateAsync(registration, context, ct); } - catch (Exception ex) { + catch (Exception) { // Try other supervisors as candidates if (!await ActivateAsync(registration, null, context, ct)) { - throw ex; + throw; } } } @@ -764,7 +764,7 @@ public sealed class EndpointRegistry : IEndpointRegistry, IApplicationEndpointRe await Try.Async(() => ClearSupervisorTwinSecretAsync( registration.DeviceId, registration.SupervisorId)); _logger.Error(ex, "Failed to activate twin"); - throw ex; + throw; } } diff --git a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Testing/src/Servers/TestData/TestDataObjectState.cs b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Testing/src/Servers/TestData/TestDataObjectState.cs index a073e3ed3a..d03bf1ea06 100644 --- a/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Testing/src/Servers/TestData/TestDataObjectState.cs +++ b/components/opc-ua/src/Microsoft.Azure.IIoT.OpcUa.Testing/src/Servers/TestData/TestDataObjectState.cs @@ -126,8 +126,8 @@ public partial class TestDataObjectState { return ServiceResult.Good; } - catch (Exception e) { - throw e; + catch (Exception) { + throw; } } diff --git a/services/src/Microsoft.Azure.IIoT.Services.All/src/Startup.cs b/services/src/Microsoft.Azure.IIoT.Services.All/src/Startup.cs index 586a75ad8b..f30e83786a 100644 --- a/services/src/Microsoft.Azure.IIoT.Services.All/src/Startup.cs +++ b/services/src/Microsoft.Azure.IIoT.Services.All/src/Startup.cs @@ -187,7 +187,7 @@ private sealed class ProcessorHost : IHostProcess, IDisposable, IHealthCheck { if (aex.InnerExceptions.All(e => e is OperationCanceledException)) { return; } - throw aex; + throw; } } diff --git a/tools/templates/sdl.yml b/tools/templates/sdl.yml index c3288af895..f527dda0dd 100644 --- a/tools/templates/sdl.yml +++ b/tools/templates/sdl.yml @@ -25,15 +25,18 @@ jobs: - task: DotNetCoreCLI@2 displayName: Restore inputs: - command: restore + command: build projects: 'Industrial-IoT.sln' feedsToUse: 'config' nugetConfigPath: './NuGet.Config' + # note: /p:SDL=true is used to enable build analyzers + arguments: '--configuration Release /p:SDL=true' - task: MSBuild@1 displayName: Build inputs: solution: 'Industrial-IoT.sln' configuration: Release + msbuildArguments: /p:SDL=true - task: securedevelopmentteam.vss-secure-development-tools.build-task-credscan.CredScan@2 displayName: 'Credential Scanner' inputs: