Check S/MIME sender/signature address

pull/168/head
M66B 5 years ago
parent ff6237d690
commit ff919d0350

@ -3971,7 +3971,7 @@ public class FragmentCompose extends FragmentBase {
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
email = getArguments().getString("email"); email = getArguments().getString("email");
View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_certificate, null); View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_select_certificate, null);
final RecyclerView rvCertificate = dview.findViewById(R.id.rvCertificate); final RecyclerView rvCertificate = dview.findViewById(R.id.rvCertificate);
final ProgressBar pbWait = dview.findViewById(R.id.pbWait); final ProgressBar pbWait = dview.findViewById(R.id.pbWait);

@ -163,6 +163,7 @@ import java.util.Properties;
import javax.mail.FolderClosedException; import javax.mail.FolderClosedException;
import javax.mail.Session; import javax.mail.Session;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMessage;
import static android.app.Activity.RESULT_OK; import static android.app.Activity.RESULT_OK;
@ -4391,6 +4392,11 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
String email = Helper.getAltSubjectName(cert); String email = Helper.getAltSubjectName(cert);
EntityCertificate record = db.certificate().getCertificate(fingerprint, email); EntityCertificate record = db.certificate().getCertificate(fingerprint, email);
String sender = null;
if (message.from != null && message.from.length == 1)
sender = ((InternetAddress) message.from[0]).getAddress();
args.putString("sender", sender);
args.putString("fingerprint", fingerprint); args.putString("fingerprint", fingerprint);
args.putString("email", email); args.putString("email", email);
args.putString("subject", Helper.getSubject(cert)); args.putString("subject", Helper.getSubject(cert));
@ -4515,49 +4521,72 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
@Override @Override
protected void onExecuted(final Bundle args, Boolean valid) { protected void onExecuted(final Bundle args, Boolean valid) {
int type = args.getInt("type"); int type = args.getInt("type");
if (EntityMessage.SMIME_SIGNONLY.equals(type)) if (EntityMessage.SMIME_SIGNONLY.equals(type)) {
String sender = args.getString("sender");
String fingerprint = args.getString("fingerprint");
String email = args.getString("email");
String subject = args.getString("subject");
byte[] encoded = args.getByteArray("encoded");
boolean known = args.getBoolean("known");
boolean match = Objects.equals(sender, email);
if (valid == null || !valid) if (valid == null || !valid)
Snackbar.make(view, R.string.title_signature_invalid, Snackbar.LENGTH_LONG).show(); Snackbar.make(view, R.string.title_signature_invalid, Snackbar.LENGTH_LONG).show();
else if (args.getBoolean("known")) else if (known && match)
Snackbar.make(view, R.string.title_signature_valid, Snackbar.LENGTH_LONG).show(); Snackbar.make(view, R.string.title_signature_valid, Snackbar.LENGTH_LONG).show();
else { else {
new AlertDialog.Builder(getContext()) LayoutInflater inflator = LayoutInflater.from(getContext());
.setTitle(R.string.title_signature_valid) View dview = inflator.inflate(R.layout.dialog_certificate, null);
.setMessage(args.getString("email") + ": " + args.getString("subject")) TextView tvSender = dview.findViewById(R.id.tvSender);
.setPositiveButton(R.string.title_signature_store, new DialogInterface.OnClickListener() { TextView tvEmail = dview.findViewById(R.id.tvEmail);
@Override TextView tvEmailInvalid = dview.findViewById(R.id.tvEmailInvalid);
public void onClick(DialogInterface dialog, int which) { TextView tvSubject = dview.findViewById(R.id.tvSubject);
new SimpleTask<Void>() {
@Override tvSender.setText(sender);
protected Void onExecute(Context context, Bundle args) throws Throwable { tvEmail.setText(email);
long id = args.getLong("id"); tvEmailInvalid.setVisibility(match ? View.GONE : View.VISIBLE);
tvSubject.setText(subject);
DB db = DB.getInstance(context);
AlertDialog.Builder builder = new AlertDialog.Builder(getContext())
.setView(dview)
.setNegativeButton(android.R.string.cancel, null);
if (!TextUtils.isEmpty(sender) && !known)
builder.setPositiveButton(R.string.title_signature_store, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) throws Throwable {
long id = args.getLong("id");
DB db = DB.getInstance(context);
EntityMessage message = db.message().getMessage(id);
if (message == null)
return null;
EntityMessage message = db.message().getMessage(id); EntityCertificate record = new EntityCertificate();
if (message == null) record.fingerprint = fingerprint;
return null; record.email = email;
record.subject = subject;
record.setEncoded(encoded);
record.id = db.certificate().insertCertificate(record);
EntityCertificate record = new EntityCertificate(); return null;
record.fingerprint = args.getString("fingerprint"); }
record.email = args.getString("email");
record.subject = args.getString("subject");
record.setEncoded(args.getByteArray("encoded"));
record.id = db.certificate().insertCertificate(record);
return null; @Override
} protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(FragmentMessages.this, args, "certificate:store");
}
});
@Override builder.show();
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(FragmentMessages.this, args, "certificate:store");
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
} }
}
} }
@Override @Override

@ -0,0 +1,89 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="24dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tvCaption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_signature_valid"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tvSenderTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="@string/title_signature_sender"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvCaption" />
<TextView
android:id="@+id/tvSender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test@example.com"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvSenderTitle" />
<TextView
android:id="@+id/tvEmailTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="@string/title_signature_email"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvSender" />
<TextView
android:id="@+id/tvEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test@example.com"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvEmailTitle" />
<TextView
android:id="@+id/tvEmailInvalid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="@string/title_signature_mismatch"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?attr/colorWarning"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvEmail" />
<TextView
android:id="@+id/tvSubjectTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="@string/title_signature_subject"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvEmailInvalid" />
<TextView
android:id="@+id/tvSubject"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CN=test@example.com"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvSubjectTitle" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>

@ -709,6 +709,10 @@
<string name="title_signature_valid">Message signature valid</string> <string name="title_signature_valid">Message signature valid</string>
<string name="title_signature_unconfirmed">Message signature valid but not confirmed</string> <string name="title_signature_unconfirmed">Message signature valid but not confirmed</string>
<string name="title_signature_invalid">Message signature invalid</string> <string name="title_signature_invalid">Message signature invalid</string>
<string name="title_signature_sender">Sender\'s address</string>
<string name="title_signature_email">Signature\'s address</string>
<string name="title_signature_mismatch">The email address of the sender and signature do not match</string>
<string name="title_signature_subject">Subject</string>
<string name="title_signature_store">Store</string> <string name="title_signature_store">Store</string>
<string name="title_search">Search</string> <string name="title_search">Search</string>

Loading…
Cancel
Save