android: Added a field to store selected user certificate

This commit is contained in:
Tobias Brunner
2012-08-27 10:48:13 +02:00
parent 8528f841de
commit e09f4120d4
2 changed files with 27 additions and 9 deletions
@@ -19,7 +19,7 @@ package org.strongswan.android.data;
public class VpnProfile implements Cloneable public class VpnProfile implements Cloneable
{ {
private String mName, mGateway, mUsername, mPassword, mCertificate; private String mName, mGateway, mUsername, mPassword, mCertificate, mUserCertificate;
private long mId = -1; private long mId = -1;
public long getId() public long getId()
@@ -77,9 +77,19 @@ public class VpnProfile implements Cloneable
return mCertificate; return mCertificate;
} }
public void setCertificateAlias(String certificate) public void setCertificateAlias(String alias)
{ {
this.mCertificate = certificate; this.mCertificate = alias;
}
public String getUserCertificateAlias()
{
return mUserCertificate;
}
public void setUserCertificateAlias(String alias)
{
this.mUserCertificate = alias;
} }
@Override @Override
@@ -37,6 +37,7 @@ public class VpnProfileDataSource
public static final String KEY_USERNAME = "username"; public static final String KEY_USERNAME = "username";
public static final String KEY_PASSWORD = "password"; public static final String KEY_PASSWORD = "password";
public static final String KEY_CERTIFICATE = "certificate"; public static final String KEY_CERTIFICATE = "certificate";
public static final String KEY_USER_CERTIFICATE = "user_certificate";
private DatabaseHelper mDbHelper; private DatabaseHelper mDbHelper;
private SQLiteDatabase mDatabase; private SQLiteDatabase mDatabase;
@@ -45,7 +46,7 @@ public class VpnProfileDataSource
private static final String DATABASE_NAME = "strongswan.db"; private static final String DATABASE_NAME = "strongswan.db";
private static final String TABLE_VPNPROFILE = "vpnprofile"; private static final String TABLE_VPNPROFILE = "vpnprofile";
private static final int DATABASE_VERSION = 1; private static final int DATABASE_VERSION = 2;
public static final String DATABASE_CREATE = public static final String DATABASE_CREATE =
"CREATE TABLE " + TABLE_VPNPROFILE + " (" + "CREATE TABLE " + TABLE_VPNPROFILE + " (" +
@@ -54,7 +55,8 @@ public class VpnProfileDataSource
KEY_GATEWAY + " TEXT NOT NULL," + KEY_GATEWAY + " TEXT NOT NULL," +
KEY_USERNAME + " TEXT NOT NULL," + KEY_USERNAME + " TEXT NOT NULL," +
KEY_PASSWORD + " TEXT," + KEY_PASSWORD + " TEXT," +
KEY_CERTIFICATE + " TEXT" + KEY_CERTIFICATE + " TEXT," +
KEY_USER_CERTIFICATE + " TEXT" +
");"; ");";
private final String[] ALL_COLUMNS = new String[] { private final String[] ALL_COLUMNS = new String[] {
KEY_ID, KEY_ID,
@@ -62,7 +64,8 @@ public class VpnProfileDataSource
KEY_GATEWAY, KEY_GATEWAY,
KEY_USERNAME, KEY_USERNAME,
KEY_PASSWORD, KEY_PASSWORD,
KEY_CERTIFICATE KEY_CERTIFICATE,
KEY_USER_CERTIFICATE,
}; };
private static class DatabaseHelper extends SQLiteOpenHelper private static class DatabaseHelper extends SQLiteOpenHelper
@@ -82,9 +85,12 @@ public class VpnProfileDataSource
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{ {
Log.w(TAG, "Upgrading database from version " + oldVersion + Log.w(TAG, "Upgrading database from version " + oldVersion +
" to " + newVersion + ", which will destroy all old data"); " to " + newVersion);
db.execSQL("DROP TABLE IF EXISTS " + TABLE_VPNPROFILE); if (oldVersion < 2)
onCreate(db); {
db.execSQL("ALTER TABLE " + TABLE_VPNPROFILE + " ADD " + KEY_USER_CERTIFICATE +
" TEXT;");
}
} }
} }
@@ -215,6 +221,7 @@ public class VpnProfileDataSource
profile.setUsername(cursor.getString(cursor.getColumnIndex(KEY_USERNAME))); profile.setUsername(cursor.getString(cursor.getColumnIndex(KEY_USERNAME)));
profile.setPassword(cursor.getString(cursor.getColumnIndex(KEY_PASSWORD))); profile.setPassword(cursor.getString(cursor.getColumnIndex(KEY_PASSWORD)));
profile.setCertificateAlias(cursor.getString(cursor.getColumnIndex(KEY_CERTIFICATE))); profile.setCertificateAlias(cursor.getString(cursor.getColumnIndex(KEY_CERTIFICATE)));
profile.setUserCertificateAlias(cursor.getString(cursor.getColumnIndex(KEY_USER_CERTIFICATE)));
return profile; return profile;
} }
@@ -226,6 +233,7 @@ public class VpnProfileDataSource
values.put(KEY_USERNAME, profile.getUsername()); values.put(KEY_USERNAME, profile.getUsername());
values.put(KEY_PASSWORD, profile.getPassword()); values.put(KEY_PASSWORD, profile.getPassword());
values.put(KEY_CERTIFICATE, profile.getCertificateAlias()); values.put(KEY_CERTIFICATE, profile.getCertificateAlias());
values.put(KEY_USER_CERTIFICATE, profile.getUserCertificateAlias());
return values; return values;
} }
} }