re-read common name from certificates on startup

This commit is contained in:
Daniel Gultsch 2016-02-02 13:43:20 +01:00
parent ba9ba8ffe2
commit fab0a45955
2 changed files with 32 additions and 2 deletions

View File

@ -1,5 +1,6 @@
package eu.siacs.conversations.crypto.axolotl;
import android.os.Bundle;
import android.security.KeyChain;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@ -39,6 +40,7 @@ import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.parser.IqParser;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.utils.SerialSingleThreadExecutor;
import eu.siacs.conversations.xml.Element;
import eu.siacs.conversations.xmpp.OnAdvancedStreamFeaturesLoaded;
@ -160,6 +162,20 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
AxolotlAddress axolotlAddress = new AxolotlAddress(bareJid, deviceId);
Log.d(Config.LOGTAG, AxolotlService.getLogprefix(account) + "Building session for remote address: " + axolotlAddress.toString());
IdentityKey identityKey = store.loadSession(axolotlAddress).getSessionState().getRemoteIdentityKey();
if(Config.X509_VERIFICATION) {
X509Certificate certificate = store.getFingerprintCertificate(identityKey.getFingerprint().replaceAll("\\s", ""));
if (certificate != null) {
Bundle information = CryptoHelper.extractCertificateInformation(certificate);
try {
final String cn = information.getString("subject_cn");
final Jid jid = Jid.fromString(bareJid);
Log.d(Config.LOGTAG,"setting common name for "+jid+" to "+cn);
account.getRoster().getContact(jid).setCommonName(cn);
} catch (final InvalidJidException ignored) {
//ignored
}
}
}
this.put(axolotlAddress, new XmppAxolotlSession(account, store, axolotlAddress, identityKey));
}
}
@ -619,6 +635,15 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
setFingerprintTrust(fingerprint, XmppAxolotlSession.Trust.TRUSTED_X509);
axolotlStore.setFingerprintCertificate(fingerprint, verification.first[0]);
fetchStatusMap.put(address, FetchStatus.SUCCESS_VERIFIED);
Bundle information = CryptoHelper.extractCertificateInformation(verification.first[0]);
try {
final String cn = information.getString("subject_cn");
final Jid jid = Jid.fromString(address.getName());
Log.d(Config.LOGTAG,"setting common name for "+jid+" to "+cn);
account.getRoster().getContact(jid).setCommonName(cn);
} catch (final InvalidJidException ignored) {
//ignored
}
finishBuildingSessionsFromPEP(address);
return;
} catch (Exception e) {

View File

@ -38,6 +38,7 @@ public class Contact implements ListItem, Blockable {
protected String systemName;
protected String serverName;
protected String presenceName;
protected String commonName;
protected Jid jid;
protected int subscription = 0;
protected String systemAccount;
@ -105,8 +106,8 @@ public class Contact implements ListItem, Blockable {
}
public String getDisplayName() {
if (this.presenceName != null && Config.X509_VERIFICATION) {
return this.presenceName;
if (this.commonName != null && Config.X509_VERIFICATION) {
return this.commonName;
} else if (this.systemName != null) {
return this.systemName;
} else if (this.serverName != null) {
@ -510,6 +511,10 @@ public class Contact implements ListItem, Blockable {
return account.getJid().toBareJid().equals(getJid().toBareJid());
}
public void setCommonName(String cn) {
this.commonName = cn;
}
public static class Lastseen {
public long time;
public String presence;