digest: add support for OpenSSL 1.1.0
[siplcs.git] / src / core / sip-sec-basic.c
blob76bd923eb637abbfc42ee98ad26ce1c214106ef7
1 /**
2 * @file sip-sec-basic.c
4 * pidgin-sipe
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).
27 #include <string.h>
29 #include <glib.h>
31 #include "sipe-common.h"
32 #include "sip-sec.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;
40 gchar *token;
41 guint length;
42 } *context_basic;
44 /* sip-sec-mech.h API implementation for Basic */
46 static gboolean
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)
56 return(FALSE);
58 /* calculate Basic token (RFC1945 section 11.1) */
59 ctx->token = g_strdup_printf("%s:%s", username, password);
60 ctx->length = strlen(ctx->token);
62 return(TRUE);
65 static gboolean
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);
76 return(TRUE);
79 static gboolean
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 */
85 return(FALSE);
88 static gboolean
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 */
94 return(FALSE);
97 static void
98 sip_sec_destroy_sec_context__basic(SipSecContext context)
100 context_basic ctx = (context_basic) context;
102 g_free(ctx->token);
103 g_free(ctx);
106 static const gchar *
107 sip_sec_context_name__basic(SIPE_UNUSED_PARAMETER SipSecContext context)
109 return("Basic");
112 SipSecContext
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);
129 Local Variables:
130 mode: c
131 c-file-style: "bsd"
132 indent-tabs-mode: t
133 tab-width: 8
134 End: