Changeset 272


Ignore:
Timestamp:
12/29/14 16:35:37 (9 years ago)
Author:
atzm
Message:

add SSL certificate verification for controller API

Location:
etherws/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • etherws/trunk/README.rst

    r260 r272  
    162162 
    163163Password can be input from stdin as well as WebSocket tunnel creation. 
    164  
    165 Note: *etherws ctl* currently cannot verify SSL certificate on controller. 
    166164 
    167165Virtual Machines Connection 
  • etherws/trunk/etherws.py

    r267 r272  
    944944            return setattr(ns, htpasswd, Htpasswd(val)) 
    945945 
    946     #if args.debug: 
    947     #    websocket.enableTrace(True) 
     946    # if args.debug: 
     947    #     websocket.enableTrace(True) 
    948948 
    949949    if args.ageout <= 0: 
     
    10181018 
    10191019def _start_ctl(args): 
     1020    def have_ssl_cert_verification(): 
     1021        return 'context' in urllib2.urlopen.__code__.co_varnames 
     1022 
    10201023    def request(args, method, params=None, id_=0): 
    10211024        req = urllib2.Request(args.ctlurl) 
     
    10301033        if params is not None: 
    10311034            data['params'] = params 
    1032         return json.loads(urllib2.urlopen(req, json.dumps(data)).read()) 
     1035        if have_ssl_cert_verification(): 
     1036            ctx = ssl.create_default_context(purpose=ssl.Purpose.SERVER_AUTH, 
     1037                                             cafile=args.ctlsslcert) 
     1038            if args.ctlinsecure: 
     1039                ctx.check_hostname = False 
     1040                ctx.verify_mode = ssl.CERT_NONE 
     1041            fp = urllib2.urlopen(req, json.dumps(data), context=ctx) 
     1042        elif args.ctlsslcert: 
     1043            raise EnvironmentError('do not support certificate verification') 
     1044        else: 
     1045            fp = urllib2.urlopen(req, json.dumps(data)) 
     1046        return json.loads(fp.read()) 
    10331047 
    10341048    def print_table(rows): 
     
    12041218    parser_ctl.add_argument('--ctlpasswd', 
    12051219                            help='password to auth control API') 
     1220    parser_ctl.add_argument('--ctlsslcert', 
     1221                            help='path to SSL certificate for control API') 
     1222    parser_ctl.add_argument( 
     1223        '--ctlinsecure', action='store_true', default=False, 
     1224        help='do not verify control API certificate') 
    12061225 
    12071226    control_method = parser_ctl.add_subparsers(dest='control_method') 
Note: See TracChangeset for help on using the changeset viewer.