summaryrefslogtreecommitdiffstats
path: root/gatchat/ppp_auth.c
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2010-04-13 14:16:29 -0500
committerDenis Kenzior <denkenz@gmail.com>2010-04-13 14:21:16 -0500
commit18e5e26acb7f9e9f8bd90f755fc432bd5a9667ca (patch)
treebdc8a449510e9674fba149b2e6f9399ab8b62f14 /gatchat/ppp_auth.c
parent42f6e8ec6ecbf3c4ff74aa52f77cf5e39c4682eb (diff)
downloadofono-18e5e26acb7f9e9f8bd90f755fc432bd5a9667ca.tar.bz2
ppp: Remove auth_ functions from ppp_auth.c
These really serve no purpose right now as we use only CHAP. So they only take up space and make the code harder to read. If we implement 1-3 auth protocols, then they're easier handled inside gatppp.c. If we have more, then a proper auth driver framework is required.
Diffstat (limited to 'gatchat/ppp_auth.c')
-rw-r--r--gatchat/ppp_auth.c120
1 files changed, 25 insertions, 95 deletions
diff --git a/gatchat/ppp_auth.c b/gatchat/ppp_auth.c
index 3f69fa37..e794ad67 100644
--- a/gatchat/ppp_auth.c
+++ b/gatchat/ppp_auth.c
@@ -44,9 +44,9 @@ struct chap_header {
guint8 data[0];
} __attribute__((packed));
-struct chap_data {
+struct ppp_chap {
guint8 method;
- struct auth_data *auth;
+ GAtPPP *ppp;
};
enum chap_code {
@@ -56,37 +56,26 @@ enum chap_code {
FAILURE
};
-void auth_set_credentials(struct auth_data *data, const char *username,
- const char *password)
-{
- if (data == NULL)
- return;
-
- g_free(data->username);
- data->username = g_strdup(username);
-
- g_free(data->password);
- data->password = g_strdup(password);
-}
-
-static void chap_process_challenge(struct auth_data *auth, guint8 *packet)
+static void chap_process_challenge(struct ppp_chap *chap, guint8 *packet)
{
struct chap_header *header = (struct chap_header *) packet;
struct chap_header *response;
- struct chap_data *data = auth->proto_data;
GChecksum *checksum;
- gchar *secret = data->auth->password;
+ const char *secret = g_at_ppp_get_password(chap->ppp);
guint16 response_length;
struct ppp_header *ppp_packet;
gsize digest_len;
/* create a checksum over id, secret, and challenge */
- checksum = g_checksum_new(data->method);
+ checksum = g_checksum_new(chap->method);
if (!checksum)
return;
+
g_checksum_update(checksum, &header->identifier, 1);
+
if (secret)
g_checksum_update(checksum, (guchar *) secret, strlen(secret));
+
g_checksum_update(checksum, &header->data[1], header->data[0]);
/* transmit a response packet */
@@ -94,7 +83,7 @@ static void chap_process_challenge(struct auth_data *auth, guint8 *packet)
* allocate space for the header, the checksum, and the ppp header,
* and the value size byte
*/
- digest_len = g_checksum_type_get_length(data->method);
+ digest_len = g_checksum_type_get_length(chap->method);
response_length = digest_len + sizeof(*header) + 1;
ppp_packet = g_try_malloc0(response_length + 2);
if (!ppp_packet)
@@ -114,115 +103,56 @@ static void chap_process_challenge(struct auth_data *auth, guint8 *packet)
}
/* transmit the packet */
- ppp_transmit(auth->ppp, (guint8 *) ppp_packet, response_length);
+ ppp_transmit(chap->ppp, (guint8 *) ppp_packet, response_length);
g_free(ppp_packet);
challenge_out:
g_checksum_free(checksum);
}
-static void chap_process_success(struct auth_data *data, guint8 *packet)
-{
- ppp_generate_event(data->ppp, PPP_SUCCESS);
-}
-
-static void chap_process_failure(struct auth_data *data, guint8 *packet)
-{
- struct chap_header *header = (struct chap_header *) packet;
-
- ppp_generate_event(data->ppp, PPP_FAIL);
- g_printerr("Failed to authenticate, message %s\n", header->data);
-}
-
/*
* parse the packet
*/
-static void chap_process_packet(struct auth_data *data, guint8 *new_packet)
+void ppp_chap_process_packet(struct ppp_chap *chap, guint8 *new_packet)
{
guint8 code = new_packet[0];
switch (code) {
case CHALLENGE:
- g_print("chap: challenge\n");
- chap_process_challenge(data, new_packet);
+ chap_process_challenge(chap, new_packet);
break;
case RESPONSE:
g_print("chap: response (not implemented)\n");
break;
case SUCCESS:
- g_print("chap: success\n");
- chap_process_success(data, new_packet);
+ ppp_auth_notify(chap->ppp, TRUE);
break;
case FAILURE:
- g_print("chap: failure\n");
- chap_process_failure(data, new_packet);
+ ppp_auth_notify(chap->ppp, FALSE);
break;
default:
- g_print("chap: unknown auth code\n");
break;
}
}
-static void chap_free(struct auth_data *auth)
+void ppp_chap_free(struct ppp_chap *chap)
{
- g_free(auth->proto_data);
+ g_free(chap);
}
-static struct chap_data *chap_new(struct auth_data *auth, guint8 method)
+struct ppp_chap *ppp_chap_new(GAtPPP *ppp, guint8 method)
{
- struct chap_data *data;
+ struct ppp_chap *chap;
- data = g_try_malloc0(sizeof(*data));
- if (!data)
+ if (method != MD5)
return NULL;
- data->auth = auth;
- switch (method) {
- case MD5:
- data->method = G_CHECKSUM_MD5;
- break;
- default:
- g_print("Unknown method\n");
- break;
- }
-
- return data;
-}
-
-void auth_set_proto(struct auth_data *data, guint16 proto, guint8 method)
-{
- if (data == NULL)
- return;
-
- switch (proto) {
- case CHAP_PROTOCOL:
- data->proto = proto;
- data->proto_data = chap_new(data, method);
- data->process_packet = chap_process_packet;
- break;
- default:
- g_print("Unknown auth protocol 0x%x\n", proto);
- break;
- }
-}
-
-void auth_free(struct auth_data *data)
-{
- if (data == NULL)
- return;
-
- chap_free(data);
- g_free(data);
-}
-
-struct auth_data *auth_new(GAtPPP *ppp)
-{
- struct auth_data *data;
-
- data = g_try_malloc0(sizeof(*data));
- if (!data)
+ chap = g_try_new0(struct ppp_chap, 1);
+ if (!chap)
return NULL;
- data->ppp = ppp;
- return data;
+ chap->ppp = ppp;
+ chap->method = G_CHECKSUM_MD5;
+
+ return chap;
}