]> git.donarmstrong.com Git - ca-certificates.git/blob - mozilla/certdata2pem.rb
Imported Debian version 20050518
[ca-certificates.git] / mozilla / certdata2pem.rb
1 #!/usr/bin/ruby
2
3 while line = $stdin.gets
4   next if line =~ /^#/
5   next if line =~ /^\s*$/
6   line.chomp!
7   if line =~ /CKA_LABEL/
8     label,type,val = line.split(' ',3)
9     val.sub!(/^"/, "")
10     val.sub!(/"$/, "")
11     fname = val.gsub(/\//,"_").gsub(/\s+/, "_").gsub(/[()]/, "=").gsub(/,/, "_") + ".crt"
12     next
13   end
14   if line =~ /CKA_VALUE MULTILINE_OCTAL/
15     data=''
16     while line = $stdin.gets
17       break if /^END/
18       line.chomp!
19       line.gsub(/\\([0-3][0-7][0-7])/) { data += $1.oct.chr }
20     end
21     open(fname, "w") do |fp|
22       fp.puts "-----BEGIN CERTIFICATE-----"
23       fp.puts [data].pack("m*")
24       fp.puts "-----END CERTIFICATE-----"
25     end
26     puts "Created #{fname}"
27   end
28 end
29 # system("c_rehash", ".")