aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNAKAMURA Hiroshi <nahi@keynauts.com>2003-07-04 14:56:11 +0000
committerNAKAMURA Hiroshi <nahi@keynauts.com>2003-07-04 14:56:11 +0000
commita7c26f43abbea922722b9c8bd9541f19c19dfe42 (patch)
tree4614b10a4dbb224db89a54e9e14590e71fc01ad3
parentc01bd3d6f02922975934acb7338e2134e3b882f3 (diff)
downloadruby-openssl-history-a7c26f43abbea922722b9c8bd9541f19c19dfe42.tar.gz
* examples/c_rehash.rb: Run as a manager of cert store directory.
-rw-r--r--ChangeLog3
-rwxr-xr-xexamples/c_rehash.rb66
2 files changed, 48 insertions, 21 deletions
diff --git a/ChangeLog b/ChangeLog
index c06c550..008e04f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+Fri, 04 Jul 2003 23:56:09 +0900 -- NAKAMURA, Hiroshi <nahi@ruby-lang.org>
+ * examples/c_rehash.rb: Run as a manager of cert store directory.
+
Fri, 04 Jul 2003 23:51:52 +0900 -- NAKAMURA, Hiroshi <nahi@ruby-lang.org>
* examples/cert_store.rb: Renamed to cert_store_view.rb.
* examples/cert_store_view.rb: Added.
diff --git a/examples/c_rehash.rb b/examples/c_rehash.rb
index 65a8859..c5e832a 100755
--- a/examples/c_rehash.rb
+++ b/examples/c_rehash.rb
@@ -8,28 +8,65 @@ class CHashDir
def initialize(dirpath)
@dirpath = dirpath
- @fingerprint_cache = @cert_cache = nil
+ @fingerprint_cache = @cert_cache = @crl_cache = nil
end
def hash_dir(silent = false)
+ # ToDo: Should lock the directory...
@silent = silent
@fingerprint_cache = Hash.new
@cert_cache = Hash.new
+ @crl_cache = Hash.new
do_hash_dir
end
- def each
- @cert_cache.each do |name_hash, certs|
- yield(certs)
+ def get_certs(name = nil)
+ if name
+ @cert_cache[hash_name(name)]
+ else
+ @cert_cache.values.flatten
+ end
+ end
+
+ def get_crls(name = nil)
+ if name
+ @crl_cache[hash_name(name)]
+ else
+ @crl_cache.values.flatten
end
end
- def get_certs(name)
- @cert_cache[hash_name(name)]
+ def delete_crl(crl)
+ File.unlink(crl_filename(crl))
+ hash_dir(true)
+ end
+
+ def add_crl(crl)
+ File.open(crl_filename(crl), "w") do |f|
+ f << crl.to_pem
+ end
+ hash_dir(true)
+ end
+
+ def load_pem_file(filepath)
+ str = File.read(filepath)
+ begin
+ OpenSSL::X509::Certificate.new(str)
+ rescue
+ begin
+ OpenSSL::X509::CRL.new(str)
+ rescue
+ nil
+ end
+ end
end
private
+ def crl_filename(crl)
+ path(hash_name(crl.issuer)) + '.pem'
+ end
+
def do_hash_dir
Dir.chdir(@dirpath) do
delete_symlink
@@ -54,19 +91,6 @@ private
end
end
- def load_pem_file(filepath)
- str = File.open(filepath).read
- begin
- OpenSSL::X509::Certificate.new(str)
- rescue
- begin
- OpenSSL::X509::CRL.new(str)
- rescue
- nil
- end
- end
- end
-
def link_hash_cert(org_filename, cert)
name_hash = hash_name(cert.subject)
fingerprint = fingerprint(cert.to_der)
@@ -93,7 +117,7 @@ private
STDERR.puts("WARNING: Skipping duplicate CRL #{org_filename}")
end
else
- (@cert_cache[name_hash] ||= []) << path(filepath)
+ (@crl_cache[name_hash] ||= []) << path(filepath)
end
end
@@ -119,7 +143,7 @@ private
File.symlink(from, to)
rescue
File.open(to, "w") do |f|
- f << File.open(from).read
+ f << File.read(from)
end
end
end