[PATCH] openconnect: add initial support for openconnect ssl vpn.

openconnect at lakedaemon.net openconnect at lakedaemon.net
Thu Jul 14 21:38:58 EDT 2011


From: Jason Cooper <cyanogen at lakedaemon.net>


Signed-off-by: Jason Cooper <cyanogen at lakedaemon.net>
---
 nexus/Android.mk                |    1 +
 nexus/OpenConnectController.cpp |   89 +++++++++++++++++++++++++++++++++++++++
 nexus/OpenConnectController.h   |   60 ++++++++++++++++++++++++++
 nexus/main.cpp                  |    2 +
 4 files changed, 152 insertions(+), 0 deletions(-)
 create mode 100644 nexus/OpenConnectController.cpp
 create mode 100644 nexus/OpenConnectController.h

diff --git a/nexus/Android.mk b/nexus/Android.mk
index f9f7110..7403066 100644
--- a/nexus/Android.mk
+++ b/nexus/Android.mk
@@ -34,6 +34,7 @@ LOCAL_SRC_FILES:=                                      \
                   SupplicantDisconnectedEvent.cpp      \
                   SupplicantStatus.cpp                 \
                   OpenVpnController.cpp                \
+                  OpenConnectController.cpp            \
                   VpnController.cpp                    \
                   LoopController.cpp                   \
                   DhcpClient.cpp DhcpListener.cpp      \
diff --git a/nexus/OpenConnectController.cpp b/nexus/OpenConnectController.cpp
new file mode 100644
index 0000000..c8012c5
--- /dev/null
+++ b/nexus/OpenConnectController.cpp
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2011 Jason Cooper <cyanogen at lakedaemon.net>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * copied from OpenVpnController.cpp which was (same license):
+ *
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <errno.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#define LOG_TAG "OpenConnectController"
+#include <cutils/log.h>
+#include <cutils/properties.h>
+
+#include <sysutils/ServiceManager.h>
+
+#include "OpenConnectController.h"
+#include "PropertyManager.h"
+
+#define DAEMON_PROP_NAME "vpn.openconnect.status"
+#define DAEMON_CONFIG_FILE "/data/misc/openconnect/openconnect.conf"
+
+OpenConnectController::OpenConnectController(PropertyManager *propmngr,
+                                     IControllerHandler *handlers) :
+                   VpnController(propmngr, handlers) {
+    mServiceManager = new ServiceManager();
+}
+
+OpenConnectController::~OpenConnectController() {
+    delete mServiceManager;
+}
+
+int OpenConnectController::start() {
+    return VpnController::start();
+}
+
+int OpenConnectController::stop() {
+    return VpnController::stop();
+}
+
+int OpenConnectController::enable() {
+    char svc[PROPERTY_VALUE_MAX];
+    char tmp[64];
+
+    if (!mPropMngr->get("vpn.gateway", tmp, sizeof(tmp))) {
+        LOGE("Error reading property 'vpn.gateway' (%s)", strerror(errno));
+        return -1;
+    }
+    snprintf(svc, sizeof(svc), "openconnect: https://%s", tmp);
+
+    if (mServiceManager->start(svc))
+        return -1;
+
+    return 0;
+}
+
+int OpenConnectController::disable() {
+    if (mServiceManager->stop("openconnect"))
+        return -1;
+    return 0;
+}
diff --git a/nexus/OpenConnectController.h b/nexus/OpenConnectController.h
new file mode 100644
index 0000000..5906038
--- /dev/null
+++ b/nexus/OpenConnectController.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2011 Jason Cooper <cyanogen at lakedaemon.net>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ * copied from OpenVpnController.h which was (same license):
+ *
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _OPEN_CONNECT_CONTROLLER_H
+#define _OPEN_CONNECT_CONTROLLER_H
+
+#include "PropertyManager.h"
+#include "VpnController.h"
+
+class ServiceManager;
+class IControllerHandler;
+
+class OpenConnectController : public VpnController {
+private:
+    ServiceManager *mServiceManager;
+
+public:
+    OpenConnectController(PropertyManager *propmngr, IControllerHandler *handlers);
+    virtual ~OpenConnectController();
+
+    int start();
+    int stop();
+
+private:
+    int enable();
+    int disable();
+};
+
+#endif
diff --git a/nexus/main.cpp b/nexus/main.cpp
index 936d33f..97afcbf 100644
--- a/nexus/main.cpp
+++ b/nexus/main.cpp
@@ -25,6 +25,7 @@
 
 #include "LoopController.h"
 #include "OpenVpnController.h"
+#include "OpenConnectController.h"
 #include "TiwlanWifiController.h"
 
 int main() {
@@ -44,6 +45,7 @@ int main() {
     nm->attachController(new TiwlanWifiController(nm->getPropMngr(), nm, "/system/lib/modules/wlan.ko", "wlan", ""));
 //    nm->attachController(new AndroidL2TPVpnController(nm->getPropMngr(), nm));
     nm->attachController(new OpenVpnController(nm->getPropMngr(), nm));
+    nm->attachController(new OpenConnectController(nm->getPropMngr(), nm));
 
 
     if (NetworkManager::Instance()->run()) {
-- 
1.7.0.4




More information about the openconnect-devel mailing list