/src/openssl/ssl/d1_msg.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright 2005-2016 The OpenSSL Project Authors. All Rights Reserved. |
3 | | * |
4 | | * Licensed under the OpenSSL license (the "License"). You may not use |
5 | | * this file except in compliance with the License. You can obtain a copy |
6 | | * in the file LICENSE in the source distribution or at |
7 | | * https://www.openssl.org/source/license.html |
8 | | */ |
9 | | |
10 | | #include "ssl_locl.h" |
11 | | |
12 | | int dtls1_write_app_data_bytes(SSL *s, int type, const void *buf_, size_t len, |
13 | | size_t *written) |
14 | 0 | { |
15 | 0 | int i; |
16 | 0 |
|
17 | 0 | if (SSL_in_init(s) && !ossl_statem_get_in_handshake(s)) { |
18 | 0 | i = s->handshake_func(s); |
19 | 0 | if (i < 0) |
20 | 0 | return i; |
21 | 0 | if (i == 0) { |
22 | 0 | SSLerr(SSL_F_DTLS1_WRITE_APP_DATA_BYTES, |
23 | 0 | SSL_R_SSL_HANDSHAKE_FAILURE); |
24 | 0 | return -1; |
25 | 0 | } |
26 | 0 | } |
27 | 0 |
|
28 | 0 | if (len > SSL3_RT_MAX_PLAIN_LENGTH) { |
29 | 0 | SSLerr(SSL_F_DTLS1_WRITE_APP_DATA_BYTES, SSL_R_DTLS_MESSAGE_TOO_BIG); |
30 | 0 | return -1; |
31 | 0 | } |
32 | 0 |
|
33 | 0 | return dtls1_write_bytes(s, type, buf_, len, written); |
34 | 0 | } |
35 | | |
36 | | int dtls1_dispatch_alert(SSL *s) |
37 | 0 | { |
38 | 0 | int i, j; |
39 | 0 | void (*cb) (const SSL *ssl, int type, int val) = NULL; |
40 | 0 | unsigned char buf[DTLS1_AL_HEADER_LENGTH]; |
41 | 0 | unsigned char *ptr = &buf[0]; |
42 | 0 | size_t written; |
43 | 0 |
|
44 | 0 | s->s3->alert_dispatch = 0; |
45 | 0 |
|
46 | 0 | memset(buf, 0, sizeof(buf)); |
47 | 0 | *ptr++ = s->s3->send_alert[0]; |
48 | 0 | *ptr++ = s->s3->send_alert[1]; |
49 | 0 |
|
50 | 0 | i = do_dtls1_write(s, SSL3_RT_ALERT, &buf[0], sizeof(buf), 0, &written); |
51 | 0 | if (i <= 0) { |
52 | 0 | s->s3->alert_dispatch = 1; |
53 | 0 | /* fprintf( stderr, "not done with alert\n" ); */ |
54 | 0 | } else { |
55 | 0 | if (s->s3->send_alert[0] == SSL3_AL_FATAL) |
56 | 0 | (void)BIO_flush(s->wbio); |
57 | 0 |
|
58 | 0 | if (s->msg_callback) |
59 | 0 | s->msg_callback(1, s->version, SSL3_RT_ALERT, s->s3->send_alert, |
60 | 0 | 2, s, s->msg_callback_arg); |
61 | 0 |
|
62 | 0 | if (s->info_callback != NULL) |
63 | 0 | cb = s->info_callback; |
64 | 0 | else if (s->ctx->info_callback != NULL) |
65 | 0 | cb = s->ctx->info_callback; |
66 | 0 |
|
67 | 0 | if (cb != NULL) { |
68 | 0 | j = (s->s3->send_alert[0] << 8) | s->s3->send_alert[1]; |
69 | 0 | cb(s, SSL_CB_WRITE_ALERT, j); |
70 | 0 | } |
71 | 0 | } |
72 | 0 | return i; |
73 | 0 | } |