aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/restricted/aws/s2n/tls/s2n_shutdown.c
blob: 4963e0e25d02879ed5f6bc1f0bec5e68ee5b3fa6 (plain) (blame)
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
/* 
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"). 
 * You may not use this file except in compliance with the License. 
 * A copy of the License is located at 
 * 
 *  http://aws.amazon.com/apache2.0 
 * 
 * or in the "license" file accompanying this file. This file is distributed 
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 
 * express or implied. See the License for the specific language governing 
 * permissions and limitations under the License. 
 */ 
 
#include <s2n.h> 
 
#include "tls/s2n_alerts.h" 
#include "tls/s2n_connection.h" 
#include "tls/s2n_tls.h" 
 
#include "utils/s2n_safety.h" 
 
int s2n_shutdown(struct s2n_connection *conn, s2n_blocked_status * more) 
{ 
    notnull_check(conn); 
    notnull_check(more); 
 
    /* Treat this call as a no-op if already wiped */ 
    if (conn->send == NULL && conn->recv == NULL) { 
        return 0; 
    } 
 
    uint64_t elapsed; 
    GUARD_AS_POSIX(s2n_timer_elapsed(conn->config, &conn->write_timer, &elapsed)); 
    S2N_ERROR_IF(elapsed < conn->delay, S2N_ERR_SHUTDOWN_PAUSED); 
 
    /* Queue our close notify, once. Use warning level so clients don't give up */ 
    GUARD(s2n_queue_writer_close_alert_warning(conn)); 
 
    /* Write it */ 
    GUARD(s2n_flush(conn, more)); 
 
    /* Assume caller isn't interested in pending incoming data */ 
    if (conn->in_status == PLAINTEXT) { 
        GUARD(s2n_stuffer_wipe(&conn->header_in)); 
        GUARD(s2n_stuffer_wipe(&conn->in)); 
        conn->in_status = ENCRYPTED; 
    } 
 
    /* Fails with S2N_ERR_SHUTDOWN_RECORD_TYPE or S2N_ERR_ALERT on receipt of anything but a close_notify */ 
    GUARD(s2n_recv_close_notify(conn, more)); 
 
    return 0; 
}