2 * @file sip-sec-tls-dsk.c
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
34 #include "sipe-common.h"
36 #include "sip-sec-mech.h"
37 #include "sip-sec-tls-dsk.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
;
47 /* sip-sec-mech.h API implementation for TLS-DSK */
50 sip_sec_acquire_cred__tls_dsk(SipSecContext context
,
51 SIPE_UNUSED_PARAMETER
const char *domain
,
52 SIPE_UNUSED_PARAMETER
const char *username
,
55 context_tls_dsk ctx
= (context_tls_dsk
)context
;
57 ctx
->state
= sipe_tls_start((gpointer
) password
);
59 /* Authentication not yet completed */
60 ctx
->common
.is_ready
= FALSE
;
64 return SIP_SEC_E_INTERNAL_ERROR
;
69 sip_sec_init_sec_context__tls_dsk(SipSecContext context
,
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 */
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
;
100 return((ctx
->common
.is_ready
|| ctx
->state
) ? SIP_SEC_E_OK
: SIP_SEC_E_INTERNAL_ERROR
);
104 sip_sec_make_signature__tls_dsk(SipSecContext context
,
106 SipSecBuffer
*signature
)
108 context_tls_dsk ctx
= (context_tls_dsk
) context
;
115 return SIP_SEC_E_INTERNAL_ERROR
;
119 sip_sec_verify_signature__tls_dsk(SipSecContext context
,
121 SipSecBuffer signature
)
123 context_tls_dsk ctx
= (context_tls_dsk
) context
;
130 return SIP_SEC_E_INTERNAL_ERROR
;
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
);
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
);