Commit ed16cfcf authored by David Woodhouse's avatar David Woodhouse

Fix Android build with NDK

The NDK doesn't include keystore.h but that only has a few error numbers
so we can define those locally.

We also can't call socket_local_client() but that's only a simple socket()
and connect() call on a Unix socket anyway.

Also make keystore_strerror() return a const char *.
Signed-off-by: default avatarDavid Woodhouse <David.Woodhouse@intel.com>
parent e75a587b
...@@ -385,11 +385,11 @@ int __attribute__ ((format (printf, 2, 3))) ...@@ -385,11 +385,11 @@ int __attribute__ ((format (printf, 2, 3)))
openconnect_SSL_printf(struct openconnect_info *vpninfo, const char *fmt, ...); openconnect_SSL_printf(struct openconnect_info *vpninfo, const char *fmt, ...);
int openconnect_print_err_cb(const char *str, size_t len, void *ptr); int openconnect_print_err_cb(const char *str, size_t len, void *ptr);
#define openconnect_report_ssl_errors(v) ERR_print_errors_cb(openconnect_print_err_cb, (v)) #define openconnect_report_ssl_errors(v) ERR_print_errors_cb(openconnect_print_err_cb, (v))
#ifdef FAKE_ANDROID_KEYSTORE #if defined (FAKE_ANDROID_KEYSTORE) || defined (ANDROID)
#define ANDROID_KEYSTORE #define ANDROID_KEYSTORE
#endif #endif
#ifdef ANDROID_KEYSTORE #ifdef ANDROID_KEYSTORE
char *keystore_strerror(int err); const char *keystore_strerror(int err);
int keystore_fetch(const char *key, unsigned char **result); int keystore_fetch(const char *key, unsigned char **result);
#endif #endif
......
...@@ -48,6 +48,10 @@ ...@@ -48,6 +48,10 @@
#include "openconnect-internal.h" #include "openconnect-internal.h"
#ifdef ANDROID_KEYSTORE
#include <sys/un.h>
#endif
/* OSX < 1.6 doesn't have AI_NUMERICSERV */ /* OSX < 1.6 doesn't have AI_NUMERICSERV */
#ifndef AI_NUMERICSERV #ifndef AI_NUMERICSERV
#define AI_NUMERICSERV 0 #define AI_NUMERICSERV 0
...@@ -431,9 +435,19 @@ int keystore_fetch(const char *key, unsigned char **result) ...@@ -431,9 +435,19 @@ int keystore_fetch(const char *key, unsigned char **result)
return ret; return ret;
} }
#elif defined (ANDROID_KEYSTORE) #elif defined (ANDROID_KEYSTORE)
#include <cutils/sockets.h> /* keystore.h isn't in the NDK so we need to define these */
#include <keystore.h> #define NO_ERROR 1
char *keystore_strerror(int err) #define LOCKED 2
#define UNINITIALIZED 3
#define SYSTEM_ERROR 4
#define PROTOCOL_ERROR 5
#define PERMISSION_DENIED 6
#define KEY_NOT_FOUND 7
#define VALUE_CORRUPTED 8
#define UNDEFINED_ACTION 9
#define WRONG_PASSWORD 10
const char *keystore_strerror(int err)
{ {
switch (-err) { switch (-err) {
case NO_ERROR: return _("No error"); case NO_ERROR: return _("No error");
...@@ -445,10 +459,10 @@ char *keystore_strerror(int err) ...@@ -445,10 +459,10 @@ char *keystore_strerror(int err)
case KEY_NOT_FOUND: return _("Key not found"); case KEY_NOT_FOUND: return _("Key not found");
case VALUE_CORRUPTED: return _("Value corrupted"); case VALUE_CORRUPTED: return _("Value corrupted");
case UNDEFINED_ACTION: return _("Undefined action"); case UNDEFINED_ACTION: return _("Undefined action");
case WRONG_PASSWORD_0: case WRONG_PASSWORD:
case WRONG_PASSWORD_1: case WRONG_PASSWORD+1:
case WRONG_PASSWORD_2: case WRONG_PASSWORD+2:
case WRONG_PASSWORD_3: return _("Wrong password"); case WRONG_PASSWORD+3: return _("Wrong password");
default: return _("Unknown error"); default: return _("Unknown error");
} }
} }
...@@ -457,17 +471,21 @@ char *keystore_strerror(int err) ...@@ -457,17 +471,21 @@ char *keystore_strerror(int err)
own strerror function above). The numbers are from Android's keystore.h */ own strerror function above). The numbers are from Android's keystore.h */
int keystore_fetch(const char *key, unsigned char **result) int keystore_fetch(const char *key, unsigned char **result)
{ {
struct sockaddr_un sa = { AF_UNIX, "/dev/socket/keystore" };
socklen_t sl = offsetof(struct sockaddr_un, sun_path) + strlen(sa.sun_path) + 1;
unsigned char *data, *p; unsigned char *data, *p;
unsigned char buf[3]; unsigned char buf[3];
int len, fd, ofs; int len, fd, ofs;
int ret = -SYSTEM_ERROR; int ret = -SYSTEM_ERROR;
fd = socket_local_client("keystore", fd = socket(AF_UNIX, SOCK_STREAM, 0);
ANDROID_SOCKET_NAMESPACE_RESERVED,
SOCK_STREAM);
if (fd < 0) if (fd < 0)
return -SYSTEM_ERROR; return -SYSTEM_ERROR;
if (connect(fd, (void *)&sa, sl)) {
close(fd);
return -SYSTEM_ERROR;
}
len = strlen(key); len = strlen(key);
buf[0] = 'g'; buf[0] = 'g';
buf[1] = len >> 8; buf[1] = len >> 8;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment