Kannel: Open Source WAP and SMS gateway  svn-r5335
wtls-secmgr.c
Go to the documentation of this file.
1 /* ====================================================================
2  * The Kannel Software License, Version 1.0
3  *
4  * Copyright (c) 2001-2018 Kannel Group
5  * Copyright (c) 1998-2001 WapIT Ltd.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Kannel Group (http://www.kannel.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Kannel" and "Kannel Group" must not be used to
28  * endorse or promote products derived from this software without
29  * prior written permission. For written permission, please
30  * contact org@kannel.org.
31  *
32  * 5. Products derived from this software may not be called "Kannel",
33  * nor may "Kannel" appear in their name, without prior written
34  * permission of the Kannel Group.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE KANNEL GROUP OR ITS CONTRIBUTORS
40  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
41  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
42  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
43  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
44  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
45  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
46  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47  * ====================================================================
48  *
49  * This software consists of voluntary contributions made by many
50  * individuals on behalf of the Kannel Group. For more information on
51  * the Kannel Group, please see <http://www.kannel.org/>.
52  *
53  * Portions of this software are based upon software originally written at
54  * WapIT Ltd., Helsinki, Finland for the Kannel project.
55  */
56 
57 /*
58  * gw/wtls-secmgr.c - wapbox wtls security manager
59  *
60  * The security manager's interface consists of two functions:
61  *
62  * wtls_secmgr_start()
63  * This starts the security manager thread.
64  *
65  * wtls_secmgr_dispatch(event)
66  * This adds a new event to the security manager's event
67  * queue.
68  *
69  * The wtls security manager is a thread that reads events from its event
70  * queue, and feeds back events to the WTLS layer. Here is where various
71  * approvals or rejections are made to requested security settings.
72  *
73  */
74 
75 #include <string.h>
76 
77 #include "gwlib/gwlib.h"
78 
79 #if (HAVE_WTLS_OPENSSL)
80 
81 #include "wtls.h"
82 
83 /*
84  * Give the status the module:
85  *
86  * limbo
87  * not running at all
88  * running
89  * operating normally
90  * terminating
91  * waiting for operations to terminate, returning to limbo
92  */
93 static enum { limbo, running, terminating } run_status = limbo;
94 
95 
96 /*
97  * The queue of incoming events.
98  */
99 static List *secmgr_queue = NULL;
100 
101 /*
102  * Private functions.
103  */
104 
105 static void main_thread(void *);
106 
107 /*
108  * Public functions.
109  */
110 
111 void wtls_secmgr_init(void);
112 void wtls_secmgr_shutdown(void);
113 void wtls_secmgr_dispatch(WAPEvent *event);
114 long wtls_secmgr_get_load(void);
115 
116 /***********************************************************************
117  * The public interface to the application layer.
118  */
119 
120 void wtls_secmgr_init(void) {
122  secmgr_queue = gwlist_create();
123  gwlist_add_producer(secmgr_queue);
126 }
127 
128 
129 void wtls_secmgr_shutdown(void) {
131  gwlist_remove_producer(secmgr_queue);
133 
135 
136  gwlist_destroy(secmgr_queue, wap_event_destroy_item);
137 }
138 
139 
140 void wtls_secmgr_dispatch(WAPEvent *event) {
142  gwlist_produce(secmgr_queue, event);
143 }
144 
145 
146 long wtls_secmgr_get_load(void) {
148  return gwlist_len(secmgr_queue);
149 }
150 
151 
152 /***********************************************************************
153  * Private functions.
154  */
155 
156 
157 static void main_thread(void *arg) {
158  WAPEvent *ind, *res, *req, *term;
159 
160  while (run_status == running && (ind = gwlist_consume(secmgr_queue)) != NULL) {
161  switch (ind->type) {
162  case SEC_Create_Ind:
163  /* Process the cipherlist */
164  /* Process the MAClist */
165  /* Process the PKIlist */
166  /* Dispatch a SEC_Create_Res */
167  res = wap_event_create(SEC_Create_Res);
168  res->u.SEC_Create_Res.addr_tuple =
169  wap_addr_tuple_duplicate(ind->u.SEC_Create_Ind.addr_tuple);
170  wtls_dispatch_event(res);
171  debug("wtls_secmgr : main_thread", 0,"Dispatching SEC_Create_Res event");
172  /* Dispatch a SEC_Exchange_Req or maybe a SEC_Commit_Req */
174  req->u.SEC_Exchange_Req.addr_tuple =
175  wap_addr_tuple_duplicate(ind->u.SEC_Create_Ind.addr_tuple);
176  wtls_dispatch_event(req);
177  debug("wtls_secmgr : main_thread", 0,"Dispatching SEC_Exchange_Req event");
178  wap_event_destroy(ind);
179  break;
180  case SEC_Terminate_Req:
181  /* Dispatch a SEC_Terminate_Req */
183  term->u.SEC_Terminate_Req.addr_tuple =
184  wap_addr_tuple_duplicate(ind->u.SEC_Create_Ind.addr_tuple);
185  term->u.SEC_Terminate_Req.alert_desc = 0;
186  term->u.SEC_Terminate_Req.alert_level = 3;
187  wtls_dispatch_event(term);
188  default:
189  panic(0, "WTLS-secmgr: Can't handle %s event",
190  wap_event_name(ind->type));
191  break;
192  }
193  }
194 }
195 
196 #endif
EXCHANGE SEC_Terminate_Req
gw_assert(wtls_machine->packet_to_send !=NULL)
static void main_thread(void *)
Definition: wap-appl.c:314
Definition: shared.h:81
void gwlist_produce(List *list, void *item)
Definition: list.c:411
long gwlist_len(List *list)
Definition: list.c:166
void wtls_dispatch_event(WAPEvent *event)
void gwthread_join_every(gwthread_func_t *func)
WAPAddrTuple * wap_addr_tuple_duplicate(WAPAddrTuple *tuple)
Definition: wap_addr.c:125
void gwlist_remove_producer(List *list)
Definition: list.c:401
void wap_event_destroy_item(void *event)
Definition: wap_events.c:130
static enum @29 run_status
const char * wap_event_name(WAPEventName type)
Definition: wap_events.c:169
#define wap_event_create(type)
Definition: wap_events.h:107
#define gwthread_create(func, arg)
Definition: gwthread.h:90
void * gwlist_consume(List *list)
Definition: list.c:427
CREATING CREATING SEC_Exchange_Req
void debug(const char *place, int err, const char *fmt,...)
Definition: log.c:726
#define panic
Definition: log.h:87
WAPEventName type
Definition: wap_events.h:88
#define gwlist_create()
Definition: list.h:136
void gwlist_add_producer(List *list)
Definition: list.c:383
union WAPEvent::@87 u
Definition: list.c:102
void wap_event_destroy(WAPEvent *event)
Definition: wap_events.c:102
void gwlist_destroy(List *list, gwlist_item_destructor_t *destructor)
Definition: list.c:145
See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.