From: Tobias Brunner Date: Thu, 25 Apr 2013 17:43:56 +0000 (+0200) Subject: android: Add measurement collector for String Version X-Git-Tag: 5.1.0dr2~2^2~41 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5c9706f30b0663e50a86bc1ad2e6c7ea7d828a8a;p=thirdparty%2Fstrongswan.git android: Add measurement collector for String Version --- 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 9357296bef..2aec690138 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 @@ -15,6 +15,11 @@ package org.strongswan.android.logic.imc; +import org.strongswan.android.logic.imc.attributes.Attribute; +import org.strongswan.android.logic.imc.attributes.AttributeType; +import org.strongswan.android.logic.imc.collectors.Collector; +import org.strongswan.android.logic.imc.collectors.StringVersionCollector; + import android.content.Context; public class AndroidImc @@ -36,6 +41,25 @@ public class AndroidImc */ public byte[] getMeasurement(int vendor, int type) { + AttributeType attributeType = AttributeType.fromValues(vendor, type); + Collector collector = null; + + switch (attributeType) + { + case IETF_STRING_VERSION: + collector = new StringVersionCollector(); + break; + default: + break; + } + if (collector != null) + { + Attribute attribute = collector.getMeasurement(); + if (attribute != null) + { + return attribute.getEncoding(); + } + } return null; } } diff --git a/src/frontends/android/src/org/strongswan/android/logic/imc/attributes/StringVersionAttribute.java b/src/frontends/android/src/org/strongswan/android/logic/imc/attributes/StringVersionAttribute.java new file mode 100644 index 0000000000..4b6f2bc37c --- /dev/null +++ b/src/frontends/android/src/org/strongswan/android/logic/imc/attributes/StringVersionAttribute.java @@ -0,0 +1,68 @@ +/* + * 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 org.strongswan.android.utils.BufferedByteWriter; + +/** + * PA-TNC String Version attribute (see section 4.2.4 of RFC 5792) + * + * 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 + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Version Len | Product Version Number (Variable Length) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Build Num Len | Internal Build Number (Variable Length) | + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + * | Config. Len | Configuration Version Number (Variable Length)| + * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + */ +public class StringVersionAttribute implements Attribute +{ + private String mVersionNumber; + private String mBuildNumber; + + /** + * Set the product version number + * @param version version number + */ + public void setProductVersionNumber(String version) + { + this.mVersionNumber = version; + } + + /** + * Set the internal build number + * @param build build number + */ + public void setInternalBuildNumber(String build) + { + this.mBuildNumber = build; + } + + @Override + public byte[] getEncoding() + { + BufferedByteWriter writer = new BufferedByteWriter(); + writer.putLen8(mVersionNumber.getBytes()); + writer.putLen8(mBuildNumber.getBytes()); + /* we don't provide a configuration number */ + writer.put((byte)0); + return writer.toByteArray(); + } +} diff --git a/src/frontends/android/src/org/strongswan/android/logic/imc/collectors/StringVersionCollector.java b/src/frontends/android/src/org/strongswan/android/logic/imc/collectors/StringVersionCollector.java new file mode 100644 index 0000000000..6e0df94a57 --- /dev/null +++ b/src/frontends/android/src/org/strongswan/android/logic/imc/collectors/StringVersionCollector.java @@ -0,0 +1,33 @@ +/* + * 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.StringVersionAttribute; + +public class StringVersionCollector implements Collector +{ + @Override + public Attribute getMeasurement() + { + StringVersionAttribute attribute = new StringVersionAttribute(); + attribute.setProductVersionNumber(android.os.Build.VERSION.RELEASE); + attribute.setInternalBuildNumber(android.os.Build.DISPLAY); + return attribute; + } +}