Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:benoit_monin
simple-obfs
simple-obfs-add-xmpp-obfsucation.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File simple-obfs-add-xmpp-obfsucation.patch of Package simple-obfs
From 51b4c75665008be31939f33e46b7b21290890da9 Mon Sep 17 00:00:00 2001 Message-Id: <51b4c75665008be31939f33e46b7b21290890da9.1641318521.git.benoit.monin@gmx.fr> From: =?UTF-8?q?Beno=C3=AEt=20Monin?= <benoit.monin@gmx.fr> Date: Sun, 10 Jan 2021 18:16:23 +0100 Subject: [PATCH] add xmpp obfsucation --- src/Makefile.am | 1 + src/local.c | 7 ++ src/obfs_xmpp.c | 195 ++++++++++++++++++++++++++++++++++++++++++++++++ src/obfs_xmpp.h | 30 ++++++++ src/server.c | 7 ++ src/utils.c | 2 +- 6 files changed, 241 insertions(+), 1 deletion(-) create mode 100644 src/obfs_xmpp.c create mode 100644 src/obfs_xmpp.h diff --git a/src/Makefile.am b/src/Makefile.am index fb1b7cd..3ef0fcd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -16,6 +16,7 @@ endif obfs_src = obfs_http.c \ obfs_tls.c \ + obfs_xmpp.c \ options.c \ base64.c diff --git a/src/local.c b/src/local.c index 2591fcd..e706ebb 100644 --- a/src/local.c +++ b/src/local.c @@ -60,6 +60,7 @@ #include "utils.h" #include "obfs_http.h" #include "obfs_tls.h" +#include "obfs_xmpp.h" #include "options.h" #include "local.h" @@ -960,6 +961,8 @@ main(int argc, char **argv) obfs_para = obfs_http; else if (strcmp(value, obfs_tls->name) == 0) obfs_para = obfs_tls; + else if (strcmp(value, obfs_xmpp->name) == 0) + obfs_para = obfs_xmpp; } else if (strcmp(key, "obfs-host") == 0) { obfs_host = value; #ifdef __linux__ @@ -1006,6 +1009,8 @@ main(int argc, char **argv) obfs_para = obfs_http; else if (strcmp(optarg, obfs_tls->name) == 0) obfs_para = obfs_tls; + else if (strcmp(optarg, obfs_xmpp->name) == 0) + obfs_para = obfs_xmpp; } else if (option_index == 3) { obfs_host = optarg; } else if (option_index == 4) { @@ -1103,6 +1108,8 @@ main(int argc, char **argv) obfs_para = obfs_http; else if (strcmp(conf->obfs, obfs_tls->name) == 0) obfs_para = obfs_tls; + else if (strcmp(conf->obfs, obfs_xmpp->name) == 0) + obfs_para = obfs_xmpp; } if (obfs_host == NULL) { obfs_host = conf->obfs_host; diff --git a/src/obfs_xmpp.c b/src/obfs_xmpp.c new file mode 100644 index 0000000..447bd8b --- /dev/null +++ b/src/obfs_xmpp.c @@ -0,0 +1,195 @@ +/* + * obfs_xmpp.c - Implementation of xmpp obfuscating + * + * Copyright (C) 2021, Benoît Monin <benoit.monin@gmx.fr> + * + * This file is part of the simple-obfs. + * + * simple-obfs is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * simple-obfs is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with simple-obfs; see the file COPYING. If not, see + * <xmpp://www.gnu.org/licenses/>. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <strings.h> +#include <ctype.h> /* isblank() */ + +#include "base64.h" +#include "utils.h" +#include "obfs_xmpp.h" + +static const char *xml_header = "<?xml version='1.0'?>"; + +static const char *xmpp_request_template = + "<?xml version='1.0'?><stream:stream xmlns=\"jabber:client\" " + "version=\"1.0\" xmlns:stream=\"http://etherx.jabber.org/streams\" " + "to=\"%s\" xml:lang=\"en\">"; + +static const char *xmpp_response_template = + "<?xml version='1.0'?><stream:stream xmlns:stream='http://etherx.jabber.org/streams' " + "xml:lang='en' from='%s' id='b4e5bc1b-87a0-4219-82a6-ad96616f7dd4' " + "version='1.0' xmlns='jabber:client'><stream:features>" + "</stream:features>"; + +static int obfs_xmpp_request(buffer_t *, size_t, obfs_t *); +static int obfs_xmpp_response(buffer_t *, size_t, obfs_t *); +static int deobfs_xmpp_request(buffer_t *, size_t, obfs_t *); +static int deobfs_xmpp_response(buffer_t *, size_t, obfs_t *); +static int check_xmpp_header(buffer_t *buf); +static void disable_xmpp(obfs_t *obfs); +static int is_enable_xmpp(obfs_t *obfs); + +static obfs_para_t obfs_xmpp_st = { + .name = "xmpp", + .port = 5222, + .send_empty_response_upon_connection = true, + + .obfs_request = &obfs_xmpp_request, + .obfs_response = &obfs_xmpp_response, + .deobfs_request = &deobfs_xmpp_request, + .deobfs_response = &deobfs_xmpp_response, + .check_obfs = &check_xmpp_header, + .disable = &disable_xmpp, + .is_enable = &is_enable_xmpp +}; + +obfs_para_t *obfs_xmpp = &obfs_xmpp_st; + +static int +obfs_xmpp_request(buffer_t *buf, size_t cap, obfs_t *obfs) +{ + + if (obfs == NULL || obfs->obfs_stage != 0) return 0; + obfs->obfs_stage++; + + char xmpp_header[512]; + + size_t obfs_len = + snprintf(xmpp_header, sizeof(xmpp_header), xmpp_request_template, obfs_xmpp->host); + size_t buf_len = buf->len; + + brealloc(buf, obfs_len + buf_len, cap); + + memmove(buf->data + obfs_len, buf->data, buf_len); + memcpy(buf->data, xmpp_header, obfs_len); + + buf->len = obfs_len + buf_len; + + return buf->len; +} + +static int +obfs_xmpp_response(buffer_t *buf, size_t cap, obfs_t *obfs) +{ + if (obfs == NULL || obfs->obfs_stage != 0) return 0; + obfs->obfs_stage++; + + char xmpp_header[512]; + + size_t buf_len = buf->len; + size_t obfs_len = + snprintf(xmpp_header, sizeof(xmpp_header), xmpp_response_template); + + brealloc(buf, obfs_len + buf_len, cap); + + memmove(buf->data + obfs_len, buf->data, buf_len); + memcpy(buf->data, xmpp_header, obfs_len); + + buf->len = obfs_len + buf_len; + + return buf->len; +} + +static int +deobfs_xmpp_request(buffer_t *buf, size_t cap, obfs_t *obfs) +{ + if (obfs == NULL || obfs->deobfs_stage != 0) return 0; + + char *data = NULL; + int len = buf->len; + int err = -1; + static const char *end_req = "xml:lang=\"en\">"; + + if (len > strlen(end_req)) + data = strstr(buf->data, end_req); + if (data != NULL) { + data += strlen(end_req); + len -= data - buf->data; + err = 0; + } + + if (!err) { + memmove(buf->data, data, len); + buf->len = len; + obfs->deobfs_stage++; + } + + return err; +} + +static int +deobfs_xmpp_response(buffer_t *buf, size_t cap, obfs_t *obfs) +{ + if (obfs == NULL || obfs->deobfs_stage != 0) return 0; + + char *data = NULL; + int len = buf->len; + int err = -1; + static const char *end_req = "</stream:features>"; + + if (len > strlen(end_req)) + data = strstr(buf->data, end_req); + if (data != NULL) { + data += strlen(end_req); + len -= data - buf->data; + err = 0; + } + + if (!err) { + memmove(buf->data, data, len); + buf->len = len; + obfs->deobfs_stage++; + } + + return err; +} + +static int +check_xmpp_header(buffer_t *buf) +{ + char *data = buf->data; + int len = buf->len; + int hlen = strlen(xml_header); + + if (len < hlen) return OBFS_NEED_MORE; + if (strncmp(data, xml_header, hlen) != 0) return OBFS_ERROR; + + return OBFS_OK; +} + + +static void +disable_xmpp(obfs_t *obfs) +{ + obfs->obfs_stage = -1; + obfs->deobfs_stage = -1; +} + +static int +is_enable_xmpp(obfs_t *obfs) +{ + return obfs->obfs_stage != -1 && obfs->deobfs_stage != -1; +} diff --git a/src/obfs_xmpp.h b/src/obfs_xmpp.h new file mode 100644 index 0000000..8c8011d --- /dev/null +++ b/src/obfs_xmpp.h @@ -0,0 +1,30 @@ +/* + * obfs_xmpp.h - Interfaces of xmpp obfuscating function + * + * Copyright (C) 2021, Benoît Monin <benoit.monin@gmx.fr> + * + * This file is part of the simple-obfs. + * + * simple-obfs is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * simple-obfs is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with simple-obfs; see the file COPYING. If not, see + * <xmpp://www.gnu.org/licenses/>. + */ + +#ifndef OBFS_XMPP_H +#define OBFS_XMPP_H + +#include "obfs.h" + +extern obfs_para_t *obfs_xmpp; + +#endif diff --git a/src/server.c b/src/server.c index a857a25..e6f3c58 100644 --- a/src/server.c +++ b/src/server.c @@ -60,6 +60,7 @@ #include "utils.h" #include "obfs_http.h" #include "obfs_tls.h" +#include "obfs_xmpp.h" #include "options.h" #include "server.h" @@ -1163,6 +1164,8 @@ main(int argc, char **argv) obfs_para = obfs_http; else if (strcmp(value, obfs_tls->name) == 0) obfs_para = obfs_tls; + else if (strcmp(value, obfs_xmpp->name) == 0) + obfs_para = obfs_xmpp; } else if (strcmp(key, "obfs-host") == 0) { obfs_host = value; } else if (strcmp(key, "failover") == 0) { @@ -1211,6 +1214,8 @@ main(int argc, char **argv) obfs_para = obfs_http; else if (strcmp(optarg, obfs_tls->name) == 0) obfs_para = obfs_tls; + else if (strcmp(optarg, obfs_xmpp->name) == 0) + obfs_para = obfs_xmpp; } else if (option_index == 3) { obfs_host = optarg; } else if (option_index == 4) { @@ -1310,6 +1315,8 @@ main(int argc, char **argv) obfs_para = obfs_http; else if (strcmp(conf->obfs, obfs_tls->name) == 0) obfs_para = obfs_tls; + else if (strcmp(conf->obfs, obfs_xmpp->name) == 0) + obfs_para = obfs_xmpp; } if (obfs_host == NULL) { obfs_host = conf->obfs_host; diff --git a/src/utils.c b/src/utils.c index 9433f0d..6485af9 100644 --- a/src/utils.c +++ b/src/utils.c @@ -269,7 +269,7 @@ usage() " -r <addr>:<port> Forward traffic to this remote server address.\n"); #endif printf( - " --obfs <http|tls> Enable obfuscating: HTTP or TLS (Experimental).\n"); + " --obfs <http|tls|xmpp> Enable obfuscating: HTTP, TLS (Experimental) or XMPP.\n"); #ifndef MODULE_REMOTE printf( " --obfs-host <host_name> Hostname for obfuscating (Experimental).\n");
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor