certstore_c 0.1.5 → 0.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f17868bc6c40ee22029b990df5920db1a54c51495d53907d1eeb18b1ff778f23
4
- data.tar.gz: '06048cdc00d4e4613a8c9ea7bdc7f08dcec8d1791b4a8a991bbb04b10e12e560'
3
+ metadata.gz: 181ac6a16240752f4b6ae0b0c9c0eba99404e840bc452e182e5528c908ec0e66
4
+ data.tar.gz: a856de78f86953d352d8f39d43ae264a2b0698633bf7a262bb1d5a87926c8ba4
5
5
  SHA512:
6
- metadata.gz: 73b42304e47fce36a05de43bad75eaa39fc102a77fb04409aa95b67d17e1de7fe901ed13a94a6cfa11f944cbb22f16175078da50a8db58d43da742451c53b7f1
7
- data.tar.gz: 8680f9c88dfb5cf78788b6bbf89befad5b5f40a05e074a391ba585980efc7b9038e4462368346fc26da94e97869e9cc83062657e4488c6cc166bdcdb7e0757a4
6
+ metadata.gz: c6b2f662310e81a7f10466bb905328df9c21fc7f0df70b1b7cff508b05267b2febf95eaef5c11baf2a1f1dd0a088a95ed03fe3da349859907dfbe99c3333065f
7
+ data.tar.gz: 0f5b6f97395ffb962c2902aa9b26f53a94f806e121220a0f9a8d1a78ee8cfad3f15faf2cfdbe43af5b613b1f86b389903c50e84f112c1778fbed276890738a04
@@ -35,11 +35,6 @@ VALUE rb_mCertstore;
35
35
  VALUE rb_cCertLoader;
36
36
  VALUE rb_eCertLoaderError;
37
37
 
38
- struct CertstoreLoader
39
- {
40
- HCERTSTORE hStore;
41
- };
42
-
43
38
  void handle_error_code(VALUE self, DWORD errCode);
44
39
  void Init_certstore_loader(VALUE rb_mCertstore);
45
40
 
@@ -14,7 +14,7 @@ have_library("crypt32")
14
14
  have_func("PFXExportCertStoreEx", "Wincrypt.h")
15
15
 
16
16
  $LDFLAGS << " -lcrypt32"
17
- $CFLAGS << " -std=c99 -fPIC -fms-extensions "
17
+ $CFLAGS << " -Wall -std=c99 -fPIC -fms-extensions "
18
18
  # $CFLAGS << " -g -O0"
19
19
 
20
20
  create_makefile("certstore/certstore")
@@ -11,6 +11,12 @@
11
11
 
12
12
  #include <certstore.h>
13
13
 
14
+ struct CertstoreLoader
15
+ {
16
+ HCERTSTORE hStore;
17
+ PCCERT_CONTEXT pContext;
18
+ };
19
+
14
20
  static void certstore_loader_free(void* certstore);
15
21
 
16
22
  static const rb_data_type_t rb_win_certstore_loader_type = {
@@ -29,6 +35,8 @@ static void
29
35
  certstore_loader_free(void* ptr)
30
36
  {
31
37
  struct CertstoreLoader* loader = (struct CertstoreLoader*)ptr;
38
+ if (loader->pContext)
39
+ CertFreeCertificateContext(loader->pContext);
32
40
  if (loader->hStore)
33
41
  CertCloseStore(loader->hStore, 0);
34
42
 
@@ -42,6 +50,8 @@ rb_win_certstore_loader_alloc(VALUE klass)
42
50
  struct CertstoreLoader* loader;
43
51
  obj = TypedData_Make_Struct(
44
52
  klass, struct CertstoreLoader, &rb_win_certstore_loader_type, loader);
53
+ loader->hStore = NULL;
54
+ loader->pContext = NULL;
45
55
  return obj;
46
56
  }
47
57
 
@@ -146,7 +156,6 @@ certificate_context_to_string(PCCERT_CONTEXT pContext)
146
156
 
147
157
  len = WideCharToMultiByte(CP_UTF8, 0, wszString, -1, NULL, 0, NULL, NULL);
148
158
  utf8str = ALLOCV_N(CHAR, vUtf8str, len);
149
- len = WideCharToMultiByte(CP_UTF8, 0, wszString, -1, NULL, 0, NULL, NULL);
150
159
  WideCharToMultiByte(CP_UTF8, 0, wszString, -1, utf8str, len, NULL, NULL);
151
160
  // malloc ((strlen(base64 cert content) + strlen(header) +
152
161
  // strlen(footer) + 1(null terminator)) length).
@@ -188,8 +197,10 @@ rb_win_certstore_loader_each_pem(VALUE self)
188
197
  self, struct CertstoreLoader, &rb_win_certstore_loader_type, loader);
189
198
 
190
199
  while ((pContext = CertEnumCertificatesInStore(loader->hStore, pContext)) != NULL) {
200
+ loader->pContext = pContext;
191
201
  VALUE rb_certificate = certificate_context_to_string(pContext);
192
202
  rb_yield(rb_certificate);
203
+ loader->pContext = NULL;
193
204
  }
194
205
 
195
206
  return Qnil;
@@ -203,7 +214,9 @@ rb_win_certstore_loader_dispose(VALUE self)
203
214
  TypedData_Get_Struct(
204
215
  self, struct CertstoreLoader, &rb_win_certstore_loader_type, loader);
205
216
 
206
- /* What should we dispose here? */
217
+ if (loader->pContext)
218
+ CertFreeCertificateContext(loader->pContext);
219
+ loader->pContext = NULL;
207
220
 
208
221
  return Qnil;
209
222
  }
@@ -211,14 +224,8 @@ rb_win_certstore_loader_dispose(VALUE self)
211
224
  static VALUE
212
225
  rb_win_certstore_loader_each(VALUE self)
213
226
  {
214
- PCCERT_CONTEXT pContext = NULL;
215
- struct CertstoreLoader* loader;
216
-
217
227
  RETURN_ENUMERATOR(self, 0, 0);
218
228
 
219
- TypedData_Get_Struct(
220
- self, struct CertstoreLoader, &rb_win_certstore_loader_type, loader);
221
-
222
229
  rb_ensure(
223
230
  rb_win_certstore_loader_each_pem, self, rb_win_certstore_loader_dispose, self);
224
231
 
@@ -293,7 +300,7 @@ rb_win_certstore_loader_add_certificate(VALUE self, VALUE rb_der_cert_bin_str)
293
300
 
294
301
  if (CertAddEncodedCertificateToStore(loader->hStore,
295
302
  X509_ASN_ENCODING,
296
- RSTRING_PTR(rb_der_cert_bin_str),
303
+ (const BYTE *)RSTRING_PTR(rb_der_cert_bin_str),
297
304
  RSTRING_LEN(rb_der_cert_bin_str),
298
305
  CERT_STORE_ADD_NEW,
299
306
  NULL)) {
@@ -474,7 +481,7 @@ rb_win_certstore_loader_export_pfx(VALUE self, VALUE rb_thumbprint, VALUE rb_pas
474
481
  ALLOCV_END(vThumbprint);
475
482
  ALLOCV_END(vPassword);
476
483
 
477
- VALUE rb_str = rb_str_new(pfxPacket.pbData, pfxPacket.cbData);
484
+ VALUE rb_str = rb_str_new((const char *)pfxPacket.pbData, pfxPacket.cbData);
478
485
 
479
486
  CryptMemFree(pfxPacket.pbData);
480
487
  CertCloseStore(hMemoryStore, CERT_CLOSE_STORE_CHECK_FLAG);
@@ -15,5 +15,5 @@
15
15
  #
16
16
 
17
17
  module Certstore
18
- VERSION = "0.1.5"
18
+ VERSION = "0.1.6"
19
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: certstore_c
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroshi Hatake
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-09-25 00:00:00.000000000 Z
11
+ date: 2019-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler