2 * @file sip-sec-basic.c
6 * Copyright (C) 2013 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 SIPE_UNUSED_PARAMETER
const gchar
*domain
,
49 const gchar
*username
,
50 const gchar
*password
)
52 context_basic ctx
= (context_basic
) context
;
54 SIPE_DEBUG_INFO_NOFORMAT("sip_sec_acquire_cred__basic: entering");
56 if (!username
|| !password
)
59 /* calculate Basic token (RFC1945 section 11.1) */
60 ctx
->token
= g_strdup_printf("%s:%s", username
, password
);
61 ctx
->length
= strlen(ctx
->token
);
67 sip_sec_init_sec_context__basic(SipSecContext context
,
68 SIPE_UNUSED_PARAMETER SipSecBuffer in_buff
,
69 SipSecBuffer
*out_buff
,
70 SIPE_UNUSED_PARAMETER
const gchar
*service_name
)
72 context_basic ctx
= (context_basic
) context
;
74 out_buff
->length
= ctx
->length
;
75 out_buff
->value
= (guint8
*) g_strdup(ctx
->token
);
81 sip_sec_make_signature__basic(SIPE_UNUSED_PARAMETER SipSecContext context
,
82 SIPE_UNUSED_PARAMETER
const gchar
*message
,
83 SIPE_UNUSED_PARAMETER SipSecBuffer
*signature
)
85 /* No implementation needed, as Basic is not used for SIP */
90 sip_sec_verify_signature__basic(SIPE_UNUSED_PARAMETER SipSecContext context
,
91 SIPE_UNUSED_PARAMETER
const gchar
*message
,
92 SIPE_UNUSED_PARAMETER SipSecBuffer signature
)
94 /* No implementation needed, as Basic is not used for SIP */
99 sip_sec_destroy_sec_context__basic(SipSecContext context
)
101 context_basic ctx
= (context_basic
) context
;
108 sip_sec_context_name__basic(SIPE_UNUSED_PARAMETER SipSecContext context
)
114 sip_sec_create_context__basic(SIPE_UNUSED_PARAMETER guint type
)
116 context_basic context
= g_malloc0(sizeof(struct _context_basic
));
117 if (!context
) return(NULL
);
119 context
->common
.acquire_cred_func
= sip_sec_acquire_cred__basic
;
120 context
->common
.init_context_func
= sip_sec_init_sec_context__basic
;
121 context
->common
.destroy_context_func
= sip_sec_destroy_sec_context__basic
;
122 context
->common
.make_signature_func
= sip_sec_make_signature__basic
;
123 context
->common
.verify_signature_func
= sip_sec_verify_signature__basic
;
124 context
->common
.context_name_func
= sip_sec_context_name__basic
;
126 return((SipSecContext
) context
);