Skip to content

Commit

Permalink
Ensured consistent waiting for certificate acceptance in all cases using
Browse files Browse the repository at this point in the history
java monitors.
  • Loading branch information
iiordanov committed Dec 21, 2013
1 parent e12d685 commit 18b0ebd
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
37 changes: 26 additions & 11 deletions eclipse_projects/bVNC/src/com/iiordanov/bVNC/RemoteCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,14 @@ public void run() {
if (connection.getConnectionType() == Constants.CONN_TYPE_SSH &&
connection.getSshHostKey().equals("")) {
handler.sendEmptyMessage(Constants.DIALOG_SSH_CERT);

// Block while user decides whether to accept certificate or not.
// The activity ends if the user taps "No", so we block indefinitely here.
synchronized (RemoteCanvas.this) {
try {
while (connection.getSshHostKey().equals("")) {
while (connection.getSshHostKey().equals("")) {
try {
RemoteCanvas.this.wait();
}
} catch (InterruptedException e) {
e.printStackTrace();
((Activity) getContext()).finish();
} catch (InterruptedException e) { e.printStackTrace(); }
}
}
}
Expand Down Expand Up @@ -1304,12 +1304,17 @@ public boolean OnVerifiyCertificate(String subject, String issuer, String finger
strings.putString("fingerprint", fingerprint);
m.obj = strings;
handler.sendMessage(m);

// Block while user decides whether to accept certificate or not. The activity ends if the user taps "No", so
// we block 'indefinitely' here.
while (!certificateAccepted) {
try {Thread.sleep(100);} catch (InterruptedException e1) { return false; }

// Block while user decides whether to accept certificate or not.
// The activity ends if the user taps "No", so we block indefinitely here.
synchronized (RemoteCanvas.this) {
while (!certificateAccepted) {
try {
RemoteCanvas.this.wait();
} catch (InterruptedException e) { e.printStackTrace(); }
}
}

return true;
}

Expand Down Expand Up @@ -1410,6 +1415,9 @@ public void onClick(DialogInterface dialog, int which) {
database.close();
// Indicate the certificate was accepted.
certificateAccepted = true;
synchronized (RemoteCanvas.this) {
RemoteCanvas.this.notifyAll();
}
}
};

Expand Down Expand Up @@ -1445,8 +1453,12 @@ public void onClick(DialogInterface dialog, int which) {
//X509Certificate c = (X509Certificate)certFactory.generateCertificate(in);
//android.util.Log.e(" Subject ", c.getSubjectDN().toString());
//android.util.Log.e(" Issuer ", c.getIssuerDN().toString());

// The certificate matches, so we proceed.
certificateAccepted = true;
synchronized (RemoteCanvas.this) {
RemoteCanvas.this.notifyAll();
}
}
} catch (CertificateEncodingException e) {
e.printStackTrace();
Expand Down Expand Up @@ -1480,6 +1492,9 @@ public void onClick(DialogInterface dialog, int which) {
public void onClick(DialogInterface dialog, int which) {
// Indicate the certificate was accepted.
certificateAccepted = true;
synchronized (RemoteCanvas.this) {
RemoteCanvas.this.notifyAll();
}
}
};
Utils.showYesNoPrompt(getContext(), getContext().getString(R.string.info_continue_connecting) + connection.getAddress () + "?",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,12 @@ public void checkServerTrusted(X509Certificate[] chain, String authType)
m.obj = chain[0];
vncCanvas.handler.sendMessage(m);

// Block while user decides whether to accept certificate.
while (!vncCanvas.certificateAccepted) {
try {
Thread.sleep(100);
} catch (InterruptedException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
synchronized (vncCanvas) {
// Block indefinitely until x509 cert is matched to a saved one or the user accepts it.
while (!vncCanvas.certificateAccepted) {
try {
vncCanvas.wait();
} catch (InterruptedException e1) { e1.printStackTrace(); }
}
}
}
Expand Down

0 comments on commit 18b0ebd

Please sign in to comment.