-
-
Notifications
You must be signed in to change notification settings - Fork 189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
support PGP #963
Comments
I am trying to implement sth. by calling // define content
let content: Vec<u8> = Vec::from("Hello World!".as_bytes());
let single_part = lettre::message::SinglePartBuilder::new()
.content_type(lettre::message::header::ContentType::TEXT_PLAIN)
.header(lettre::message::header::ContentTransferEncoding::Base64)
.body(content.clone());
// create signature
let mut ctx = gpgme::Context::from_protocol(gpgme::Protocol::OpenPgp).unwrap();
ctx.set_armor(true);
let key = ctx
.get_secret_key("2F41D7EE4EC511199A5468D645ED94248268D858")
.unwrap();
ctx.add_signer(&key).unwrap();
let mut sign_output: Vec<u8> = Vec::new();
let mut sign_input: Vec<u8> =
// Vec::from(single_part.formatted()); // base64-encoded content plus headers
// Vec::from(single_part.raw_body()); // base-64-encoded content
content.clone(); // raw content
println!(
"sign_input: >{}<",
String::from_utf8(sign_input.clone()).unwrap()
);
let sign_result = ctx
.sign(gpgme::SignMode::Detached, &mut sign_input, &mut sign_output)
.unwrap();
let hash_alg = sign_result
.new_signatures()
.next()
.unwrap()
.hash_algorithm();
// create message
let message = lettre::message::MessageBuilder::new()
.from(lettre::message::Mailbox::new(
Some("Dummy".to_string()),
lettre::Address::new("dummy", "example.com").unwrap(),
))
.to(lettre::message::Mailbox::new(
Some("Ilka".to_string()),
lettre::Address::new("ilka", "example.com").unwrap(),
))
.multipart(
lettre::message::MultiPart::signed(
"application/pgp-signature".to_string(),
format!("pgp-{}", hash_alg.to_string().to_lowercase()),
)
.singlepart(single_part)
.singlepart(
lettre::message::Attachment::new("signature.asc".to_string()).body(
sign_output,
lettre::message::header::ContentType::from_str("application/pgp-signature")
.unwrap(),
),
),
)
.unwrap(); The resulting message looks promising (this is the "source code" of the message received with Thunderbird from the target mail service, I removed the signature content):
Unfortunately, the resulting signature does not seem to be valid. Regardless which I also tried GPGME_SIG_MODE_CLEAR which works fine. However, this is not recommended and I could not get it to work with attachments. |
I got it working after I read through RFC 3156:
minimum working example: https://gitlab.com/islabtech/examples/rust-pgp-signed-mail |
Is your feature request related to a problem? Please describe.
I want to send PGP-signed / PGP-encrypted emails. GnuPG is already set up and I use it with my main mail client. Now, I want to use it with
lettre
.Describe the solution you'd like
Describe alternatives you've considered
read into PGP specification, call
gnupg
myself, create the message body myself and hand the custom message body tolettre
Additional context
The text was updated successfully, but these errors were encountered: