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