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.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +18 -0
- data/Gemfile +16 -0
- data/LICENSE.txt +21 -0
- data/README.md +132 -0
- data/Rakefile +21 -0
- data/ext/rucades/cplib/Blob.h +192 -0
- data/ext/rucades/cplib/DateTime.h +518 -0
- data/ext/rucades/cplib/StringProxy.h +281 -0
- data/ext/rucades/cpstldll.h +183 -0
- data/ext/rucades/errormsg.cpp +561 -0
- data/ext/rucades/errormsg.h +31 -0
- data/ext/rucades/extconf.rb +91 -0
- data/ext/rucades/rucades.cpp +90 -0
- data/ext/rucades/rucades.h +14 -0
- data/ext/rucades/rucades_about.cpp +75 -0
- data/ext/rucades/rucades_about.h +26 -0
- data/ext/rucades/rucades_algorithm.cpp +54 -0
- data/ext/rucades/rucades_algorithm.h +28 -0
- data/ext/rucades/rucades_attribute.cpp +112 -0
- data/ext/rucades/rucades_attribute.h +30 -0
- data/ext/rucades/rucades_attributes.cpp +62 -0
- data/ext/rucades/rucades_attributes.h +28 -0
- data/ext/rucades/rucades_basic_constraints.cpp +67 -0
- data/ext/rucades/rucades_basic_constraints.h +27 -0
- data/ext/rucades/rucades_blobs.cpp +46 -0
- data/ext/rucades/rucades_blobs.h +25 -0
- data/ext/rucades/rucades_certificate.cpp +182 -0
- data/ext/rucades/rucades_certificate.h +59 -0
- data/ext/rucades/rucades_certificate_status.cpp +36 -0
- data/ext/rucades/rucades_certificate_status.h +23 -0
- data/ext/rucades/rucades_certificates.cpp +140 -0
- data/ext/rucades/rucades_certificates.h +31 -0
- data/ext/rucades/rucades_const.cpp +241 -0
- data/ext/rucades/rucades_crl.cpp +84 -0
- data/ext/rucades/rucades_crl.h +29 -0
- data/ext/rucades/rucades_eku.cpp +55 -0
- data/ext/rucades/rucades_eku.h +26 -0
- data/ext/rucades/rucades_ekus.cpp +43 -0
- data/ext/rucades/rucades_ekus.h +27 -0
- data/ext/rucades/rucades_encoded_data.cpp +41 -0
- data/ext/rucades/rucades_encoded_data.h +23 -0
- data/ext/rucades/rucades_enveloped_data.cpp +122 -0
- data/ext/rucades/rucades_enveloped_data.h +33 -0
- data/ext/rucades/rucades_extended_key_usage.cpp +53 -0
- data/ext/rucades/rucades_extended_key_usage.h +27 -0
- data/ext/rucades/rucades_hashed_data.cpp +90 -0
- data/ext/rucades/rucades_hashed_data.h +31 -0
- data/ext/rucades/rucades_key_usage.cpp +116 -0
- data/ext/rucades/rucades_key_usage.h +33 -0
- data/ext/rucades/rucades_oid.cpp +70 -0
- data/ext/rucades/rucades_oid.h +30 -0
- data/ext/rucades/rucades_private_key.cpp +86 -0
- data/ext/rucades/rucades_private_key.h +31 -0
- data/ext/rucades/rucades_public_key.cpp +59 -0
- data/ext/rucades/rucades_public_key.h +28 -0
- data/ext/rucades/rucades_raw_signature.cpp +42 -0
- data/ext/rucades/rucades_raw_signature.h +26 -0
- data/ext/rucades/rucades_recipients.cpp +63 -0
- data/ext/rucades/rucades_recipients.h +28 -0
- data/ext/rucades/rucades_signature_status.cpp +35 -0
- data/ext/rucades/rucades_signature_status.h +23 -0
- data/ext/rucades/rucades_signed_data.cpp +253 -0
- data/ext/rucades/rucades_signed_data.h +41 -0
- data/ext/rucades/rucades_signed_xml.cpp +87 -0
- data/ext/rucades/rucades_signed_xml.h +29 -0
- data/ext/rucades/rucades_signer.cpp +157 -0
- data/ext/rucades/rucades_signer.h +45 -0
- data/ext/rucades/rucades_signers.cpp +43 -0
- data/ext/rucades/rucades_signers.h +27 -0
- data/ext/rucades/rucades_store.cpp +78 -0
- data/ext/rucades/rucades_store.h +34 -0
- data/ext/rucades/rucades_symmetric_algorithm.cpp +107 -0
- data/ext/rucades/rucades_symmetric_algorithm.h +30 -0
- data/ext/rucades/rucades_tools.cpp +18 -0
- data/ext/rucades/rucades_version.cpp +60 -0
- data/ext/rucades/rucades_version.h +24 -0
- data/ext/rucades/stdafx.h +190 -0
- data/lib/rucades/version.rb +9 -0
- data/lib/rucades.rb +36 -0
- data/samples/encrypt_decrypt.rb +25 -0
- data/samples/sign_verify.rb +28 -0
- data/samples/sign_verify_hash.rb +30 -0
- data/samples/sign_verify_xml.rb +44 -0
- data/sig/rucades.rbs +4 -0
- metadata +156 -0
|
@@ -0,0 +1,561 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* \file $RCSfile$
|
|
3
|
+
* \version $Revision: 201331 $
|
|
4
|
+
* \date $Date:: 2019-10-25 11:27:11 +0300#$
|
|
5
|
+
* \author $Author: cross $
|
|
6
|
+
*
|
|
7
|
+
* \brief .
|
|
8
|
+
*
|
|
9
|
+
* .
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// "*_e.h"
|
|
13
|
+
#define FACILITY_TSPCLI 0x210
|
|
14
|
+
#define FACILITY_OCSPCLI 0x211
|
|
15
|
+
#define FACILITY_TSPSRV 0x212
|
|
16
|
+
#define FACILITY_OCSPSRV 0x213
|
|
17
|
+
|
|
18
|
+
#ifdef UNIX
|
|
19
|
+
# include "CSP_WinCrypt.h"
|
|
20
|
+
# include "CSP_WinError.h"
|
|
21
|
+
# include <cstdint>
|
|
22
|
+
# include <string>
|
|
23
|
+
# include "ocspcli_e.h"
|
|
24
|
+
# include "tspcli_e.h"
|
|
25
|
+
#else //_WIN32
|
|
26
|
+
|
|
27
|
+
# define STRICT // . MS,
|
|
28
|
+
// Visual C++ STRICT .
|
|
29
|
+
# define WIN32_LEAN_AND_MEAN //
|
|
30
|
+
# define _WIN32_WINNT 0x0501 // XP
|
|
31
|
+
|
|
32
|
+
// ActCtx.h
|
|
33
|
+
#define ISOLATION_AWARE_ENABLED 1
|
|
34
|
+
|
|
35
|
+
#include <windows.h>
|
|
36
|
+
#include <ole2.h>
|
|
37
|
+
#include <lmerr.h>
|
|
38
|
+
#include <lmcons.h>
|
|
39
|
+
#include <activeds.h>
|
|
40
|
+
#include <ActCtx.h>
|
|
41
|
+
|
|
42
|
+
#endif //_WIN32
|
|
43
|
+
|
|
44
|
+
#ifndef UNIX
|
|
45
|
+
#pragma warning (push)
|
|
46
|
+
#pragma warning (disable:4838)
|
|
47
|
+
#endif
|
|
48
|
+
#include <atlstr.h>
|
|
49
|
+
#ifndef UNIX
|
|
50
|
+
#pragma warning (pop)
|
|
51
|
+
#endif
|
|
52
|
+
#include "errormsg.h"
|
|
53
|
+
|
|
54
|
+
static LPCWSTR eng_wrong_name = L"Wrong name format or an attempt is made to open container of another CSP.";
|
|
55
|
+
|
|
56
|
+
#ifndef UNIX
|
|
57
|
+
inline void _trimrigth(LPTSTR szBuf, LPCTSTR pszTargets);
|
|
58
|
+
|
|
59
|
+
static LPCWSTR rus_wrong_name = L" .";
|
|
60
|
+
static BOOL MakeOurMessage(HRESULT hr, LPWSTR szBuf, DWORD chBufLen, DWORD dwLangId)
|
|
61
|
+
{
|
|
62
|
+
if (hr == SCARD_E_CARD_UNSUPPORTED) {
|
|
63
|
+
LPCWSTR wrong_name_text;
|
|
64
|
+
if (PRIMARYLANGID(dwLangId) == 0x19)
|
|
65
|
+
wrong_name_text = rus_wrong_name;
|
|
66
|
+
else
|
|
67
|
+
wrong_name_text = eng_wrong_name;
|
|
68
|
+
_tcsncpy(szBuf, wrong_name_text, chBufLen - 1);
|
|
69
|
+
return TRUE;
|
|
70
|
+
}
|
|
71
|
+
return FALSE;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
BOOL GetErrorMessage(
|
|
75
|
+
HRESULT hr, LPTSTR szBuf, DWORD chBufLen, DWORD dwLangId)
|
|
76
|
+
{
|
|
77
|
+
static CryptoPro::ActCtx::CActCtxHandle actCtxAssociated;
|
|
78
|
+
|
|
79
|
+
if (!chBufLen)
|
|
80
|
+
{
|
|
81
|
+
return FALSE;
|
|
82
|
+
}
|
|
83
|
+
szBuf[0] = 0;
|
|
84
|
+
HMODULE hInst = 0;
|
|
85
|
+
DWORD dwFacility = HRESULT_FACILITY(hr);
|
|
86
|
+
switch (dwFacility) {
|
|
87
|
+
case FACILITY_TSPCLI:
|
|
88
|
+
{
|
|
89
|
+
CryptoPro::ActCtx::CActCtxActivator activator(actCtxAssociated);
|
|
90
|
+
hInst = ::GetModuleHandle(TEXT("tspcli.dll"));
|
|
91
|
+
if (hInst)
|
|
92
|
+
{
|
|
93
|
+
break;
|
|
94
|
+
}
|
|
95
|
+
hInst = ::GetModuleHandle(TEXT("cades.dll"));
|
|
96
|
+
if (hInst)
|
|
97
|
+
{
|
|
98
|
+
//TODO: ,
|
|
99
|
+
// .
|
|
100
|
+
static CryptoPro::ActCtx::CActCtxHandle actCtxCadesDll(hInst);
|
|
101
|
+
CryptoPro::ActCtx::CActCtxActivator activatorCadesDll(actCtxCadesDll);
|
|
102
|
+
hInst = ::GetModuleHandle(TEXT("tspcli.dll"));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
break;
|
|
106
|
+
case FACILITY_OCSPCLI:
|
|
107
|
+
{
|
|
108
|
+
CryptoPro::ActCtx::CActCtxActivator activator(actCtxAssociated);
|
|
109
|
+
hInst = ::GetModuleHandle(TEXT("ocspcli.dll"));
|
|
110
|
+
if (hInst)
|
|
111
|
+
{
|
|
112
|
+
break;
|
|
113
|
+
}
|
|
114
|
+
hInst = ::GetModuleHandle(TEXT("cades.dll"));
|
|
115
|
+
if (hInst)
|
|
116
|
+
{
|
|
117
|
+
//TODO: ,
|
|
118
|
+
// .
|
|
119
|
+
static CryptoPro::ActCtx::CActCtxHandle actCtxCadesDll(hInst);
|
|
120
|
+
CryptoPro::ActCtx::CActCtxActivator activatorCadesDll(actCtxCadesDll);
|
|
121
|
+
hInst = ::GetModuleHandle(TEXT("ocspcli.dll"));
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
break;
|
|
125
|
+
case FACILITY_MSMQ:
|
|
126
|
+
hInst = ::GetModuleHandle(TEXT("mqutil.dll"));
|
|
127
|
+
break;
|
|
128
|
+
case FACILITY_ITF:
|
|
129
|
+
hInst = ::GetModuleHandle(TEXT("oledb32r.dll"));
|
|
130
|
+
break;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (!hInst
|
|
134
|
+
&& (dwFacility == FACILITY_TSPCLI || dwFacility == FACILITY_OCSPCLI))
|
|
135
|
+
{
|
|
136
|
+
// ,
|
|
137
|
+
// . , cadescom.dll
|
|
138
|
+
// .
|
|
139
|
+
//
|
|
140
|
+
// GetModuleHandleEx(
|
|
141
|
+
// GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS) ,
|
|
142
|
+
//
|
|
143
|
+
// . , ..
|
|
144
|
+
// , hInst 0.
|
|
145
|
+
::GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS
|
|
146
|
+
| GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, _T(" "), &hInst);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
DWORD dwCode = HRESULT_CODE(hr);
|
|
150
|
+
if (!hInst)
|
|
151
|
+
{
|
|
152
|
+
if (dwCode >= NERR_BASE && dwCode <= MAX_NERR)
|
|
153
|
+
{
|
|
154
|
+
hInst = ::GetModuleHandle(MESSAGE_FILENAME);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
BOOL dwRet = FALSE;
|
|
158
|
+
DWORD dwFlagsMod = FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_HMODULE;
|
|
159
|
+
|
|
160
|
+
dwRet = MakeOurMessage(hr, szBuf, chBufLen, dwLangId);
|
|
161
|
+
if (!dwRet) {
|
|
162
|
+
if (hInst) {
|
|
163
|
+
dwRet = FormatMessage(dwFlagsMod, hInst, hr, dwLangId, szBuf, chBufLen, NULL);
|
|
164
|
+
// ,
|
|
165
|
+
// 0 ( )
|
|
166
|
+
if (!dwRet && dwLangId)
|
|
167
|
+
dwRet = FormatMessage(dwFlagsMod, hInst, hr, 0, szBuf, chBufLen, NULL);
|
|
168
|
+
hInst = 0;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
DWORD dwFlagsSys = FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM;
|
|
172
|
+
if (!dwRet) {
|
|
173
|
+
dwRet = FormatMessage(dwFlagsSys, 0, hr, dwLangId, szBuf, chBufLen, NULL);
|
|
174
|
+
// ,
|
|
175
|
+
// 0 ( )
|
|
176
|
+
if (!dwRet && dwLangId)
|
|
177
|
+
dwRet = FormatMessage(dwFlagsSys, 0, hr, 0, szBuf, chBufLen, NULL);
|
|
178
|
+
}
|
|
179
|
+
if (!dwRet)
|
|
180
|
+
{
|
|
181
|
+
hInst = ::GetModuleHandle(TEXT("winhttp.dll"));
|
|
182
|
+
if (hInst)
|
|
183
|
+
{
|
|
184
|
+
// dwCode, hr!
|
|
185
|
+
dwRet = FormatMessage(dwFlagsMod, hInst, dwCode, dwLangId, szBuf, chBufLen, NULL);
|
|
186
|
+
// ,
|
|
187
|
+
// 0 ( )
|
|
188
|
+
if (!dwRet && dwLangId)
|
|
189
|
+
dwRet = FormatMessage(dwFlagsMod, hInst, dwCode, 0, szBuf, chBufLen, NULL);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (!dwRet)
|
|
193
|
+
{
|
|
194
|
+
hInst = ::GetModuleHandle(TEXT("ntdsbmsg.dll"));
|
|
195
|
+
if (hInst)
|
|
196
|
+
{
|
|
197
|
+
dwRet = FormatMessage(dwFlagsMod, hInst, hr, dwLangId, szBuf, chBufLen, NULL);
|
|
198
|
+
// ,
|
|
199
|
+
// 0 ( )
|
|
200
|
+
if (!dwRet && dwLangId)
|
|
201
|
+
dwRet = FormatMessage(dwFlagsMod, hInst, hr, 0, szBuf, chBufLen, NULL);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (!dwRet)
|
|
205
|
+
{
|
|
206
|
+
hInst = ::GetModuleHandle(TEXT("wininet.dll"));
|
|
207
|
+
if (hInst)
|
|
208
|
+
{
|
|
209
|
+
dwRet = FormatMessage(dwFlagsMod, hInst, hr, dwLangId, szBuf, chBufLen, NULL);
|
|
210
|
+
// ,
|
|
211
|
+
// 0 ( )
|
|
212
|
+
if (!dwRet && dwLangId)
|
|
213
|
+
dwRet = FormatMessage(dwFlagsMod, hInst, hr, 0, szBuf, chBufLen, NULL);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (!dwRet && hr >= 0x80005000 && hr < 0x80006000) {
|
|
217
|
+
switch(hr) {
|
|
218
|
+
#define ADSERROR(x) case x: _tcsncpy_s(szBuf, chBufLen, _T(#x), _TRUNCATE); dwRet = TRUE; break
|
|
219
|
+
ADSERROR(E_ADS_BAD_PATHNAME);
|
|
220
|
+
ADSERROR(E_ADS_INVALID_DOMAIN_OBJECT);
|
|
221
|
+
ADSERROR(E_ADS_INVALID_USER_OBJECT);
|
|
222
|
+
ADSERROR(E_ADS_INVALID_COMPUTER_OBJECT);
|
|
223
|
+
ADSERROR(E_ADS_UNKNOWN_OBJECT);
|
|
224
|
+
ADSERROR(E_ADS_PROPERTY_NOT_SET);
|
|
225
|
+
ADSERROR(E_ADS_PROPERTY_NOT_SUPPORTED);
|
|
226
|
+
ADSERROR(E_ADS_PROPERTY_INVALID);
|
|
227
|
+
ADSERROR(E_ADS_BAD_PARAMETER);
|
|
228
|
+
ADSERROR(E_ADS_OBJECT_UNBOUND);
|
|
229
|
+
ADSERROR(E_ADS_PROPERTY_NOT_MODIFIED);
|
|
230
|
+
ADSERROR(E_ADS_PROPERTY_MODIFIED);
|
|
231
|
+
ADSERROR(E_ADS_CANT_CONVERT_DATATYPE);
|
|
232
|
+
ADSERROR(E_ADS_PROPERTY_NOT_FOUND);
|
|
233
|
+
ADSERROR(E_ADS_OBJECT_EXISTS);
|
|
234
|
+
ADSERROR(E_ADS_SCHEMA_VIOLATION);
|
|
235
|
+
ADSERROR(E_ADS_COLUMN_NOT_SET);
|
|
236
|
+
ADSERROR(E_ADS_INVALID_FILTER);
|
|
237
|
+
#undef ADSERROR
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (dwRet && szBuf[0])
|
|
241
|
+
_trimrigth(szBuf, _T("\r\n"));
|
|
242
|
+
if (dwFacility == FACILITY_WIN32 || hr >= 0x80005000 && hr < 0x80006000)
|
|
243
|
+
{
|
|
244
|
+
WCHAR szExtErr[256];
|
|
245
|
+
WCHAR szProv[256];
|
|
246
|
+
LPCTSTR szFormat;
|
|
247
|
+
if (szBuf[0])
|
|
248
|
+
szFormat = _T(" [%ws, #%d (%ws)]");
|
|
249
|
+
else
|
|
250
|
+
szFormat = _T("ADs [%ws, #%d (%ws)]");
|
|
251
|
+
// Get extended error value.
|
|
252
|
+
hInst = ::GetModuleHandle(TEXT("activeds.dll"));
|
|
253
|
+
if (hInst)
|
|
254
|
+
{
|
|
255
|
+
typedef HRESULT (WINAPI *LPADSGETLASTERROR)
|
|
256
|
+
(LPDWORD, LPWSTR, DWORD, LPWSTR, DWORD);
|
|
257
|
+
LPADSGETLASTERROR lpADsGetLastError = LPADSGETLASTERROR(
|
|
258
|
+
GetProcAddress(hInst, "ADsGetLastError"));
|
|
259
|
+
if (lpADsGetLastError != NULL) {
|
|
260
|
+
hr = lpADsGetLastError( &dwCode, szExtErr, 256, szProv, 256);
|
|
261
|
+
if (SUCCEEDED(hr) && dwCode != 0) {
|
|
262
|
+
TCHAR szFormattedBuf[MAX_PATH];
|
|
263
|
+
if (_stprintf_s(szFormattedBuf, MAX_PATH,
|
|
264
|
+
szFormat, szProv, dwCode, szExtErr) > 0)
|
|
265
|
+
if (!_tcsncat_s(szBuf, chBufLen, szFormattedBuf,
|
|
266
|
+
_TRUNCATE))
|
|
267
|
+
dwRet = TRUE;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return dwRet ? TRUE : FALSE;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
void _trimrigth(LPTSTR szBuf, LPCTSTR pszTargets)
|
|
276
|
+
{
|
|
277
|
+
// if we're not trimming anything, we're not doing any work
|
|
278
|
+
if( (pszTargets == NULL) || (*pszTargets == 0) )
|
|
279
|
+
return;
|
|
280
|
+
// find beginning of trailing matches
|
|
281
|
+
// by starting at beginning
|
|
282
|
+
LPCTSTR psz = szBuf;
|
|
283
|
+
LPCTSTR pszLast = NULL;
|
|
284
|
+
while (*psz != 0) {
|
|
285
|
+
if (_tcschr( pszTargets, *psz ) != NULL) {
|
|
286
|
+
if (pszLast == NULL)
|
|
287
|
+
pszLast = psz;
|
|
288
|
+
} else
|
|
289
|
+
pszLast = NULL;
|
|
290
|
+
psz = psz + 1;
|
|
291
|
+
}
|
|
292
|
+
if (pszLast != NULL ) {
|
|
293
|
+
// truncate at left-most matching character
|
|
294
|
+
int iLast = int(pszLast - szBuf);
|
|
295
|
+
szBuf[iLast] = 0;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const ATL::CAtlStringW GetErrorMessage(HRESULT hr, DWORD dwLangId)
|
|
300
|
+
{
|
|
301
|
+
ATL::CAtlString sBuf;
|
|
302
|
+
TCHAR *szBuf = sBuf.GetBuffer(1024);
|
|
303
|
+
BOOL res = GetErrorMessage(hr, szBuf, 1024, dwLangId);
|
|
304
|
+
sBuf.ReleaseBuffer();
|
|
305
|
+
if (!res)
|
|
306
|
+
sBuf.AppendFormat(L"Unknown error code (0x%08X)", hr);
|
|
307
|
+
|
|
308
|
+
return sBuf;
|
|
309
|
+
}
|
|
310
|
+
#else //UNIX
|
|
311
|
+
|
|
312
|
+
typedef enum _CAPICOM_ERROR_CODE
|
|
313
|
+
{
|
|
314
|
+
CAPICOM_E_ENCODE_INVALID_TYPE = 0x80880100,
|
|
315
|
+
CAPICOM_E_EKU_INVALID_OID = 0x80880200,
|
|
316
|
+
CAPICOM_E_EKU_OID_NOT_INITIALIZED = 0x80880201,
|
|
317
|
+
CAPICOM_E_CERTIFICATE_NOT_INITIALIZED = 0x80880210,
|
|
318
|
+
CAPICOM_E_CERTIFICATE_NO_PRIVATE_KEY = 0x80880211,
|
|
319
|
+
CAPICOM_E_CHAIN_NOT_BUILT = 0x80880220,
|
|
320
|
+
CAPICOM_E_STORE_NOT_OPENED = 0x80880230,
|
|
321
|
+
CAPICOM_E_STORE_EMPTY = 0x80880231,
|
|
322
|
+
CAPICOM_E_STORE_INVALID_OPEN_MODE = 0x80880232,
|
|
323
|
+
CAPICOM_E_STORE_INVALID_SAVE_AS_TYPE = 0x80880233,
|
|
324
|
+
CAPICOM_E_ATTRIBUTE_NAME_NOT_INITIALIZED = 0x80880240,
|
|
325
|
+
CAPICOM_E_ATTRIBUTE_VALUE_NOT_INITIALIZED = 0x80880241,
|
|
326
|
+
CAPICOM_E_ATTRIBUTE_INVALID_NAME = 0x80880242,
|
|
327
|
+
CAPICOM_E_ATTRIBUTE_INVALID_VALUE = 0x80880243,
|
|
328
|
+
CAPICOM_E_SIGNER_NOT_INITIALIZED = 0x80880250,
|
|
329
|
+
CAPICOM_E_SIGNER_NOT_FOUND = 0x80880251,
|
|
330
|
+
CAPICOM_E_SIGNER_NO_CHAIN = 0x80880252,
|
|
331
|
+
CAPICOM_E_SIGNER_INVALID_USAGE = 0x80880253,
|
|
332
|
+
CAPICOM_E_SIGN_NOT_INITIALIZED = 0x80880260,
|
|
333
|
+
CAPICOM_E_SIGN_INVALID_TYPE = 0x80880261,
|
|
334
|
+
CAPICOM_E_SIGN_NOT_SIGNED = 0x80880262,
|
|
335
|
+
CAPICOM_E_INVALID_ALGORITHM = 0x80880270,
|
|
336
|
+
CAPICOM_E_INVALID_KEY_LENGTH = 0x80880271,
|
|
337
|
+
CAPICOM_E_ENVELOP_NOT_INITIALIZED = 0x80880280,
|
|
338
|
+
CAPICOM_E_ENVELOP_INVALID_TYPE = 0x80880281,
|
|
339
|
+
CAPICOM_E_ENVELOP_NO_RECIPIENT = 0x80880282,
|
|
340
|
+
CAPICOM_E_ENVELOP_RECIPIENT_NOT_FOUND = 0x80880283,
|
|
341
|
+
CAPICOM_E_ENCRYPT_NOT_INITIALIZED = 0x80880290,
|
|
342
|
+
CAPICOM_E_ENCRYPT_INVALID_TYPE = 0x80880291,
|
|
343
|
+
CAPICOM_E_ENCRYPT_NO_SECRET = 0x80880292,
|
|
344
|
+
CAPICOM_E_NOT_SUPPORTED = 0x80880900,
|
|
345
|
+
CAPICOM_E_UI_DISABLED = 0x80880901,
|
|
346
|
+
CAPICOM_E_CANCELLED = 0x80880902,
|
|
347
|
+
CAPICOM_E_NOT_ALLOWED = 0x80880903,
|
|
348
|
+
CAPICOM_E_OUT_OF_RESOURCE = 0x80880904,
|
|
349
|
+
CAPICOM_E_INTERNAL = 0x80880911,
|
|
350
|
+
CAPICOM_E_UNKNOWN = 0x80880999,
|
|
351
|
+
CAPICOM_E_PRIVATE_KEY_NOT_INITIALIZED = 0x80880300,
|
|
352
|
+
CAPICOM_E_PRIVATE_KEY_NOT_EXPORTABLE = 0x80880301,
|
|
353
|
+
CAPICOM_E_ENCODE_NOT_INITIALIZED = 0x80880320,
|
|
354
|
+
CAPICOM_E_EXTENSION_NOT_INITIALIZED = 0x80880330,
|
|
355
|
+
CAPICOM_E_PROPERTY_NOT_INITIALIZED = 0x80880340,
|
|
356
|
+
CAPICOM_E_FIND_INVALID_TYPE = 0x80880350,
|
|
357
|
+
CAPICOM_E_FIND_INVALID_PREDEFINED_POLICY = 0x80880351,
|
|
358
|
+
CAPICOM_E_CODE_NOT_INITIALIZED = 0x80880360,
|
|
359
|
+
CAPICOM_E_CODE_NOT_SIGNED = 0x80880361,
|
|
360
|
+
CAPICOM_E_CODE_DESCRIPTION_NOT_INITIALIZED = 0x80880362,
|
|
361
|
+
CAPICOM_E_CODE_DESCRIPTION_URL_NOT_INITIALIZED = 0x80880363,
|
|
362
|
+
CAPICOM_E_CODE_INVALID_TIMESTAMP_URL = 0x80880364,
|
|
363
|
+
CAPICOM_E_HASH_NO_DATA = 0x80880370,
|
|
364
|
+
CAPICOM_E_INVALID_CONVERT_TYPE = 0x80880380
|
|
365
|
+
} CAPICOM_ERROR_CODE;
|
|
366
|
+
|
|
367
|
+
const ATL::CAtlStringW GetErrorMessage(HRESULT hr, DWORD dwLangId){
|
|
368
|
+
UNUSED(dwLangId);
|
|
369
|
+
ATL::CAtlStringW ret;
|
|
370
|
+
switch(hr){
|
|
371
|
+
case TSPCLI_ERROR_HTTP:
|
|
372
|
+
case OCSPCLI_ERROR_HTTP:
|
|
373
|
+
ret = L"HTTP error occurred while sending request.";
|
|
374
|
+
break;
|
|
375
|
+
case TSPCLI_ERROR_PolicyDeniedAuthType:
|
|
376
|
+
case OCSPCLI_ERROR_PolicyDeniedAuthType:
|
|
377
|
+
ret = L"Specified authentication type prohibited by group policy.";
|
|
378
|
+
break;
|
|
379
|
+
case TSPCLI_ERROR_PolicyDeniedProxyAuthType:
|
|
380
|
+
case OCSPCLI_ERROR_PolicyDeniedProxyAuthType:
|
|
381
|
+
ret = L"Specified proxy authentication type prohibited by group policy.";
|
|
382
|
+
break;
|
|
383
|
+
case TSPCLI_ERROR_PolicyDeniedURL:
|
|
384
|
+
ret = L"Specified time-stamp authority prohibited by group policy.";
|
|
385
|
+
break;
|
|
386
|
+
case OCSPCLI_ERROR_PolicyDeniedURL:
|
|
387
|
+
ret = L"Specified OCSP server authority prohibited by group policy.";
|
|
388
|
+
break;
|
|
389
|
+
case TSPCLI_ERROR_PolicyDeniedNonce:
|
|
390
|
+
ret = L"Nonce usage prohibited by group policy.";
|
|
391
|
+
break;
|
|
392
|
+
case TSPCLI_ERROR_PolicyDeniedHashAlg:
|
|
393
|
+
ret = L"Specified hash algorithm prohibited by group policy.";
|
|
394
|
+
break;
|
|
395
|
+
case TSPCLI_ERROR_PolicyDeniedPolicyID:
|
|
396
|
+
ret = L"Specified PolicyID prohibited by group policy.";
|
|
397
|
+
break;
|
|
398
|
+
case TSPCLI_ERROR_IncorrectNonce:
|
|
399
|
+
ret = L" The values of request's and stamp's \"Nonce\" fields are not equal.";
|
|
400
|
+
break;
|
|
401
|
+
case TSPCLI_ERROR_AddressIsEmpty:
|
|
402
|
+
ret = L"The URL of TSP service is not specified.";
|
|
403
|
+
break;
|
|
404
|
+
case TSPCLI_ERROR_ExpiredStamp:
|
|
405
|
+
ret = L"The time stamp is expired (ProducedAt value).";
|
|
406
|
+
break;
|
|
407
|
+
case TSPCLI_ERROR_DataHashIsEmpty:
|
|
408
|
+
ret = L"Request does not contain data hash.";
|
|
409
|
+
break;
|
|
410
|
+
case TSPCLI_ERROR_UnsuccessfullResponse:
|
|
411
|
+
ret = L"TSA response is unsuccessful.";
|
|
412
|
+
break;
|
|
413
|
+
case 0xC2100140: //TSPCLI_ERROR_LicenseExpired
|
|
414
|
+
ret = L"No TSP Client license has been entered or TSP Client license is expired.";
|
|
415
|
+
break;
|
|
416
|
+
case OCSPCLI_ERROR_PolicyDeniedSignedRequest:
|
|
417
|
+
ret = L"Signed OCSP requests prohibited by group policy.";
|
|
418
|
+
break;
|
|
419
|
+
case OCSPCLI_ERROR_PolicyDeniedUnsignedRequest:
|
|
420
|
+
ret = L"Unsigned OCSP requests prohibited by group policy.";
|
|
421
|
+
break;
|
|
422
|
+
case OCSPCLI_ERROR_IncorrectNonce:
|
|
423
|
+
ret = L"The values of OCSP-request's and response's \"Nonce\" extensions are not equal.";
|
|
424
|
+
break;
|
|
425
|
+
case OCSPCLI_ERROR_AddressIsEmpty:
|
|
426
|
+
ret = L"The URL of OCSP service is not specified.";
|
|
427
|
+
break;
|
|
428
|
+
case OCSPCLI_ERROR_ExpiredResponse:
|
|
429
|
+
ret = L"OCSP-response is expired by ProducedAt or by NextUpdate.";
|
|
430
|
+
break;
|
|
431
|
+
case OCSPCLI_ERROR_ExpiredThisUpdate:
|
|
432
|
+
ret = L"ThisUpdate value of single response is expired.";
|
|
433
|
+
break;
|
|
434
|
+
case OCSPCLI_ERROR_IncorrectNextUpdate:
|
|
435
|
+
ret = L" NextUpdate value of single response is less than ThisUpdate.";
|
|
436
|
+
break;
|
|
437
|
+
case OCSPCLI_ERROR_ReqRespNotMatch:
|
|
438
|
+
ret = L"OCSP-response does not contain requested certificate status.";
|
|
439
|
+
break;
|
|
440
|
+
case OCSPCLI_ERROR_CertStatusIsRevoked:
|
|
441
|
+
ret = L"Certificate is revoked.";
|
|
442
|
+
break;
|
|
443
|
+
case OCSPCLI_ERROR_CertStatusIsUnknown:
|
|
444
|
+
ret = L"Certificate status is unknown.";
|
|
445
|
+
break;
|
|
446
|
+
case OCSPCLI_ERROR_UnsuccessfullResponse:
|
|
447
|
+
ret = L"OCSP-response is unsuccessful.";
|
|
448
|
+
break;
|
|
449
|
+
case OCSPCLI_ERROR_PolicyDeniedExtension:
|
|
450
|
+
ret = L"Encountered extension (AcceptableTypes or Nonce) prohibited by group policy.";
|
|
451
|
+
break;
|
|
452
|
+
case ERROR_BAD_CONFIGURATION:
|
|
453
|
+
ret = L"The configuration data or license for this product is corrupt or not present.";
|
|
454
|
+
break;
|
|
455
|
+
case 0x8007064a: //License info isn't present
|
|
456
|
+
ret = L"The configuration data or license for this product is corrupt or not present.";
|
|
457
|
+
break;
|
|
458
|
+
case CRYPT_E_REVOKED:
|
|
459
|
+
ret = L"The certificate is revoked.";
|
|
460
|
+
break;
|
|
461
|
+
case ERROR_NO_DATA_DETECTED:
|
|
462
|
+
ret = L"The data you supplied have zero length.";
|
|
463
|
+
break;
|
|
464
|
+
case CRYPT_E_NO_REVOCATION_CHECK:
|
|
465
|
+
ret = L"The revocation function was unable to check revocation for the certificate.";
|
|
466
|
+
break;
|
|
467
|
+
case 0x8007006E:
|
|
468
|
+
ret = L"The system cannot open the device or file specified.";
|
|
469
|
+
break;
|
|
470
|
+
case NTE_BAD_ALGID:
|
|
471
|
+
case CRYPT_E_OID_FORMAT: // oid UNIX
|
|
472
|
+
ret = L"Invalid algorithm specified.";
|
|
473
|
+
break;
|
|
474
|
+
case REGDB_E_CLASSNOTREG:
|
|
475
|
+
ret = L"Class not registered.";
|
|
476
|
+
break;
|
|
477
|
+
case OLE_E_BLANK:
|
|
478
|
+
ret = L"Uninitialized object.";
|
|
479
|
+
break;
|
|
480
|
+
case CAPICOM_E_STORE_NOT_OPENED:
|
|
481
|
+
ret = L"The Store object does not represent an opened certificate store.";
|
|
482
|
+
break;
|
|
483
|
+
case E_INVALIDARG:
|
|
484
|
+
ret = L"The parameter is incorrect.";
|
|
485
|
+
break;
|
|
486
|
+
case 0x80070002: // returned by OpenStore(Existing) if no store
|
|
487
|
+
ret = L"The system cannot find the file specified.";
|
|
488
|
+
break;
|
|
489
|
+
case E_NOT_VALID_STATE:
|
|
490
|
+
ret = L"The group or resource is not in the correct state to perform the requested operation.";
|
|
491
|
+
break;
|
|
492
|
+
case E_NOTIMPL:
|
|
493
|
+
ret = L"Not implemented.";
|
|
494
|
+
break;
|
|
495
|
+
case ERROR_ALREADY_EXISTS:
|
|
496
|
+
ret = L"Cannot create a file when that file already exists.";
|
|
497
|
+
break;
|
|
498
|
+
case 0x800700B7: //ERROR_ALREADY_EXISTS in HRESULT variant
|
|
499
|
+
ret = L"Cannot create a file when that file already exists.";
|
|
500
|
+
break;
|
|
501
|
+
case NS_E_CURL_INVALIDSCHEME:
|
|
502
|
+
ret = L"The URL contains an invalid scheme.";
|
|
503
|
+
break;
|
|
504
|
+
case SCARD_W_WRONG_CHV:
|
|
505
|
+
ret = L"The private key cannot be accessed because the wrong PIN was presented.";
|
|
506
|
+
break;
|
|
507
|
+
case CRYPT_E_NOT_FOUND:
|
|
508
|
+
ret = L"Cannot find object or property.";
|
|
509
|
+
break;
|
|
510
|
+
case NTE_BAD_SIGNATURE:
|
|
511
|
+
ret = L"Invalid Signature.";
|
|
512
|
+
break;
|
|
513
|
+
case ERROR_DS_INSUFF_ACCESS_RIGHTS:
|
|
514
|
+
ret = L"Insufficient access rights to perform the operation.";
|
|
515
|
+
break;
|
|
516
|
+
case 0x800705B9: //ERROR_XML_PARSE_ERROR in HRESULT variant
|
|
517
|
+
ret = L"The system was unable to parse the requested XML data.";
|
|
518
|
+
break;
|
|
519
|
+
case 0x800705BA: //ERROR_XMLDSIG_ERROR in HRESULT variant
|
|
520
|
+
ret = L"An error was encountered while processing an XML digital signature.";
|
|
521
|
+
break;
|
|
522
|
+
case 0x800B010E: //CERT_E_REVOCATION_FAILURE
|
|
523
|
+
ret = L"The revocation process could not continue - the certificate(s) could not be checked.";
|
|
524
|
+
break;
|
|
525
|
+
case OCSPCLI_ERROR_ResponseWithUnallowedExtension:
|
|
526
|
+
ret = L"OCSP-response contains unallowed critical extension.";
|
|
527
|
+
break;
|
|
528
|
+
case NTE_EXISTS:
|
|
529
|
+
ret = L"Object already exists.";
|
|
530
|
+
break;
|
|
531
|
+
case CRYPT_E_HASH_VALUE:
|
|
532
|
+
ret = L"The hash value is not correct";
|
|
533
|
+
break;
|
|
534
|
+
case OCSPCLI_ERROR_ResponseWithIncorrectTimeStamp:
|
|
535
|
+
ret = L"OCSP Responder time is out of sync with Time Stamping Authority";
|
|
536
|
+
break;
|
|
537
|
+
case OCSPCLI_ERROR_UntrustedSitesDisabled:
|
|
538
|
+
ret = L"Untrusted sites disabled";
|
|
539
|
+
break;
|
|
540
|
+
case 0xC2110140: //OCSPCLI_ERROR_LicenseExpired
|
|
541
|
+
ret = L"No OCSP Client license has been entered or OCSP Client license is expired";
|
|
542
|
+
break;
|
|
543
|
+
case SCARD_E_CARD_UNSUPPORTED:
|
|
544
|
+
ret = eng_wrong_name;
|
|
545
|
+
break;
|
|
546
|
+
case NTE_PERM:
|
|
547
|
+
ret = L"Access denied";
|
|
548
|
+
break;
|
|
549
|
+
case CERT_E_UNTRUSTEDROOT:
|
|
550
|
+
ret = L"A certificate chain processed correctly, but terminated in a root certificate which is not trusted by the trust provider";
|
|
551
|
+
break;
|
|
552
|
+
case CRYPT_E_NO_DECRYPT_CERT:
|
|
553
|
+
ret = L"Cannot find the certificate and private key to use for decryption";
|
|
554
|
+
break;
|
|
555
|
+
default:
|
|
556
|
+
ret = L"Internal error.";
|
|
557
|
+
break;
|
|
558
|
+
}
|
|
559
|
+
return ret;
|
|
560
|
+
}
|
|
561
|
+
#endif //UNIX
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* \file $RCSfile$
|
|
3
|
+
* \version $Revision$
|
|
4
|
+
* \date $Date:: $
|
|
5
|
+
* \author $Author$
|
|
6
|
+
*
|
|
7
|
+
* \brief ��������� ��� �������������� ��������� �� �������.
|
|
8
|
+
*
|
|
9
|
+
* ��������� ��� �������������� ��������� �� �������.
|
|
10
|
+
*/
|
|
11
|
+
#ifndef _ERRORMSG_H_INCLUDED
|
|
12
|
+
#define _ERRORMSG_H_INCLUDED
|
|
13
|
+
|
|
14
|
+
#if defined _WIN32
|
|
15
|
+
#ifdef __cplusplus
|
|
16
|
+
extern "C" {
|
|
17
|
+
#endif // __cplusplus
|
|
18
|
+
BOOL GetErrorMessage(HRESULT hr, LPWSTR szBuf, DWORD chBufLen, DWORD dwLangId = 0);
|
|
19
|
+
#if defined( __cplusplus )
|
|
20
|
+
}
|
|
21
|
+
#endif /* defined( __cplusplus ) */
|
|
22
|
+
|
|
23
|
+
#else //_WIN32
|
|
24
|
+
const ATL::CAtlStringW GetErrorMessage(HRESULT hr, DWORD dwLangId = 0);
|
|
25
|
+
#endif /* _WIN32 */
|
|
26
|
+
|
|
27
|
+
#if defined _WIN32 && defined __CSTRINGT_H__
|
|
28
|
+
const ATL::CAtlStringW GetErrorMessage(HRESULT hr, DWORD dwLangId = 0);
|
|
29
|
+
#endif // _WIN32 && __CSTRINGT_H__
|
|
30
|
+
|
|
31
|
+
#endif /* _ERRORMSG_H_INCLUDED */
|
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
require "mkmf-rice"
|
|
8
|
+
require "fiddle"
|
|
9
|
+
|
|
10
|
+
# rubocop:disable Style/GlobalVars
|
|
11
|
+
|
|
12
|
+
INCDIRS = [
|
|
13
|
+
"/usr/include/boost",
|
|
14
|
+
"/opt/cprocsp/include",
|
|
15
|
+
"/opt/cprocsp/include/cpcsp",
|
|
16
|
+
"/opt/cprocsp/include/pki/atl",
|
|
17
|
+
"/opt/cprocsp/include/pki/cppcades",
|
|
18
|
+
"/opt/cprocsp/include/pki/cplib",
|
|
19
|
+
"/opt/cprocsp/include/pki"
|
|
20
|
+
].freeze
|
|
21
|
+
|
|
22
|
+
CXXDEFS = [
|
|
23
|
+
" -DUNIX",
|
|
24
|
+
" -fpermissive",
|
|
25
|
+
" -Wno-narrowing",
|
|
26
|
+
" -Wno-deprecated-declarations",
|
|
27
|
+
" -Wno-write-strings",
|
|
28
|
+
" -DLEGACY_FORMAT_MESSAGE_IMPL"
|
|
29
|
+
].freeze
|
|
30
|
+
|
|
31
|
+
ARM64_CXXDEFS = [
|
|
32
|
+
"-DLINUX",
|
|
33
|
+
"-DPROC_TYPE_ARM64=7",
|
|
34
|
+
"-DPROCESSOR_TYPE=PROC_TYPE_ARM64",
|
|
35
|
+
"-Wno-write-strings"
|
|
36
|
+
].freeze
|
|
37
|
+
|
|
38
|
+
INCDIRS.each { |dir| $INCFLAGS << " -I#{dir}" }
|
|
39
|
+
|
|
40
|
+
$defs << " -DSIZEOF_VOID_P=#{Fiddle::SIZEOF_VOIDP}"
|
|
41
|
+
|
|
42
|
+
CXXDEFS.each { |df| $defs << df }
|
|
43
|
+
ARM64_CXXDEFS.each { |df| $defs << df } if RUBY_PLATFORM =~ /aarch64-linux/
|
|
44
|
+
|
|
45
|
+
$DLDFLAGS << if RUBY_PLATFORM =~ /aarch64-linux/
|
|
46
|
+
" -L/opt/cprocsp/lib/aarch64"
|
|
47
|
+
else
|
|
48
|
+
" -L/opt/cprocsp/lib/amd64"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
$LOCAL_LIBS << " -lcppcades"
|
|
52
|
+
|
|
53
|
+
$srcs = [
|
|
54
|
+
"rucades.cpp",
|
|
55
|
+
"rucades_const.cpp",
|
|
56
|
+
"rucades_tools.cpp",
|
|
57
|
+
"errormsg.cpp",
|
|
58
|
+
"rucades_about.cpp",
|
|
59
|
+
"rucades_algorithm.cpp",
|
|
60
|
+
"rucades_attribute.cpp",
|
|
61
|
+
"rucades_attributes.cpp",
|
|
62
|
+
"rucades_basic_constraints.cpp",
|
|
63
|
+
"rucades_blobs.cpp",
|
|
64
|
+
"rucades_certificate.cpp",
|
|
65
|
+
"rucades_certificates.cpp",
|
|
66
|
+
"rucades_certificate_status.cpp",
|
|
67
|
+
"rucades_crl.cpp",
|
|
68
|
+
"rucades_eku.cpp",
|
|
69
|
+
"rucades_ekus.cpp",
|
|
70
|
+
"rucades_encoded_data.cpp",
|
|
71
|
+
"rucades_enveloped_data.cpp",
|
|
72
|
+
"rucades_extended_key_usage.cpp",
|
|
73
|
+
"rucades_hashed_data.cpp",
|
|
74
|
+
"rucades_key_usage.cpp",
|
|
75
|
+
"rucades_oid.cpp",
|
|
76
|
+
"rucades_private_key.cpp",
|
|
77
|
+
"rucades_public_key.cpp",
|
|
78
|
+
"rucades_raw_signature.cpp",
|
|
79
|
+
"rucades_recipients.cpp",
|
|
80
|
+
"rucades_signature_status.cpp",
|
|
81
|
+
"rucades_signed_data.cpp",
|
|
82
|
+
"rucades_signed_xml.cpp",
|
|
83
|
+
"rucades_signer.cpp",
|
|
84
|
+
"rucades_signers.cpp",
|
|
85
|
+
"rucades_store.cpp",
|
|
86
|
+
"rucades_symmetric_algorithm.cpp",
|
|
87
|
+
"rucades_version.cpp"
|
|
88
|
+
]
|
|
89
|
+
|
|
90
|
+
# rubocop:enable Style/GlobalVars
|
|
91
|
+
create_makefile("rucades/rucades")
|