change some parameters in the library to meet the needs of the website httpbin.org

Fork of MiniTLS-GPL by Donatien Garnier

Committer:
MiniTLS
Date:
Mon Jun 09 14:57:54 2014 +0000
Revision:
2:527a66d0a1a9
Change name to MiniTLS and added doc

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MiniTLS 2:527a66d0a1a9 1 /*
MiniTLS 2:527a66d0a1a9 2 MiniTLS - A super trimmed down TLS/SSL Library for embedded devices
MiniTLS 2:527a66d0a1a9 3 Author: Donatien Garnier
MiniTLS 2:527a66d0a1a9 4 Copyright (C) 2013-2014 AppNearMe Ltd
MiniTLS 2:527a66d0a1a9 5
MiniTLS 2:527a66d0a1a9 6 This program is free software; you can redistribute it and/or
MiniTLS 2:527a66d0a1a9 7 modify it under the terms of the GNU General Public License
MiniTLS 2:527a66d0a1a9 8 as published by the Free Software Foundation; either version 2
MiniTLS 2:527a66d0a1a9 9 of the License, or (at your option) any later version.
MiniTLS 2:527a66d0a1a9 10
MiniTLS 2:527a66d0a1a9 11 This program is distributed in the hope that it will be useful,
MiniTLS 2:527a66d0a1a9 12 but WITHOUT ANY WARRANTY; without even the implied warranty of
MiniTLS 2:527a66d0a1a9 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
MiniTLS 2:527a66d0a1a9 14 GNU General Public License for more details.
MiniTLS 2:527a66d0a1a9 15
MiniTLS 2:527a66d0a1a9 16 You should have received a copy of the GNU General Public License
MiniTLS 2:527a66d0a1a9 17 along with this program; if not, write to the Free Software
MiniTLS 2:527a66d0a1a9 18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
MiniTLS 2:527a66d0a1a9 19 *//**
MiniTLS 2:527a66d0a1a9 20 * \file tls_alert.c
MiniTLS 2:527a66d0a1a9 21 * \copyright Copyright (c) AppNearMe Ltd 2013
MiniTLS 2:527a66d0a1a9 22 * \author Donatien Garnier
MiniTLS 2:527a66d0a1a9 23 */
MiniTLS 2:527a66d0a1a9 24
MiniTLS 2:527a66d0a1a9 25 #define __DEBUG__ 4
MiniTLS 2:527a66d0a1a9 26 #ifndef __MODULE__
MiniTLS 2:527a66d0a1a9 27 #define __MODULE__ "tls_alert.c"
MiniTLS 2:527a66d0a1a9 28 #endif
MiniTLS 2:527a66d0a1a9 29
MiniTLS 2:527a66d0a1a9 30 #include "core/fwk.h"
MiniTLS 2:527a66d0a1a9 31 #include "inc/minitls_errors.h"
MiniTLS 2:527a66d0a1a9 32 #include "tls_alert.h"
MiniTLS 2:527a66d0a1a9 33
MiniTLS 2:527a66d0a1a9 34 minitls_err_t tls_alert_send( tls_record_t* record, tls_message_alert_level_t level, tls_message_alert_description_t description, buffer_t* buffer_tx )
MiniTLS 2:527a66d0a1a9 35 {
MiniTLS 2:527a66d0a1a9 36 if( buffer_size(buffer_tx) < 2 )
MiniTLS 2:527a66d0a1a9 37 {
MiniTLS 2:527a66d0a1a9 38 return MINITLS_ERR_BUFFER_TOO_SMALL;
MiniTLS 2:527a66d0a1a9 39 }
MiniTLS 2:527a66d0a1a9 40
MiniTLS 2:527a66d0a1a9 41 buffer_reset(buffer_tx);
MiniTLS 2:527a66d0a1a9 42
MiniTLS 2:527a66d0a1a9 43 buffer_nu8_write(buffer_tx, level);
MiniTLS 2:527a66d0a1a9 44 buffer_nu8_write(buffer_tx, description);
MiniTLS 2:527a66d0a1a9 45
MiniTLS 2:527a66d0a1a9 46 minitls_err_t ret = tls_record_send(record, TLS_ALERT, buffer_tx);
MiniTLS 2:527a66d0a1a9 47 if(ret)
MiniTLS 2:527a66d0a1a9 48 {
MiniTLS 2:527a66d0a1a9 49 return ret;
MiniTLS 2:527a66d0a1a9 50 }
MiniTLS 2:527a66d0a1a9 51
MiniTLS 2:527a66d0a1a9 52 return MINITLS_OK;
MiniTLS 2:527a66d0a1a9 53 }
MiniTLS 2:527a66d0a1a9 54
MiniTLS 2:527a66d0a1a9 55 minitls_err_t tls_alert_process( tls_record_t* record, buffer_t* buffer_rx )
MiniTLS 2:527a66d0a1a9 56 {
MiniTLS 2:527a66d0a1a9 57 if( buffer_length(buffer_rx) < 2 )
MiniTLS 2:527a66d0a1a9 58 {
MiniTLS 2:527a66d0a1a9 59 return MINITLS_ERR_BUFFER_TOO_SMALL;
MiniTLS 2:527a66d0a1a9 60 }
MiniTLS 2:527a66d0a1a9 61
MiniTLS 2:527a66d0a1a9 62 tls_message_alert_level_t level = buffer_nu8_read(buffer_rx);
MiniTLS 2:527a66d0a1a9 63 tls_message_alert_description_t description = buffer_nu8_read(buffer_rx);
MiniTLS 2:527a66d0a1a9 64
MiniTLS 2:527a66d0a1a9 65 WARN("Alert: type: %d, description: %d", level, description);
MiniTLS 2:527a66d0a1a9 66 if(description == CLOSE_NOTIFY)
MiniTLS 2:527a66d0a1a9 67 {
MiniTLS 2:527a66d0a1a9 68 return MINITLS_ERR_CONNECTION_CLOSED;
MiniTLS 2:527a66d0a1a9 69 }
MiniTLS 2:527a66d0a1a9 70
MiniTLS 2:527a66d0a1a9 71 //Always return error
MiniTLS 2:527a66d0a1a9 72 return MINITLS_ERR_PEER;
MiniTLS 2:527a66d0a1a9 73 }