tls: internalize state handling
[siplcs.git] / src / core / sip-sec-tls-dsk.c
blobf9b6b3adc2989bf66d3cd8e245a82fa63c2dbef6
1 /**
2 * @file sip-sec-tls-dsk.c
4 * pidgin-sipe
6 * Copyright (C) 2011 SIPE Project <http://sipe.sourceforge.net/>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 * Specification references:
26 * - [MS-SIPAE]: http://msdn.microsoft.com/en-us/library/cc431510.aspx
27 * - [MS-OCAUTHWS]: http://msdn.microsoft.com/en-us/library/ff595592.aspx
28 * - MS Tech-Ed Europe 2010 "UNC310: Microsoft Lync 2010 Technology Explained"
29 * http://ecn.channel9.msdn.com/o9/te/Europe/2010/pptx/unc310.pptx
32 #include <glib.h>
34 #include "sipe-common.h"
35 #include "sip-sec.h"
36 #include "sip-sec-mech.h"
37 #include "sip-sec-tls-dsk.h"
38 #include "sipe-tls.h"
39 #include "sipe-utils.h"
41 /* Security context for TLS-DSK */
42 typedef struct _context_tls_dsk {
43 struct sip_sec_context common;
44 struct sipe_tls_state *state;
45 } *context_tls_dsk;
47 /* sip-sec-mech.h API implementation for TLS-DSK */
49 static sip_uint32
50 sip_sec_acquire_cred__tls_dsk(SipSecContext context,
51 SIPE_UNUSED_PARAMETER const char *domain,
52 SIPE_UNUSED_PARAMETER const char *username,
53 const char *password)
55 context_tls_dsk ctx = (context_tls_dsk)context;
57 ctx->state = sipe_tls_start((gpointer) password);
58 if (ctx->state) {
59 /* Authentication not yet completed */
60 ctx->common.is_ready = FALSE;
62 return SIP_SEC_E_OK;
63 } else {
64 return SIP_SEC_E_INTERNAL_ERROR;
68 static sip_uint32
69 sip_sec_init_sec_context__tls_dsk(SipSecContext context,
70 SipSecBuffer in_buff,
71 SipSecBuffer *out_buff,
72 SIPE_UNUSED_PARAMETER const char *service_name)
74 context_tls_dsk ctx = (context_tls_dsk) context;
75 struct sipe_tls_state *state = ctx->state;
77 state->in_buffer = in_buff.value;
78 state->in_length = in_buff.length;
80 if (sipe_tls_next(state)) {
81 if (state->session_key) {
82 /* Authentication is completed */
83 ctx->common.is_ready = TRUE;
85 /* TBD... copy session key */
87 sipe_tls_free(state);
88 ctx->state = NULL;
89 } else {
90 out_buff->value = state->out_buffer;
91 out_buff->length = state->out_length;
92 /* we take ownership of the buffer */
93 state->out_buffer = NULL;
95 } else {
96 sipe_tls_free(state);
97 ctx->state = NULL;
100 return((ctx->common.is_ready || ctx->state) ? SIP_SEC_E_OK : SIP_SEC_E_INTERNAL_ERROR);
103 static sip_uint32
104 sip_sec_make_signature__tls_dsk(SipSecContext context,
105 const char *message,
106 SipSecBuffer *signature)
108 context_tls_dsk ctx = (context_tls_dsk) context;
110 /* temporary */
111 (void)ctx;
112 (void)message;
113 (void)signature;
115 return SIP_SEC_E_INTERNAL_ERROR;
118 static sip_uint32
119 sip_sec_verify_signature__tls_dsk(SipSecContext context,
120 const char *message,
121 SipSecBuffer signature)
123 context_tls_dsk ctx = (context_tls_dsk) context;
125 /* temporary */
126 (void)ctx;
127 (void)message;
128 (void)signature;
130 return SIP_SEC_E_INTERNAL_ERROR;
133 static void
134 sip_sec_destroy_sec_context__tls_dsk(SipSecContext context)
136 context_tls_dsk ctx = (context_tls_dsk) context;
138 sipe_tls_free(ctx->state);
139 g_free(ctx);
142 SipSecContext
143 sip_sec_create_context__tls_dsk(SIPE_UNUSED_PARAMETER guint type)
145 context_tls_dsk context = g_malloc0(sizeof(struct _context_tls_dsk));
146 if (!context) return(NULL);
148 context->common.acquire_cred_func = sip_sec_acquire_cred__tls_dsk;
149 context->common.init_context_func = sip_sec_init_sec_context__tls_dsk;
150 context->common.destroy_context_func = sip_sec_destroy_sec_context__tls_dsk;
151 context->common.make_signature_func = sip_sec_make_signature__tls_dsk;
152 context->common.verify_signature_func = sip_sec_verify_signature__tls_dsk;
154 return((SipSecContext) context);
158 Local Variables:
159 mode: c
160 c-file-style: "bsd"
161 indent-tabs-mode: t
162 tab-width: 8
163 End: