2 * @file sip-sec-basic.c
6 * Copyright (C) 2013-2015 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 * Implementation for HTTP "WWW-Authenticate: Basic" scheme (RFC1945).
31 #include "sipe-common.h"
33 #include "sip-sec-mech.h"
34 #include "sip-sec-basic.h"
35 #include "sipe-backend.h"
37 /* Security context for Basic */
38 typedef struct _context_basic
{
39 struct sip_sec_context common
;
44 /* sip-sec-mech.h API implementation for Basic */
47 sip_sec_acquire_cred__basic(SipSecContext context
,
48 const gchar
*username
,
49 const gchar
*password
)
51 context_basic ctx
= (context_basic
) context
;
53 SIPE_DEBUG_INFO_NOFORMAT("sip_sec_acquire_cred__basic: entering");
55 if (!username
|| !password
)
58 /* calculate Basic token (RFC1945 section 11.1) */
59 ctx
->token
= g_strdup_printf("%s:%s", username
, password
);
60 ctx
->length
= strlen(ctx
->token
);
66 sip_sec_init_sec_context__basic(SipSecContext context
,
67 SIPE_UNUSED_PARAMETER SipSecBuffer in_buff
,
68 SipSecBuffer
*out_buff
,
69 SIPE_UNUSED_PARAMETER
const gchar
*service_name
)
71 context_basic ctx
= (context_basic
) context
;
73 out_buff
->length
= ctx
->length
;
74 out_buff
->value
= (guint8
*) g_strdup(ctx
->token
);
80 sip_sec_make_signature__basic(SIPE_UNUSED_PARAMETER SipSecContext context
,
81 SIPE_UNUSED_PARAMETER
const gchar
*message
,
82 SIPE_UNUSED_PARAMETER SipSecBuffer
*signature
)
84 /* No implementation needed, as Basic is not used for SIP */
89 sip_sec_verify_signature__basic(SIPE_UNUSED_PARAMETER SipSecContext context
,
90 SIPE_UNUSED_PARAMETER
const gchar
*message
,
91 SIPE_UNUSED_PARAMETER SipSecBuffer signature
)
93 /* No implementation needed, as Basic is not used for SIP */
98 sip_sec_destroy_sec_context__basic(SipSecContext context
)
100 context_basic ctx
= (context_basic
) context
;
107 sip_sec_context_name__basic(SIPE_UNUSED_PARAMETER SipSecContext context
)
113 sip_sec_create_context__basic(SIPE_UNUSED_PARAMETER guint type
)
115 context_basic context
= g_malloc0(sizeof(struct _context_basic
));
116 if (!context
) return(NULL
);
118 context
->common
.acquire_cred_func
= sip_sec_acquire_cred__basic
;
119 context
->common
.init_context_func
= sip_sec_init_sec_context__basic
;
120 context
->common
.destroy_context_func
= sip_sec_destroy_sec_context__basic
;
121 context
->common
.make_signature_func
= sip_sec_make_signature__basic
;
122 context
->common
.verify_signature_func
= sip_sec_verify_signature__basic
;
123 context
->common
.context_name_func
= sip_sec_context_name__basic
;
125 return((SipSecContext
) context
);