~ubuntu-branches/ubuntu/karmic/pyca/karmic

« back to all changes in this revision

Viewing changes to cgi-bin/ns-check-rev.py

  • Committer: Bazaar Package Importer
  • Author(s): Lars Bahner
  • Date: 2003-12-02 19:39:35 UTC
  • Revision ID: james.westby@ubuntu.com-20031202193935-fzzt289mntvy6a8q
Tags: upstream-20031118
ImportĀ upstreamĀ versionĀ 20031118

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
"""
 
4
ns-check-rev.py
 
5
(c) by Michael Stroeder <michael@stroeder.com>
 
6
 
 
7
CGI-BIN for On-line checking of certificates -
 
8
a handler for URL in Netscape extension nsRevocationUrl.
 
9
 
 
10
Have look at a x509_extensions-section and the
 
11
attributes nsBaseUrl and nsRevocationUrl
 
12
 
 
13
Input:
 
14
 
 
15
PATH_INFO
 
16
- Name of CA in openssl.cnf (section [ca] of openssl.cnf)
 
17
QUERY_STRING
 
18
- Serial number of desired certificate
 
19
  max. 8 digits hexadecimal (32 Bit)
 
20
 
 
21
Examples:
 
22
  ns-check-rev.py/Persona?537A
 
23
  checks if certificate number 0x537A issued of CA "Persona" is valid
 
24
 
 
25
Output:
 
26
 
 
27
  Content-type: application/x-netscape-revocation
 
28
  0 if certificate is valid <=> V in index.txt
 
29
  1 if certificate is invalid
 
30
"""
 
31
 
 
32
Version='0.6.6'
 
33
 
 
34
import sys, os, string, re, pycacnf, htmlbase, openssl
 
35
 
 
36
from pycacnf import opensslcnf, pyca_section
 
37
 
 
38
# Ein paar Umgebungsvariablen auslesen, welche der Apache liefert
 
39
request_method  = os.environ['REQUEST_METHOD']
 
40
query_string    = os.environ['QUERY_STRING']
 
41
ca_name = os.environ.get('PATH_INFO','')[1:]
 
42
 
 
43
# Wir lesen rein gar nix von Standardeingabe => gleich dicht machen
 
44
sys.stdin.close()
 
45
 
 
46
# Hier die ueblichen Paranoid-Pruefungen der Parameter
 
47
rm = (re.compile('[0-9a-fA-F]+')).match(query_string)
 
48
if (request_method!='GET') or \
 
49
   (len(query_string)>8) or \
 
50
   not rm or \
 
51
   rm.group(0)!=query_string:
 
52
  # Skript nicht mit GET aufgerufen
 
53
  # Seriennummer mit mehr 32 Bit
 
54
  # Parameter war keine Hex-Nummer
 
55
  # => Kommentarloses Ende
 
56
  sys.exit(0)
 
57
 
 
58
if not ca_name:
 
59
  htmlbase.PrintErrorMsg('No certificate authority.')
 
60
  sys.exit(0)
 
61
 
 
62
if not opensslcnf.data['ca'].has_key(ca_name):
 
63
  # CA-Definition nicht in openssl-Konfiguration enthalten
 
64
  htmlbase.PrintErrorMsg('Unknown certificate authority "%s"!' % ca_name)
 
65
  sys.exit(0)
 
66
 
 
67
ca_section=opensslcnf.data[opensslcnf.data['ca'][ca_name]]
 
68
ca_dir = ca_section.get('dir','')
 
69
ca_database = string.replace(ca_section.get('database','$dir/index.txt'),'$dir',ca_dir)
 
70
 
 
71
# Hex-String in Integer wandeln
 
72
serialnumber=string.atoi(query_string,16)
 
73
 
 
74
# Eintrag suchen lassen
 
75
entry = openssl.db.GetEntrybySerial(ca_database,serialnumber)
 
76
 
 
77
# Header schreiben
 
78
print 'Content-type: application/x-netscape-revocation\n'
 
79
 
 
80
# Kein Zertifikat mit angegebener Nummer gefunden
 
81
if not entry:
 
82
  print 1
 
83
  sys.exit(0)
 
84
 
 
85
# Zertifikat gueltig <=> type-Feld ist 'V'
 
86
print not (entry and openssl.db.IsValid(entry))
 
87
 
 
88
#if entry[openssl.db.DB_type]==openssl.db.DB_TYPE_VAL:
 
89
#  print 0
 
90
#else:
 
91
#  print 1
 
92
 
 
93
sys.exit(0)
 
94