cam 1.79 KB
Newer Older
ale's avatar
ale committed
1 2 3 4 5
#!/usr/bin/python


import os, sys
import logging
6
sys.path.insert(0, os.path.join(os.path.dirname(sys.argv[0]), 'lib'))
ale's avatar
ale committed
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

from utils import *
from cfg import *

# commands
from gen import gen
from newca import newca
from list import list
from files import files
from initfs import initfs
from check import check


def Usage():
    print '''
CAM v0.1 - (c)2006 by <ale@incal.net> 
A Certification Authority manager for complex situations.
Usage: %s <COMMAND> [<ARG>...]
Known commands:

  init
    Initialize the environment by creating the necessary
    directory structure

  newca [<RSA_CRT> [<DSA_CRT>]]
    Create a new CA certificate (otherwise you can import
    your own certificates)

  gen <TAG>...
    Create (or re-create) the certificates corresponding
    to TAG

  list
    List all known certificates

  files <TAG>...
    Dump all the certificate-related files of this TAG

  check
    Should be run weekly from a cron job to warn you if
    some certificates are about to expire (controlled by
    the 'warning_days' parameter in the 'global' section
    of the configuration)


The configuration will be read from '%s'.
It consists of a ini-style file, with one 'ca' section that
specifies global CA parameters, and more sections for each
tag with certificate-specific information. See the examples
for more details on how to write your own configuration.

''' % (sys.argv[0], config_file_path)
    sys.exit(0)


if len(sys.argv) < 2 or sys.argv[1] == 'help':
    Usage()

cmd = sys.argv[1]
if cmd == 'init':
    initfs()
elif cmd == 'gen':
    for tag in sys.argv[2:]:
	gen(tag)
elif cmd == 'newca':
    newca()
elif cmd == 'list':
    list(sys.argv[2:])
elif cmd == 'files':
    for tag in sys.argv[2:]:
	files(tag)
elif cmd == 'check':
    check()
else:
    print 'Unknown command \'%s\'.' % cmd
    Usage()