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

Initial version of the application. #1

Open
wants to merge 53 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
5b0d697
Add initial empty projects.
razvanionapp Jun 5, 2022
b2d0cc9
Setting up the initial empty projects.
razvanionapp Jun 5, 2022
c05ae6a
Modified gitignore to ignore .vs folder
razvanionapp Jun 5, 2022
d3318c1
Update gitignore for .vs, bin and obj folders.
razvanionapp Jun 6, 2022
958d5be
Add original code for Pkcs11Signature and X509Certificate2Signature. …
razvanionapp Jun 6, 2022
adab008
Change Pkcs11Signature to get only the slots that have an inserted to…
razvanionapp Jun 6, 2022
96cf456
squash! Change Pkcs11Signature to get only the slots that have an ins…
razvanionapp Jun 6, 2022
2c4ebd7
Change X509Certificate2Signature to support RSACng, passing the PIN p…
razvanionapp Jun 6, 2022
61e0a18
Create IExternalSignatureWithChain from base IExternalSignature and h…
razvanionapp Jun 6, 2022
96c8a9b
Create SignatureFactory
razvanionapp Jun 6, 2022
94c3d55
Add the pdf auto signer top level functionality.
razvanionapp Jun 6, 2022
27f5a78
Rename IPdfAutoSigner to IDocAutoSigner and PdfAutoSigner to PdfDocAu…
razvanionapp Jun 6, 2022
46341b7
Ignore csproj.user files.
razvanionapp Jun 6, 2022
832674b
Update parameter order and default values
razvanionapp Jun 6, 2022
9bf0403
Add the console app and the unit tests projects for Lib.
razvanionapp Jun 6, 2022
a64b988
Updated README.md in the PdfAutoSigner.Lib.App
razvanionapp Jun 6, 2022
6b2fe11
Add support to be able to run as a service\daemon
razvanionapp Jun 6, 2022
c8c9355
Fix localhost port number
razvanionapp Jun 6, 2022
430ba78
Enable CORS.
razvanionapp Jun 6, 2022
8df3c52
Full flow between the lib and the web app.
razvanionapp Jun 7, 2022
faa2e30
Update tokensettings.json - SafeNet for 32 bit.
razvanionapp Jun 8, 2022
6f10606
Add log4net support; log to files from the web app
razvanionapp Jun 8, 2022
17158cc
Check for pin and signature in SignController
razvanionapp Jun 8, 2022
1590e83
Add Select(pin) so that we can actually use the signature from contro…
razvanionapp Jun 8, 2022
dafd134
Add generic exception handler. Improve exception handling and logging.
razvanionapp Jun 8, 2022
19fdcba
Scripts to publish to windows and mac.
razvanionapp Jun 10, 2022
e19724b
Working Windows installer.
razvanionapp Jun 14, 2022
042b3f9
Updated osx_package.
razvanionapp Jun 16, 2022
2e54015
Added unit tests for LocalApp and some refactoring.
razvanionapp Jun 16, 2022
24c1802
Add azure-pipelines.yml
razvanionapp Jun 16, 2022
e52cc4c
Fixed compilation issue in the LocalApi tests
razvanionapp Jun 16, 2022
c75055b
Create an Azure pipeline for installers
razvanionapp Jun 17, 2022
e0ed29d
Add azure installers pipeline
razvanionapp Jun 17, 2022
2e86960
Create the actual pipeline for Windows and MacOS installers.
razvanionapp Jun 20, 2022
10a21d7
Updated README files and the solution.
razvanionapp Jun 21, 2022
295f8d0
Add swagger, version controller and cleanup solution.
razvanionapp Jun 21, 2022
4e9f5e7
Fixed warnings. Logout user from token with pkcs11. Ignore wix genera…
razvanionapp Jun 21, 2022
c834582
Ignore ComponentsGenerated.wxs
razvanionapp Jun 21, 2022
9cfb045
Fix tests.
razvanionapp Jun 21, 2022
dcd0177
Fix test running in the Azure pipeline.
razvanionapp Jun 21, 2022
0d9695a
Run tests on macOS
razvanionapp Jun 21, 2022
a520cc8
Print private key type.
razvanionapp Jun 22, 2022
e082232
Update certificate signature class to use the new getters for the pri…
razvanionapp Jun 22, 2022
353483f
Fix algorithms to SHA256.
razvanionapp Jun 22, 2022
b30bb55
Create test to sign a document with a self-signed certificate without…
razvanionapp Jun 22, 2022
569cdaa
Fixed test on macOS.
razvanionapp Jun 22, 2022
81dfc3f
Add license header to all code files.
razvanionapp Jun 22, 2022
0e65f06
Create Directory.Build.Props to add copyright, license, versioning et…
razvanionapp Jun 23, 2022
a3dd2e9
Enable AllOrigins CORS.
razvanionapp Jun 27, 2022
e844618
Add file to describe the token settings file.
razvanionapp Jun 27, 2022
346b4a5
Moved from Windows service to Windows scheduled task.
razvanionapp Jun 29, 2022
f316840
Clean warnings. Enhanced logging for the config. Update docs.
razvanionapp Jun 30, 2022
b7bd469
Fixed unit test. Improved documentation.
razvanionapp Jun 30, 2022
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
237 changes: 237 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
# Remove the line below if you want to inherit .editorconfig settings from higher directories
root = true

# C# files
[*.cs]

#### Core EditorConfig Options ####

# Indentation and spacing
indent_size = 4
indent_style = space
tab_width = 4

# New line preferences
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
file_header_template = unset

# this. and Me. preferences
dotnet_style_qualification_for_event = false
dotnet_style_qualification_for_field = false
dotnet_style_qualification_for_method = false
dotnet_style_qualification_for_property = false

# Language keywords vs BCL types preferences
dotnet_style_predefined_type_for_locals_parameters_members = true
dotnet_style_predefined_type_for_member_access = true

# Parentheses preferences
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity
dotnet_style_parentheses_in_other_operators = never_if_unnecessary
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity

# Modifier preferences
dotnet_style_require_accessibility_modifiers = for_non_interface_members

# Expression-level preferences
dotnet_style_coalesce_expression = true
dotnet_style_collection_initializer = true
dotnet_style_explicit_tuple_names = true
dotnet_style_namespace_match_folder = true
dotnet_style_null_propagation = true
dotnet_style_object_initializer = true
dotnet_style_operator_placement_when_wrapping = beginning_of_line
dotnet_style_prefer_auto_properties = true
dotnet_style_prefer_compound_assignment = true
dotnet_style_prefer_conditional_expression_over_assignment = true
dotnet_style_prefer_conditional_expression_over_return = true
dotnet_style_prefer_inferred_anonymous_type_member_names = true
dotnet_style_prefer_inferred_tuple_names = true
dotnet_style_prefer_is_null_check_over_reference_equality_method = true
dotnet_style_prefer_simplified_boolean_expressions = true
dotnet_style_prefer_simplified_interpolation = true

# Field preferences
dotnet_style_readonly_field = true

# Parameter preferences
dotnet_code_quality_unused_parameters = all

# Suppression preferences
dotnet_remove_unnecessary_suppression_exclusions = none

# New line preferences
dotnet_style_allow_multiple_blank_lines_experimental = true
dotnet_style_allow_statement_immediately_after_block_experimental = true

#### C# Coding Conventions ####

# var preferences
csharp_style_var_elsewhere = false
csharp_style_var_for_built_in_types = false
csharp_style_var_when_type_is_apparent = false

# Expression-bodied members
csharp_style_expression_bodied_accessors = true:silent
csharp_style_expression_bodied_constructors = false:silent
csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = false:silent
csharp_style_expression_bodied_methods = false:silent
csharp_style_expression_bodied_operators = false:silent
csharp_style_expression_bodied_properties = true:silent

# Pattern matching preferences
csharp_style_pattern_matching_over_as_with_null_check = true
csharp_style_pattern_matching_over_is_with_cast_check = true
csharp_style_prefer_extended_property_pattern = true
csharp_style_prefer_not_pattern = true
csharp_style_prefer_pattern_matching = true
csharp_style_prefer_switch_expression = true

# Null-checking preferences
csharp_style_conditional_delegate_call = true
csharp_style_prefer_parameter_null_checking = true

# Modifier preferences
csharp_prefer_static_local_function = true
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:silent
csharp_prefer_simple_using_statement = true:suggestion
csharp_style_namespace_declarations = block_scoped:silent
csharp_style_prefer_method_group_conversion = true:silent

# Expression-level preferences
csharp_prefer_simple_default_expression = true
csharp_style_deconstructed_variable_declaration = true
csharp_style_implicit_object_creation_when_type_is_apparent = true
csharp_style_inlined_variable_declaration = true
csharp_style_prefer_index_operator = true
csharp_style_prefer_local_over_anonymous_function = true
csharp_style_prefer_null_check_over_type_check = true
csharp_style_prefer_range_operator = true
csharp_style_prefer_tuple_swap = true
csharp_style_throw_expression = true
csharp_style_unused_value_assignment_preference = discard_variable
csharp_style_unused_value_expression_statement_preference = discard_variable

# 'using' directive preferences
csharp_using_directive_placement = outside_namespace:silent

# New line preferences
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true
csharp_style_allow_embedded_statements_on_same_line_experimental = true

#### 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 = all
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

# 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

# Wrapping preferences
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.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

# Symbol specifications

dotnet_naming_symbols.interface.applicable_kinds = interface
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
dotnet_naming_symbols.interface.required_modifiers =

dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
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, private_protected
dotnet_naming_symbols.non_field_members.required_modifiers =

# 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.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

[*.{cs,vb}]
dotnet_style_coalesce_expression = true:suggestion
dotnet_style_null_propagation = true:suggestion
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_object_initializer = true:suggestion
dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 4
indent_size = 4
end_of_line = crlf
dotnet_style_collection_initializer = true:suggestion

file_header_template = PdfAutoSigner signs PDF files automatically using a hardware security module. \nCopyright (C) Plant An App\n \nThis program is free software: you can redistribute it and/or modify \nit under the terms of the GNU Affero General Public License as \npublished by the Free Software Foundation, either version 3 of the \nLicense, or (at your option) any later version. \n \nThis program is distributed in the hope that it will be useful, \nbut WITHOUT ANY WARRANTY; without even the implied warranty of \nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \nGNU Affero General Public License for more details. \n \nYou should have received a copy of the GNU Affero General Public License \nalong with this program. If not, see <https://www.gnu.org/licenses/>.
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
################################################################################
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
################################################################################

**/bin/
**/obj/
.vs/
**/*.csproj.user

**/hello-signed-pkcs11.pdf
**/hello-signed-cert.pdf
Comment on lines +10 to +11
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not think we should have these here.

PdfAutoSigner.LocalApi.Installer/Installs/**
PdfAutoSigner.LocalApi.Installer/ComponentsGenerated.wxs
/PdfAutoSigner.LocalApi.Installer/ComponentsGenerated.wxs
13 changes: 13 additions & 0 deletions Directory.Build.Props
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project>
<PropertyGroup>
<Version>1.0.0.0</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<FileVersion>1.0.0.0</FileVersion>
<Company>PlantAnApp, iText Group</Company>
<Authors>Plant An App, iText Group</Authors>
<Copyright>(C) Plant An App, (C) iText Group</Copyright>
<PackageLicenseFile>C:\Work\Projects\PdfAutoSignerAndJava\_code\PlantAnApp.PdfAutoSigner\license.rtf</PackageLicenseFile>
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
<RepositoryUrl>https://github.com/razvanionapp/PlantAnApp.PdfAutoSigner.git</RepositoryUrl>
Comment on lines +6 to +11
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this should be updated.

</PropertyGroup>
</Project>
40 changes: 40 additions & 0 deletions PdfAutoSigner.Lib.App/CommandLineOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// PdfAutoSigner signs PDF files automatically using a hardware security module.
// Copyright (C) Plant An App
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY

using CommandLine;
using System.Diagnostics.CodeAnalysis;

namespace PdfAutoSigner.Lib.App
{
internal class CommandLineOptions
{
[Value(index: 0, Required = true, HelpText = "Input Pdf to sign.")]
[NotNull]
public string? InputFilePath { get; set; }

[Value(index: 1, Required = true, HelpText = "Output Pdf to sign.")]
[NotNull]
public string? OutputFilePath { get; set; }

[Value(index: 2, Required = true, HelpText = "Lib path (for PKCS11 mode) or issuer name (for certificates mode).")]
[NotNull]
public string? LibPathOrIssuerName { get; set; }

[Option(shortName: 'c', Required = false, HelpText = "Use certificates to sign. By default it uses PKCS11.", Default = false)]
public bool UseCertificates { get; set; }

[Option(shortName: 'p', Required = false, HelpText = "Pin for the usb token. If not provided, it will try to read the 'TokenPin' from the config.", Default = null)]
public string? Pin { get; set; }

[Option(shortName: 'i', Required = false, HelpText = "Index of the signature to sign the certificate with.", Default = 0UL)]
public ulong SignatureIdx { get; set; }
}
}
32 changes: 32 additions & 0 deletions PdfAutoSigner.Lib.App/ConfigHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// PdfAutoSigner signs PDF files automatically using a hardware security module.
// Copyright (C) Plant An App
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY

using Microsoft.Extensions.Configuration;
namespace PdfAutoSigner.Lib.App
{
internal class ConfigHelper
{
private const string PinSecretsManagerPath = "TokenPin";

public static IConfigurationRoot GetIConfigurationRoot()
{
return new ConfigurationBuilder()
.AddUserSecrets("fb3dd1b7-a8ac-499d-bd09-c2760b970f39")
.Build();
}

public static string GetPin()
{
var config = GetIConfigurationRoot();
return config[PinSecretsManagerPath];
}
}
}
23 changes: 23 additions & 0 deletions PdfAutoSigner.Lib.App/PdfAutoSigner.Lib.App.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<UserSecretsId>fb3dd1b7-a8ac-499d-bd09-c2760b970f39</UserSecretsId>
<Platforms>AnyCPU</Platforms>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\PdfAutoSigner.Lib\PdfAutoSigner.Lib.csproj" />
</ItemGroup>

</Project>
Loading