Commit 30e9cf22 authored by Sam Rushing's avatar Sam Rushing

Merge branch 'master' of github.com:ironport/shrapnel

parents 157d9407 d141b425
...@@ -9,3 +9,6 @@ coro/dns/packet.c ...@@ -9,3 +9,6 @@ coro/dns/packet.c
coro/event_queue.cpp coro/event_queue.cpp
*.pyc *.pyc
*.so *.so
coro.egg-info
dist
distribute-*
...@@ -285,6 +285,7 @@ class http_request: ...@@ -285,6 +285,7 @@ class http_request:
ho['connection'] = 'close' ho['connection'] = 'close'
self.chunking = chunked self.chunking = chunked
self.close = close_it
ho['server'] = 'shrapnel httpd/%s' % __version__ ho['server'] = 'shrapnel httpd/%s' % __version__
ho['date'] = http_date.build_http_date (coro.now_usec / coro.microseconds) ho['date'] = http_date.build_http_date (coro.now_usec / coro.microseconds)
......
...@@ -32,6 +32,19 @@ cdef extern from "arpa/inet.h": ...@@ -32,6 +32,19 @@ cdef extern from "arpa/inet.h":
int ntohl (int) int ntohl (int)
int ntohs (int) int ntohs (int)
cdef extern from "netdb.h":
struct addrinfo:
int ai_flags # input flags
int ai_family # protocol family for socket
int ai_socktype # socket type
int ai_protocol # protocol for socket
int ai_addrlen # length of socket-address
sockaddr *ai_addr # socket-address for socket
char *ai_canonname # canonical name for service location
addrinfo *ai_next # pointer to next in list
int getaddrinfo (const char *hostname, const char *servname, const addrinfo *hints, addrinfo **res)
void freeaddrinfo (addrinfo *ai)
cdef extern from "sys/socket.h": cdef extern from "sys/socket.h":
int AF_UNSPEC, AF_INET, AF_INET6, AF_UNIX int AF_UNSPEC, AF_INET, AF_INET6, AF_UNIX
int SOCK_STREAM, SOCK_DGRAM, SOL_SOCKET, INADDR_ANY int SOCK_STREAM, SOCK_DGRAM, SOL_SOCKET, INADDR_ANY
......
...@@ -820,9 +820,24 @@ cdef public class sock [ object sock_object, type sock_type ]: ...@@ -820,9 +820,24 @@ cdef public class sock [ object sock_object, type sock_type ]:
cdef sockaddr_in6 * sin6 = <sockaddr_in6 *> sa cdef sockaddr_in6 * sin6 = <sockaddr_in6 *> sa
cdef bytes ip cdef bytes ip
cdef uint16_t port cdef uint16_t port
cdef int percent
cdef int flowinfo
cdef int scope_id
cdef addrinfo * ai
if len(address) == 4:
# as per python return value from getaddrinfo() and arg to connect()
ip, port, flowinfo, scope_id = address
sin6.sin6_flowinfo = htonl (flowinfo)
sin6.sin6_scope_id = scope_id
elif len(address) == 2:
ip, port = address ip, port = address
if not ip: if not ip:
ip = b'::' ip = b'::'
percent = ip.find ('%')
if percent != -1:
ip = ip[:percent]
# XXX hack, should make scope id an option?
sin6.sin6_scope_id = 2
sin6.sin6_family = AF_INET6 sin6.sin6_family = AF_INET6
IF UNAME_SYSNAME == "FreeBSD": IF UNAME_SYSNAME == "FreeBSD":
sin6.sin6_len = sizeof(sockaddr_in6) sin6.sin6_len = sizeof(sockaddr_in6)
......
...@@ -47,7 +47,10 @@ class coro_socket_transport(l4_transport.Transport): ...@@ -47,7 +47,10 @@ class coro_socket_transport(l4_transport.Transport):
self.bind_ip = bind_ip self.bind_ip = bind_ip
self.hostname = hostname self.hostname = hostname
if sock is None: if sock is None:
self.s = coro.make_socket(socket.AF_INET, socket.SOCK_STREAM) if ':' in ip:
self.s = coro.tcp6_sock()
else:
self.s = coro.tcp_sock()
else: else:
self.s = sock self.s = sock
self.peer = self.s.getpeername() self.peer = self.s.getpeername()
...@@ -55,7 +58,14 @@ class coro_socket_transport(l4_transport.Transport): ...@@ -55,7 +58,14 @@ class coro_socket_transport(l4_transport.Transport):
def connect(self): def connect(self):
if self.bind_ip is not None: if self.bind_ip is not None:
self.s.bind((self.bind_ip, 0)) self.s.bind((self.bind_ip, 0))
if '%' in self.ip:
# link local address, need 4-tuple
ai = socket.getaddrinfo (self.ip, self.port)
address = ai[0][4]
ip, port, flowinfo, scope_id = address
ip, intf = ip.split ('%')
self.s.connect ((ip, port, flowinfo, scope_id))
else:
self.s.connect((self.ip, self.port)) self.s.connect((self.ip, self.port))
def read(self, bytes): def read(self, bytes):
......
...@@ -41,12 +41,18 @@ import coro ...@@ -41,12 +41,18 @@ import coro
def usage(): def usage():
print 'test_coro_client [-l login_name] [-p port] hostname | user@hostname' print 'test_coro_client [-l login_name] [-p port] hostname | user@hostname'
import re
is_ip_re = re.compile ('[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$')
# cheap emulation of inet_utils.is_ip()
def is_ip (s): def is_ip (s):
return is_ip_re.match (s) if s.count ('%') == 1:
s, intf = s.split('%')
try:
socket.inet_pton (coro.AF.INET6, s)
return True
except socket.error:
try:
socket.inet_pton (coro.AF.INET, s)
return True
except:
return False
oldterm = None oldterm = None
oldflags = None oldflags = None
......
...@@ -651,11 +651,14 @@ class SSH_Transport: ...@@ -651,11 +651,14 @@ class SSH_Transport:
Separate function to help with unittests. Separate function to help with unittests.
""" """
cookie = random.get_random_data(16) cookie = random.get_random_data(16)
server_keys = [x.name for x in self.self2remote.supported_server_keys]
server_keys.reverse()
packet = ssh_packet.pack_payload(ssh_packet.PAYLOAD_MSG_KEXINIT, packet = ssh_packet.pack_payload(ssh_packet.PAYLOAD_MSG_KEXINIT,
(SSH_MSG_KEXINIT, (SSH_MSG_KEXINIT,
cookie, cookie,
[x.name for x in self.self2remote.supported_key_exchanges], [x.name for x in self.self2remote.supported_key_exchanges],
[x.name for x in self.self2remote.supported_server_keys], #[x.name for x in self.self2remote.supported_server_keys],
server_keys,
[x.name for x in self.c2s.supported_ciphers], [x.name for x in self.c2s.supported_ciphers],
[x.name for x in self.s2c.supported_ciphers], [x.name for x in self.s2c.supported_ciphers],
[x.name for x in self.c2s.supported_macs], [x.name for x in self.c2s.supported_macs],
......
...@@ -1114,7 +1114,7 @@ cdef class ssl_ctx: ...@@ -1114,7 +1114,7 @@ cdef class ssl_ctx:
for proto in protos: for proto in protos:
r.append (chr (len (proto))) r.append (chr (len (proto)))
r.append (proto) r.append (proto)
self.next_protos = ''.join (r) self.next_protos = <bytes> (''.join (r))
SSL_CTX_set_next_protos_advertised_cb (self.ctx, next_protos_server_callback, <void*>self) SSL_CTX_set_next_protos_advertised_cb (self.ctx, next_protos_server_callback, <void*>self)
SSL_CTX_set_next_proto_select_cb (self.ctx, next_protos_client_callback, <void*>self) SSL_CTX_set_next_proto_select_cb (self.ctx, next_protos_client_callback, <void*>self)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment