Fixed S/MIME canonicalization

pull/213/head
M66B 2 years ago
parent 2dc37e916d
commit 68cd4fea28

@ -3836,7 +3836,7 @@ public class FragmentCompose extends FragmentBase {
bpContent.setContent(imessage.getContent(), imessage.getContentType()); bpContent.setContent(imessage.getContent(), imessage.getContentType());
try (OutputStream out = new MessageHelper.CanonicalizingStream( try (OutputStream out = new MessageHelper.CanonicalizingStream(
new BufferedOutputStream(new FileOutputStream(input)))) { new BufferedOutputStream(new FileOutputStream(input)), EntityAttachment.PGP_CONTENT, null)) {
bpContent.writeTo(out); bpContent.writeTo(out);
} }
} else { } else {
@ -4250,7 +4250,7 @@ public class FragmentCompose extends FragmentBase {
// Build content // Build content
File sinput = new File(tmp, draft.id + ".smime_sign"); File sinput = new File(tmp, draft.id + ".smime_sign");
try (OutputStream os = new MessageHelper.CanonicalizingStream( try (OutputStream os = new MessageHelper.CanonicalizingStream(
new BufferedOutputStream(new FileOutputStream(sinput)))) { new BufferedOutputStream(new FileOutputStream(sinput)), EntityAttachment.SMIME_CONTENT, null)) {
bpContent.writeTo(os); bpContent.writeTo(os);
} }

@ -4101,7 +4101,7 @@ public class MessageHelper {
throw new ParseException("Signed boundary missing"); throw new ParseException("Signed boundary missing");
File file = local.getFile(context); File file = local.getFile(context);
try (OutputStream os = new BufferedOutputStream(new CanonicalizingStream(new FileOutputStream(file), boundary))) { try (OutputStream os = new BufferedOutputStream(new CanonicalizingStream(new FileOutputStream(file), apart.encrypt, boundary))) {
apart.part.writeTo(os); apart.part.writeTo(os);
} }
@ -5762,6 +5762,7 @@ public class MessageHelper {
static class CanonicalizingStream extends FilterOutputStream { static class CanonicalizingStream extends FilterOutputStream {
private OutputStream os; private OutputStream os;
private int content;
private String boundary; private String boundary;
private int boundaries = 0; private int boundaries = 0;
@ -5773,15 +5774,10 @@ public class MessageHelper {
// PGP: https://datatracker.ietf.org/doc/html/rfc3156#section-5 // PGP: https://datatracker.ietf.org/doc/html/rfc3156#section-5
// S/MIME: https://datatracker.ietf.org/doc/html/rfc8551#section-3.1.1 // S/MIME: https://datatracker.ietf.org/doc/html/rfc8551#section-3.1.1
public CanonicalizingStream(OutputStream out) { public CanonicalizingStream(OutputStream out, int content, String boundary) {
super(out);
this.os = out;
this.boundary = null;
}
public CanonicalizingStream(OutputStream out, String boundary) {
super(out); super(out);
this.os = out; this.os = out;
this.content = content;
this.boundary = "--" + boundary; this.boundary = "--" + boundary;
} }
@ -5842,7 +5838,8 @@ public class MessageHelper {
return false; return false;
} }
line = line.replaceAll(" +$", ""); if (EntityAttachment.PGP_CONTENT.equals(content) || boundary == null)
line = line.replaceAll(" +$", "");
os.write(line.getBytes(StandardCharsets.ISO_8859_1)); os.write(line.getBytes(StandardCharsets.ISO_8859_1));

Loading…
Cancel
Save