From 44330a171f80ccaed77b68bd1d7fd24cae303efe Mon Sep 17 00:00:00 2001 From: Tobias Brunner Date: Fri, 26 Apr 2013 18:17:32 +0200 Subject: [PATCH] android: Add measurement collector for ITA Settings --- .../jni/libandroidbridge/byod/imc_android.c | 5 +- .../android/logic/imc/AndroidImc.java | 4 + .../logic/imc/attributes/AttributeType.java | 5 +- .../attributes/PrivateEnterpriseNumber.java | 1 + .../imc/attributes/SettingsAttribute.java | 78 +++++++++++++++++++ .../imc/collectors/SettingsCollector.java | 59 ++++++++++++++ 6 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 src/frontends/android/src/org/strongswan/android/logic/imc/attributes/SettingsAttribute.java create mode 100644 src/frontends/android/src/org/strongswan/android/logic/imc/collectors/SettingsCollector.java diff --git a/src/frontends/android/jni/libandroidbridge/byod/imc_android.c b/src/frontends/android/jni/libandroidbridge/byod/imc_android.c index 4079e4c280..70419c9134 100644 --- a/src/frontends/android/jni/libandroidbridge/byod/imc_android.c +++ b/src/frontends/android/jni/libandroidbridge/byod/imc_android.c @@ -363,7 +363,10 @@ static TNC_Result receive_message(imc_msg_t *in_msg) { case PEN_IETF: handle_ietf_attribute(attr_type, attr, out_msg); - /* fall-through */ + continue; + case PEN_ITA: + handle_ita_attribute(attr_type, attr, out_msg); + continue; default: continue; } diff --git a/src/frontends/android/src/org/strongswan/android/logic/imc/AndroidImc.java b/src/frontends/android/src/org/strongswan/android/logic/imc/AndroidImc.java index 2219c517d5..1c298bef3d 100644 --- a/src/frontends/android/src/org/strongswan/android/logic/imc/AndroidImc.java +++ b/src/frontends/android/src/org/strongswan/android/logic/imc/AndroidImc.java @@ -21,6 +21,7 @@ import org.strongswan.android.logic.imc.collectors.Collector; import org.strongswan.android.logic.imc.collectors.InstalledPackagesCollector; import org.strongswan.android.logic.imc.collectors.PortFilterCollector; import org.strongswan.android.logic.imc.collectors.ProductInformationCollector; +import org.strongswan.android.logic.imc.collectors.SettingsCollector; import org.strongswan.android.logic.imc.collectors.StringVersionCollector; import android.content.Context; @@ -75,6 +76,9 @@ public class AndroidImc case IETF_INSTALLED_PACKAGES: collector = new InstalledPackagesCollector(mContext); break; + case ITA_SETTINGS: + collector = new SettingsCollector(mContext, args); + break; default: break; } diff --git a/src/frontends/android/src/org/strongswan/android/logic/imc/attributes/AttributeType.java b/src/frontends/android/src/org/strongswan/android/logic/imc/attributes/AttributeType.java index 8d915142a0..52eef97f89 100644 --- a/src/frontends/android/src/org/strongswan/android/logic/imc/attributes/AttributeType.java +++ b/src/frontends/android/src/org/strongswan/android/logic/imc/attributes/AttributeType.java @@ -19,6 +19,7 @@ package org.strongswan.android.logic.imc.attributes; public enum AttributeType { + /* IETF standard PA-TNC attribute types defined by RFC 5792 */ IETF_TESTING(PrivateEnterpriseNumber.IETF, 0), IETF_ATTRIBUTE_REQUEST(PrivateEnterpriseNumber.IETF, 1), IETF_PRODUCT_INFORMATION(PrivateEnterpriseNumber.IETF, 2), @@ -32,7 +33,9 @@ public enum AttributeType IETF_REMEDIATION_INSTRUCTIONS(PrivateEnterpriseNumber.IETF, 10), IETF_FORWARDING_ENABLED(PrivateEnterpriseNumber.IETF, 11), IETF_FACTORY_DEFAULT_PWD_ENABLED(PrivateEnterpriseNumber.IETF, 12), - IETF_RESERVED(PrivateEnterpriseNumber.IETF, 0xffffffff); + IETF_RESERVED(PrivateEnterpriseNumber.IETF, 0xffffffff), + /* ITA attributes */ + ITA_SETTINGS(PrivateEnterpriseNumber.ITA, 4); private PrivateEnterpriseNumber mVendor; private int mType; diff --git a/src/frontends/android/src/org/strongswan/android/logic/imc/attributes/PrivateEnterpriseNumber.java b/src/frontends/android/src/org/strongswan/android/logic/imc/attributes/PrivateEnterpriseNumber.java index 5af20a855b..9db702ec0c 100644 --- a/src/frontends/android/src/org/strongswan/android/logic/imc/attributes/PrivateEnterpriseNumber.java +++ b/src/frontends/android/src/org/strongswan/android/logic/imc/attributes/PrivateEnterpriseNumber.java @@ -19,6 +19,7 @@ public enum PrivateEnterpriseNumber { IETF(0x000000), GOOGLE(0x002B79), + ITA(0x00902a), UNASSIGNED(0xfffffe), RESERVED(0xffffff); diff --git a/src/frontends/android/src/org/strongswan/android/logic/imc/attributes/SettingsAttribute.java b/src/frontends/android/src/org/strongswan/android/logic/imc/attributes/SettingsAttribute.java new file mode 100644 index 0000000000..37d820168b --- /dev/null +++ b/src/frontends/android/src/org/strongswan/android/logic/imc/attributes/SettingsAttribute.java @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2013 Tobias Brunner + * Copyright (C) 2012 Christoph Buehler + * Copyright (C) 2012 Patrick Loetscher + * Hochschule fuer Technik Rapperswil + * + * This program 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 2 of the License, or (at your + * option) any later version. See . + * + * This program 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. + */ + +package org.strongswan.android.logic.imc.attributes; + +import java.util.LinkedList; + +import org.strongswan.android.utils.BufferedByteWriter; + +import android.util.Pair; + +/** + * ITA Settings attribute + * + * 1 2 3 + * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Settings Count | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Name Length | Name (Variable Length) ~ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * ~ Name (Variable Length) ~ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Value Length | Value (Variable Length) ~ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * ~ Value (Variable Length) ~ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Name Length | Name (Variable Length) ~ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * ~ Name (Variable Length) ~ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Value Length | Value (Variable Length) ~ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * ~ Value (Variable Length) ~ + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * ........................... + */ +public class SettingsAttribute implements Attribute +{ + private final LinkedList> mSettings = new LinkedList>(); + + /** + * Add a setting to this attribute. + * @param name name of the setting + * @param value value of the setting + */ + public void addSetting(String name, String value) + { + mSettings.add(new Pair(name, value)); + } + + @Override + public byte[] getEncoding() + { + BufferedByteWriter writer = new BufferedByteWriter(); + writer.put32(mSettings.size()); + for (Pair pair : mSettings) + { + writer.putLen16(pair.first.getBytes()); + writer.putLen16(pair.second.getBytes()); + } + return writer.toByteArray(); + } +} diff --git a/src/frontends/android/src/org/strongswan/android/logic/imc/collectors/SettingsCollector.java b/src/frontends/android/src/org/strongswan/android/logic/imc/collectors/SettingsCollector.java new file mode 100644 index 0000000000..3f6bcff6f0 --- /dev/null +++ b/src/frontends/android/src/org/strongswan/android/logic/imc/collectors/SettingsCollector.java @@ -0,0 +1,59 @@ +/* + * Copyright (C) 2013 Tobias Brunner + * Copyright (C) 2012 Christoph Buehler + * Copyright (C) 2012 Patrick Loetscher + * Hochschule fuer Technik Rapperswil + * + * This program 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 2 of the License, or (at your + * option) any later version. See . + * + * This program 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. + */ + +package org.strongswan.android.logic.imc.collectors; + +import org.strongswan.android.logic.imc.attributes.Attribute; +import org.strongswan.android.logic.imc.attributes.SettingsAttribute; + +import android.content.ContentResolver; +import android.content.Context; + +public class SettingsCollector implements Collector +{ + private final ContentResolver mContentResolver; + private final String[] mSettings; + + public SettingsCollector(Context context, String[] args) + { + mContentResolver = context.getContentResolver(); + mSettings = args; + } + + @Override + public Attribute getMeasurement() + { + if (mSettings == null || mSettings.length == 0) + { + return null; + } + SettingsAttribute attribute = new SettingsAttribute(); + for (String name : mSettings) + { + String value = android.provider.Settings.Secure.getString(mContentResolver, name.toLowerCase()); + if (value == null) + { + value = android.provider.Settings.System.getString(mContentResolver, name.toLowerCase()); + } + if (value != null) + { + attribute.addSetting(name, value); + } + } + return attribute; + } +} -- 2.47.3