rucades 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/.rubocop.yml +18 -0
  4. data/Gemfile +16 -0
  5. data/LICENSE.txt +21 -0
  6. data/README.md +132 -0
  7. data/Rakefile +21 -0
  8. data/ext/rucades/cplib/Blob.h +192 -0
  9. data/ext/rucades/cplib/DateTime.h +518 -0
  10. data/ext/rucades/cplib/StringProxy.h +281 -0
  11. data/ext/rucades/cpstldll.h +183 -0
  12. data/ext/rucades/errormsg.cpp +561 -0
  13. data/ext/rucades/errormsg.h +31 -0
  14. data/ext/rucades/extconf.rb +91 -0
  15. data/ext/rucades/rucades.cpp +90 -0
  16. data/ext/rucades/rucades.h +14 -0
  17. data/ext/rucades/rucades_about.cpp +75 -0
  18. data/ext/rucades/rucades_about.h +26 -0
  19. data/ext/rucades/rucades_algorithm.cpp +54 -0
  20. data/ext/rucades/rucades_algorithm.h +28 -0
  21. data/ext/rucades/rucades_attribute.cpp +112 -0
  22. data/ext/rucades/rucades_attribute.h +30 -0
  23. data/ext/rucades/rucades_attributes.cpp +62 -0
  24. data/ext/rucades/rucades_attributes.h +28 -0
  25. data/ext/rucades/rucades_basic_constraints.cpp +67 -0
  26. data/ext/rucades/rucades_basic_constraints.h +27 -0
  27. data/ext/rucades/rucades_blobs.cpp +46 -0
  28. data/ext/rucades/rucades_blobs.h +25 -0
  29. data/ext/rucades/rucades_certificate.cpp +182 -0
  30. data/ext/rucades/rucades_certificate.h +59 -0
  31. data/ext/rucades/rucades_certificate_status.cpp +36 -0
  32. data/ext/rucades/rucades_certificate_status.h +23 -0
  33. data/ext/rucades/rucades_certificates.cpp +140 -0
  34. data/ext/rucades/rucades_certificates.h +31 -0
  35. data/ext/rucades/rucades_const.cpp +241 -0
  36. data/ext/rucades/rucades_crl.cpp +84 -0
  37. data/ext/rucades/rucades_crl.h +29 -0
  38. data/ext/rucades/rucades_eku.cpp +55 -0
  39. data/ext/rucades/rucades_eku.h +26 -0
  40. data/ext/rucades/rucades_ekus.cpp +43 -0
  41. data/ext/rucades/rucades_ekus.h +27 -0
  42. data/ext/rucades/rucades_encoded_data.cpp +41 -0
  43. data/ext/rucades/rucades_encoded_data.h +23 -0
  44. data/ext/rucades/rucades_enveloped_data.cpp +122 -0
  45. data/ext/rucades/rucades_enveloped_data.h +33 -0
  46. data/ext/rucades/rucades_extended_key_usage.cpp +53 -0
  47. data/ext/rucades/rucades_extended_key_usage.h +27 -0
  48. data/ext/rucades/rucades_hashed_data.cpp +90 -0
  49. data/ext/rucades/rucades_hashed_data.h +31 -0
  50. data/ext/rucades/rucades_key_usage.cpp +116 -0
  51. data/ext/rucades/rucades_key_usage.h +33 -0
  52. data/ext/rucades/rucades_oid.cpp +70 -0
  53. data/ext/rucades/rucades_oid.h +30 -0
  54. data/ext/rucades/rucades_private_key.cpp +86 -0
  55. data/ext/rucades/rucades_private_key.h +31 -0
  56. data/ext/rucades/rucades_public_key.cpp +59 -0
  57. data/ext/rucades/rucades_public_key.h +28 -0
  58. data/ext/rucades/rucades_raw_signature.cpp +42 -0
  59. data/ext/rucades/rucades_raw_signature.h +26 -0
  60. data/ext/rucades/rucades_recipients.cpp +63 -0
  61. data/ext/rucades/rucades_recipients.h +28 -0
  62. data/ext/rucades/rucades_signature_status.cpp +35 -0
  63. data/ext/rucades/rucades_signature_status.h +23 -0
  64. data/ext/rucades/rucades_signed_data.cpp +253 -0
  65. data/ext/rucades/rucades_signed_data.h +41 -0
  66. data/ext/rucades/rucades_signed_xml.cpp +87 -0
  67. data/ext/rucades/rucades_signed_xml.h +29 -0
  68. data/ext/rucades/rucades_signer.cpp +157 -0
  69. data/ext/rucades/rucades_signer.h +45 -0
  70. data/ext/rucades/rucades_signers.cpp +43 -0
  71. data/ext/rucades/rucades_signers.h +27 -0
  72. data/ext/rucades/rucades_store.cpp +78 -0
  73. data/ext/rucades/rucades_store.h +34 -0
  74. data/ext/rucades/rucades_symmetric_algorithm.cpp +107 -0
  75. data/ext/rucades/rucades_symmetric_algorithm.h +30 -0
  76. data/ext/rucades/rucades_tools.cpp +18 -0
  77. data/ext/rucades/rucades_version.cpp +60 -0
  78. data/ext/rucades/rucades_version.h +24 -0
  79. data/ext/rucades/stdafx.h +190 -0
  80. data/lib/rucades/version.rb +9 -0
  81. data/lib/rucades.rb +36 -0
  82. data/samples/encrypt_decrypt.rb +25 -0
  83. data/samples/sign_verify.rb +28 -0
  84. data/samples/sign_verify_hash.rb +30 -0
  85. data/samples/sign_verify_xml.rb +44 -0
  86. data/sig/rucades.rbs +4 -0
  87. metadata +156 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 4fd27dc9278b75b81b8fc96898ce331306aecc605c1a835c7faf489636bd7fb7
4
+ data.tar.gz: df1a0809662b65193fefc70717625ddf113b579c9834b7c5280eef4027636498
5
+ SHA512:
6
+ metadata.gz: 0c13087b8bec3848b95fda4c4b30f5036cab7e7f7b5a6b41ca59668d66fdd2c17ffec3d5f034230dd9ec31aec8c83ad6e5359ec20812ef1b82d6bfb7c0cc3e60
7
+ data.tar.gz: 8e1209804fd594a1959685c2c5196d3f374cffac2dfeae3072d41bf9313c1470fd22a0804c57bec6a5a501f602308cd9e362c6c3f121f8265cad261bc9d6cfb9
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,18 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.7
3
+ SuggestExtensions: false
4
+ NewCops: enable
5
+
6
+ Style/StringLiterals:
7
+ Enabled: true
8
+ EnforcedStyle: double_quotes
9
+
10
+ Style/StringLiteralsInInterpolation:
11
+ Enabled: true
12
+ EnforcedStyle: double_quotes
13
+
14
+ Layout/LineLength:
15
+ Max: 150
16
+
17
+ Gemspec/RequireMFA:
18
+ Enabled: false
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2023 Maxim [maxirmx] Samsonov (https://sw.consulting)
4
+ # All rights reserved.
5
+ # This file is a part of rucades
6
+
7
+ source "https://rubygems.org"
8
+
9
+ gemspec
10
+
11
+ gem "rake", "~> 13.0"
12
+ gem "rake-compiler", "~> 1.2"
13
+ gem "rspec", "~> 3.0"
14
+ gem "rubocop", "~> 1.21"
15
+ gem "rubocop-rake", "~> 0.6"
16
+ gem "rubocop-rspec", "~> 2.23"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2023 Maxim Samsonov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,132 @@
1
+ # Rucades
2
+
3
+ Вас приветсвует Rucades - CAdESCOM Ruby binding!
4
+
5
+ Gem реализует интерфейс, аналогичный [CAdESCOM](https://docs.cryptopro.ru/cades/reference/cadescom)
6
+ и разработан путём повторения функциональности [pycades](https://docs.cryptopro.ru/cades/pycades)
7
+
8
+ [![Build-and-test](https://github.com/maxirmx/rucades/actions/workflows/main.yml/badge.svg)](https://github.com/maxirmx/rucades/actions/workflows/main.yml)
9
+
10
+ ## Совместимость
11
+
12
+ Gem тестировался в следующем окружении:
13
+ * Ububtu 20, 22
14
+ * Ruby 2.7.8, 3.1.7, 3.2.11, 3.3.11, 3.4.9, 4.0.5
15
+
16
+ Вероятно, Gem совместим с другими вариантами Linux, однако КриптоПро ЭЦП SDK доступно только для Ubuntu.
17
+
18
+ ## Установка
19
+
20
+ * Установите пакеты для сборки
21
+ ```
22
+ sudo apt update
23
+ sudo apt install cmake build-essential libboost-all-dev ruby-dev tar git wget libffi-dev
24
+ sudo gem install bundler
25
+ ```
26
+ * Скачайте архив с [КриптоПро CSP](https://cryptopro.ru/products/csp/downloads) для Вашей архитектуры, распакуйте его и установите КриптоПро CSP
27
+ Например,
28
+
29
+ _для amd64_
30
+ ```
31
+ wget -O linux-arm64_deb.tgz https://cryptopro.ru/sites/default/files/private/csp/50/11455/linux-arm64_deb.tgz
32
+ tar xvf linux-arm64_deb.tgz
33
+ cd linux-arm64_deb
34
+ sudo ./install.sh
35
+ ```
36
+
37
+ _для arm64_
38
+ ```
39
+ wget -O linux-arm64_deb.tgz https://cryptopro.ru/sites/default/files/private/csp/50/11455/linux-arm64_deb.tgz
40
+ tar xvf linux-arm64_deb.tgz
41
+ cd linux-arm64_deb
42
+ sudo ./install.sh
43
+ ```
44
+ * Установите пакет cprocsp-devel
45
+ ```
46
+ sudo apt install ./lsb-cprocsp-devel_5.0*.deb
47
+ ```
48
+ * Скачайте архив с [КриптоПро ЭЦП SDK](https://cryptopro.ru/products/cades/downloads), распакуйте его и установите пакет cprocsp-pki-cades (версия не ниже 2.0.14071)
49
+
50
+ _для amd64_
51
+ ```
52
+ tar xvf cades-linux-amd64.tar.gz
53
+ cd cades-linux-amd64
54
+ sudo apt install ./cprocsp-pki-cades*.deb
55
+ ```
56
+
57
+ _для arm64_
58
+ ```
59
+ tar xvf cades-linux-arm64.tar.gz
60
+ cd cades-linux-arm64
61
+ sudo apt install ./cprocsp-pki-cades*.deb
62
+ ```
63
+ * Добавьте в Gemfile Вашего проекта следующую строку:
64
+ ```
65
+ gem 'rucades', git: 'https://github.com/maxirmx/rucades'
66
+ ```
67
+
68
+ * Выполните
69
+ ```
70
+ bundle install
71
+ ```
72
+ !!! Компиляция расширения может занять 10-15 минут. Во время компиляции Ruby не выводит никаких сообщений. !!!
73
+
74
+ * Проверка установки
75
+
76
+ Скрипт _test.rb_
77
+ ```
78
+ require 'rucades'
79
+ puts "CADES SDK version: #{Rucades::About.new.version.to_s}"
80
+ ```
81
+ Запуск
82
+ ```
83
+ bundle exec ruby test.rb
84
+ ```
85
+
86
+ Ожидаемый результат (или что-то похожее)
87
+ ```
88
+ CADES SDK version: 2.0.14892
89
+ ```
90
+
91
+ ## Использование
92
+
93
+ В каталоге samples есть 4 примера, унаследованные от pycades:
94
+ * encrypt - decrypt
95
+ * sign - verify signature
96
+ * sign xml document - verify signature
97
+ * sign hash - verify signature
98
+
99
+ Для запуска примеров необходим сертификат с привязкой к закрытому ключу.
100
+ Тестовый сертификат можно установить с помощью команды:
101
+
102
+ _для amd64_
103
+ ```
104
+ /opt/cprocsp/bin/amd64/cryptcp -createcert -dn "CN=test" -provtype 80 -cont '\\.\HDIMAGE\test' -ca https://cryptopro.ru/certsrv
105
+ ```
106
+
107
+ _для arm64_
108
+ ```
109
+ /opt/cprocsp/bin/aarch64/cryptcp -createcert -dn "CN=test" -provtype 80 -cont '\\.\HDIMAGE\test' -ca https://cryptopro.ru/certsrv
110
+ ```
111
+
112
+ RSpec обеспечивает покрытие тестами всех классов и примерно 70% функций.
113
+ Однако, следует иметь в виду, что тестируются С++ --> Ruby bindings, а не функциональность.
114
+ То есть RSpec проверяет, что функция создалась с нужным имененм и параметрами, но не правильность её работы.
115
+
116
+ ## Разработка
117
+
118
+ Этот Gem использует
119
+ * [bundler](https://bundler.io/guides/getting_started.html) для управления зависимстями
120
+ * [rake](https://ruby.github.io/rake/) для управления сборкой
121
+ * [RSpec](https://rspec.info/) 'to make TDD productive and fun'
122
+ * [Rice](https://jasonroelofs.com/rice/4.x/introduction.html) для генерации Ruby bindings
123
+
124
+ Чтобы начать разработку нужно:
125
+ * прочитать документацию на Rice
126
+ * установить зависимости, как описано выше в разделе установка
127
+ * ```bundle install```
128
+ * ```rake --tasks```
129
+
130
+ ## Лицензия
131
+
132
+ [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ require "rake/extensiontask"
13
+
14
+ task build: :compile
15
+ task spec: :compile
16
+
17
+ Rake::ExtensionTask.new("rucades") do |ext|
18
+ ext.lib_dir = "lib/rucades"
19
+ end
20
+
21
+ task default: %i[compile spec]
@@ -0,0 +1,192 @@
1
+ /*
2
+ * Copyright(C) 2004 ������ ���
3
+ *
4
+ * ���� ���� �������� ����������, ����������
5
+ * �������������� �������� ������ ���.
6
+ *
7
+ * ����� ����� ����� ����� �� ����� ���� �����������,
8
+ * ����������, ���������� �� ������ �����,
9
+ * ������������ ��� �������������� ����� ��������,
10
+ * ���������������, �������� �� ���� � ��� ��
11
+ * ����� ������������ ������� ��� ����������������
12
+ * ���������� ���������� � ��������� ������ ���.
13
+ */
14
+
15
+ /*!
16
+ * \file $RCSfile$
17
+ * \version $Revision$
18
+ * \date $Date:: $
19
+ * \author $Author$
20
+ *
21
+ * \brief ����� �����.
22
+ */
23
+
24
+ #ifndef _CPLIB_BLOB_H_INCLUDED
25
+ #define _CPLIB_BLOB_H_INCLUDED
26
+
27
+ #include <algorithm>
28
+ #include <list>
29
+ #include <cplib/StringProxy.h>
30
+
31
+ namespace CryptoPro {
32
+
33
+ /**
34
+ * \class CBlob Blob.h <cplib/Blob.h>
35
+ * \brief �������� ������������������ ������������ �����.
36
+ *
37
+ * ����� ������������ ��� �������� �������� ������������������.
38
+ * ����� �������������� ��� ��� �������� �������������� ASN.1 ��������,
39
+ * ��� � ��� �������� ������������ �������� ������.
40
+ *
41
+ */
42
+ class CPLIB_CLASS CBlob
43
+ {
44
+ public:
45
+ /// ������� ������ ������
46
+ CBlob();
47
+ /**
48
+ * \brief ������� � �������������� ������
49
+ *
50
+ * \param ptr [in] ��������� �� ������ ������ ���������� � ������
51
+ * \param length [in] ����� ������ � ������
52
+ * \remarks ��� ������������� ������ ������� ������ ��� ��������
53
+ * ������ � �������� �� ���� �� ���������� � ��������� ptr �����.
54
+ */
55
+ CBlob(const unsigned char *ptr, unsigned long length );
56
+ /**
57
+ * \brief ������� ������
58
+ *
59
+ * \param length [in] ����� ������ � ������
60
+ * \remarks ��� ������������� ������ ������� ��������� ���������� ������
61
+ * ��� ������.
62
+ */
63
+ CBlob( unsigned long length );
64
+ /// ���������� ������.
65
+ ~CBlob();
66
+
67
+ /**
68
+ * \brief ������� ����� ��������� �������.
69
+ *
70
+ * \param src [in] ������, ����� �������� ���������
71
+ */
72
+ CBlob( const CBlob &src );
73
+ /**
74
+ * \brief �������� �������� ������ � �������.
75
+ *
76
+ * \param src [in] ������, ������� ���������� � �������
77
+ * \return ������ �� ������� ������.
78
+ */
79
+ CBlob& operator=( const CBlob &src );
80
+
81
+ /**
82
+ * \brief �������� ������������ (�������������).
83
+ *
84
+ * \param right [in] ������, �������������� � ��������
85
+ * \remarks ��� ���������� ���� �������� � ����� �������� ������� ��������������
86
+ * ������, ������������� �� ��������� �������.
87
+ * \return ������ �� ������� ������.
88
+ */
89
+ CBlob& operator+=( const CBlob &right );
90
+ /**
91
+ * \brief �������� �������� �� ���������.
92
+ *
93
+ * \param src [in] ������ ��� ���������
94
+ * \remarks ������������ ��������� ��������� ��������.
95
+ * \return true � ������ ���������, false � ������ ������.
96
+ */
97
+ bool operator==( const CBlob &src ) const;
98
+ /**
99
+ * \brief �������� �������� �� �����������.
100
+ *
101
+ * \param src [in] ������ ��� ���������
102
+ * \remarks ������������ ��������� ��������� ��������.
103
+ * \return true � ������ �����������, false � ������ ������.
104
+ */
105
+ bool operator!=( const CBlob &src ) const;
106
+ /**
107
+ * \brief �������� ������������������� ��������� (������).
108
+ *
109
+ * \param src [in] ������ ��� ���������
110
+ * \return true � ������ ���� ������� ������ ������, false � ������ ������.
111
+ */
112
+ bool operator<( const CBlob &src ) const;
113
+ /**
114
+ * \brief �������� ������������������� ��������� (������ ��� �����).
115
+ *
116
+ * \param src [in] ������ ��� ���������
117
+ * \return true � ������ ���� ������� ������ ������ ��� �����, false � ������ ������.
118
+ */
119
+ bool operator<=( const CBlob &src ) const;
120
+ /**
121
+ * \brief �������� ������������������� ��������� (������).
122
+ *
123
+ * \param src [in] ������ ��� ���������
124
+ * \return true � ������ ���� ������� ������ ������, false � ������ ������.
125
+ */
126
+ bool operator>( const CBlob &src ) const;
127
+ /**
128
+ * \brief �������� ������������������� ��������� (������ ��� �����).
129
+ *
130
+ * \param src [in] ������ ��� ���������
131
+ * \return true � ������ ���� ������� ������ ������ ��� �����, false � ������ ������.
132
+ */
133
+ bool operator>=( const CBlob &src ) const;
134
+
135
+ /**
136
+ * \brief ��������� ������� �������.
137
+ *
138
+ * \param length [in] ����� ����� ������
139
+ * \remarks ���� length ������ ������� �����, �� ������ ������
140
+ * � �������� �� ���� �� ������� ����� �� ������ ������ ��������.
141
+ * ���� length ������ ������� �����, �� ����������� ������ ��
142
+ * �������� �� 0 �� length-1.
143
+ */
144
+ void resize_to( unsigned long length );
145
+ /**
146
+ * \brief �������� ������ ��������.
147
+ *
148
+ * \param right [in] ������ ��� ������
149
+ * \remarks ������� �� ���������� ����������.
150
+ */
151
+ void swap( CBlob &right ) throw();
152
+ /// �������������� ������� ���� ������.
153
+ void reverse();
154
+ /**
155
+ * \brief �������� �������
156
+ *
157
+ * ������ ��������� � ���������� ������� �����
158
+ */
159
+ void clear();
160
+ /**
161
+ * \brief ��������� ������ � ������
162
+ *
163
+ * \param ptr [in] ��������� �� ������ ������
164
+ * \param length [in] ����� ������
165
+ */
166
+ void assign(const unsigned char *ptr, unsigned long length );
167
+ void readFromFile( const char *name );
168
+ void writeToFile( const char *name ) const;
169
+ void readFromFile( const wchar_t *name );
170
+ void writeToFile( const wchar_t *name ) const;
171
+ void readFromHexString( const char *str );
172
+ CStringProxy writeToHexString(unsigned long SpaceInterval = 0) const;
173
+
174
+ unsigned long cbData() const;
175
+ unsigned char* pbData() const;
176
+ private:
177
+ unsigned long m_cbData;
178
+ unsigned char *m_pbData;
179
+ };
180
+
181
+ // VS2008 bug/feature: ������� ���������������� �������� ��������� �������
182
+ // (����� - ����������) ������ ���������� ������� ����������������� �������
183
+ // �������� ������ (����� - CDllList<>), ����� �� DLL �� ����� ��������������
184
+ // ������ ��������� �������.
185
+ EXPIMP_CDLLLIST_ITERATORS(CBlob, CPLIB_EXTERN_TEMPLATE, CPLIB_CLASS);
186
+
187
+ /// ������ �������� CBlob
188
+ class CPLIB_CLASS CBlobList: public CDllList<CBlob> {};
189
+
190
+ } // namespace CryptoPro
191
+
192
+ #endif // _CPLIB_BLOB_H_INCLUDED