diff options
Diffstat (limited to 'src/lib/libcrypto/bio')
-rw-r--r-- | src/lib/libcrypto/bio/Makefile | 222 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/b_sock.c | 2 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bio.h | 70 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bio_err.c | 3 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bio_lcl.h | 36 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bio_lib.c | 28 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bss_bio.c | 18 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bss_dgram.c | 996 | ||||
-rw-r--r-- | src/lib/libcrypto/bio/bss_rtcp.c | 294 |
9 files changed, 578 insertions, 1091 deletions
diff --git a/src/lib/libcrypto/bio/Makefile b/src/lib/libcrypto/bio/Makefile new file mode 100644 index 0000000000..c395d80496 --- /dev/null +++ b/src/lib/libcrypto/bio/Makefile | |||
@@ -0,0 +1,222 @@ | |||
1 | # | ||
2 | # OpenSSL/crypto/bio/Makefile | ||
3 | # | ||
4 | |||
5 | DIR= bio | ||
6 | TOP= ../.. | ||
7 | CC= cc | ||
8 | INCLUDES= -I.. -I$(TOP) -I../../include | ||
9 | CFLAG=-g | ||
10 | MAKEFILE= Makefile | ||
11 | AR= ar r | ||
12 | |||
13 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
14 | |||
15 | GENERAL=Makefile | ||
16 | TEST= | ||
17 | APPS= | ||
18 | |||
19 | LIB=$(TOP)/libcrypto.a | ||
20 | LIBSRC= bio_lib.c bio_cb.c bio_err.c \ | ||
21 | bss_mem.c bss_null.c bss_fd.c \ | ||
22 | bss_file.c bss_sock.c bss_conn.c \ | ||
23 | bf_null.c bf_buff.c b_print.c b_dump.c \ | ||
24 | b_sock.c bss_acpt.c bf_nbio.c bss_log.c bss_bio.c \ | ||
25 | bss_dgram.c | ||
26 | # bf_lbuf.c | ||
27 | LIBOBJ= bio_lib.o bio_cb.o bio_err.o \ | ||
28 | bss_mem.o bss_null.o bss_fd.o \ | ||
29 | bss_file.o bss_sock.o bss_conn.o \ | ||
30 | bf_null.o bf_buff.o b_print.o b_dump.o \ | ||
31 | b_sock.o bss_acpt.o bf_nbio.o bss_log.o bss_bio.o \ | ||
32 | bss_dgram.o | ||
33 | # bf_lbuf.o | ||
34 | |||
35 | SRC= $(LIBSRC) | ||
36 | |||
37 | EXHEADER= bio.h | ||
38 | HEADER= bio_lcl.h $(EXHEADER) | ||
39 | |||
40 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
41 | |||
42 | top: | ||
43 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
44 | |||
45 | all: lib | ||
46 | |||
47 | lib: $(LIBOBJ) | ||
48 | $(AR) $(LIB) $(LIBOBJ) | ||
49 | $(RANLIB) $(LIB) || echo Never mind. | ||
50 | @touch lib | ||
51 | |||
52 | files: | ||
53 | $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO | ||
54 | |||
55 | links: | ||
56 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | ||
57 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | ||
58 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) | ||
59 | |||
60 | install: | ||
61 | @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile... | ||
62 | @headerlist="$(EXHEADER)"; for i in $$headerlist; \ | ||
63 | do \ | ||
64 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | ||
65 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | ||
66 | done; | ||
67 | |||
68 | tags: | ||
69 | ctags $(SRC) | ||
70 | |||
71 | tests: | ||
72 | |||
73 | lint: | ||
74 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
75 | |||
76 | depend: | ||
77 | @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile... | ||
78 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) | ||
79 | |||
80 | dclean: | ||
81 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
82 | mv -f Makefile.new $(MAKEFILE) | ||
83 | |||
84 | clean: | ||
85 | rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
86 | |||
87 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
88 | |||
89 | b_dump.o: ../../e_os.h ../../include/openssl/bio.h | ||
90 | b_dump.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
91 | b_dump.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
92 | b_dump.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
93 | b_dump.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
94 | b_dump.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
95 | b_dump.o: ../../include/openssl/symhacks.h ../cryptlib.h b_dump.c bio_lcl.h | ||
96 | b_print.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h | ||
97 | b_print.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
98 | b_print.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
99 | b_print.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
100 | b_print.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
101 | b_print.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
102 | b_print.o: ../../include/openssl/symhacks.h ../cryptlib.h b_print.c | ||
103 | b_sock.o: ../../e_os.h ../../include/openssl/bio.h | ||
104 | b_sock.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
105 | b_sock.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h | ||
106 | b_sock.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
107 | b_sock.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
108 | b_sock.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h | ||
109 | b_sock.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
110 | b_sock.o: ../cryptlib.h b_sock.c | ||
111 | bf_buff.o: ../../e_os.h ../../include/openssl/bio.h | ||
112 | bf_buff.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
113 | bf_buff.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
114 | bf_buff.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
115 | bf_buff.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
116 | bf_buff.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
117 | bf_buff.o: ../../include/openssl/symhacks.h ../cryptlib.h bf_buff.c | ||
118 | bf_nbio.o: ../../e_os.h ../../include/openssl/bio.h | ||
119 | bf_nbio.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
120 | bf_nbio.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
121 | bf_nbio.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
122 | bf_nbio.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
123 | bf_nbio.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h | ||
124 | bf_nbio.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
125 | bf_nbio.o: ../cryptlib.h bf_nbio.c | ||
126 | bf_null.o: ../../e_os.h ../../include/openssl/bio.h | ||
127 | bf_null.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
128 | bf_null.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
129 | bf_null.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
130 | bf_null.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
131 | bf_null.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
132 | bf_null.o: ../../include/openssl/symhacks.h ../cryptlib.h bf_null.c | ||
133 | bio_cb.o: ../../e_os.h ../../include/openssl/bio.h | ||
134 | bio_cb.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
135 | bio_cb.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
136 | bio_cb.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
137 | bio_cb.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
138 | bio_cb.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
139 | bio_cb.o: ../../include/openssl/symhacks.h ../cryptlib.h bio_cb.c | ||
140 | bio_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h | ||
141 | bio_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
142 | bio_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
143 | bio_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
144 | bio_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
145 | bio_err.o: ../../include/openssl/symhacks.h bio_err.c | ||
146 | bio_lib.o: ../../e_os.h ../../include/openssl/bio.h | ||
147 | bio_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
148 | bio_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
149 | bio_lib.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
150 | bio_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
151 | bio_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
152 | bio_lib.o: ../../include/openssl/symhacks.h ../cryptlib.h bio_lib.c | ||
153 | bss_acpt.o: ../../e_os.h ../../include/openssl/bio.h | ||
154 | bss_acpt.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
155 | bss_acpt.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
156 | bss_acpt.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
157 | bss_acpt.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
158 | bss_acpt.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
159 | bss_acpt.o: ../../include/openssl/symhacks.h ../cryptlib.h bss_acpt.c | ||
160 | bss_bio.o: ../../e_os.h ../../include/openssl/bio.h | ||
161 | bss_bio.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
162 | bss_bio.o: ../../include/openssl/err.h ../../include/openssl/lhash.h | ||
163 | bss_bio.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
164 | bss_bio.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h | ||
165 | bss_bio.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
166 | bss_bio.o: bss_bio.c | ||
167 | bss_conn.o: ../../e_os.h ../../include/openssl/bio.h | ||
168 | bss_conn.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
169 | bss_conn.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
170 | bss_conn.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
171 | bss_conn.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
172 | bss_conn.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
173 | bss_conn.o: ../../include/openssl/symhacks.h ../cryptlib.h bss_conn.c | ||
174 | bss_dgram.o: ../../e_os.h ../../include/openssl/bio.h | ||
175 | bss_dgram.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
176 | bss_dgram.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
177 | bss_dgram.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
178 | bss_dgram.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
179 | bss_dgram.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
180 | bss_dgram.o: ../../include/openssl/symhacks.h ../cryptlib.h bss_dgram.c | ||
181 | bss_fd.o: ../../e_os.h ../../include/openssl/bio.h | ||
182 | bss_fd.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
183 | bss_fd.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
184 | bss_fd.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
185 | bss_fd.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
186 | bss_fd.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
187 | bss_fd.o: ../../include/openssl/symhacks.h ../cryptlib.h bio_lcl.h bss_fd.c | ||
188 | bss_file.o: ../../e_os.h ../../include/openssl/bio.h | ||
189 | bss_file.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
190 | bss_file.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
191 | bss_file.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
192 | bss_file.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
193 | bss_file.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
194 | bss_file.o: ../../include/openssl/symhacks.h ../cryptlib.h bio_lcl.h bss_file.c | ||
195 | bss_log.o: ../../e_os.h ../../include/openssl/bio.h | ||
196 | bss_log.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
197 | bss_log.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
198 | bss_log.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
199 | bss_log.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
200 | bss_log.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
201 | bss_log.o: ../../include/openssl/symhacks.h ../cryptlib.h bss_log.c | ||
202 | bss_mem.o: ../../e_os.h ../../include/openssl/bio.h | ||
203 | bss_mem.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
204 | bss_mem.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
205 | bss_mem.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
206 | bss_mem.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
207 | bss_mem.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
208 | bss_mem.o: ../../include/openssl/symhacks.h ../cryptlib.h bss_mem.c | ||
209 | bss_null.o: ../../e_os.h ../../include/openssl/bio.h | ||
210 | bss_null.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
211 | bss_null.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
212 | bss_null.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
213 | bss_null.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
214 | bss_null.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
215 | bss_null.o: ../../include/openssl/symhacks.h ../cryptlib.h bss_null.c | ||
216 | bss_sock.o: ../../e_os.h ../../include/openssl/bio.h | ||
217 | bss_sock.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
218 | bss_sock.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
219 | bss_sock.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
220 | bss_sock.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
221 | bss_sock.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
222 | bss_sock.o: ../../include/openssl/symhacks.h ../cryptlib.h bss_sock.c | ||
diff --git a/src/lib/libcrypto/bio/b_sock.c b/src/lib/libcrypto/bio/b_sock.c index 41f958be71..d47310d650 100644 --- a/src/lib/libcrypto/bio/b_sock.c +++ b/src/lib/libcrypto/bio/b_sock.c | |||
@@ -960,6 +960,7 @@ int BIO_set_tcp_ndelay(int s, int on) | |||
960 | #endif | 960 | #endif |
961 | return(ret == 0); | 961 | return(ret == 0); |
962 | } | 962 | } |
963 | #endif | ||
963 | 964 | ||
964 | int BIO_socket_nbio(int s, int mode) | 965 | int BIO_socket_nbio(int s, int mode) |
965 | { | 966 | { |
@@ -972,4 +973,3 @@ int BIO_socket_nbio(int s, int mode) | |||
972 | #endif | 973 | #endif |
973 | return(ret == 0); | 974 | return(ret == 0); |
974 | } | 975 | } |
975 | #endif | ||
diff --git a/src/lib/libcrypto/bio/bio.h b/src/lib/libcrypto/bio/bio.h index 05699ab212..ab47abcf14 100644 --- a/src/lib/libcrypto/bio/bio.h +++ b/src/lib/libcrypto/bio/bio.h | |||
@@ -68,14 +68,6 @@ | |||
68 | 68 | ||
69 | #include <openssl/crypto.h> | 69 | #include <openssl/crypto.h> |
70 | 70 | ||
71 | #ifndef OPENSSL_NO_SCTP | ||
72 | # ifndef OPENSSL_SYS_VMS | ||
73 | # include <stdint.h> | ||
74 | # else | ||
75 | # include <inttypes.h> | ||
76 | # endif | ||
77 | #endif | ||
78 | |||
79 | #ifdef __cplusplus | 71 | #ifdef __cplusplus |
80 | extern "C" { | 72 | extern "C" { |
81 | #endif | 73 | #endif |
@@ -103,9 +95,6 @@ extern "C" { | |||
103 | #define BIO_TYPE_BIO (19|0x0400) /* (half a) BIO pair */ | 95 | #define BIO_TYPE_BIO (19|0x0400) /* (half a) BIO pair */ |
104 | #define BIO_TYPE_LINEBUFFER (20|0x0200) /* filter */ | 96 | #define BIO_TYPE_LINEBUFFER (20|0x0200) /* filter */ |
105 | #define BIO_TYPE_DGRAM (21|0x0400|0x0100) | 97 | #define BIO_TYPE_DGRAM (21|0x0400|0x0100) |
106 | #ifndef OPENSSL_NO_SCTP | ||
107 | #define BIO_TYPE_DGRAM_SCTP (24|0x0400|0x0100) | ||
108 | #endif | ||
109 | #define BIO_TYPE_ASN1 (22|0x0200) /* filter */ | 98 | #define BIO_TYPE_ASN1 (22|0x0200) /* filter */ |
110 | #define BIO_TYPE_COMP (23|0x0200) /* filter */ | 99 | #define BIO_TYPE_COMP (23|0x0200) /* filter */ |
111 | 100 | ||
@@ -157,7 +146,6 @@ extern "C" { | |||
157 | /* #endif */ | 146 | /* #endif */ |
158 | 147 | ||
159 | #define BIO_CTRL_DGRAM_QUERY_MTU 40 /* as kernel for current MTU */ | 148 | #define BIO_CTRL_DGRAM_QUERY_MTU 40 /* as kernel for current MTU */ |
160 | #define BIO_CTRL_DGRAM_GET_FALLBACK_MTU 47 | ||
161 | #define BIO_CTRL_DGRAM_GET_MTU 41 /* get cached value for MTU */ | 149 | #define BIO_CTRL_DGRAM_GET_MTU 41 /* get cached value for MTU */ |
162 | #define BIO_CTRL_DGRAM_SET_MTU 42 /* set cached value for | 150 | #define BIO_CTRL_DGRAM_SET_MTU 42 /* set cached value for |
163 | * MTU. want to use this | 151 | * MTU. want to use this |
@@ -173,22 +161,7 @@ extern "C" { | |||
173 | #define BIO_CTRL_DGRAM_SET_PEER 44 /* Destination for the data */ | 161 | #define BIO_CTRL_DGRAM_SET_PEER 44 /* Destination for the data */ |
174 | 162 | ||
175 | #define BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT 45 /* Next DTLS handshake timeout to | 163 | #define BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT 45 /* Next DTLS handshake timeout to |
176 | * adjust socket timeouts */ | 164 | * adjust socket timeouts */ |
177 | |||
178 | #ifndef OPENSSL_NO_SCTP | ||
179 | /* SCTP stuff */ | ||
180 | #define BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE 50 | ||
181 | #define BIO_CTRL_DGRAM_SCTP_ADD_AUTH_KEY 51 | ||
182 | #define BIO_CTRL_DGRAM_SCTP_NEXT_AUTH_KEY 52 | ||
183 | #define BIO_CTRL_DGRAM_SCTP_AUTH_CCS_RCVD 53 | ||
184 | #define BIO_CTRL_DGRAM_SCTP_GET_SNDINFO 60 | ||
185 | #define BIO_CTRL_DGRAM_SCTP_SET_SNDINFO 61 | ||
186 | #define BIO_CTRL_DGRAM_SCTP_GET_RCVINFO 62 | ||
187 | #define BIO_CTRL_DGRAM_SCTP_SET_RCVINFO 63 | ||
188 | #define BIO_CTRL_DGRAM_SCTP_GET_PRINFO 64 | ||
189 | #define BIO_CTRL_DGRAM_SCTP_SET_PRINFO 65 | ||
190 | #define BIO_CTRL_DGRAM_SCTP_SAVE_SHUTDOWN 70 | ||
191 | #endif | ||
192 | 165 | ||
193 | /* modifiers */ | 166 | /* modifiers */ |
194 | #define BIO_FP_READ 0x02 | 167 | #define BIO_FP_READ 0x02 |
@@ -358,34 +331,6 @@ typedef struct bio_f_buffer_ctx_struct | |||
358 | /* Prefix and suffix callback in ASN1 BIO */ | 331 | /* Prefix and suffix callback in ASN1 BIO */ |
359 | typedef int asn1_ps_func(BIO *b, unsigned char **pbuf, int *plen, void *parg); | 332 | typedef int asn1_ps_func(BIO *b, unsigned char **pbuf, int *plen, void *parg); |
360 | 333 | ||
361 | #ifndef OPENSSL_NO_SCTP | ||
362 | /* SCTP parameter structs */ | ||
363 | struct bio_dgram_sctp_sndinfo | ||
364 | { | ||
365 | uint16_t snd_sid; | ||
366 | uint16_t snd_flags; | ||
367 | uint32_t snd_ppid; | ||
368 | uint32_t snd_context; | ||
369 | }; | ||
370 | |||
371 | struct bio_dgram_sctp_rcvinfo | ||
372 | { | ||
373 | uint16_t rcv_sid; | ||
374 | uint16_t rcv_ssn; | ||
375 | uint16_t rcv_flags; | ||
376 | uint32_t rcv_ppid; | ||
377 | uint32_t rcv_tsn; | ||
378 | uint32_t rcv_cumtsn; | ||
379 | uint32_t rcv_context; | ||
380 | }; | ||
381 | |||
382 | struct bio_dgram_sctp_prinfo | ||
383 | { | ||
384 | uint16_t pr_policy; | ||
385 | uint32_t pr_value; | ||
386 | }; | ||
387 | #endif | ||
388 | |||
389 | /* connect BIO stuff */ | 334 | /* connect BIO stuff */ |
390 | #define BIO_CONN_S_BEFORE 1 | 335 | #define BIO_CONN_S_BEFORE 1 |
391 | #define BIO_CONN_S_GET_IP 2 | 336 | #define BIO_CONN_S_GET_IP 2 |
@@ -683,9 +628,6 @@ BIO_METHOD *BIO_f_linebuffer(void); | |||
683 | BIO_METHOD *BIO_f_nbio_test(void); | 628 | BIO_METHOD *BIO_f_nbio_test(void); |
684 | #ifndef OPENSSL_NO_DGRAM | 629 | #ifndef OPENSSL_NO_DGRAM |
685 | BIO_METHOD *BIO_s_datagram(void); | 630 | BIO_METHOD *BIO_s_datagram(void); |
686 | #ifndef OPENSSL_NO_SCTP | ||
687 | BIO_METHOD *BIO_s_datagram_sctp(void); | ||
688 | #endif | ||
689 | #endif | 631 | #endif |
690 | 632 | ||
691 | /* BIO_METHOD *BIO_f_ber(void); */ | 633 | /* BIO_METHOD *BIO_f_ber(void); */ |
@@ -728,15 +670,6 @@ int BIO_set_tcp_ndelay(int sock,int turn_on); | |||
728 | 670 | ||
729 | BIO *BIO_new_socket(int sock, int close_flag); | 671 | BIO *BIO_new_socket(int sock, int close_flag); |
730 | BIO *BIO_new_dgram(int fd, int close_flag); | 672 | BIO *BIO_new_dgram(int fd, int close_flag); |
731 | #ifndef OPENSSL_NO_SCTP | ||
732 | BIO *BIO_new_dgram_sctp(int fd, int close_flag); | ||
733 | int BIO_dgram_is_sctp(BIO *bio); | ||
734 | int BIO_dgram_sctp_notification_cb(BIO *b, | ||
735 | void (*handle_notifications)(BIO *bio, void *context, void *buf), | ||
736 | void *context); | ||
737 | int BIO_dgram_sctp_wait_for_dry(BIO *b); | ||
738 | int BIO_dgram_sctp_msg_waiting(BIO *b); | ||
739 | #endif | ||
740 | BIO *BIO_new_fd(int fd, int close_flag); | 673 | BIO *BIO_new_fd(int fd, int close_flag); |
741 | BIO *BIO_new_connect(char *host_port); | 674 | BIO *BIO_new_connect(char *host_port); |
742 | BIO *BIO_new_accept(char *host_port); | 675 | BIO *BIO_new_accept(char *host_port); |
@@ -801,7 +734,6 @@ void ERR_load_BIO_strings(void); | |||
801 | #define BIO_F_BUFFER_CTRL 114 | 734 | #define BIO_F_BUFFER_CTRL 114 |
802 | #define BIO_F_CONN_CTRL 127 | 735 | #define BIO_F_CONN_CTRL 127 |
803 | #define BIO_F_CONN_STATE 115 | 736 | #define BIO_F_CONN_STATE 115 |
804 | #define BIO_F_DGRAM_SCTP_READ 132 | ||
805 | #define BIO_F_FILE_CTRL 116 | 737 | #define BIO_F_FILE_CTRL 116 |
806 | #define BIO_F_FILE_READ 130 | 738 | #define BIO_F_FILE_READ 130 |
807 | #define BIO_F_LINEBUFFER_CTRL 129 | 739 | #define BIO_F_LINEBUFFER_CTRL 129 |
diff --git a/src/lib/libcrypto/bio/bio_err.c b/src/lib/libcrypto/bio/bio_err.c index 0dbfbd80d3..a224edd5a0 100644 --- a/src/lib/libcrypto/bio/bio_err.c +++ b/src/lib/libcrypto/bio/bio_err.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* crypto/bio/bio_err.c */ | 1 | /* crypto/bio/bio_err.c */ |
2 | /* ==================================================================== | 2 | /* ==================================================================== |
3 | * Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 1999-2006 The OpenSSL Project. All rights reserved. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions | 6 | * modification, are permitted provided that the following conditions |
@@ -95,7 +95,6 @@ static ERR_STRING_DATA BIO_str_functs[]= | |||
95 | {ERR_FUNC(BIO_F_BUFFER_CTRL), "BUFFER_CTRL"}, | 95 | {ERR_FUNC(BIO_F_BUFFER_CTRL), "BUFFER_CTRL"}, |
96 | {ERR_FUNC(BIO_F_CONN_CTRL), "CONN_CTRL"}, | 96 | {ERR_FUNC(BIO_F_CONN_CTRL), "CONN_CTRL"}, |
97 | {ERR_FUNC(BIO_F_CONN_STATE), "CONN_STATE"}, | 97 | {ERR_FUNC(BIO_F_CONN_STATE), "CONN_STATE"}, |
98 | {ERR_FUNC(BIO_F_DGRAM_SCTP_READ), "DGRAM_SCTP_READ"}, | ||
99 | {ERR_FUNC(BIO_F_FILE_CTRL), "FILE_CTRL"}, | 98 | {ERR_FUNC(BIO_F_FILE_CTRL), "FILE_CTRL"}, |
100 | {ERR_FUNC(BIO_F_FILE_READ), "FILE_READ"}, | 99 | {ERR_FUNC(BIO_F_FILE_READ), "FILE_READ"}, |
101 | {ERR_FUNC(BIO_F_LINEBUFFER_CTRL), "LINEBUFFER_CTRL"}, | 100 | {ERR_FUNC(BIO_F_LINEBUFFER_CTRL), "LINEBUFFER_CTRL"}, |
diff --git a/src/lib/libcrypto/bio/bio_lcl.h b/src/lib/libcrypto/bio/bio_lcl.h new file mode 100644 index 0000000000..e7f7ec8d8b --- /dev/null +++ b/src/lib/libcrypto/bio/bio_lcl.h | |||
@@ -0,0 +1,36 @@ | |||
1 | #include <openssl/bio.h> | ||
2 | |||
3 | #if BIO_FLAGS_UPLINK==0 | ||
4 | /* Shortcut UPLINK calls on most platforms... */ | ||
5 | #define UP_stdin stdin | ||
6 | #define UP_stdout stdout | ||
7 | #define UP_stderr stderr | ||
8 | #define UP_fprintf fprintf | ||
9 | #define UP_fgets fgets | ||
10 | #define UP_fread fread | ||
11 | #define UP_fwrite fwrite | ||
12 | #undef UP_fsetmod | ||
13 | #define UP_feof feof | ||
14 | #define UP_fclose fclose | ||
15 | |||
16 | #define UP_fopen fopen | ||
17 | #define UP_fseek fseek | ||
18 | #define UP_ftell ftell | ||
19 | #define UP_fflush fflush | ||
20 | #define UP_ferror ferror | ||
21 | #ifdef _WIN32 | ||
22 | #define UP_fileno _fileno | ||
23 | #define UP_open _open | ||
24 | #define UP_read _read | ||
25 | #define UP_write _write | ||
26 | #define UP_lseek _lseek | ||
27 | #define UP_close _close | ||
28 | #else | ||
29 | #define UP_fileno fileno | ||
30 | #define UP_open open | ||
31 | #define UP_read read | ||
32 | #define UP_write write | ||
33 | #define UP_lseek lseek | ||
34 | #define UP_close close | ||
35 | #endif | ||
36 | #endif | ||
diff --git a/src/lib/libcrypto/bio/bio_lib.c b/src/lib/libcrypto/bio/bio_lib.c index 9c9646afa8..e12bc3a2ca 100644 --- a/src/lib/libcrypto/bio/bio_lib.c +++ b/src/lib/libcrypto/bio/bio_lib.c | |||
@@ -521,40 +521,40 @@ void BIO_free_all(BIO *bio) | |||
521 | 521 | ||
522 | BIO *BIO_dup_chain(BIO *in) | 522 | BIO *BIO_dup_chain(BIO *in) |
523 | { | 523 | { |
524 | BIO *ret=NULL,*eoc=NULL,*bio,*new_bio; | 524 | BIO *ret=NULL,*eoc=NULL,*bio,*new; |
525 | 525 | ||
526 | for (bio=in; bio != NULL; bio=bio->next_bio) | 526 | for (bio=in; bio != NULL; bio=bio->next_bio) |
527 | { | 527 | { |
528 | if ((new_bio=BIO_new(bio->method)) == NULL) goto err; | 528 | if ((new=BIO_new(bio->method)) == NULL) goto err; |
529 | new_bio->callback=bio->callback; | 529 | new->callback=bio->callback; |
530 | new_bio->cb_arg=bio->cb_arg; | 530 | new->cb_arg=bio->cb_arg; |
531 | new_bio->init=bio->init; | 531 | new->init=bio->init; |
532 | new_bio->shutdown=bio->shutdown; | 532 | new->shutdown=bio->shutdown; |
533 | new_bio->flags=bio->flags; | 533 | new->flags=bio->flags; |
534 | 534 | ||
535 | /* This will let SSL_s_sock() work with stdin/stdout */ | 535 | /* This will let SSL_s_sock() work with stdin/stdout */ |
536 | new_bio->num=bio->num; | 536 | new->num=bio->num; |
537 | 537 | ||
538 | if (!BIO_dup_state(bio,(char *)new_bio)) | 538 | if (!BIO_dup_state(bio,(char *)new)) |
539 | { | 539 | { |
540 | BIO_free(new_bio); | 540 | BIO_free(new); |
541 | goto err; | 541 | goto err; |
542 | } | 542 | } |
543 | 543 | ||
544 | /* copy app data */ | 544 | /* copy app data */ |
545 | if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_BIO, &new_bio->ex_data, | 545 | if (!CRYPTO_dup_ex_data(CRYPTO_EX_INDEX_BIO, &new->ex_data, |
546 | &bio->ex_data)) | 546 | &bio->ex_data)) |
547 | goto err; | 547 | goto err; |
548 | 548 | ||
549 | if (ret == NULL) | 549 | if (ret == NULL) |
550 | { | 550 | { |
551 | eoc=new_bio; | 551 | eoc=new; |
552 | ret=eoc; | 552 | ret=eoc; |
553 | } | 553 | } |
554 | else | 554 | else |
555 | { | 555 | { |
556 | BIO_push(eoc,new_bio); | 556 | BIO_push(eoc,new); |
557 | eoc=new_bio; | 557 | eoc=new; |
558 | } | 558 | } |
559 | } | 559 | } |
560 | return(ret); | 560 | return(ret); |
diff --git a/src/lib/libcrypto/bio/bss_bio.c b/src/lib/libcrypto/bio/bss_bio.c index 52ef0ebcb3..76bd48e767 100644 --- a/src/lib/libcrypto/bio/bss_bio.c +++ b/src/lib/libcrypto/bio/bss_bio.c | |||
@@ -277,10 +277,10 @@ static int bio_read(BIO *bio, char *buf, int size_) | |||
277 | */ | 277 | */ |
278 | /* WARNING: The non-copying interface is largely untested as of yet | 278 | /* WARNING: The non-copying interface is largely untested as of yet |
279 | * and may contain bugs. */ | 279 | * and may contain bugs. */ |
280 | static ossl_ssize_t bio_nread0(BIO *bio, char **buf) | 280 | static ssize_t bio_nread0(BIO *bio, char **buf) |
281 | { | 281 | { |
282 | struct bio_bio_st *b, *peer_b; | 282 | struct bio_bio_st *b, *peer_b; |
283 | ossl_ssize_t num; | 283 | ssize_t num; |
284 | 284 | ||
285 | BIO_clear_retry_flags(bio); | 285 | BIO_clear_retry_flags(bio); |
286 | 286 | ||
@@ -315,15 +315,15 @@ static ossl_ssize_t bio_nread0(BIO *bio, char **buf) | |||
315 | return num; | 315 | return num; |
316 | } | 316 | } |
317 | 317 | ||
318 | static ossl_ssize_t bio_nread(BIO *bio, char **buf, size_t num_) | 318 | static ssize_t bio_nread(BIO *bio, char **buf, size_t num_) |
319 | { | 319 | { |
320 | struct bio_bio_st *b, *peer_b; | 320 | struct bio_bio_st *b, *peer_b; |
321 | ossl_ssize_t num, available; | 321 | ssize_t num, available; |
322 | 322 | ||
323 | if (num_ > SSIZE_MAX) | 323 | if (num_ > SSIZE_MAX) |
324 | num = SSIZE_MAX; | 324 | num = SSIZE_MAX; |
325 | else | 325 | else |
326 | num = (ossl_ssize_t)num_; | 326 | num = (ssize_t)num_; |
327 | 327 | ||
328 | available = bio_nread0(bio, buf); | 328 | available = bio_nread0(bio, buf); |
329 | if (num > available) | 329 | if (num > available) |
@@ -428,7 +428,7 @@ static int bio_write(BIO *bio, const char *buf, int num_) | |||
428 | * (example usage: bio_nwrite0(), write to buffer, bio_nwrite() | 428 | * (example usage: bio_nwrite0(), write to buffer, bio_nwrite() |
429 | * or just bio_nwrite(), write to buffer) | 429 | * or just bio_nwrite(), write to buffer) |
430 | */ | 430 | */ |
431 | static ossl_ssize_t bio_nwrite0(BIO *bio, char **buf) | 431 | static ssize_t bio_nwrite0(BIO *bio, char **buf) |
432 | { | 432 | { |
433 | struct bio_bio_st *b; | 433 | struct bio_bio_st *b; |
434 | size_t num; | 434 | size_t num; |
@@ -476,15 +476,15 @@ static ossl_ssize_t bio_nwrite0(BIO *bio, char **buf) | |||
476 | return num; | 476 | return num; |
477 | } | 477 | } |
478 | 478 | ||
479 | static ossl_ssize_t bio_nwrite(BIO *bio, char **buf, size_t num_) | 479 | static ssize_t bio_nwrite(BIO *bio, char **buf, size_t num_) |
480 | { | 480 | { |
481 | struct bio_bio_st *b; | 481 | struct bio_bio_st *b; |
482 | ossl_ssize_t num, space; | 482 | ssize_t num, space; |
483 | 483 | ||
484 | if (num_ > SSIZE_MAX) | 484 | if (num_ > SSIZE_MAX) |
485 | num = SSIZE_MAX; | 485 | num = SSIZE_MAX; |
486 | else | 486 | else |
487 | num = (ossl_ssize_t)num_; | 487 | num = (ssize_t)num_; |
488 | 488 | ||
489 | space = bio_nwrite0(bio, buf); | 489 | space = bio_nwrite0(bio, buf); |
490 | if (num > space) | 490 | if (num > space) |
diff --git a/src/lib/libcrypto/bio/bss_dgram.c b/src/lib/libcrypto/bio/bss_dgram.c index 1b1e4bec81..71ebe987b6 100644 --- a/src/lib/libcrypto/bio/bss_dgram.c +++ b/src/lib/libcrypto/bio/bss_dgram.c | |||
@@ -70,13 +70,6 @@ | |||
70 | #include <sys/timeb.h> | 70 | #include <sys/timeb.h> |
71 | #endif | 71 | #endif |
72 | 72 | ||
73 | #ifndef OPENSSL_NO_SCTP | ||
74 | #include <netinet/sctp.h> | ||
75 | #include <fcntl.h> | ||
76 | #define OPENSSL_SCTP_DATA_CHUNK_TYPE 0x00 | ||
77 | #define OPENSSL_SCTP_FORWARD_CUM_TSN_CHUNK_TYPE 0xc0 | ||
78 | #endif | ||
79 | |||
80 | #ifdef OPENSSL_SYS_LINUX | 73 | #ifdef OPENSSL_SYS_LINUX |
81 | #define IP_MTU 14 /* linux is lame */ | 74 | #define IP_MTU 14 /* linux is lame */ |
82 | #endif | 75 | #endif |
@@ -95,18 +88,6 @@ static int dgram_new(BIO *h); | |||
95 | static int dgram_free(BIO *data); | 88 | static int dgram_free(BIO *data); |
96 | static int dgram_clear(BIO *bio); | 89 | static int dgram_clear(BIO *bio); |
97 | 90 | ||
98 | #ifndef OPENSSL_NO_SCTP | ||
99 | static int dgram_sctp_write(BIO *h, const char *buf, int num); | ||
100 | static int dgram_sctp_read(BIO *h, char *buf, int size); | ||
101 | static int dgram_sctp_puts(BIO *h, const char *str); | ||
102 | static long dgram_sctp_ctrl(BIO *h, int cmd, long arg1, void *arg2); | ||
103 | static int dgram_sctp_new(BIO *h); | ||
104 | static int dgram_sctp_free(BIO *data); | ||
105 | #ifdef SCTP_AUTHENTICATION_EVENT | ||
106 | static void dgram_sctp_handle_auth_free_key_event(BIO *b, union sctp_notification *snp); | ||
107 | #endif | ||
108 | #endif | ||
109 | |||
110 | static int BIO_dgram_should_retry(int s); | 91 | static int BIO_dgram_should_retry(int s); |
111 | 92 | ||
112 | static void get_current_time(struct timeval *t); | 93 | static void get_current_time(struct timeval *t); |
@@ -125,22 +106,6 @@ static BIO_METHOD methods_dgramp= | |||
125 | NULL, | 106 | NULL, |
126 | }; | 107 | }; |
127 | 108 | ||
128 | #ifndef OPENSSL_NO_SCTP | ||
129 | static BIO_METHOD methods_dgramp_sctp= | ||
130 | { | ||
131 | BIO_TYPE_DGRAM_SCTP, | ||
132 | "datagram sctp socket", | ||
133 | dgram_sctp_write, | ||
134 | dgram_sctp_read, | ||
135 | dgram_sctp_puts, | ||
136 | NULL, /* dgram_gets, */ | ||
137 | dgram_sctp_ctrl, | ||
138 | dgram_sctp_new, | ||
139 | dgram_sctp_free, | ||
140 | NULL, | ||
141 | }; | ||
142 | #endif | ||
143 | |||
144 | typedef struct bio_dgram_data_st | 109 | typedef struct bio_dgram_data_st |
145 | { | 110 | { |
146 | union { | 111 | union { |
@@ -157,40 +122,6 @@ typedef struct bio_dgram_data_st | |||
157 | struct timeval socket_timeout; | 122 | struct timeval socket_timeout; |
158 | } bio_dgram_data; | 123 | } bio_dgram_data; |
159 | 124 | ||
160 | #ifndef OPENSSL_NO_SCTP | ||
161 | typedef struct bio_dgram_sctp_save_message_st | ||
162 | { | ||
163 | BIO *bio; | ||
164 | char *data; | ||
165 | int length; | ||
166 | } bio_dgram_sctp_save_message; | ||
167 | |||
168 | typedef struct bio_dgram_sctp_data_st | ||
169 | { | ||
170 | union { | ||
171 | struct sockaddr sa; | ||
172 | struct sockaddr_in sa_in; | ||
173 | #if OPENSSL_USE_IPV6 | ||
174 | struct sockaddr_in6 sa_in6; | ||
175 | #endif | ||
176 | } peer; | ||
177 | unsigned int connected; | ||
178 | unsigned int _errno; | ||
179 | unsigned int mtu; | ||
180 | struct bio_dgram_sctp_sndinfo sndinfo; | ||
181 | struct bio_dgram_sctp_rcvinfo rcvinfo; | ||
182 | struct bio_dgram_sctp_prinfo prinfo; | ||
183 | void (*handle_notifications)(BIO *bio, void *context, void *buf); | ||
184 | void* notification_context; | ||
185 | int in_handshake; | ||
186 | int ccs_rcvd; | ||
187 | int ccs_sent; | ||
188 | int save_shutdown; | ||
189 | int peer_auth_tested; | ||
190 | bio_dgram_sctp_save_message saved_message; | ||
191 | } bio_dgram_sctp_data; | ||
192 | #endif | ||
193 | |||
194 | BIO_METHOD *BIO_s_datagram(void) | 125 | BIO_METHOD *BIO_s_datagram(void) |
195 | { | 126 | { |
196 | return(&methods_dgramp); | 127 | return(&methods_dgramp); |
@@ -616,27 +547,6 @@ static long dgram_ctrl(BIO *b, int cmd, long num, void *ptr) | |||
616 | ret = 0; | 547 | ret = 0; |
617 | #endif | 548 | #endif |
618 | break; | 549 | break; |
619 | case BIO_CTRL_DGRAM_GET_FALLBACK_MTU: | ||
620 | switch (data->peer.sa.sa_family) | ||
621 | { | ||
622 | case AF_INET: | ||
623 | ret = 576 - 20 - 8; | ||
624 | break; | ||
625 | #if OPENSSL_USE_IPV6 | ||
626 | case AF_INET6: | ||
627 | #ifdef IN6_IS_ADDR_V4MAPPED | ||
628 | if (IN6_IS_ADDR_V4MAPPED(&data->peer.sa_in6.sin6_addr)) | ||
629 | ret = 576 - 20 - 8; | ||
630 | else | ||
631 | #endif | ||
632 | ret = 1280 - 40 - 8; | ||
633 | break; | ||
634 | #endif | ||
635 | default: | ||
636 | ret = 576 - 20 - 8; | ||
637 | break; | ||
638 | } | ||
639 | break; | ||
640 | case BIO_CTRL_DGRAM_GET_MTU: | 550 | case BIO_CTRL_DGRAM_GET_MTU: |
641 | return data->mtu; | 551 | return data->mtu; |
642 | break; | 552 | break; |
@@ -828,912 +738,6 @@ static int dgram_puts(BIO *bp, const char *str) | |||
828 | return(ret); | 738 | return(ret); |
829 | } | 739 | } |
830 | 740 | ||
831 | #ifndef OPENSSL_NO_SCTP | ||
832 | BIO_METHOD *BIO_s_datagram_sctp(void) | ||
833 | { | ||
834 | return(&methods_dgramp_sctp); | ||
835 | } | ||
836 | |||
837 | BIO *BIO_new_dgram_sctp(int fd, int close_flag) | ||
838 | { | ||
839 | BIO *bio; | ||
840 | int ret, optval = 20000; | ||
841 | int auth_data = 0, auth_forward = 0; | ||
842 | unsigned char *p; | ||
843 | struct sctp_authchunk auth; | ||
844 | struct sctp_authchunks *authchunks; | ||
845 | socklen_t sockopt_len; | ||
846 | #ifdef SCTP_AUTHENTICATION_EVENT | ||
847 | #ifdef SCTP_EVENT | ||
848 | struct sctp_event event; | ||
849 | #else | ||
850 | struct sctp_event_subscribe event; | ||
851 | #endif | ||
852 | #endif | ||
853 | |||
854 | bio=BIO_new(BIO_s_datagram_sctp()); | ||
855 | if (bio == NULL) return(NULL); | ||
856 | BIO_set_fd(bio,fd,close_flag); | ||
857 | |||
858 | /* Activate SCTP-AUTH for DATA and FORWARD-TSN chunks */ | ||
859 | auth.sauth_chunk = OPENSSL_SCTP_DATA_CHUNK_TYPE; | ||
860 | ret = setsockopt(fd, IPPROTO_SCTP, SCTP_AUTH_CHUNK, &auth, sizeof(struct sctp_authchunk)); | ||
861 | OPENSSL_assert(ret >= 0); | ||
862 | auth.sauth_chunk = OPENSSL_SCTP_FORWARD_CUM_TSN_CHUNK_TYPE; | ||
863 | ret = setsockopt(fd, IPPROTO_SCTP, SCTP_AUTH_CHUNK, &auth, sizeof(struct sctp_authchunk)); | ||
864 | OPENSSL_assert(ret >= 0); | ||
865 | |||
866 | /* Test if activation was successful. When using accept(), | ||
867 | * SCTP-AUTH has to be activated for the listening socket | ||
868 | * already, otherwise the connected socket won't use it. */ | ||
869 | sockopt_len = (socklen_t)(sizeof(sctp_assoc_t) + 256 * sizeof(uint8_t)); | ||
870 | authchunks = OPENSSL_malloc(sockopt_len); | ||
871 | memset(authchunks, 0, sizeof(sockopt_len)); | ||
872 | ret = getsockopt(fd, IPPROTO_SCTP, SCTP_LOCAL_AUTH_CHUNKS, authchunks, &sockopt_len); | ||
873 | OPENSSL_assert(ret >= 0); | ||
874 | |||
875 | for (p = (unsigned char*) authchunks + sizeof(sctp_assoc_t); | ||
876 | p < (unsigned char*) authchunks + sockopt_len; | ||
877 | p += sizeof(uint8_t)) | ||
878 | { | ||
879 | if (*p == OPENSSL_SCTP_DATA_CHUNK_TYPE) auth_data = 1; | ||
880 | if (*p == OPENSSL_SCTP_FORWARD_CUM_TSN_CHUNK_TYPE) auth_forward = 1; | ||
881 | } | ||
882 | |||
883 | OPENSSL_free(authchunks); | ||
884 | |||
885 | OPENSSL_assert(auth_data); | ||
886 | OPENSSL_assert(auth_forward); | ||
887 | |||
888 | #ifdef SCTP_AUTHENTICATION_EVENT | ||
889 | #ifdef SCTP_EVENT | ||
890 | memset(&event, 0, sizeof(struct sctp_event)); | ||
891 | event.se_assoc_id = 0; | ||
892 | event.se_type = SCTP_AUTHENTICATION_EVENT; | ||
893 | event.se_on = 1; | ||
894 | ret = setsockopt(fd, IPPROTO_SCTP, SCTP_EVENT, &event, sizeof(struct sctp_event)); | ||
895 | OPENSSL_assert(ret >= 0); | ||
896 | #else | ||
897 | sockopt_len = (socklen_t) sizeof(struct sctp_event_subscribe); | ||
898 | ret = getsockopt(fd, IPPROTO_SCTP, SCTP_EVENTS, &event, &sockopt_len); | ||
899 | OPENSSL_assert(ret >= 0); | ||
900 | |||
901 | event.sctp_authentication_event = 1; | ||
902 | |||
903 | ret = setsockopt(fd, IPPROTO_SCTP, SCTP_EVENTS, &event, sizeof(struct sctp_event_subscribe)); | ||
904 | OPENSSL_assert(ret >= 0); | ||
905 | #endif | ||
906 | #endif | ||
907 | |||
908 | /* Disable partial delivery by setting the min size | ||
909 | * larger than the max record size of 2^14 + 2048 + 13 | ||
910 | */ | ||
911 | ret = setsockopt(fd, IPPROTO_SCTP, SCTP_PARTIAL_DELIVERY_POINT, &optval, sizeof(optval)); | ||
912 | OPENSSL_assert(ret >= 0); | ||
913 | |||
914 | return(bio); | ||
915 | } | ||
916 | |||
917 | int BIO_dgram_is_sctp(BIO *bio) | ||
918 | { | ||
919 | return (BIO_method_type(bio) == BIO_TYPE_DGRAM_SCTP); | ||
920 | } | ||
921 | |||
922 | static int dgram_sctp_new(BIO *bi) | ||
923 | { | ||
924 | bio_dgram_sctp_data *data = NULL; | ||
925 | |||
926 | bi->init=0; | ||
927 | bi->num=0; | ||
928 | data = OPENSSL_malloc(sizeof(bio_dgram_sctp_data)); | ||
929 | if (data == NULL) | ||
930 | return 0; | ||
931 | memset(data, 0x00, sizeof(bio_dgram_sctp_data)); | ||
932 | #ifdef SCTP_PR_SCTP_NONE | ||
933 | data->prinfo.pr_policy = SCTP_PR_SCTP_NONE; | ||
934 | #endif | ||
935 | bi->ptr = data; | ||
936 | |||
937 | bi->flags=0; | ||
938 | return(1); | ||
939 | } | ||
940 | |||
941 | static int dgram_sctp_free(BIO *a) | ||
942 | { | ||
943 | bio_dgram_sctp_data *data; | ||
944 | |||
945 | if (a == NULL) return(0); | ||
946 | if ( ! dgram_clear(a)) | ||
947 | return 0; | ||
948 | |||
949 | data = (bio_dgram_sctp_data *)a->ptr; | ||
950 | if(data != NULL) OPENSSL_free(data); | ||
951 | |||
952 | return(1); | ||
953 | } | ||
954 | |||
955 | #ifdef SCTP_AUTHENTICATION_EVENT | ||
956 | void dgram_sctp_handle_auth_free_key_event(BIO *b, union sctp_notification *snp) | ||
957 | { | ||
958 | unsigned int sockopt_len = 0; | ||
959 | int ret; | ||
960 | struct sctp_authkey_event* authkeyevent = &snp->sn_auth_event; | ||
961 | |||
962 | if (authkeyevent->auth_indication == SCTP_AUTH_FREE_KEY) | ||
963 | { | ||
964 | struct sctp_authkeyid authkeyid; | ||
965 | |||
966 | /* delete key */ | ||
967 | authkeyid.scact_keynumber = authkeyevent->auth_keynumber; | ||
968 | sockopt_len = sizeof(struct sctp_authkeyid); | ||
969 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_DELETE_KEY, | ||
970 | &authkeyid, sockopt_len); | ||
971 | } | ||
972 | } | ||
973 | #endif | ||
974 | |||
975 | static int dgram_sctp_read(BIO *b, char *out, int outl) | ||
976 | { | ||
977 | int ret = 0, n = 0, i, optval; | ||
978 | socklen_t optlen; | ||
979 | bio_dgram_sctp_data *data = (bio_dgram_sctp_data *)b->ptr; | ||
980 | union sctp_notification *snp; | ||
981 | struct msghdr msg; | ||
982 | struct iovec iov; | ||
983 | struct cmsghdr *cmsg; | ||
984 | char cmsgbuf[512]; | ||
985 | |||
986 | if (out != NULL) | ||
987 | { | ||
988 | clear_socket_error(); | ||
989 | |||
990 | do | ||
991 | { | ||
992 | memset(&data->rcvinfo, 0x00, sizeof(struct bio_dgram_sctp_rcvinfo)); | ||
993 | iov.iov_base = out; | ||
994 | iov.iov_len = outl; | ||
995 | msg.msg_name = NULL; | ||
996 | msg.msg_namelen = 0; | ||
997 | msg.msg_iov = &iov; | ||
998 | msg.msg_iovlen = 1; | ||
999 | msg.msg_control = cmsgbuf; | ||
1000 | msg.msg_controllen = 512; | ||
1001 | msg.msg_flags = 0; | ||
1002 | n = recvmsg(b->num, &msg, 0); | ||
1003 | |||
1004 | if (msg.msg_controllen > 0) | ||
1005 | { | ||
1006 | for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg)) | ||
1007 | { | ||
1008 | if (cmsg->cmsg_level != IPPROTO_SCTP) | ||
1009 | continue; | ||
1010 | #ifdef SCTP_RCVINFO | ||
1011 | if (cmsg->cmsg_type == SCTP_RCVINFO) | ||
1012 | { | ||
1013 | struct sctp_rcvinfo *rcvinfo; | ||
1014 | |||
1015 | rcvinfo = (struct sctp_rcvinfo *)CMSG_DATA(cmsg); | ||
1016 | data->rcvinfo.rcv_sid = rcvinfo->rcv_sid; | ||
1017 | data->rcvinfo.rcv_ssn = rcvinfo->rcv_ssn; | ||
1018 | data->rcvinfo.rcv_flags = rcvinfo->rcv_flags; | ||
1019 | data->rcvinfo.rcv_ppid = rcvinfo->rcv_ppid; | ||
1020 | data->rcvinfo.rcv_tsn = rcvinfo->rcv_tsn; | ||
1021 | data->rcvinfo.rcv_cumtsn = rcvinfo->rcv_cumtsn; | ||
1022 | data->rcvinfo.rcv_context = rcvinfo->rcv_context; | ||
1023 | } | ||
1024 | #endif | ||
1025 | #ifdef SCTP_SNDRCV | ||
1026 | if (cmsg->cmsg_type == SCTP_SNDRCV) | ||
1027 | { | ||
1028 | struct sctp_sndrcvinfo *sndrcvinfo; | ||
1029 | |||
1030 | sndrcvinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg); | ||
1031 | data->rcvinfo.rcv_sid = sndrcvinfo->sinfo_stream; | ||
1032 | data->rcvinfo.rcv_ssn = sndrcvinfo->sinfo_ssn; | ||
1033 | data->rcvinfo.rcv_flags = sndrcvinfo->sinfo_flags; | ||
1034 | data->rcvinfo.rcv_ppid = sndrcvinfo->sinfo_ppid; | ||
1035 | data->rcvinfo.rcv_tsn = sndrcvinfo->sinfo_tsn; | ||
1036 | data->rcvinfo.rcv_cumtsn = sndrcvinfo->sinfo_cumtsn; | ||
1037 | data->rcvinfo.rcv_context = sndrcvinfo->sinfo_context; | ||
1038 | } | ||
1039 | #endif | ||
1040 | } | ||
1041 | } | ||
1042 | |||
1043 | if (n <= 0) | ||
1044 | { | ||
1045 | if (n < 0) | ||
1046 | ret = n; | ||
1047 | break; | ||
1048 | } | ||
1049 | |||
1050 | if (msg.msg_flags & MSG_NOTIFICATION) | ||
1051 | { | ||
1052 | snp = (union sctp_notification*) out; | ||
1053 | if (snp->sn_header.sn_type == SCTP_SENDER_DRY_EVENT) | ||
1054 | { | ||
1055 | #ifdef SCTP_EVENT | ||
1056 | struct sctp_event event; | ||
1057 | #else | ||
1058 | struct sctp_event_subscribe event; | ||
1059 | socklen_t eventsize; | ||
1060 | #endif | ||
1061 | /* If a message has been delayed until the socket | ||
1062 | * is dry, it can be sent now. | ||
1063 | */ | ||
1064 | if (data->saved_message.length > 0) | ||
1065 | { | ||
1066 | dgram_sctp_write(data->saved_message.bio, data->saved_message.data, | ||
1067 | data->saved_message.length); | ||
1068 | OPENSSL_free(data->saved_message.data); | ||
1069 | data->saved_message.length = 0; | ||
1070 | } | ||
1071 | |||
1072 | /* disable sender dry event */ | ||
1073 | #ifdef SCTP_EVENT | ||
1074 | memset(&event, 0, sizeof(struct sctp_event)); | ||
1075 | event.se_assoc_id = 0; | ||
1076 | event.se_type = SCTP_SENDER_DRY_EVENT; | ||
1077 | event.se_on = 0; | ||
1078 | i = setsockopt(b->num, IPPROTO_SCTP, SCTP_EVENT, &event, sizeof(struct sctp_event)); | ||
1079 | OPENSSL_assert(i >= 0); | ||
1080 | #else | ||
1081 | eventsize = sizeof(struct sctp_event_subscribe); | ||
1082 | i = getsockopt(b->num, IPPROTO_SCTP, SCTP_EVENTS, &event, &eventsize); | ||
1083 | OPENSSL_assert(i >= 0); | ||
1084 | |||
1085 | event.sctp_sender_dry_event = 0; | ||
1086 | |||
1087 | i = setsockopt(b->num, IPPROTO_SCTP, SCTP_EVENTS, &event, sizeof(struct sctp_event_subscribe)); | ||
1088 | OPENSSL_assert(i >= 0); | ||
1089 | #endif | ||
1090 | } | ||
1091 | |||
1092 | #ifdef SCTP_AUTHENTICATION_EVENT | ||
1093 | if (snp->sn_header.sn_type == SCTP_AUTHENTICATION_EVENT) | ||
1094 | dgram_sctp_handle_auth_free_key_event(b, snp); | ||
1095 | #endif | ||
1096 | |||
1097 | if (data->handle_notifications != NULL) | ||
1098 | data->handle_notifications(b, data->notification_context, (void*) out); | ||
1099 | |||
1100 | memset(out, 0, outl); | ||
1101 | } | ||
1102 | else | ||
1103 | ret += n; | ||
1104 | } | ||
1105 | while ((msg.msg_flags & MSG_NOTIFICATION) && (msg.msg_flags & MSG_EOR) && (ret < outl)); | ||
1106 | |||
1107 | if (ret > 0 && !(msg.msg_flags & MSG_EOR)) | ||
1108 | { | ||
1109 | /* Partial message read, this should never happen! */ | ||
1110 | |||
1111 | /* The buffer was too small, this means the peer sent | ||
1112 | * a message that was larger than allowed. */ | ||
1113 | if (ret == outl) | ||
1114 | return -1; | ||
1115 | |||
1116 | /* Test if socket buffer can handle max record | ||
1117 | * size (2^14 + 2048 + 13) | ||
1118 | */ | ||
1119 | optlen = (socklen_t) sizeof(int); | ||
1120 | ret = getsockopt(b->num, SOL_SOCKET, SO_RCVBUF, &optval, &optlen); | ||
1121 | OPENSSL_assert(ret >= 0); | ||
1122 | OPENSSL_assert(optval >= 18445); | ||
1123 | |||
1124 | /* Test if SCTP doesn't partially deliver below | ||
1125 | * max record size (2^14 + 2048 + 13) | ||
1126 | */ | ||
1127 | optlen = (socklen_t) sizeof(int); | ||
1128 | ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_PARTIAL_DELIVERY_POINT, | ||
1129 | &optval, &optlen); | ||
1130 | OPENSSL_assert(ret >= 0); | ||
1131 | OPENSSL_assert(optval >= 18445); | ||
1132 | |||
1133 | /* Partially delivered notification??? Probably a bug.... */ | ||
1134 | OPENSSL_assert(!(msg.msg_flags & MSG_NOTIFICATION)); | ||
1135 | |||
1136 | /* Everything seems ok till now, so it's most likely | ||
1137 | * a message dropped by PR-SCTP. | ||
1138 | */ | ||
1139 | memset(out, 0, outl); | ||
1140 | BIO_set_retry_read(b); | ||
1141 | return -1; | ||
1142 | } | ||
1143 | |||
1144 | BIO_clear_retry_flags(b); | ||
1145 | if (ret < 0) | ||
1146 | { | ||
1147 | if (BIO_dgram_should_retry(ret)) | ||
1148 | { | ||
1149 | BIO_set_retry_read(b); | ||
1150 | data->_errno = get_last_socket_error(); | ||
1151 | } | ||
1152 | } | ||
1153 | |||
1154 | /* Test if peer uses SCTP-AUTH before continuing */ | ||
1155 | if (!data->peer_auth_tested) | ||
1156 | { | ||
1157 | int ii, auth_data = 0, auth_forward = 0; | ||
1158 | unsigned char *p; | ||
1159 | struct sctp_authchunks *authchunks; | ||
1160 | |||
1161 | optlen = (socklen_t)(sizeof(sctp_assoc_t) + 256 * sizeof(uint8_t)); | ||
1162 | authchunks = OPENSSL_malloc(optlen); | ||
1163 | memset(authchunks, 0, sizeof(optlen)); | ||
1164 | ii = getsockopt(b->num, IPPROTO_SCTP, SCTP_PEER_AUTH_CHUNKS, authchunks, &optlen); | ||
1165 | OPENSSL_assert(ii >= 0); | ||
1166 | |||
1167 | for (p = (unsigned char*) authchunks + sizeof(sctp_assoc_t); | ||
1168 | p < (unsigned char*) authchunks + optlen; | ||
1169 | p += sizeof(uint8_t)) | ||
1170 | { | ||
1171 | if (*p == OPENSSL_SCTP_DATA_CHUNK_TYPE) auth_data = 1; | ||
1172 | if (*p == OPENSSL_SCTP_FORWARD_CUM_TSN_CHUNK_TYPE) auth_forward = 1; | ||
1173 | } | ||
1174 | |||
1175 | OPENSSL_free(authchunks); | ||
1176 | |||
1177 | if (!auth_data || !auth_forward) | ||
1178 | { | ||
1179 | BIOerr(BIO_F_DGRAM_SCTP_READ,BIO_R_CONNECT_ERROR); | ||
1180 | return -1; | ||
1181 | } | ||
1182 | |||
1183 | data->peer_auth_tested = 1; | ||
1184 | } | ||
1185 | } | ||
1186 | return(ret); | ||
1187 | } | ||
1188 | |||
1189 | static int dgram_sctp_write(BIO *b, const char *in, int inl) | ||
1190 | { | ||
1191 | int ret; | ||
1192 | bio_dgram_sctp_data *data = (bio_dgram_sctp_data *)b->ptr; | ||
1193 | struct bio_dgram_sctp_sndinfo *sinfo = &(data->sndinfo); | ||
1194 | struct bio_dgram_sctp_prinfo *pinfo = &(data->prinfo); | ||
1195 | struct bio_dgram_sctp_sndinfo handshake_sinfo; | ||
1196 | struct iovec iov[1]; | ||
1197 | struct msghdr msg; | ||
1198 | struct cmsghdr *cmsg; | ||
1199 | #if defined(SCTP_SNDINFO) && defined(SCTP_PRINFO) | ||
1200 | char cmsgbuf[CMSG_SPACE(sizeof(struct sctp_sndinfo)) + CMSG_SPACE(sizeof(struct sctp_prinfo))]; | ||
1201 | struct sctp_sndinfo *sndinfo; | ||
1202 | struct sctp_prinfo *prinfo; | ||
1203 | #else | ||
1204 | char cmsgbuf[CMSG_SPACE(sizeof(struct sctp_sndrcvinfo))]; | ||
1205 | struct sctp_sndrcvinfo *sndrcvinfo; | ||
1206 | #endif | ||
1207 | |||
1208 | clear_socket_error(); | ||
1209 | |||
1210 | /* If we're send anything else than application data, | ||
1211 | * disable all user parameters and flags. | ||
1212 | */ | ||
1213 | if (in[0] != 23) { | ||
1214 | memset(&handshake_sinfo, 0x00, sizeof(struct bio_dgram_sctp_sndinfo)); | ||
1215 | #ifdef SCTP_SACK_IMMEDIATELY | ||
1216 | handshake_sinfo.snd_flags = SCTP_SACK_IMMEDIATELY; | ||
1217 | #endif | ||
1218 | sinfo = &handshake_sinfo; | ||
1219 | } | ||
1220 | |||
1221 | /* If we have to send a shutdown alert message and the | ||
1222 | * socket is not dry yet, we have to save it and send it | ||
1223 | * as soon as the socket gets dry. | ||
1224 | */ | ||
1225 | if (data->save_shutdown && !BIO_dgram_sctp_wait_for_dry(b)) | ||
1226 | { | ||
1227 | data->saved_message.bio = b; | ||
1228 | data->saved_message.length = inl; | ||
1229 | data->saved_message.data = OPENSSL_malloc(inl); | ||
1230 | memcpy(data->saved_message.data, in, inl); | ||
1231 | return inl; | ||
1232 | } | ||
1233 | |||
1234 | iov[0].iov_base = (char *)in; | ||
1235 | iov[0].iov_len = inl; | ||
1236 | msg.msg_name = NULL; | ||
1237 | msg.msg_namelen = 0; | ||
1238 | msg.msg_iov = iov; | ||
1239 | msg.msg_iovlen = 1; | ||
1240 | msg.msg_control = (caddr_t)cmsgbuf; | ||
1241 | msg.msg_controllen = 0; | ||
1242 | msg.msg_flags = 0; | ||
1243 | #if defined(SCTP_SNDINFO) && defined(SCTP_PRINFO) | ||
1244 | cmsg = (struct cmsghdr *)cmsgbuf; | ||
1245 | cmsg->cmsg_level = IPPROTO_SCTP; | ||
1246 | cmsg->cmsg_type = SCTP_SNDINFO; | ||
1247 | cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndinfo)); | ||
1248 | sndinfo = (struct sctp_sndinfo *)CMSG_DATA(cmsg); | ||
1249 | memset(sndinfo, 0, sizeof(struct sctp_sndinfo)); | ||
1250 | sndinfo->snd_sid = sinfo->snd_sid; | ||
1251 | sndinfo->snd_flags = sinfo->snd_flags; | ||
1252 | sndinfo->snd_ppid = sinfo->snd_ppid; | ||
1253 | sndinfo->snd_context = sinfo->snd_context; | ||
1254 | msg.msg_controllen += CMSG_SPACE(sizeof(struct sctp_sndinfo)); | ||
1255 | |||
1256 | cmsg = (struct cmsghdr *)&cmsgbuf[CMSG_SPACE(sizeof(struct sctp_sndinfo))]; | ||
1257 | cmsg->cmsg_level = IPPROTO_SCTP; | ||
1258 | cmsg->cmsg_type = SCTP_PRINFO; | ||
1259 | cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_prinfo)); | ||
1260 | prinfo = (struct sctp_prinfo *)CMSG_DATA(cmsg); | ||
1261 | memset(prinfo, 0, sizeof(struct sctp_prinfo)); | ||
1262 | prinfo->pr_policy = pinfo->pr_policy; | ||
1263 | prinfo->pr_value = pinfo->pr_value; | ||
1264 | msg.msg_controllen += CMSG_SPACE(sizeof(struct sctp_prinfo)); | ||
1265 | #else | ||
1266 | cmsg = (struct cmsghdr *)cmsgbuf; | ||
1267 | cmsg->cmsg_level = IPPROTO_SCTP; | ||
1268 | cmsg->cmsg_type = SCTP_SNDRCV; | ||
1269 | cmsg->cmsg_len = CMSG_LEN(sizeof(struct sctp_sndrcvinfo)); | ||
1270 | sndrcvinfo = (struct sctp_sndrcvinfo *)CMSG_DATA(cmsg); | ||
1271 | memset(sndrcvinfo, 0, sizeof(struct sctp_sndrcvinfo)); | ||
1272 | sndrcvinfo->sinfo_stream = sinfo->snd_sid; | ||
1273 | sndrcvinfo->sinfo_flags = sinfo->snd_flags; | ||
1274 | #ifdef __FreeBSD__ | ||
1275 | sndrcvinfo->sinfo_flags |= pinfo->pr_policy; | ||
1276 | #endif | ||
1277 | sndrcvinfo->sinfo_ppid = sinfo->snd_ppid; | ||
1278 | sndrcvinfo->sinfo_context = sinfo->snd_context; | ||
1279 | sndrcvinfo->sinfo_timetolive = pinfo->pr_value; | ||
1280 | msg.msg_controllen += CMSG_SPACE(sizeof(struct sctp_sndrcvinfo)); | ||
1281 | #endif | ||
1282 | |||
1283 | ret = sendmsg(b->num, &msg, 0); | ||
1284 | |||
1285 | BIO_clear_retry_flags(b); | ||
1286 | if (ret <= 0) | ||
1287 | { | ||
1288 | if (BIO_dgram_should_retry(ret)) | ||
1289 | { | ||
1290 | BIO_set_retry_write(b); | ||
1291 | data->_errno = get_last_socket_error(); | ||
1292 | } | ||
1293 | } | ||
1294 | return(ret); | ||
1295 | } | ||
1296 | |||
1297 | static long dgram_sctp_ctrl(BIO *b, int cmd, long num, void *ptr) | ||
1298 | { | ||
1299 | long ret=1; | ||
1300 | bio_dgram_sctp_data *data = NULL; | ||
1301 | unsigned int sockopt_len = 0; | ||
1302 | struct sctp_authkeyid authkeyid; | ||
1303 | struct sctp_authkey *authkey; | ||
1304 | |||
1305 | data = (bio_dgram_sctp_data *)b->ptr; | ||
1306 | |||
1307 | switch (cmd) | ||
1308 | { | ||
1309 | case BIO_CTRL_DGRAM_QUERY_MTU: | ||
1310 | /* Set to maximum (2^14) | ||
1311 | * and ignore user input to enable transport | ||
1312 | * protocol fragmentation. | ||
1313 | * Returns always 2^14. | ||
1314 | */ | ||
1315 | data->mtu = 16384; | ||
1316 | ret = data->mtu; | ||
1317 | break; | ||
1318 | case BIO_CTRL_DGRAM_SET_MTU: | ||
1319 | /* Set to maximum (2^14) | ||
1320 | * and ignore input to enable transport | ||
1321 | * protocol fragmentation. | ||
1322 | * Returns always 2^14. | ||
1323 | */ | ||
1324 | data->mtu = 16384; | ||
1325 | ret = data->mtu; | ||
1326 | break; | ||
1327 | case BIO_CTRL_DGRAM_SET_CONNECTED: | ||
1328 | case BIO_CTRL_DGRAM_CONNECT: | ||
1329 | /* Returns always -1. */ | ||
1330 | ret = -1; | ||
1331 | break; | ||
1332 | case BIO_CTRL_DGRAM_SET_NEXT_TIMEOUT: | ||
1333 | /* SCTP doesn't need the DTLS timer | ||
1334 | * Returns always 1. | ||
1335 | */ | ||
1336 | break; | ||
1337 | case BIO_CTRL_DGRAM_SCTP_SET_IN_HANDSHAKE: | ||
1338 | if (num > 0) | ||
1339 | data->in_handshake = 1; | ||
1340 | else | ||
1341 | data->in_handshake = 0; | ||
1342 | |||
1343 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_NODELAY, &data->in_handshake, sizeof(int)); | ||
1344 | break; | ||
1345 | case BIO_CTRL_DGRAM_SCTP_ADD_AUTH_KEY: | ||
1346 | /* New shared key for SCTP AUTH. | ||
1347 | * Returns 0 on success, -1 otherwise. | ||
1348 | */ | ||
1349 | |||
1350 | /* Get active key */ | ||
1351 | sockopt_len = sizeof(struct sctp_authkeyid); | ||
1352 | ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, &authkeyid, &sockopt_len); | ||
1353 | if (ret < 0) break; | ||
1354 | |||
1355 | /* Add new key */ | ||
1356 | sockopt_len = sizeof(struct sctp_authkey) + 64 * sizeof(uint8_t); | ||
1357 | authkey = OPENSSL_malloc(sockopt_len); | ||
1358 | memset(authkey, 0x00, sockopt_len); | ||
1359 | authkey->sca_keynumber = authkeyid.scact_keynumber + 1; | ||
1360 | #ifndef __FreeBSD__ | ||
1361 | /* This field is missing in FreeBSD 8.2 and earlier, | ||
1362 | * and FreeBSD 8.3 and higher work without it. | ||
1363 | */ | ||
1364 | authkey->sca_keylength = 64; | ||
1365 | #endif | ||
1366 | memcpy(&authkey->sca_key[0], ptr, 64 * sizeof(uint8_t)); | ||
1367 | |||
1368 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_KEY, authkey, sockopt_len); | ||
1369 | if (ret < 0) break; | ||
1370 | |||
1371 | /* Reset active key */ | ||
1372 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, | ||
1373 | &authkeyid, sizeof(struct sctp_authkeyid)); | ||
1374 | if (ret < 0) break; | ||
1375 | |||
1376 | break; | ||
1377 | case BIO_CTRL_DGRAM_SCTP_NEXT_AUTH_KEY: | ||
1378 | /* Returns 0 on success, -1 otherwise. */ | ||
1379 | |||
1380 | /* Get active key */ | ||
1381 | sockopt_len = sizeof(struct sctp_authkeyid); | ||
1382 | ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, &authkeyid, &sockopt_len); | ||
1383 | if (ret < 0) break; | ||
1384 | |||
1385 | /* Set active key */ | ||
1386 | authkeyid.scact_keynumber = authkeyid.scact_keynumber + 1; | ||
1387 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, | ||
1388 | &authkeyid, sizeof(struct sctp_authkeyid)); | ||
1389 | if (ret < 0) break; | ||
1390 | |||
1391 | /* CCS has been sent, so remember that and fall through | ||
1392 | * to check if we need to deactivate an old key | ||
1393 | */ | ||
1394 | data->ccs_sent = 1; | ||
1395 | |||
1396 | case BIO_CTRL_DGRAM_SCTP_AUTH_CCS_RCVD: | ||
1397 | /* Returns 0 on success, -1 otherwise. */ | ||
1398 | |||
1399 | /* Has this command really been called or is this just a fall-through? */ | ||
1400 | if (cmd == BIO_CTRL_DGRAM_SCTP_AUTH_CCS_RCVD) | ||
1401 | data->ccs_rcvd = 1; | ||
1402 | |||
1403 | /* CSS has been both, received and sent, so deactivate an old key */ | ||
1404 | if (data->ccs_rcvd == 1 && data->ccs_sent == 1) | ||
1405 | { | ||
1406 | /* Get active key */ | ||
1407 | sockopt_len = sizeof(struct sctp_authkeyid); | ||
1408 | ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_ACTIVE_KEY, &authkeyid, &sockopt_len); | ||
1409 | if (ret < 0) break; | ||
1410 | |||
1411 | /* Deactivate key or delete second last key if | ||
1412 | * SCTP_AUTHENTICATION_EVENT is not available. | ||
1413 | */ | ||
1414 | authkeyid.scact_keynumber = authkeyid.scact_keynumber - 1; | ||
1415 | #ifdef SCTP_AUTH_DEACTIVATE_KEY | ||
1416 | sockopt_len = sizeof(struct sctp_authkeyid); | ||
1417 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_DEACTIVATE_KEY, | ||
1418 | &authkeyid, sockopt_len); | ||
1419 | if (ret < 0) break; | ||
1420 | #endif | ||
1421 | #ifndef SCTP_AUTHENTICATION_EVENT | ||
1422 | if (authkeyid.scact_keynumber > 0) | ||
1423 | { | ||
1424 | authkeyid.scact_keynumber = authkeyid.scact_keynumber - 1; | ||
1425 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_AUTH_DELETE_KEY, | ||
1426 | &authkeyid, sizeof(struct sctp_authkeyid)); | ||
1427 | if (ret < 0) break; | ||
1428 | } | ||
1429 | #endif | ||
1430 | |||
1431 | data->ccs_rcvd = 0; | ||
1432 | data->ccs_sent = 0; | ||
1433 | } | ||
1434 | break; | ||
1435 | case BIO_CTRL_DGRAM_SCTP_GET_SNDINFO: | ||
1436 | /* Returns the size of the copied struct. */ | ||
1437 | if (num > (long) sizeof(struct bio_dgram_sctp_sndinfo)) | ||
1438 | num = sizeof(struct bio_dgram_sctp_sndinfo); | ||
1439 | |||
1440 | memcpy(ptr, &(data->sndinfo), num); | ||
1441 | ret = num; | ||
1442 | break; | ||
1443 | case BIO_CTRL_DGRAM_SCTP_SET_SNDINFO: | ||
1444 | /* Returns the size of the copied struct. */ | ||
1445 | if (num > (long) sizeof(struct bio_dgram_sctp_sndinfo)) | ||
1446 | num = sizeof(struct bio_dgram_sctp_sndinfo); | ||
1447 | |||
1448 | memcpy(&(data->sndinfo), ptr, num); | ||
1449 | break; | ||
1450 | case BIO_CTRL_DGRAM_SCTP_GET_RCVINFO: | ||
1451 | /* Returns the size of the copied struct. */ | ||
1452 | if (num > (long) sizeof(struct bio_dgram_sctp_rcvinfo)) | ||
1453 | num = sizeof(struct bio_dgram_sctp_rcvinfo); | ||
1454 | |||
1455 | memcpy(ptr, &data->rcvinfo, num); | ||
1456 | |||
1457 | ret = num; | ||
1458 | break; | ||
1459 | case BIO_CTRL_DGRAM_SCTP_SET_RCVINFO: | ||
1460 | /* Returns the size of the copied struct. */ | ||
1461 | if (num > (long) sizeof(struct bio_dgram_sctp_rcvinfo)) | ||
1462 | num = sizeof(struct bio_dgram_sctp_rcvinfo); | ||
1463 | |||
1464 | memcpy(&(data->rcvinfo), ptr, num); | ||
1465 | break; | ||
1466 | case BIO_CTRL_DGRAM_SCTP_GET_PRINFO: | ||
1467 | /* Returns the size of the copied struct. */ | ||
1468 | if (num > (long) sizeof(struct bio_dgram_sctp_prinfo)) | ||
1469 | num = sizeof(struct bio_dgram_sctp_prinfo); | ||
1470 | |||
1471 | memcpy(ptr, &(data->prinfo), num); | ||
1472 | ret = num; | ||
1473 | break; | ||
1474 | case BIO_CTRL_DGRAM_SCTP_SET_PRINFO: | ||
1475 | /* Returns the size of the copied struct. */ | ||
1476 | if (num > (long) sizeof(struct bio_dgram_sctp_prinfo)) | ||
1477 | num = sizeof(struct bio_dgram_sctp_prinfo); | ||
1478 | |||
1479 | memcpy(&(data->prinfo), ptr, num); | ||
1480 | break; | ||
1481 | case BIO_CTRL_DGRAM_SCTP_SAVE_SHUTDOWN: | ||
1482 | /* Returns always 1. */ | ||
1483 | if (num > 0) | ||
1484 | data->save_shutdown = 1; | ||
1485 | else | ||
1486 | data->save_shutdown = 0; | ||
1487 | break; | ||
1488 | |||
1489 | default: | ||
1490 | /* Pass to default ctrl function to | ||
1491 | * process SCTP unspecific commands | ||
1492 | */ | ||
1493 | ret=dgram_ctrl(b, cmd, num, ptr); | ||
1494 | break; | ||
1495 | } | ||
1496 | return(ret); | ||
1497 | } | ||
1498 | |||
1499 | int BIO_dgram_sctp_notification_cb(BIO *b, | ||
1500 | void (*handle_notifications)(BIO *bio, void *context, void *buf), | ||
1501 | void *context) | ||
1502 | { | ||
1503 | bio_dgram_sctp_data *data = (bio_dgram_sctp_data *) b->ptr; | ||
1504 | |||
1505 | if (handle_notifications != NULL) | ||
1506 | { | ||
1507 | data->handle_notifications = handle_notifications; | ||
1508 | data->notification_context = context; | ||
1509 | } | ||
1510 | else | ||
1511 | return -1; | ||
1512 | |||
1513 | return 0; | ||
1514 | } | ||
1515 | |||
1516 | int BIO_dgram_sctp_wait_for_dry(BIO *b) | ||
1517 | { | ||
1518 | int is_dry = 0; | ||
1519 | int n, sockflags, ret; | ||
1520 | union sctp_notification snp; | ||
1521 | struct msghdr msg; | ||
1522 | struct iovec iov; | ||
1523 | #ifdef SCTP_EVENT | ||
1524 | struct sctp_event event; | ||
1525 | #else | ||
1526 | struct sctp_event_subscribe event; | ||
1527 | socklen_t eventsize; | ||
1528 | #endif | ||
1529 | bio_dgram_sctp_data *data = (bio_dgram_sctp_data *)b->ptr; | ||
1530 | |||
1531 | /* set sender dry event */ | ||
1532 | #ifdef SCTP_EVENT | ||
1533 | memset(&event, 0, sizeof(struct sctp_event)); | ||
1534 | event.se_assoc_id = 0; | ||
1535 | event.se_type = SCTP_SENDER_DRY_EVENT; | ||
1536 | event.se_on = 1; | ||
1537 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_EVENT, &event, sizeof(struct sctp_event)); | ||
1538 | #else | ||
1539 | eventsize = sizeof(struct sctp_event_subscribe); | ||
1540 | ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_EVENTS, &event, &eventsize); | ||
1541 | if (ret < 0) | ||
1542 | return -1; | ||
1543 | |||
1544 | event.sctp_sender_dry_event = 1; | ||
1545 | |||
1546 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_EVENTS, &event, sizeof(struct sctp_event_subscribe)); | ||
1547 | #endif | ||
1548 | if (ret < 0) | ||
1549 | return -1; | ||
1550 | |||
1551 | /* peek for notification */ | ||
1552 | memset(&snp, 0x00, sizeof(union sctp_notification)); | ||
1553 | iov.iov_base = (char *)&snp; | ||
1554 | iov.iov_len = sizeof(union sctp_notification); | ||
1555 | msg.msg_name = NULL; | ||
1556 | msg.msg_namelen = 0; | ||
1557 | msg.msg_iov = &iov; | ||
1558 | msg.msg_iovlen = 1; | ||
1559 | msg.msg_control = NULL; | ||
1560 | msg.msg_controllen = 0; | ||
1561 | msg.msg_flags = 0; | ||
1562 | |||
1563 | n = recvmsg(b->num, &msg, MSG_PEEK); | ||
1564 | if (n <= 0) | ||
1565 | { | ||
1566 | if ((n < 0) && (get_last_socket_error() != EAGAIN) && (get_last_socket_error() != EWOULDBLOCK)) | ||
1567 | return -1; | ||
1568 | else | ||
1569 | return 0; | ||
1570 | } | ||
1571 | |||
1572 | /* if we find a notification, process it and try again if necessary */ | ||
1573 | while (msg.msg_flags & MSG_NOTIFICATION) | ||
1574 | { | ||
1575 | memset(&snp, 0x00, sizeof(union sctp_notification)); | ||
1576 | iov.iov_base = (char *)&snp; | ||
1577 | iov.iov_len = sizeof(union sctp_notification); | ||
1578 | msg.msg_name = NULL; | ||
1579 | msg.msg_namelen = 0; | ||
1580 | msg.msg_iov = &iov; | ||
1581 | msg.msg_iovlen = 1; | ||
1582 | msg.msg_control = NULL; | ||
1583 | msg.msg_controllen = 0; | ||
1584 | msg.msg_flags = 0; | ||
1585 | |||
1586 | n = recvmsg(b->num, &msg, 0); | ||
1587 | if (n <= 0) | ||
1588 | { | ||
1589 | if ((n < 0) && (get_last_socket_error() != EAGAIN) && (get_last_socket_error() != EWOULDBLOCK)) | ||
1590 | return -1; | ||
1591 | else | ||
1592 | return is_dry; | ||
1593 | } | ||
1594 | |||
1595 | if (snp.sn_header.sn_type == SCTP_SENDER_DRY_EVENT) | ||
1596 | { | ||
1597 | is_dry = 1; | ||
1598 | |||
1599 | /* disable sender dry event */ | ||
1600 | #ifdef SCTP_EVENT | ||
1601 | memset(&event, 0, sizeof(struct sctp_event)); | ||
1602 | event.se_assoc_id = 0; | ||
1603 | event.se_type = SCTP_SENDER_DRY_EVENT; | ||
1604 | event.se_on = 0; | ||
1605 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_EVENT, &event, sizeof(struct sctp_event)); | ||
1606 | #else | ||
1607 | eventsize = (socklen_t) sizeof(struct sctp_event_subscribe); | ||
1608 | ret = getsockopt(b->num, IPPROTO_SCTP, SCTP_EVENTS, &event, &eventsize); | ||
1609 | if (ret < 0) | ||
1610 | return -1; | ||
1611 | |||
1612 | event.sctp_sender_dry_event = 0; | ||
1613 | |||
1614 | ret = setsockopt(b->num, IPPROTO_SCTP, SCTP_EVENTS, &event, sizeof(struct sctp_event_subscribe)); | ||
1615 | #endif | ||
1616 | if (ret < 0) | ||
1617 | return -1; | ||
1618 | } | ||
1619 | |||
1620 | #ifdef SCTP_AUTHENTICATION_EVENT | ||
1621 | if (snp.sn_header.sn_type == SCTP_AUTHENTICATION_EVENT) | ||
1622 | dgram_sctp_handle_auth_free_key_event(b, &snp); | ||
1623 | #endif | ||
1624 | |||
1625 | if (data->handle_notifications != NULL) | ||
1626 | data->handle_notifications(b, data->notification_context, (void*) &snp); | ||
1627 | |||
1628 | /* found notification, peek again */ | ||
1629 | memset(&snp, 0x00, sizeof(union sctp_notification)); | ||
1630 | iov.iov_base = (char *)&snp; | ||
1631 | iov.iov_len = sizeof(union sctp_notification); | ||
1632 | msg.msg_name = NULL; | ||
1633 | msg.msg_namelen = 0; | ||
1634 | msg.msg_iov = &iov; | ||
1635 | msg.msg_iovlen = 1; | ||
1636 | msg.msg_control = NULL; | ||
1637 | msg.msg_controllen = 0; | ||
1638 | msg.msg_flags = 0; | ||
1639 | |||
1640 | /* if we have seen the dry already, don't wait */ | ||
1641 | if (is_dry) | ||
1642 | { | ||
1643 | sockflags = fcntl(b->num, F_GETFL, 0); | ||
1644 | fcntl(b->num, F_SETFL, O_NONBLOCK); | ||
1645 | } | ||
1646 | |||
1647 | n = recvmsg(b->num, &msg, MSG_PEEK); | ||
1648 | |||
1649 | if (is_dry) | ||
1650 | { | ||
1651 | fcntl(b->num, F_SETFL, sockflags); | ||
1652 | } | ||
1653 | |||
1654 | if (n <= 0) | ||
1655 | { | ||
1656 | if ((n < 0) && (get_last_socket_error() != EAGAIN) && (get_last_socket_error() != EWOULDBLOCK)) | ||
1657 | return -1; | ||
1658 | else | ||
1659 | return is_dry; | ||
1660 | } | ||
1661 | } | ||
1662 | |||
1663 | /* read anything else */ | ||
1664 | return is_dry; | ||
1665 | } | ||
1666 | |||
1667 | int BIO_dgram_sctp_msg_waiting(BIO *b) | ||
1668 | { | ||
1669 | int n, sockflags; | ||
1670 | union sctp_notification snp; | ||
1671 | struct msghdr msg; | ||
1672 | struct iovec iov; | ||
1673 | bio_dgram_sctp_data *data = (bio_dgram_sctp_data *)b->ptr; | ||
1674 | |||
1675 | /* Check if there are any messages waiting to be read */ | ||
1676 | do | ||
1677 | { | ||
1678 | memset(&snp, 0x00, sizeof(union sctp_notification)); | ||
1679 | iov.iov_base = (char *)&snp; | ||
1680 | iov.iov_len = sizeof(union sctp_notification); | ||
1681 | msg.msg_name = NULL; | ||
1682 | msg.msg_namelen = 0; | ||
1683 | msg.msg_iov = &iov; | ||
1684 | msg.msg_iovlen = 1; | ||
1685 | msg.msg_control = NULL; | ||
1686 | msg.msg_controllen = 0; | ||
1687 | msg.msg_flags = 0; | ||
1688 | |||
1689 | sockflags = fcntl(b->num, F_GETFL, 0); | ||
1690 | fcntl(b->num, F_SETFL, O_NONBLOCK); | ||
1691 | n = recvmsg(b->num, &msg, MSG_PEEK); | ||
1692 | fcntl(b->num, F_SETFL, sockflags); | ||
1693 | |||
1694 | /* if notification, process and try again */ | ||
1695 | if (n > 0 && (msg.msg_flags & MSG_NOTIFICATION)) | ||
1696 | { | ||
1697 | #ifdef SCTP_AUTHENTICATION_EVENT | ||
1698 | if (snp.sn_header.sn_type == SCTP_AUTHENTICATION_EVENT) | ||
1699 | dgram_sctp_handle_auth_free_key_event(b, &snp); | ||
1700 | #endif | ||
1701 | |||
1702 | memset(&snp, 0x00, sizeof(union sctp_notification)); | ||
1703 | iov.iov_base = (char *)&snp; | ||
1704 | iov.iov_len = sizeof(union sctp_notification); | ||
1705 | msg.msg_name = NULL; | ||
1706 | msg.msg_namelen = 0; | ||
1707 | msg.msg_iov = &iov; | ||
1708 | msg.msg_iovlen = 1; | ||
1709 | msg.msg_control = NULL; | ||
1710 | msg.msg_controllen = 0; | ||
1711 | msg.msg_flags = 0; | ||
1712 | n = recvmsg(b->num, &msg, 0); | ||
1713 | |||
1714 | if (data->handle_notifications != NULL) | ||
1715 | data->handle_notifications(b, data->notification_context, (void*) &snp); | ||
1716 | } | ||
1717 | |||
1718 | } while (n > 0 && (msg.msg_flags & MSG_NOTIFICATION)); | ||
1719 | |||
1720 | /* Return 1 if there is a message to be read, return 0 otherwise. */ | ||
1721 | if (n > 0) | ||
1722 | return 1; | ||
1723 | else | ||
1724 | return 0; | ||
1725 | } | ||
1726 | |||
1727 | static int dgram_sctp_puts(BIO *bp, const char *str) | ||
1728 | { | ||
1729 | int n,ret; | ||
1730 | |||
1731 | n=strlen(str); | ||
1732 | ret=dgram_sctp_write(bp,str,n); | ||
1733 | return(ret); | ||
1734 | } | ||
1735 | #endif | ||
1736 | |||
1737 | static int BIO_dgram_should_retry(int i) | 741 | static int BIO_dgram_should_retry(int i) |
1738 | { | 742 | { |
1739 | int err; | 743 | int err; |
diff --git a/src/lib/libcrypto/bio/bss_rtcp.c b/src/lib/libcrypto/bio/bss_rtcp.c new file mode 100644 index 0000000000..7dae485564 --- /dev/null +++ b/src/lib/libcrypto/bio/bss_rtcp.c | |||
@@ -0,0 +1,294 @@ | |||
1 | /* crypto/bio/bss_rtcp.c */ | ||
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
3 | * All rights reserved. | ||
4 | * | ||
5 | * This package is an SSL implementation written | ||
6 | * by Eric Young (eay@cryptsoft.com). | ||
7 | * The implementation was written so as to conform with Netscapes SSL. | ||
8 | * | ||
9 | * This library is free for commercial and non-commercial use as long as | ||
10 | * the following conditions are aheared to. The following conditions | ||
11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
13 | * included with this distribution is covered by the same copyright terms | ||
14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
15 | * | ||
16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
17 | * the code are not to be removed. | ||
18 | * If this package is used in a product, Eric Young should be given attribution | ||
19 | * as the author of the parts of the library used. | ||
20 | * This can be in the form of a textual message at program startup or | ||
21 | * in documentation (online or textual) provided with the package. | ||
22 | * | ||
23 | * Redistribution and use in source and binary forms, with or without | ||
24 | * modification, are permitted provided that the following conditions | ||
25 | * are met: | ||
26 | * 1. Redistributions of source code must retain the copyright | ||
27 | * notice, this list of conditions and the following disclaimer. | ||
28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
29 | * notice, this list of conditions and the following disclaimer in the | ||
30 | * documentation and/or other materials provided with the distribution. | ||
31 | * 3. All advertising materials mentioning features or use of this software | ||
32 | * must display the following acknowledgement: | ||
33 | * "This product includes cryptographic software written by | ||
34 | * Eric Young (eay@cryptsoft.com)" | ||
35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
36 | * being used are not cryptographic related :-). | ||
37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
38 | * the apps directory (application code) you must include an acknowledgement: | ||
39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
40 | * | ||
41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
51 | * SUCH DAMAGE. | ||
52 | * | ||
53 | * The licence and distribution terms for any publically available version or | ||
54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
55 | * copied and put under another distribution licence | ||
56 | * [including the GNU Public Licence.] | ||
57 | */ | ||
58 | |||
59 | /* Written by David L. Jones <jonesd@kcgl1.eng.ohio-state.edu> | ||
60 | * Date: 22-JUL-1996 | ||
61 | * Revised: 25-SEP-1997 Update for 0.8.1, BIO_CTRL_SET -> BIO_C_SET_FD | ||
62 | */ | ||
63 | /* VMS */ | ||
64 | #include <stdio.h> | ||
65 | #include <stdlib.h> | ||
66 | #include <string.h> | ||
67 | #include <errno.h> | ||
68 | #include "cryptlib.h" | ||
69 | #include <openssl/bio.h> | ||
70 | |||
71 | #include <iodef.h> /* VMS IO$_ definitions */ | ||
72 | #include <starlet.h> | ||
73 | |||
74 | typedef unsigned short io_channel; | ||
75 | /*************************************************************************/ | ||
76 | struct io_status { short status, count; long flags; }; | ||
77 | |||
78 | struct rpc_msg { /* Should have member alignment inhibited */ | ||
79 | char channel; /* 'A'-app data. 'R'-remote client 'G'-global */ | ||
80 | char function; /* 'G'-get, 'P'-put, 'C'-confirm, 'X'-close */ | ||
81 | unsigned short int length; /* Amount of data returned or max to return */ | ||
82 | char data[4092]; /* variable data */ | ||
83 | }; | ||
84 | #define RPC_HDR_SIZE (sizeof(struct rpc_msg) - 4092) | ||
85 | |||
86 | struct rpc_ctx { | ||
87 | int filled, pos; | ||
88 | struct rpc_msg msg; | ||
89 | }; | ||
90 | |||
91 | static int rtcp_write(BIO *h,const char *buf,int num); | ||
92 | static int rtcp_read(BIO *h,char *buf,int size); | ||
93 | static int rtcp_puts(BIO *h,const char *str); | ||
94 | static int rtcp_gets(BIO *h,char *str,int size); | ||
95 | static long rtcp_ctrl(BIO *h,int cmd,long arg1,void *arg2); | ||
96 | static int rtcp_new(BIO *h); | ||
97 | static int rtcp_free(BIO *data); | ||
98 | |||
99 | static BIO_METHOD rtcp_method= | ||
100 | { | ||
101 | BIO_TYPE_FD, | ||
102 | "RTCP", | ||
103 | rtcp_write, | ||
104 | rtcp_read, | ||
105 | rtcp_puts, | ||
106 | rtcp_gets, | ||
107 | rtcp_ctrl, | ||
108 | rtcp_new, | ||
109 | rtcp_free, | ||
110 | NULL, | ||
111 | }; | ||
112 | |||
113 | BIO_METHOD *BIO_s_rtcp(void) | ||
114 | { | ||
115 | return(&rtcp_method); | ||
116 | } | ||
117 | /*****************************************************************************/ | ||
118 | /* Decnet I/O routines. | ||
119 | */ | ||
120 | |||
121 | #ifdef __DECC | ||
122 | #pragma message save | ||
123 | #pragma message disable DOLLARID | ||
124 | #endif | ||
125 | |||
126 | static int get ( io_channel chan, char *buffer, int maxlen, int *length ) | ||
127 | { | ||
128 | int status; | ||
129 | struct io_status iosb; | ||
130 | status = sys$qiow ( 0, chan, IO$_READVBLK, &iosb, 0, 0, | ||
131 | buffer, maxlen, 0, 0, 0, 0 ); | ||
132 | if ( (status&1) == 1 ) status = iosb.status; | ||
133 | if ( (status&1) == 1 ) *length = iosb.count; | ||
134 | return status; | ||
135 | } | ||
136 | |||
137 | static int put ( io_channel chan, char *buffer, int length ) | ||
138 | { | ||
139 | int status; | ||
140 | struct io_status iosb; | ||
141 | status = sys$qiow ( 0, chan, IO$_WRITEVBLK, &iosb, 0, 0, | ||
142 | buffer, length, 0, 0, 0, 0 ); | ||
143 | if ( (status&1) == 1 ) status = iosb.status; | ||
144 | return status; | ||
145 | } | ||
146 | |||
147 | #ifdef __DECC | ||
148 | #pragma message restore | ||
149 | #endif | ||
150 | |||
151 | /***************************************************************************/ | ||
152 | |||
153 | static int rtcp_new(BIO *bi) | ||
154 | { | ||
155 | struct rpc_ctx *ctx; | ||
156 | bi->init=1; | ||
157 | bi->num=0; | ||
158 | bi->flags = 0; | ||
159 | bi->ptr=OPENSSL_malloc(sizeof(struct rpc_ctx)); | ||
160 | ctx = (struct rpc_ctx *) bi->ptr; | ||
161 | ctx->filled = 0; | ||
162 | ctx->pos = 0; | ||
163 | return(1); | ||
164 | } | ||
165 | |||
166 | static int rtcp_free(BIO *a) | ||
167 | { | ||
168 | if (a == NULL) return(0); | ||
169 | if ( a->ptr ) OPENSSL_free ( a->ptr ); | ||
170 | a->ptr = NULL; | ||
171 | return(1); | ||
172 | } | ||
173 | |||
174 | static int rtcp_read(BIO *b, char *out, int outl) | ||
175 | { | ||
176 | int status, length; | ||
177 | struct rpc_ctx *ctx; | ||
178 | /* | ||
179 | * read data, return existing. | ||
180 | */ | ||
181 | ctx = (struct rpc_ctx *) b->ptr; | ||
182 | if ( ctx->pos < ctx->filled ) { | ||
183 | length = ctx->filled - ctx->pos; | ||
184 | if ( length > outl ) length = outl; | ||
185 | memmove ( out, &ctx->msg.data[ctx->pos], length ); | ||
186 | ctx->pos += length; | ||
187 | return length; | ||
188 | } | ||
189 | /* | ||
190 | * Requst more data from R channel. | ||
191 | */ | ||
192 | ctx->msg.channel = 'R'; | ||
193 | ctx->msg.function = 'G'; | ||
194 | ctx->msg.length = sizeof(ctx->msg.data); | ||
195 | status = put ( b->num, (char *) &ctx->msg, RPC_HDR_SIZE ); | ||
196 | if ( (status&1) == 0 ) { | ||
197 | return -1; | ||
198 | } | ||
199 | /* | ||
200 | * Read. | ||
201 | */ | ||
202 | ctx->pos = ctx->filled = 0; | ||
203 | status = get ( b->num, (char *) &ctx->msg, sizeof(ctx->msg), &length ); | ||
204 | if ( (status&1) == 0 ) length = -1; | ||
205 | if ( ctx->msg.channel != 'R' || ctx->msg.function != 'C' ) { | ||
206 | length = -1; | ||
207 | } | ||
208 | ctx->filled = length - RPC_HDR_SIZE; | ||
209 | |||
210 | if ( ctx->pos < ctx->filled ) { | ||
211 | length = ctx->filled - ctx->pos; | ||
212 | if ( length > outl ) length = outl; | ||
213 | memmove ( out, ctx->msg.data, length ); | ||
214 | ctx->pos += length; | ||
215 | return length; | ||
216 | } | ||
217 | |||
218 | return length; | ||
219 | } | ||
220 | |||
221 | static int rtcp_write(BIO *b, const char *in, int inl) | ||
222 | { | ||
223 | int status, i, segment, length; | ||
224 | struct rpc_ctx *ctx; | ||
225 | /* | ||
226 | * Output data, send in chunks no larger that sizeof(ctx->msg.data). | ||
227 | */ | ||
228 | ctx = (struct rpc_ctx *) b->ptr; | ||
229 | for ( i = 0; i < inl; i += segment ) { | ||
230 | segment = inl - i; | ||
231 | if ( segment > sizeof(ctx->msg.data) ) segment = sizeof(ctx->msg.data); | ||
232 | ctx->msg.channel = 'R'; | ||
233 | ctx->msg.function = 'P'; | ||
234 | ctx->msg.length = segment; | ||
235 | memmove ( ctx->msg.data, &in[i], segment ); | ||
236 | status = put ( b->num, (char *) &ctx->msg, segment + RPC_HDR_SIZE ); | ||
237 | if ((status&1) == 0 ) { i = -1; break; } | ||
238 | |||
239 | status = get ( b->num, (char *) &ctx->msg, sizeof(ctx->msg), &length ); | ||
240 | if ( ((status&1) == 0) || (length < RPC_HDR_SIZE) ) { i = -1; break; } | ||
241 | if ( (ctx->msg.channel != 'R') || (ctx->msg.function != 'C') ) { | ||
242 | printf("unexpected response when confirming put %c %c\n", | ||
243 | ctx->msg.channel, ctx->msg.function ); | ||
244 | |||
245 | } | ||
246 | } | ||
247 | return(i); | ||
248 | } | ||
249 | |||
250 | static long rtcp_ctrl(BIO *b, int cmd, long num, void *ptr) | ||
251 | { | ||
252 | long ret=1; | ||
253 | |||
254 | switch (cmd) | ||
255 | { | ||
256 | case BIO_CTRL_RESET: | ||
257 | case BIO_CTRL_EOF: | ||
258 | ret = 1; | ||
259 | break; | ||
260 | case BIO_C_SET_FD: | ||
261 | b->num = num; | ||
262 | ret = 1; | ||
263 | break; | ||
264 | case BIO_CTRL_SET_CLOSE: | ||
265 | case BIO_CTRL_FLUSH: | ||
266 | case BIO_CTRL_DUP: | ||
267 | ret=1; | ||
268 | break; | ||
269 | case BIO_CTRL_GET_CLOSE: | ||
270 | case BIO_CTRL_INFO: | ||
271 | case BIO_CTRL_GET: | ||
272 | case BIO_CTRL_PENDING: | ||
273 | case BIO_CTRL_WPENDING: | ||
274 | default: | ||
275 | ret=0; | ||
276 | break; | ||
277 | } | ||
278 | return(ret); | ||
279 | } | ||
280 | |||
281 | static int rtcp_gets(BIO *bp, char *buf, int size) | ||
282 | { | ||
283 | return(0); | ||
284 | } | ||
285 | |||
286 | static int rtcp_puts(BIO *bp, const char *str) | ||
287 | { | ||
288 | int length; | ||
289 | if (str == NULL) return(0); | ||
290 | length = strlen ( str ); | ||
291 | if ( length == 0 ) return (0); | ||
292 | return rtcp_write ( bp,str, length ); | ||
293 | } | ||
294 | |||