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: #include <stdio.h>
61: #include <openssl/objects.h>
62: #include "ssl_locl.h"
63:
64: const char dtls1_version_str[]="DTLSv1" OPENSSL_VERSION_PTEXT;
65:
66: SSL3_ENC_METHOD DTLSv1_enc_data={
67: dtls1_enc,
68: tls1_mac,
69: tls1_setup_key_block,
70: tls1_generate_master_secret,
71: tls1_change_cipher_state,
72: tls1_final_finish_mac,
73: TLS1_FINISH_MAC_LENGTH,
74: tls1_cert_verify_mac,
75: TLS_MD_CLIENT_FINISH_CONST,TLS_MD_CLIENT_FINISH_CONST_SIZE,
76: TLS_MD_SERVER_FINISH_CONST,TLS_MD_SERVER_FINISH_CONST_SIZE,
77: tls1_alert_code,
78: };
79:
80: long dtls1_default_timeout(void)
81: {
82:
83:
84: return(60*60*2);
85: }
86:
87: IMPLEMENT_dtls1_meth_func(dtlsv1_base_method,
88: ssl_undefined_function,
89: ssl_undefined_function,
90: ssl_bad_method)
91:
92: int dtls1_new(SSL *s)
93: {
94: DTLS1_STATE *d1;
95:
96: if (!ssl3_new(s)) return(0);
97: if ((d1=OPENSSL_malloc(sizeof *d1)) == NULL) return (0);
98: memset(d1,0, sizeof *d1);
99:
100:
101: #if defined(OPENSSL_SYS_VMS) || defined(VMS_TEST)
102: d1->bitmap.length=64;
103: #else
104: d1->bitmap.length=sizeof(d1->bitmap.map) * 8;
105: #endif
106: pq_64bit_init(&(d1->bitmap.map));
107: pq_64bit_init(&(d1->bitmap.max_seq_num));
108:
109: pq_64bit_init(&(d1->next_bitmap.map));
110: pq_64bit_init(&(d1->next_bitmap.max_seq_num));
111:
112: d1->unprocessed_rcds.q=pqueue_new();
113: d1->processed_rcds.q=pqueue_new();
114: d1->buffered_messages = pqueue_new();
115: d1->sent_messages=pqueue_new();
116:
117: if ( s->server)
118: {
119: d1->cookie_len = sizeof(s->d1->cookie);
120: }
121:
122: if( ! d1->unprocessed_rcds.q || ! d1->processed_rcds.q
123: || ! d1->buffered_messages || ! d1->sent_messages)
124: {
125: if ( d1->unprocessed_rcds.q) pqueue_free(d1->unprocessed_rcds.q);
126: if ( d1->processed_rcds.q) pqueue_free(d1->processed_rcds.q);
127: if ( d1->buffered_messages) pqueue_free(d1->buffered_messages);
128: if ( d1->sent_messages) pqueue_free(d1->sent_messages);
129: OPENSSL_free(d1);
130: return (0);
131: }
132:
133: s->d1=d1;
134: s->method->ssl_clear(s);
135: return(1);
136: }
137:
138: void dtls1_free(SSL *s)
139: {
140: pitem *item = NULL;
141: hm_fragment *frag = NULL;
142:
143: ssl3_free(s);
144:
145: while( (item = pqueue_pop(s->d1->unprocessed_rcds.q)) != NULL)
146: {
147: OPENSSL_free(item->data);
148: pitem_free(item);
149: }
150: pqueue_free(s->d1->unprocessed_rcds.q);
151:
152: while( (item = pqueue_pop(s->d1->processed_rcds.q)) != NULL)
153: {
154: OPENSSL_free(item->data);
155: pitem_free(item);
156: }
157: pqueue_free(s->d1->processed_rcds.q);
158:
159: while( (item = pqueue_pop(s->d1->buffered_messages)) != NULL)
160: {
161: frag = (hm_fragment *)item->data;
162: OPENSSL_free(frag->fragment);
163: OPENSSL_free(frag);
164: pitem_free(item);
165: }
166: pqueue_free(s->d1->buffered_messages);
167:
168: while ( (item = pqueue_pop(s->d1->sent_messages)) != NULL)
169: {
170: frag = (hm_fragment *)item->data;
171: OPENSSL_free(frag->fragment);
172: OPENSSL_free(frag);
173: pitem_free(item);
174: }
175: pqueue_free(s->d1->sent_messages);
176:
177: pq_64bit_free(&(s->d1->bitmap.map));
178: pq_64bit_free(&(s->d1->bitmap.max_seq_num));
179:
180: pq_64bit_free(&(s->d1->next_bitmap.map));
181: pq_64bit_free(&(s->d1->next_bitmap.max_seq_num));
182:
183: OPENSSL_free(s->d1);
184: }
185:
186: void dtls1_clear(SSL *s)
187: {
188: ssl3_clear(s);
189: s->version=DTLS1_VERSION;
190: }
191:
192:
193:
194:
195:
196:
197:
198:
199: SSL_CIPHER *dtls1_get_cipher(unsigned int u)
200: {
201: SSL_CIPHER *ciph = ssl3_get_cipher(u);
202:
203: if (ciph != NULL)
204: {
205: if ((ciph->algorithms&SSL_ENC_MASK) == SSL_RC4)
206: return NULL;
207: }
208:
209: return ciph;
210: }