certstore_c 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d980868eb22aa3b7a16701cb9f61f349018ba203c9ea723aa263f26f48b2fbd3
4
- data.tar.gz: b068d4b2c25eb8ee020923969c52bb03e24771867e371d4666bd1a2f12a1bd37
3
+ metadata.gz: 32b40c0e8ae962aa68d6c2fd6cb86df0ec314e21d40bdee26de0a3f06c46a42b
4
+ data.tar.gz: 1c03f74ab3269365b93b144065e08cb50fbf48ca23d07996a818583da550e100
5
5
  SHA512:
6
- metadata.gz: 333b89dbd8a05a0a270f480ef047e34abd01657fa9c0e7bce9601c50ff0f5ad84fcfa62cd9d4f4c4c8d997c0fe22a08aadcc21c33fd7395de4897db9d226f093
7
- data.tar.gz: 209ef9bc316eabf364be79c7f667c3b8e7f3ac45ad2bbbf37047280b97d57ad640f21fd965869e50855b4259be6a932741c2b9614c78b4540ce81c75fdf38eb2
6
+ metadata.gz: e958c5a56fa98ccf15d27ea2f3b07c853351d0e2639eb0bd19ce0e7746c1bb22041279f2e49f562c6471f4f7c5603c0a6ab39b348250394221e5f8164077868c
7
+ data.tar.gz: e11e7dca9a24157ef53a28d3b49ded628e3514ac58f166737731fc7ef3a80dbb9d0117ba1b9e7352b7ff118a2a9110cb606de32f26564babc45c5de629d6175a
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ["Hiroshi Hatake"]
10
10
  spec.email = ["cosmo0920.wp@gmail.com"]
11
11
 
12
- spec.summary = %q{Windows CertStore loader.}
12
+ spec.summary = %q{Windows CertStore loader and ruby-openssl extension for TLS connection.}
13
13
  spec.description = spec.summary
14
14
  spec.homepage = "https://github.com/cosmo0920/certstore_c"
15
15
 
@@ -220,6 +220,96 @@ error:
220
220
  rb_raise(rb_eCertLoaderError, errBuf);
221
221
  }
222
222
 
223
+ static VALUE
224
+ rb_win_certstore_loader_add_certificate(VALUE self, VALUE rb_der_cert_bin_str)
225
+ {
226
+ struct CertstoreLoader *loader;
227
+ CHAR errBuf[256];
228
+
229
+ Check_Type(rb_der_cert_bin_str, T_STRING);
230
+
231
+ TypedData_Get_Struct(self, struct CertstoreLoader, &rb_win_certstore_loader_type, loader);
232
+
233
+ if (CertAddEncodedCertificateToStore(loader->hStore, X509_ASN_ENCODING,
234
+ RSTRING_PTR(rb_der_cert_bin_str), RSTRING_LEN(rb_der_cert_bin_str),
235
+ CERT_STORE_ADD_NEW,
236
+ NULL)) {
237
+ return Qtrue;
238
+ } else {
239
+ DWORD errCode = GetLastError();
240
+
241
+ switch (errCode){
242
+ case CRYPT_E_EXISTS:
243
+ return Qfalse;
244
+ default: {
245
+ sprintf(errBuf, "Cannot add certificates. ErrorCode: %d", GetLastError());
246
+ goto error;
247
+
248
+ }
249
+ }
250
+ }
251
+
252
+ return Qtrue;
253
+
254
+ error:
255
+
256
+ rb_raise(rb_eCertLoaderError, errBuf);
257
+ }
258
+
259
+ static VALUE
260
+ rb_win_certstore_loader_delete_certificate(VALUE self, VALUE rb_thumbprint)
261
+ {
262
+ VALUE vThumbprint;
263
+ PCCERT_CONTEXT pContext = NULL;
264
+ struct CertstoreLoader *loader;
265
+ DWORD len;
266
+ CHAR errBuf[256];
267
+
268
+ Check_Type(rb_thumbprint, T_STRING);
269
+
270
+ TypedData_Get_Struct(self, struct CertstoreLoader, &rb_win_certstore_loader_type, loader);
271
+
272
+ // thumbprint : To wide char
273
+ len = MultiByteToWideChar(CP_UTF8, 0, RSTRING_PTR(rb_thumbprint), RSTRING_LEN(rb_thumbprint), NULL, 0);
274
+ WCHAR *winThumbprint = ALLOCV_N(WCHAR, vThumbprint, len+1);
275
+ MultiByteToWideChar(CP_UTF8, 0, RSTRING_PTR(rb_thumbprint), RSTRING_LEN(rb_thumbprint), winThumbprint, len);
276
+ winThumbprint[len] = L'\0';
277
+
278
+ BYTE pbThumb[CERT_THUMBPRINT_SIZE];
279
+ CRYPT_HASH_BLOB blob;
280
+ blob.cbData = CERT_THUMBPRINT_SIZE;
281
+ blob.pbData = pbThumb;
282
+ CryptStringToBinaryW(winThumbprint, CERT_THUMBPRINT_STR_LENGTH, CRYPT_STRING_HEX, pbThumb,
283
+ &blob.cbData, NULL, NULL);
284
+
285
+ pContext = CertFindCertificateInStore(
286
+ loader->hStore,
287
+ X509_ASN_ENCODING | PKCS_7_ASN_ENCODING,
288
+ 0,
289
+ CERT_FIND_HASH,
290
+ &blob,
291
+ pContext);
292
+
293
+ if (!pContext)
294
+ goto error;
295
+
296
+ BOOL result = CertDeleteCertificateFromStore(pContext);
297
+ CertFreeCertificateContext(pContext);
298
+ ALLOCV_END(vThumbprint);
299
+
300
+ if (result)
301
+ return Qtrue;
302
+ else
303
+ return Qfalse;
304
+
305
+ error:
306
+
307
+ CertFreeCertificateContext(pContext);
308
+
309
+ sprintf(errBuf, "Cannot find certificates with thumbprint(%S)", winThumbprint);
310
+ rb_raise(rb_eCertLoaderError, errBuf);
311
+ }
312
+
223
313
  static VALUE
224
314
  rb_win_certstore_loader_export_pfx(VALUE self, VALUE rb_thumbprint, VALUE rb_password)
225
315
  {
@@ -316,5 +406,7 @@ Init_certstore_loader(VALUE rb_mCertstore)
316
406
  rb_define_method(rb_cCertLoader, "initialize", rb_win_certstore_loader_initialize, 2);
317
407
  rb_define_method(rb_cCertLoader, "each", rb_win_certstore_loader_each, 0);
318
408
  rb_define_method(rb_cCertLoader, "find_cert", rb_win_certstore_loader_find_certificate, 1);
409
+ rb_define_method(rb_cCertLoader, "delete_cert", rb_win_certstore_loader_delete_certificate, 1);
410
+ rb_define_method(rb_cCertLoader, "add_cert", rb_win_certstore_loader_add_certificate, 1);
319
411
  rb_define_method(rb_cCertLoader, "export_pfx", rb_win_certstore_loader_export_pfx, 2);
320
412
  }
@@ -60,6 +60,18 @@ module Certstore
60
60
  def valid_duration?(x509_obj)
61
61
  x509_obj.not_before < Time.now.utc && x509_obj.not_after > Time.now.utc
62
62
  end
63
+
64
+ def add_certificate(cert_path)
65
+ File.readable?(cert_path)
66
+ File.open(cert_path) do |file|
67
+ @loader.add_cert(::OpenSSL::X509::Certificate.new(file.read).to_der)
68
+ end
69
+ end
70
+
71
+ def delete_certificate(thumbprint)
72
+ thumbprint = cleanup_thumbprint(thumbprint)
73
+ @loader.delete_cert(thumbprint)
74
+ end
63
75
  end
64
76
  end
65
77
  end
@@ -15,5 +15,5 @@
15
15
  #
16
16
 
17
17
  module Certstore
18
- VERSION = "0.1.2"
18
+ VERSION = "0.1.3"
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.2
4
+ version: 0.1.3
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-04 00:00:00.000000000 Z
11
+ date: 2019-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,7 +86,7 @@ dependencies:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
88
  version: 3.3.3
89
- description: Windows CertStore loader.
89
+ description: Windows CertStore loader and ruby-openssl extension for TLS connection.
90
90
  email:
91
91
  - cosmo0920.wp@gmail.com
92
92
  executables: []
@@ -139,5 +139,5 @@ rubyforge_project:
139
139
  rubygems_version: 2.7.3
140
140
  signing_key:
141
141
  specification_version: 4
142
- summary: Windows CertStore loader.
142
+ summary: Windows CertStore loader and ruby-openssl extension for TLS connection.
143
143
  test_files: []