Skip to content

Commit 5110cb9

Browse files
committed
Fix for PIN-retry on eap-tls
1 parent cb7a3ff commit 5110cb9

File tree

4 files changed

+53
-14
lines changed

4 files changed

+53
-14
lines changed

AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="uk.ac.swansea.eduroamcat"
4-
android:versionCode="48"
5-
android:versionName="1.2.3">
4+
android:versionCode="49"
5+
android:versionName="1.2.4">
66

77
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
88
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />

src/uk/ac/swansea/eduroamcat/AuthenticationMethod.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ public boolean loadClientCert(String ausercert, String format, String encoding,S
273273
this.setClientCertPass(keypass);
274274
//store orignal cypher text
275275
this.clientCert=ausercert;
276+
Boolean keyError=false;
276277

277278
if ( format.compareToIgnoreCase("PKCS12")==0) {
278279
try {
@@ -295,24 +296,29 @@ public boolean loadClientCert(String ausercert, String format, String encoding,S
295296
try {
296297
privateKey = (PrivateKey) keyStore.getKey(alias,keypass.toCharArray());
297298
} catch (UnrecoverableKeyException e) {
299+
keyError=true;
298300
e.printStackTrace();
299301
}
300302
}
301303
}
302304
catch (java.security.KeyStoreException ke) {
303305
eduroamCAT.debug("KeyStore Exception "+ ke);
306+
keyError=true;
304307
} catch (CertificateException e) {
308+
keyError=true;
305309
e.printStackTrace();
306310
} catch (NoSuchAlgorithmException e) {
311+
keyError=true;
307312
e.printStackTrace();
308313
} catch (IOException e) {
314+
keyError=true;
309315
e.printStackTrace();
310316
}
311317

312318
}
313319

314320
//If cert is set
315-
if (keyStore!=null)
321+
if (keyStore!=null && keyError==false)
316322
{
317323
eduroamCAT.debug("ClientCert installed:"+ausercert);
318324
// checks on supported eap types?
@@ -332,6 +338,7 @@ public boolean loadClientCert(String ausercert, String format, String encoding,S
332338
//return Client cert key
333339
public PrivateKey getClientPrivateKey() {
334340
try {
341+
if (keyStore!=null)
335342
if (keyStore.size() > 0) {
336343
Enumeration<String> aliases = keyStore.aliases();
337344
while (aliases.hasMoreElements()) {
@@ -375,6 +382,7 @@ public Certificate[] getClientChain() {
375382
public X509Certificate getClientCert()
376383
{
377384
try {
385+
if (keyStore!=null)
378386
if (keyStore.size() > 0) {
379387
Enumeration<String> aliases = keyStore.aliases();
380388
while (aliases.hasMoreElements()) {

src/uk/ac/swansea/eduroamcat/ConfigProfile.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ public void setConfigError(String errorMessage)
3636
this.error=true;
3737
this.errorMessage=errorMessage;
3838
}
39+
40+
//remove error
41+
public void clearConfigError()
42+
{
43+
this.error=false;
44+
this.errorMessage="";
45+
}
3946

4047
//Return if error or not
4148
public boolean isError()

src/uk/ac/swansea/eduroamcat/EAPMetadata.java

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ public class EAPMetadata extends Activity {
5151
static Button discard,install;
5252
ProfilesStorage db = new ProfilesStorage(this);
5353
String keyPass=""; //default to nothing to start (optional)
54+
//global clietn cert value for retry
55+
static NodeList clientCert;
5456

5557
public boolean testExternalStorage()
5658
{
@@ -428,6 +430,21 @@ public void onClick(DialogInterface dialog, int which) {
428430
.show();
429431
// finish();
430432
}
433+
434+
if (eduroamCAT.profiles!=null)
435+
if (eduroamCAT.profiles.size()>0)
436+
if (eduroamCAT.profiles.get(eduroamCAT.profiles.size()-1).isError())
437+
{
438+
//if eap-tls, request pin again
439+
int lastAuthMethod = 0;
440+
lastAuthMethod = eduroamCAT.profiles.get(eduroamCAT.profiles.size()-1).getNumberAuthenticationMethods();
441+
if (eduroamCAT.profiles.get(eduroamCAT.profiles.size()-1).getAuthenticationMethod(lastAuthMethod-1).getOuterEAPType()==13)
442+
if (eduroamCAT.profiles.get(eduroamCAT.profiles.size()-1).getAuthenticationMethod(lastAuthMethod-1).getClientPrivateKey()==null)
443+
{
444+
requestKeypass(getString(R.string.PinDialog),getString(R.string.PinDialog),this, clientCert);
445+
eduroamCAT.debug("No valid auth method in profile. check if tls and req PIN again");
446+
}
447+
}
431448
}
432449

433450
/**
@@ -439,7 +456,7 @@ private void setupActionBar() {
439456

440457
}
441458

442-
public static void requestKeypass(String message, String title, Activity activ, final NodeList clientCert, final AuthenticationMethod newAuthMethod)
459+
public static void requestKeypass(String message, String title, Activity activ, final NodeList clientCertx)
443460
{
444461
// Set an EditText view to get user input
445462
final EditText input = new EditText(activ);
@@ -453,7 +470,7 @@ public void onClick(DialogInterface dialog, int which) {
453470
eduroamCAT.debug("PIN=" + pin);
454471
String certstring = "";
455472
Element Clientcert = null;
456-
473+
if (clientCertx.getLength()>0) clientCert = clientCertx;
457474
if (clientCert.getLength() > 0) {
458475
for (int s = 0; s < clientCert.getLength(); s++) {
459476
Clientcert = (Element) clientCert.item(s);
@@ -478,13 +495,16 @@ public void onClick(DialogInterface dialog, int which) {
478495
if (aAuthMethod.getOuterEAPType()==13)
479496
try {
480497
eduroamCAT.debug("adding client cert:" +tmp + "with pin "+pin);
481-
aAuthMethod.loadClientCert(tmp, Clientcert.getAttribute("format"), Clientcert.getAttribute("encoding"), pin);
482-
aAuthMethod.setClientCertPass(pin);
483-
aProfile.removeAuthenticationMethod(i);
484-
aProfile.addAuthenticationMethod(aAuthMethod);
485-
eduroamCAT.profiles.set(eduroamCAT.profiles.size() - 1,aProfile);
498+
if (aAuthMethod.loadClientCert(tmp, Clientcert.getAttribute("format"), Clientcert.getAttribute("encoding"), pin)) {
499+
aAuthMethod.setClientCertPass(pin);
500+
aProfile.removeAuthenticationMethod(i);
501+
aProfile.addAuthenticationMethod(aAuthMethod);
502+
eduroamCAT.profiles.set(eduroamCAT.profiles.size() - 1, aProfile);
503+
}
504+
else eduroamCAT.profiles.get(eduroamCAT.profiles.size()-1).setConfigError("Client cert error");
486505
} catch (KeyStoreException e) {
487506
e.printStackTrace();
507+
eduroamCAT.profiles.get(eduroamCAT.profiles.size()-1).setConfigError("Client cert error");
488508
}
489509
}
490510
}
@@ -493,6 +513,12 @@ public void onClick(DialogInterface dialog, int which) {
493513
}
494514
}
495515
})
516+
.setNegativeButton(R.string.discard_button, new DialogInterface.OnClickListener() {
517+
public void onClick(DialogInterface dialog, int which) {
518+
//cancel install of
519+
eduroamCAT.debug("User discard...");
520+
}
521+
})
496522
.setView(input)
497523
.show();
498524
}
@@ -630,10 +656,8 @@ public ArrayList<ConfigProfile> parseProfile(String config) throws IOException,
630656

631657
//get Client cert
632658
//get keypass from user
633-
NodeList clientCert = authElement.getElementsByTagName("ClientCertificate");
634-
if (clientCert.getLength()>0) requestKeypass("Enter PIN","Enter PIN",this,clientCert,newAuthMethod);
635-
636-
659+
clientCert = authElement.getElementsByTagName("ClientCertificate");
660+
if (clientCert.getLength()>0) requestKeypass(getString(R.string.PinDialog),getString(R.string.PinDialog),this,clientCert);
637661
}
638662
}
639663

0 commit comments

Comments
 (0)