""" Command line IR back-end control program for rpkid and pubd. $Id$ Copyright (C) 2009--2010 Internet Systems Consortium ("ISC") Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. Portions copyright (C) 2007--2008 American Registry for Internet Numbers ("ARIN") Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. THE SOFTWARE IS PROVIDED "AS IS" AND ARIN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ARIN BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. """ import getopt, sys, textwrap import rpki.left_right, rpki.http, rpki.x509, rpki.config, rpki.log import rpki.publication, rpki.async pem_out = None class UsageWrapper(textwrap.TextWrapper): """ Call interface around Python textwrap.Textwrapper class. """ def __call__(self, *args): """ Format arguments, with TextWrapper indentation. """ return self.fill(textwrap.dedent(" ".join(args))) usage_fill = UsageWrapper(subsequent_indent = " " * 4) class reply_elt_mixin(object): """ Protocol mix-in for printout of reply PDUs. """ is_cmd = False def client_reply_decode(self): pass def client_reply_show(self): print self.element_name for i in self.attributes + self.elements: if getattr(self, i) is not None: print " %s: %s" % (i, getattr(self, i)) class cmd_elt_mixin(reply_elt_mixin): """ Protocol mix-in for command line client element PDUs. """ is_cmd = True ## @var excludes # XML attributes and elements that should not be allowed as command # line arguments. excludes = () @classmethod def usage(cls): """ Generate usage message for this PDU. """ args = " ".join("--" + x + "=" for x in cls.attributes + cls.elements if x not in cls.excludes) bools = " ".join("--" + x for x in cls.booleans) if args and bools: return args + " " + bools else: return args or bools def client_getopt(self, argv): """ Parse options for this class. """ opts, argv = getopt.getopt(argv, "", [x + "=" for x in self.attributes + self.elements if x not in self.excludes] + list(self.booleans)) for o, a in opts: o = o[2:] handler = getattr(self, "client_query_" + o, None) if handler is not None: handler(a) elif o in self.booleans: setattr(self, o, True) else: assert o in self.attributes setattr(self, o, a) return argv def client_query_bpki_cert(self, arg): """ Special handler for --bpki_cert option. """ self.bpki_cert = rpki.x509.X509(Auto_file = arg) def client_query_glue(self, arg): """ Special handler for --bpki_glue option. """ self.bpki_glue = rpki.x509.X509(Auto_file = arg) def client_query_bpki_cms_cert(self, arg): """ Special handler for --bpki_cms_cert option. """ self.bpki_cms_cert = rpki.x509.X509(Auto_file = arg) def client_query_cms_glue(self, arg): """ Special handler for --bpki_cms_glue option. """ self.bpki_cms_glue = rpki.x509.X509(Auto_file = arg) class cmd_msg_mixin(object): """ Protocol mix-in for command line client message PDUs. """ @classmethod def usage(cls): """ Generate usage message for this PDU. """ for k, v in cls.pdus.items(): if v.is_cmd: print usage_fill(k, v.usage()) # left-right protcol class self_elt(cmd_elt_mixin, rpki.left_right.self_elt): pass class bsc_elt(cmd_elt_mixin, rpki.left_right.bsc_elt): excludes = ("pkcs10_request",) def client_query_signing_cert(self, arg): """--signing_cert option.""" self.signing_cert = rpki.x509.X509(Auto_file = arg) def client_query_signing_cert_crl(self, arg): """--signing_cert_crl option.""" self.signing_cert_crl = rpki.x509.CRL(Auto_file = arg) def client_reply_decode(self): global pem_out if pem_out is not None and self.pkcs10_request is not None: if isinstance(pem_out, str): pem_out = open(pem_out, "w") pem_out.write(self.pkcs10_request.get_PEM()) class parent_elt(cmd_elt_mixin, rpki.left_right.parent_elt): pass class child_elt(cmd_elt_mixin, rpki.left_right.child_elt): pass class repository_elt(cmd_elt_mixin, rpki.left_right.repository_elt): pass class list_published_objects_elt(cmd_elt_mixin, rpki.left_right.list_published_objects_elt): excludes = ("uri",) class list_received_resources_elt(cmd_elt_mixin, rpki.left_right.list_received_resources_elt): excludes = ("parent_handle", "notBefore", "notAfter", "uri", "sia_uri", "aia_uri", "asn", "ipv4", "ipv6") class report_error_elt(reply_elt_mixin, rpki.left_right.report_error_elt): pass class left_right_msg(cmd_msg_mixin, rpki.left_right.msg): pdus = dict((x.element_name, x) for x in (self_elt, bsc_elt, parent_elt, child_elt, repository_elt, list_published_objects_elt, list_received_resources_elt, report_error_elt)) class left_right_sax_handler(rpki.left_right.sax_handler): pdu = left_right_msg class left_right_cms_msg(rpki.left_right.cms_msg): saxify = left_right_sax_handler.saxify # Publication protocol class config_elt(cmd_elt_mixin, rpki.publication.config_elt): def client_query_bpki_crl(self, arg): """ Special handler for --bpki_crl option. """ self.bpki_crl = rpki.x509.CRL(Auto_file = arg) class client_elt(cmd_elt_mixin, rpki.publication.client_elt): pass class certificate_elt(cmd_elt_mixin, rpki.publication.certificate_elt): pass class crl_elt(cmd_elt_mixin, rpki.publication.crl_elt): pass class manifest_elt(cmd_elt_mixin, rpki.publication.manifest_elt): pass class roa_elt(cmd_elt_mixin, rpki.publication.roa_elt): pass class report_error_elt(reply_elt_mixin, rpki.publication.report_error_elt): pass class publication_msg(cmd_msg_mixin, rpki.publication.msg): pdus = dict((x.element_name, x) for x in (config_elt, client_elt, certificate_elt, crl_elt, manifest_elt, roa_elt, report_error_elt)) class publication_sax_handler(rpki.publication.sax_handler): pdu = publication_msg class publication_cms_msg(rpki.publication.cms_msg): saxify = publication_sax_handler.saxify # Usage top_opts = ["config=", "help", "pem_out=", "quiet", "verbose"] def usage(code = 1): if __doc__ is not None: print __doc__.strip() print print "Usage:" print print "# Top-level options:" print usage_fill(*["--" + x for x in top_opts]) print print "# left-right protocol:" left_right_msg.usage() print print "# publication protocol:" publication_msg.usage() sys.exit(code) # Main program rpki.log.init("irbe_cli") argv = sys.argv[1:] if not argv: usage(0) cfg_file = None verbose = True opts, argv = getopt.getopt(argv, "c:hpqv?", top_opts) for o, a in opts: if o in ("-?", "-h", "--help"): usage(0) elif o in ("-c", "--config"): cfg_file = a elif o in ("-p", "--pem_out"): pem_out = a elif o in ("-q", "--quiet"): verbose = False elif o in ("-v", "--verbose"): verbose = True if not argv: usage(1) cfg = rpki.config.parser(cfg_file, "irbe_cli") q_msg_left_right = [] q_msg_publication = [] while argv: if argv[0] in left_right_msg.pdus: q_pdu = left_right_msg.pdus[argv[0]]() q_msg = q_msg_left_right elif argv[0] in publication_msg.pdus: q_pdu = publication_msg.pdus[argv[0]]() q_msg = q_msg_publication else: usage(1) argv = q_pdu.client_getopt(argv[1:]) q_msg.append(q_pdu) if q_msg_left_right: class left_right_proto(object): cms_msg = left_right_cms_msg msg = left_right_msg call_rpkid = rpki.async.sync_wrapper(rpki.http.caller( proto = left_right_proto, client_key = rpki.x509.RSA( Auto_file = cfg.get("rpkid-irbe-key")), client_cert = rpki.x509.X509(Auto_file = cfg.get("rpkid-irbe-cert")), server_ta = rpki.x509.X509(Auto_file = cfg.get("rpkid-bpki-ta")), server_cert = rpki.x509.X509(Auto_file = cfg.get("rpkid-cert")), url = cfg.get("rpkid-url"), debug = verbose)) call_rpkid(*q_msg_left_right) if q_msg_publication: class publication_proto(object): msg = publication_msg cms_msg = publication_cms_msg call_pubd = rpki.async.sync_wrapper(rpki.http.caller( proto = publication_proto, client_key = rpki.x509.RSA( Auto_file = cfg.get("pubd-irbe-key")), client_cert = rpki.x509.X509(Auto_file = cfg.get("pubd-irbe-cert")), server_ta = rpki.x509.X509(Auto_file = cfg.get("pubd-bpki-ta")), server_cert = rpki.x509.X509(Auto_file = cfg.get("pubd-cert")), url = cfg.get("pubd-url")), debug = verbose) call_pubd(*q_msg_publication) har */ .highlight .dl { color: #D20; background-color: #FFF0F0 } /* Literal.String.Delimiter */ .highlight .sd { color: #D20; background-color: #FFF0F0 } /* Literal.String.Doc */ .highlight .s2 { color: #D20; background-color: #FFF0F0 } /* Literal.String.Double */ .highlight .se { color: #04D; background-color: #FFF0F0 } /* Literal.String.Escape */ .highlight .sh { color: #D20; background-color: #FFF0F0 } /* Literal.String.Heredoc */ .highlight .si { color: #33B; background-color: #FFF0F0 } /* Literal.String.Interpol */ .highlight .sx { color: #2B2; background-color: #F0FFF0 } /* Literal.String.Other */ .highlight .sr { color: #080; background-color: #FFF0FF } /* Literal.String.Regex */ .highlight .s1 { color: #D20; background-color: #FFF0F0 } /* Literal.String.Single */ .highlight .ss { color: #A60; background-color: #FFF0F0 } /* Literal.String.Symbol */ .highlight .bp { color: #038 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #06B; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #369 } /* Name.Variable.Class */ .highlight .vg { color: #D70 } /* Name.Variable.Global */ .highlight .vi { color: #33B } /* Name.Variable.Instance */ .highlight .vm { color: #369 } /* Name.Variable.Magic */ .highlight .il { color: #00D; font-weight: bold } /* Literal.Number.Integer.Long */
/* crypto/evp/p_enc.c */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
* by Eric Young (eay@cryptsoft.com).
* The implementation was written so as to conform with Netscapes SSL.
*
* This library is free for commercial and non-commercial use as long as
* the following conditions are aheared to. The following conditions
* apply to all code found in this distribution, be it the RC4, RSA,
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
* included with this distribution is covered by the same copyright terms
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
*
* Copyright remains Eric Young's, and as such any Copyright notices in
* the code are not to be removed.
* If this package is used in a product, Eric Young should be given attribution
* as the author of the parts of the library used.
* This can be in the form of a textual message at program startup or
* in documentation (online or textual) provided with the package.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* "This product includes cryptographic software written by
* Eric Young (eay@cryptsoft.com)"
* The word 'cryptographic' can be left out if the rouines from the library
* being used are not cryptographic related :-).
* 4. If you include any Windows specific code (or a derivative thereof) from
* the apps directory (application code) you must include an acknowledgement:
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
*
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* The licence and distribution terms for any publically available version or
* derivative of this code cannot be changed. i.e. this code cannot simply be
* copied and put under another distribution licence
* [including the GNU Public Licence.]
*/
#include <stdio.h>
#include "cryptlib.h"
#include <openssl/rand.h>
#ifndef OPENSSL_NO_RSA
#include <openssl/rsa.h>
#endif
#include <openssl/evp.h>
#include <openssl/objects.h>
#include <openssl/x509.h>
int EVP_PKEY_encrypt(unsigned char *ek, const unsigned char *key, int key_len,
EVP_PKEY *pubk)
{
int ret=0;
#ifndef OPENSSL_NO_RSA
if (pubk->type != EVP_PKEY_RSA)
{
#endif
EVPerr(EVP_F_EVP_PKEY_ENCRYPT,EVP_R_PUBLIC_KEY_NOT_RSA);
#ifndef OPENSSL_NO_RSA
goto err;
}
ret=RSA_public_encrypt(key_len,key,ek,pubk->pkey.rsa,RSA_PKCS1_PADDING);
err:
#endif
return(ret);
}