2 * ustream-ssl - library for SSL over ustream
4 * Copyright (C) 2012 Felix Fietkau <nbd@openwrt.org>
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 #include <libubox/ustream.h>
23 #include "ustream-ssl.h"
24 #include "ustream-internal.h"
26 static int s_ustream_read(char *buf
, int len
, void *ctx
)
28 struct ustream
*s
= ctx
;
35 sbuf
= ustream_get_read_buf(s
, &slen
);
42 memcpy(buf
, sbuf
, slen
);
43 ustream_consume(s
, slen
);
48 static int s_ustream_write(char *buf
, int len
, void *ctx
)
50 struct ustream
*s
= ctx
;
55 return ustream_write(s
, buf
, len
, false);
58 static int io_recv_cb(SSL
* ssl
, char *buf
, int sz
, void *ctx
)
60 return s_ustream_read(buf
, sz
, ctx
);
63 static int io_send_cb(SSL
* ssl
, char *buf
, int sz
, void *ctx
)
65 return s_ustream_write(buf
, sz
, ctx
);
68 __hidden
void ustream_set_io(struct ustream_ssl
*us
)
71 wolfSSL_set_fd(us
->ssl
, us
->fd
.fd
);
75 wolfSSL_SSLSetIORecv(us
->ssl
, io_recv_cb
);
76 wolfSSL_SSLSetIOSend(us
->ssl
, io_send_cb
);
77 wolfSSL_SetIOReadCtx(us
->ssl
, us
->conn
);
78 wolfSSL_SetIOWriteCtx(us
->ssl
, us
->conn
);