File: ca-index.py

package info (click to toggle)
pyca 20031118-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 644 kB
  • ctags: 933
  • sloc: python: 4,998; sh: 646; makefile: 43
file content (91 lines) | stat: -rwxr-xr-x 2,232 bytes parent folder | download | duplicates (5)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/python

"""
ca-index.py
(c) by Michael Stroeder <michael@stroeder.com>

This CGI-BIN program shows a pretty index of the CA definitions in
OpenSSL's config file (e.g. named openssl.cnf)
"""

__version__ = '0.6.6'

import os, sys, types, string, pycacnf, openssl, htmlbase

from pycacnf import opensslcnf, pyca_section

nsGetCertUrl = pyca_section.get('nsGetCertUrl','')
nsViewCertUrl = pyca_section.get('nsViewCertUrl','')
nsEnrollUrl  = pyca_section.get('nsEnrollUrl','')

ca_names = opensslcnf.sectionkeys.get('ca',[])

if not ca_names:
  htmlbase.PrintErrorMsg('No certificate authorities found.')
  sys.exit(0)

htmlbase.PrintHeader('Overview of certificate authorities')
htmlbase.PrintHeading('Overview of certificate authorities')
print """<TABLE BORDER WIDTH=100%>
<TR>
  <TH>CA name</TH>
  <TH COLSPAN=2>CA certificate</TH>
  <TH COLSPAN=2>CRL</TH>
  <TH>certificate<BR>types</TH>
  <TH>Comment</TH>
  <TH>View policy</TH>
</TR>
"""

for ca_name in ca_names:
  ca = opensslcnf.getcadata(ca_name)
  if nsEnrollUrl and ca.isclientcert():
    nsCertTypeStr = '<A HREF="%s%s/%s">%s</A>' % (ca.nsBaseUrl,nsEnrollUrl,ca_name,ca.nsCertTypeStr)
  else:
    if ca.nsCertTypeStr:
      nsCertTypeStr = '%s' % (ca.nsCertTypeStr)
    else:
      nsCertTypeStr = '&nbsp;'
  if ca.nsCaRevocationUrl:
    nsCaRevocationUrl='<A HREF="%s%s">load</A>' % (ca.nsBaseUrl,ca.nsCaRevocationUrl)
    nsViewRevocationUrl='<A HREF="%s%s/%s/crl">view</A>' % (ca.nsBaseUrl,nsViewCertUrl,ca_name)
  else:
    nsCaRevocationUrl   = '&nbsp;'
    nsViewRevocationUrl = '&nbsp;'
  if ca.nsCaPolicyUrl:
    nsCaPolicyUrl='<A HREF="%s%s">Policy of %s</A>' % (ca.nsBaseUrl,ca.nsCaPolicyUrl,ca_name)
  else:
    nsCaPolicyUrl='-'

  print """
<TR>
  <TD>%s</TD>
  <TD><A HREF="%s%s/%s/ca.crt">load</A></TD>
  <TD><A HREF="%s%s/%s/ca">view</A></TD>
  <TD>%s</TD>
  <TD>%s</TD>
  <TD>%s</TD>
  <TD>%s</TD>
  <TD>%s</TD>
<TR>
""" % (
  ca_name,
  ca.nsBaseUrl,
  nsGetCertUrl,
  ca_name,
  ca.nsBaseUrl,
  nsViewCertUrl,
  ca_name,
  nsCaRevocationUrl,
  nsViewRevocationUrl,
  nsCertTypeStr,
  ca.nsComment,
  nsCaPolicyUrl
)

print '</TABLE><P>'

print '<A HREF="cert-query.py">Search for issued certificates.</A>'

htmlbase.PrintFooter()
sys.exit(0)