summaryrefslogtreecommitdiffstats
path: root/scripts/external_libs/platform/fedora18/zmq/auth/certs.py
blob: 4d26ad7bd82fc088156417bacbc80d0261255848 (plain)
1
2
3
4
5
6
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
"""0MQ authentication related functions and classes."""

# Copyright (C) PyZMQ Developers
# Distributed under the terms of the Modified BSD License.


import datetime
import glob
import io
import os
import zmq
from zmq.utils.strtypes import bytes, unicode, b, u


_cert_secret_banner = u("""#   ****  Generated on {0} by pyzmq  ****
#   ZeroMQ CURVE **Secret** Certificate
#   DO NOT PROVIDE THIS FILE TO OTHER USERS nor change its permissions.

""")

_cert_public_banner = u("""#   ****  Generated on {0} by pyzmq  ****
#   ZeroMQ CURVE Public Certificate
#   Exchange securely, or use a secure mechanism to verify the contents
#   of this file after exchange. Store public certificates in your home
#   directory, in the .curve subdirectory.

""")

def _write_key_file(key_filename, banner, public_key, secret_key=None, metadata=None, encoding='utf-8'):
    """Create a certificate file"""
    if isinstance(public_key, bytes):
        public_key = public_key.decode(encoding)
    if isinstance(secret_key, bytes):
        secret_key = secret_key.decode(encoding)
    with io.open(key_filename, 'w', encoding='utf8') as f:
        f.write(banner.format(datetime.datetime.now()))

        f.write(u('metadata\n'))
        if metadata:
            for k, v in metadata.items():
                if isinstance(v, bytes):
                    v = v.decode(encoding)
                f.write(u("    {0} = {1}\n").format(k, v))

        f.write(u('curve\n'))
        f.write(u("    public-key = \"{0}\"\n").format(public_key))

        if secret_key:
            f.write(u("    secret-key = \"{0}\"\n").format(secret_key))


def create_certificates(key_dir, name, metadata=None):
    """Create zmq certificates.
    
    Returns the file paths to the public and secret certificate files.
    """
    public_key, secret_key = zmq.curve_keypair()
    base_filename = os.path.join(key_dir, name)
    secret_key_file = "{0}.key_secret".format(base_filename)
    public_key_file = "{0}.key".format(base_filename)
    now = datetime.datetime.now()

    _write_key_file(public_key_file,
                    _cert_public_banner.format(now),
                    public_key)

    _write_key_file(secret_key_file,
                    _cert_secret_banner.format(now),
                    public_key,
                    secret_key=secret_key,
                    metadata=metadata)

    return public_key_file, secret_key_file


def load_certificate(filename):
    """Load public and secret key from a zmq certificate.
    
    Returns (public_key, secret_key)
    
    If the certificate file only contains the public key,
    secret_key will be None.
    """
    public_key = None
    secret_key = None
    if not os.path.exists(filename):
        raise IOError("Invalid certificate file: {0}".format(filename))

    with open(filename, 'rb') as f:
        for line in f:
            line = line.strip()
            if line.startswith(b'#'):
                continue
            if line.startswith(b'public-key'):
                public_key = line.split(b"=", 1)[1].strip(b' \t\'"')
            if line.startswith(b'secret-key'):
                secret_key = line.split(b"=", 1)[1].strip(b' \t\'"')
            if public_key and secret_key:
                break
    
    return public_key, secret_key


def load_certificates(directory='.'):
    """Load public keys from all certificates in a directory"""
    certs = {}
    if not os.path.isdir(directory):
        raise IOError("Invalid certificate directory: {0}".format(directory))
    # Follow czmq pattern of public keys stored in *.key files.
    glob_string = os.path.join(directory, "*.key")
    
    cert_files = glob.glob(glob_string)
    for cert_file in cert_files:
        public_key, _ = load_certificate(cert_file)
        if public_key:
            certs[public_key] = 'OK'
    return certs

__all__ = ['create_certificates', 'load_certificate', 'load_certificates']
ump only in image gbp_bridge_domain_dump_reply only in image gbp_endpoint_details definition changed gbp_endpoint_group_add only in image gbp_endpoint_group_add_del only in file gbp_endpoint_group_add_del_reply only in file gbp_endpoint_group_add_reply only in image gbp_endpoint_group_del only in image gbp_endpoint_group_del_reply only in image gbp_endpoint_learn_set_inactive_threshold only in image gbp_endpoint_learn_set_inactive_threshold_reply only in image gbp_ext_itf_add_del only in image gbp_ext_itf_add_del_reply only in image gbp_ext_itf_details only in image gbp_ext_itf_dump only in image gbp_route_domain_add only in image gbp_route_domain_add_reply only in image gbp_route_domain_del only in image gbp_route_domain_del_reply only in image gbp_route_domain_details only in image gbp_route_domain_dump only in image gbp_route_domain_dump_reply only in image gbp_vxlan_tunnel_add only in image gbp_vxlan_tunnel_add_reply only in image gbp_vxlan_tunnel_del only in image gbp_vxlan_tunnel_del_reply only in image gbp_vxlan_tunnel_details only in image gbp_vxlan_tunnel_dump only in image igmp_proxy_device_add_del only in image igmp_proxy_device_add_del_interface only in image igmp_proxy_device_add_del_interface_reply only in image igmp_proxy_device_add_del_reply only in image ip6_mfib_details definition changed ip_container_proxy_details only in image ip_container_proxy_dump only in image ip_mfib_details definition changed ip_punt_redirect definition changed ip_punt_redirect_details only in image ip_punt_redirect_dump only in image ip_source_check_interface_add_del only in image ip_source_check_interface_add_del_reply only in image ipip_6rd_add_tunnel_reply definition changed ipip_6rd_del_tunnel definition changed ipip_add_tunnel_reply definition changed ipip_del_tunnel definition changed ipip_tunnel_details definition changed ipip_tunnel_dump definition changed ipsec_backend_details only in image ipsec_backend_dump only in image ipsec_sa_details definition changed ipsec_select_backend only in image ipsec_select_backend_reply only in image ipsec_tunnel_if_add_del definition changed map_add_del_rule definition changed map_add_domain definition changed map_another_segment definition changed map_domain_details definition changed map_if_enable_disable only in image map_if_enable_disable_reply only in image map_param_add_del_pre_resolve only in image map_param_add_del_pre_resolve_reply only in image map_param_get only in image map_param_get_reply only in image map_param_set_fragmentation only in image map_param_set_fragmentation_reply only in image map_param_set_icmp6 only in image map_param_set_icmp6_reply only in image map_param_set_icmp only in image map_param_set_icmp_reply only in image map_param_set_reassembly only in image map_param_set_reassembly_reply only in image map_param_set_security_check only in image map_param_set_security_check_reply only in image map_param_set_tcp only in image map_param_set_tcp_reply only in image map_param_set_traffic_class only in image map_param_set_traffic_class_reply only in image map_rule_details definition changed memclnt_delete definition changed nat44_add_del_lb_static_mapping definition changed nat44_lb_static_mapping_add_del_local only in image nat44_lb_static_mapping_add_del_local_reply only in image nat44_lb_static_mapping_details definition changed nsim_configure definition changed punt only in file punt_details only in image punt_dump only in image punt_reply only in file punt_socket_deregister definition changed punt_socket_details only in image punt_socket_dump only in image punt_socket_register definition changed set_ip_flow_hash definition changed set_punt only in image set_punt_reply only in image show_version_reply definition changed stats_get_poller_delay only in file stats_get_poller_delay_reply only in file sw_interface_bond_details definition changed sw_interface_details definition changed sw_interface_ip6_set_link_local_address only in file sw_interface_ip6_set_link_local_address_reply only in file sw_interface_tap_v2_details definition changed syslog_get_filter only in image syslog_get_filter_reply only in image syslog_get_sender only in image syslog_get_sender_reply only in image syslog_set_filter only in image syslog_set_filter_reply only in image syslog_set_sender only in image syslog_set_sender_reply only in image tap_create_v2 definition changed unmap_segment definition changed vnet_bier_neighbor_counters only in file vnet_get_summary_stats only in file vnet_get_summary_stats_reply only in file vnet_interface_combined_counters only in file vnet_interface_simple_counters only in file vnet_ip4_fib_counters only in file vnet_ip4_mfib_counters only in file vnet_ip4_nbr_counters only in file vnet_ip6_fib_counters only in file vnet_ip6_mfib_counters only in file vnet_ip6_nbr_counters only in file vnet_per_interface_combined_counters only in file vnet_per_interface_simple_counters only in file vnet_udp_encap_counters only in file want_bier_neighbor_stats only in file want_bier_neighbor_stats_reply only in file want_interface_combined_stats only in file want_interface_combined_stats_reply only in file want_interface_simple_stats only in file want_interface_simple_stats_reply only in file want_ip4_fib_stats only in file want_ip4_fib_stats_reply only in file want_ip4_mfib_stats only in file want_ip4_mfib_stats_reply only in file want_ip4_nbr_stats only in file want_ip4_nbr_stats_reply only in file want_ip6_fib_stats only in file want_ip6_fib_stats_reply only in file want_ip6_mfib_stats only in file want_ip6_mfib_stats_reply only in file want_ip6_nbr_stats only in file want_ip6_nbr_stats_reply only in file want_per_interface_combined_stats only in file want_per_interface_combined_stats_reply only in file want_per_interface_simple_stats only in file want_per_interface_simple_stats_reply only in file want_stats only in file want_stats_reply only in file want_udp_encap_stats only in file want_udp_encap_stats_reply only in file =============================================== ================== Found 170 api message signature differences Patches that changed API definitions ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``src/vnet/interface_types.api`` * `53fffa1 <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=53fffa1>`_ API: Add support for type aliases ``src/vnet/interface.api`` * `f49ba0e <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=f49ba0e>`_ stats: Deprecate old stats framework * `53fffa1 <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=53fffa1>`_ API: Add support for type aliases * `5100aa9 <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=5100aa9>`_ vnet: store hw interface speed in kbps instead of using flags ``src/vnet/syslog/syslog.api`` * `b4515b4 <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=b4515b4>`_ Add RFC5424 syslog protocol support (VPP-1139) ``src/vnet/fib/fib_types.api`` * `775f73c <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=775f73c>`_ FIB: encode the label stack in the FIB path during table dump ``src/vnet/ip/ip.api`` * `7c03ed4 <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=7c03ed4>`_ VOM: mroutes * `3460b01 <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=3460b01>`_ api: ip_source_check_interface_add_del api is added. * `609e121 <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=609e121>`_ VPP-1507: Added binary api to dump configured ip_punt_redirect * `2af0e3a <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=2af0e3a>`_ flow-hash: Add symmetric flag for flow hashing * `47527b2 <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=47527b2>`_ IP-punt: add documentation to the API and fix IP address init * `5bb1eca <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=5bb1eca>`_ IPv6: Make link-local configurable per-interface (VPP-1446) * `75b9f45 <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=75b9f45>`_ ip: add container proxy dump API (VPP-1364) ``src/vnet/ip/ip_types.api`` * `8c8acc0 <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=8c8acc0>`_ API: Change ip4_address and ip6_address to use type alias. * `ffba3c3 <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=ffba3c3>`_ MAP: Use explicit address/prefix types in API ``src/vnet/ip/punt.api`` * `e88865d <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=e88865d>`_ VPP-1506: dump local punts and registered punt sockets ``src/vnet/ipsec/ipsec.api`` * `4c422f9 <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=4c422f9>`_ Add IPSec interface FIB index for TX packet * `b4a7a7d <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=b4a7a7d>`_ Add UDP encap flag * `b4d3053 <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=b4d3053>`_ ipsec: infra for selecting backends * `871bca9 <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=871bca9>`_ VPP-1450: binary api call for dumping SPD to interface registration ``src/vnet/l2/l2.api`` * `e26c81f <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=e26c81f>`_ L2 BD API to flush all IP-MAC entries in the specified BD * `8006c6a <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=8006c6a>`_ PAPI: Add MACAddress object wrapper for vl_api_mac_address_t * `93cc3ee <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=93cc3ee>`_ GBP Endpoint Learning * `4d5b917 <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=4d5b917>`_ BD ARP entry use common API types ``src/vnet/vxlan-gbp/vxlan_gbp.api`` * `93cc3ee <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=93cc3ee>`_ GBP Endpoint Learning ``src/vnet/ipip/ipip.api`` * `53fffa1 <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=53fffa1>`_ API: Add support for type aliases ``src/vnet/session/session.api`` * `d85de68 <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=d85de68>`_ vcl: wait for segments with segment handle * `fa76a76 <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=fa76a76>`_ session: segment handle in accept/connect notifications * `c1f5a43 <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=c1f5a43>`_ session: cleanup use of api_client_index * `c0d532d <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=c0d532d>`_ session: mark apis for deprecation ``src/vnet/ethernet/ethernet_types.api`` * `8006c6a <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=8006c6a>`_ PAPI: Add MACAddress object wrapper for vl_api_mac_address_t ``src/vnet/bonding/bond.api`` * `ad9d528 <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=ad9d528>`_ bonding: support custom interface IDs ``src/vnet/devices/tap/tapv2.api`` * `754f24b <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=754f24b>`_ tapv2: add "tap_flags" field to the TAPv2 interface API ``src/vlibmemory/memclnt.api`` * `eaec2a6 <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=eaec2a6>`_ bapi: add options to have vpp cleanup client registration ``src/vpp/api/vpe.api`` * `f49ba0e <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=f49ba0e>`_ stats: Deprecate old stats framework * `413f4a5 <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=413f4a5>`_ API: Use string type instead of u8. ``src/plugins/acl/acl.api`` * `bb5d22d <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=bb5d22d>`_ New api in order to get max entries of connection table is added. ``src/plugins/nsim/nsim.api`` * `10c5ff1 <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=10c5ff1>`_ nsim: add packet loss simulation, docs ``src/plugins/gbp/gbp.api`` * `1c17e2e <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=1c17e2e>`_ GBP: add allowed ethertypes to contracts * `b6a4795 <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=b6a4795>`_ GBP: l3-out subnets * `33b81da <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=33b81da>`_ vom: Add support for redirect contracts in gbp * `13a08cc <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=13a08cc>`_ GBP: redirect contracts * `c29c0af <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=c29c0af>`_ GBP: Endpoints with VLAN tags and birdges that don't learn * `93cc3ee <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=93cc3ee>`_ GBP Endpoint Learning ``src/plugins/nat/nat.api`` * `b686508 <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=b686508>`_ NAT44: nat44_add_del_lb_static_mapping enhancements (VPP-1514) ``src/plugins/map/map.api`` * `fc7344f <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=fc7344f>`_ MAP: Convert from DPO to input feature. * `f34597f <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=f34597f>`_ MAP: Add API support for MAP input feature. * `5a2e278 <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=5a2e278>`_ MAP: Add API support for setting parameters. * `a173a7a <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=a173a7a>`_ MAP: Use bool type in map.api instead of u8. * `ffba3c3 <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=ffba3c3>`_ MAP: Use explicit address/prefix types in API ``src/plugins/igmp/igmp.api`` * `97748ca <https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commit;h=97748ca>`_ IGMP: proxy device