File: certdata2pem.rb

package info (click to toggle)
ca-certificates 20080809
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,312 kB
  • ctags: 3
  • sloc: sh: 369; makefile: 106; ruby: 33
file content (36 lines) | stat: -rw-r--r-- 857 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/ruby

while line = $stdin.gets
  next if line =~ /^#/
  if line =~ /^\s*$/
     fname = nil
     next
  end
  line.chomp!
  if line =~ /CKA_LABEL/
    label,type,val = line.split(' ',3)
    val.sub!(/^"/, "")
    val.sub!(/"$/, "")
    fname = val.gsub(/\//,"_").gsub(/\s+/, "_").gsub(/[()]/, "=").gsub(/,/, "_") + ".crt"
    next
  end
  if line =~ /CKA_VALUE MULTILINE_OCTAL/
    if fname.nil?
      puts "E: unexpected CKA_VALUE MULTILINE_OCTAL"
      next
    end
    data=''
    while line = $stdin.gets
      break if line =~ /^END/
      line.chomp!
      line.gsub(/\\([0-3][0-7][0-7])/) { data += $1.oct.chr }
    end
    open(fname, "w") do |fp|
      fp.puts "-----BEGIN CERTIFICATE-----"
      fp.puts [data].pack("m*")
      fp.puts "-----END CERTIFICATE-----"
    end
    puts "Created #{fname}"
  end
end
# system("c_rehash", ".")