17279 pkgrecv should support ssl certs and keys
authorBart Smaalders <Bart.Smaalders@Oracle.COM>
Thu, 21 Oct 2010 17:22:19 -0700
changeset 2116 01cac360e383
parent 2115 c6a812ab117a
child 2117 83afe4aabe78
17279 pkgrecv should support ssl certs and keys
src/man/pkgrecv.1.txt
src/modules/client/transport/transport.py
src/pull.py
--- a/src/man/pkgrecv.1.txt	Thu Oct 21 14:28:40 2010 -0700
+++ b/src/man/pkgrecv.1.txt	Thu Oct 21 17:22:19 2010 -0700
@@ -6,7 +6,8 @@
 
 SYNOPSIS
      /usr/bin/pkgrecv [-s src_uri] [-d (path|dest_uri)] [-c cache_dir]
-         [-kr] [-m match] [-n] [--raw] (fmri|pattern) ...
+         [-kr] [-m match] [-n] [--raw] [--key keyfile --cert certfile] 
+         (fmri|pattern) ...
      /usr/bin/pkgrecv [-s src_uri] --newest
 
 DESCRIPTION
@@ -51,6 +52,12 @@
      -s src_repo_uri A URI representing the location of a pkg(5) repository
                      from which to receive package data.
 
+     --cert file     Specify a client SSL certificate file to use for package 
+                     retrieval from an HTTPS repository.
+
+     --key file      Specify a client SSL key file to use for package retrieval
+                     from an HTTPS repository.
+
      --newest        List the most recent versions of the packages available
                      from the specified repository and exit.  (All other
                      options except -s will be ignored.)
@@ -63,6 +70,8 @@
                      perhaps by correcting file contents or providing
                      additional package metadata.
 
+
+
 EXAMPLES
      Example 1:  List newest packages available from the repository on
      the system named 'test'.
--- a/src/modules/client/transport/transport.py	Thu Oct 21 14:28:40 2010 -0700
+++ b/src/modules/client/transport/transport.py	Thu Oct 21 17:22:19 2010 -0700
@@ -2805,7 +2805,8 @@
 # need to configure a transport and or publishers.
 
 def setup_publisher(repo_uri, prefix, xport, xport_cfg,
-    remote_prefix=False, remote_publishers=False):
+    remote_prefix=False, remote_publishers=False, ssl_key=None, 
+    ssl_cert=None):
         """Given transport 'xport' and publisher configuration 'xport_cfg'
         take the string that identifies a repository by uri in 'repo_uri'
         and create a publisher object.  The caller must specify the prefix.
@@ -2824,6 +2825,11 @@
                 repouri_list = [publisher.RepositoryURI(repo_uri)]
                 repo = publisher.Repository(origins=repouri_list)
 
+        for origin in repo.origins:
+                if origin.scheme == "https": 
+                        origin.ssl_key = ssl_key
+                        origin.ssl_cert = ssl_cert
+
         pub = publisher.Publisher(prefix=prefix, repositories=[repo])
 
         if not remote_prefix and not remote_publishers:
@@ -2854,6 +2860,12 @@
                 else:
                         psr.origins = repouri_list
 
+                for newrepo in p.repositories:
+                        for origin in newrepo.origins:
+                                if origin.scheme == "https": 
+                                        origin.ssl_key = ssl_key
+                                        origin.ssl_cert = ssl_cert
+
                 xport_cfg.add_publisher(p)
 
         # Return first publisher in list
--- a/src/pull.py	Thu Oct 21 14:28:40 2010 -0700
+++ b/src/pull.py	Thu Oct 21 17:22:19 2010 -0700
@@ -88,9 +88,10 @@
 
         msg(_("""\
 Usage:
-        pkgrecv [-s src_repo_uri] [-d (path|dest_uri)] [-kr] [-m match] [-n]
-            [--raw] (fmri|pattern) ...
-        pkgrecv [-s src_repo_uri] --newest
+        pkgrecv [-s src_uri] [-d (path|dest_uri)] [-c cache_dir]
+            [-kr] [-m match] [-n] [--raw] [--key keyfile --cert certfile] 
+            (fmri|pattern) ...
+        pkgrecv [-s src_repo_uri] --newest 
 
 Options:
         -c cache_dir    The path to a directory that will be used to cache
@@ -138,6 +139,10 @@
                         perhaps by correcting file contents or providing
                         additional package metadata.
 
+        --key keyfile   Specify a client SSL key file to use for pkg retrieval.
+
+        --cert certfile Specify a client SSL certificate file to use for pkg retrieval.
+
 Environment:
         PKG_DEST        Destination directory or repository URI
         PKG_SRC         Source repository URI"""))
@@ -372,6 +377,8 @@
         incoming_dir = None
         src_pub = None
         raw = False
+        key = None
+        cert = None
 
         temp_root = misc.config_temp_root()
 
@@ -382,8 +389,8 @@
         src_uri = os.environ.get("PKG_SRC", None)
 
         try:
-                opts, pargs = getopt.getopt(sys.argv[1:], "c:d:hkm:nrs:",
-                    ["newest", "raw"])
+                opts, pargs = getopt.getopt(sys.argv[1:], "c:d:hkm:nrs:", 
+                    ["key=", "cert=", "newest", "raw"])
         except getopt.GetoptError, e:
                 usage(_("Illegal option -- %s") % e.opt)
 
@@ -413,6 +420,10 @@
                         list_newest = True
                 elif opt == "--raw":
                         raw = True
+                elif opt == "--key":
+                        key= arg
+                elif opt == "--cert":
+                        cert = arg
 
         if not src_uri:
                 usage(_("a source repository must be provided"))
@@ -445,7 +456,7 @@
 
         # Configure src publisher(s).
         transport.setup_publisher(src_uri, "source", xport, xport_cfg,
-            remote_prefix=True)
+            remote_prefix=True, ssl_key=key, ssl_cert=cert)
 
         any_unmatched = []
         total_processed = 0