00001 """ 00002 RPKI engine daemon. This is still very much a work in progress. 00003 00004 Usage: python rpkid.py [ { -c | --config } configfile ] 00005 [ { -h | --help } ] 00006 [ { -p | --profile } outputfile ] 00007 00008 Default configuration file is rpkid.conf, override with --config option. 00009 00010 $Id: rpkid.py 2452 2009-05-27 02:54:24Z sra $ 00011 00012 Copyright (C) 2009 Internet Systems Consortium ("ISC") 00013 00014 Permission to use, copy, modify, and distribute this software for any 00015 purpose with or without fee is hereby granted, provided that the above 00016 copyright notice and this permission notice appear in all copies. 00017 00018 THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 00019 REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 00020 AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 00021 INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 00022 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 00023 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 00024 PERFORMANCE OF THIS SOFTWARE. 00025 00026 Portions copyright (C) 2007--2008 American Registry for Internet Numbers ("ARIN") 00027 00028 Permission to use, copy, modify, and distribute this software for any 00029 purpose with or without fee is hereby granted, provided that the above 00030 copyright notice and this permission notice appear in all copies. 00031 00032 THE SOFTWARE IS PROVIDED "AS IS" AND ARIN DISCLAIMS ALL WARRANTIES WITH 00033 REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 00034 AND FITNESS. IN NO EVENT SHALL ARIN BE LIABLE FOR ANY SPECIAL, DIRECT, 00035 INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 00036 LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 00037 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 00038 PERFORMANCE OF THIS SOFTWARE. 00039 """ 00040 00041 import os, time, getopt, sys 00042 import rpki.resource_set, rpki.up_down, rpki.left_right, rpki.x509, rpki.sql 00043 import rpki.https, rpki.config, rpki.exceptions, rpki.relaxng, rpki.log 00044 import rpki.rpki_engine 00045 00046 os.environ["TZ"] = "UTC" 00047 time.tzset() 00048 00049 rpki.log.init("rpkid") 00050 00051 cfg_file = "rpkid.conf" 00052 profile = None 00053 00054 opts, argv = getopt.getopt(sys.argv[1:], "c:hp:?", ["config=", "help", "profile="]) 00055 for o, a in opts: 00056 if o in ("-h", "--help", "-?"): 00057 print __doc__ 00058 sys.exit(0) 00059 elif o in ("-c", "--config"): 00060 cfg_file = a 00061 elif o in ("-p", "--profile"): 00062 profile = a 00063 if argv: 00064 raise RuntimeError, "Unexpected arguments %s" % argv 00065 00066 def main(): 00067 00068 cfg = rpki.config.parser(cfg_file, "rpkid") 00069 00070 startup_msg = cfg.get("startup-message", "") 00071 if startup_msg: 00072 rpki.log.info(startup_msg) 00073 00074 if profile: 00075 rpki.log.info("Running in profile mode with output to %s" % profile) 00076 00077 gctx = rpki.rpki_engine.rpkid_context(cfg) 00078 00079 rpki.https.server(host = gctx.https_server_host, 00080 port = gctx.https_server_port, 00081 server_key = gctx.rpkid_key, 00082 server_cert = gctx.rpkid_cert, 00083 dynamic_https_trust_anchor = gctx.build_https_ta_cache, 00084 handlers = (("/left-right", gctx.left_right_handler), 00085 ("/up-down/", gctx.up_down_handler), 00086 ("/cronjob", gctx.cronjob_handler))) 00087 00088 if profile: 00089 import cProfile 00090 cProfile.run("main()", profile) 00091 else: 00092 main()