S/MIME Bagian 2: Ditandatangani, Disegel, dan Dikirim melalui SparkPost

S/MIME Bagian 2: Ditandatangani, Disegel, dan Dikirim melalui SparkPost

S/MIME Bagian 2: Ditandatangani, Disegel, dan Dikirim melalui SparkPost

Dec 31, 2018

Diterbitkan oleh

Diterbitkan oleh

Bird

Bird

Kategori:

Kategori:

Email

Email

Ready to see Bird
in action?

Ready to see Bird
in action?

S/MIME Part 2: Signed, Sealed, and Delivered through SparkPost

Dalam angsuran ini, kami akan:

  • Instal beberapa alat bantu baris perintah sederhana untuk menandatangani dan mengenkripsi email

  • Dapatkan kunci pengirim / sertifikat untuk penandatanganan

  • Kirim pesan yang ditandatangani melalui SparkPost, dan lihat pesan yang diterima

  • Opsional, dapatkan sertifikat penerima Anda untuk enkripsi

  • Kirim pesan yang ditandatangani dan dienkripsi melalui SparkPost, dan lihat pesan yang diterima

  • Cobalah alat bantu mandiri yang praktis "mimeshow" untuk melihat bagian dalam file email.

Oke - mari kita mulai!

1. Instal alat

The demonstration tools are in Github di sini, complete with installation instructions. You might notice the “build passing” logo – Travis and pytest automatically check the build status. Note these tools are not officially supported by SparkPost, but I’ve tried to make them robust and easy to use.

If you have some acquaintance with Python and pip, installation should feel pretty familiar. The Pipfile takes care of the external dependencies automatically for you. Once it’s done, you can check everything’s installed by running

./sparkpostSMIME.py -h

Anda akan melihat teks bantuan yang ramah. Selanjutnya, kita perlu...

2. Dapatkan kunci pengirim / sertifikat untuk penandatanganan

Jika Anda sudah memiliki file kunci untuk identitas pengirim, Anda bisa langsung melanjutkan. Jika tidak, berikut ini ada dua opsi yang dapat dipilih:

a) Kunci uji/sertifikat yang ditandatangani sendiri (tidak berlaku secara eksternal)



If you’re just testing, you can make “self signed” certificates and keys for an email address using the command line tool openssl on Linux,  following a procedure such as yang ini. At the end of that process, you’ll have a smime.p12  file. Rename this file to match your sending identity, including the @ sign, for example, alice@example.com.p12 .

or

b) Kunci / sertifikat yang berlaku secara eksternal



If you want to get externally valid keys / certificates that enable you to sign, tdi sini’s a list of providers here. I found Comodo works well (free for non-commercial use), and it’s easier than the self-sign procedure above. Follow the sign-up process, receive your validation mail, and be sure to open the link in Firefox. Go to Firefox Preferences / Privasi and Security. Scroll to Certificates / View Certificates:


Select your certificate, and use the “Backup” option to save as a file in PKCS12 format (add the file extension .p12 to your filename) which carries the private key and the public certificate chain.


Berikan kata sandi untuk mengamankan file .p12:

Membuat file kunci publik (.crt) dan pribadi (.pem) yang terpisah

Apakah Anda menggunakan a) atau b), sekarang Anda akan memiliki file .p12 untuk identitas pengirim Anda. Ini adalah langkah maju yang besar - minum kopi sekarang!

Sekarang kita perlu membuat file kunci publik dan privat yang terpisah seperti ini - gantilah alamat email Anda dengan alamat email yang ada pada contoh. (Mac OSX dan Linux):

openssl pkcs12 -in alice\@example.com.p12 -clcerts -nokeys -out alice\@example.com.crt openssl pkcs12 -in alice\@example.com.p12 -nocerts -nodes -out alice\@example.com.pem

You’ll need to enter the password you provided earlier. Note those backslashes \ are used to melarikan diri the @ sign – not separating the names of a directory path (that’s a forward-slash / on Mac OSX and Linux).

If you’re using Windows, there are openssl implementations available such as the MINGW64 one built into the Alat bantu baris perintah Git, but I found it tended to just lock up. You’ll probably find it easier and quicker to do this on Linux and then copy your files over. Those same Git tools for Windows come with a nice ssh client you can use to login to a Linux box, such as an Amazon EC2 instance.


2.1 Menandatangani pesan

Sudah ada kunci/sertifikat tiruan dan file sumber email di direktori tes untuk alice@example.com, sehingga Anda dapat memperoleh beberapa keluaran bahkan sebelum Anda memiliki kunci Anda sendiri. Cukup ketik yang berikut ini:

cd tests ../sparkpostSMIME.py example_email1.eml --sign

Dan kau akan mendapatkannya:

To: Bob <bob@example.com> From: Alice <alice@example.com> Subject: A message MIME-Version: 1.0 Content-Type: application/x-pkcs7-mime; smime-type=signed-data; name="smime.p7m" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="smime.p7m" MIIKXAYJKoZIhvcNAQcCoIIKTTCCCkkCAQExDzANBglghkgBZQMEAgEFADCCAQoGCSqGSIb3DQEH AaCB/ASB+VRvOiBCb2IgPGJvYkBleGFtcGxlLmNvbT4NCkZyb206IEFsaWNlIDxhbGljZUBleGFt : :

You can’t actually send emails from example.com via SparkPost unless you own that domain, so the next step is to use your own key and send a signed message from your own domain.


3. Mengirim pesan yang ditandatangani melalui SparkPost

Now let’s use a real sending domain, set up as per the SparkPost Panduan Pengguna Baru. We have the sender certificate and key files in the current directory:

steve@thetucks.com.crt steve@thetucks.com.pem

The file tests/declaration.eml is included in the project. It’s just a text file, so you can customize the From: address to suit your own sending domain and the To: address to suit your test recipient. The beginning of the file looks like this:

To: Bob <bob.lumreeker@gmail.com> From: Steve <steve@thetucks.com> Subject: Here is our declaration MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-GB When in the Course of human events it becomes necessary …


Tetapkan kunci API Anda:

export SPARKPOST_API_KEY=<<Put your API key here>>

Kirim email:

./sparkpostSMIME.py tests/declaration.eml --sign --send_api


Anda akan lihat:

Opened connection to https://api.sparkpost.com/api/v1 Sending tests/declaration.eml From: Steve <steve@thetucks.com> To: Bob  <bob.lumreeker@gmail.com> OK - in 1.15 seconds

Sekitar satu detik kemudian, email tersebut tiba di inbox milik Bob. Thunderbird menampilkannya dengan titik merah pada amplop, yang menunjukkan tanda tangan pengirim yang valid.

Sukses! Habiskan kopi Anda, Anda sudah berhasil. Jika Anda mengalami masalah, periksa alamat From: di file email Anda sudah sesuai dengan nama file .crt dan .pem.


4. Mengenkripsi pesan

Untuk mengenkripsi sebuah pesan, Anda memerlukan kunci publik penerima dalam bentuk sertifikat. Ini adalah file teks yang terlihat seperti ini:

Bag Attributes   friendlyName: s COMODO CA Limited ID #2   localKeyID: 32 84 AB 9C 56 5C 80 C6 89 4D 40 46 DD D4 7C 71 E8 CD ED C1 subject=/emailAddress=bob.lumreeker@gmail.com issuer=/C=GB/ST=Greater Manchester/L=Salford/O=COMODO CA Limited/CN=COMODO RSA Client Authentication and Secure Email CA -----BEGIN CERTIFICATE----- looks like random characters in here -----END CERTIFICATE-----

Ada sertifikat penerima tiruan untuk bob@example.com di direktori tes, sehingga Anda bisa berlatih dengannya sebelum memiliki sertifikat yang sebenarnya:

cd tests ../sparkpostSMIME.py example_email1.eml --sign --encrypt


Kau akan lihat:


To: Bob <bob@example.com> From: Alice <alice@example.com> Subject: A message MIME-Version: 1.0 Content-Type: application/pkcs7-mime; smime-type=enveloped-data; name=smime.p7m Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=smime.p7m MIIRwQYJKoZIhvcNAQcDoIIRsjCCEa4CAQAxggKlMIICoQIBADCBijCBhDELMAkG :

You’ll notice the length of output is quite a bit longer than with an terenkripsi message because it carries a lot of informasi tambahan as well as the scrambled message itself.


4.1 Mengirim pesan terenkripsi dan ditandatangani melalui SparkPost

Let’s send an encrypted message to a real email address. You can follow the same process as before (self-signed or a provider such as Comodo) to get a public key / certificate for your own recipient addresses. You only need the .crt file – the recipient does not ever need to give you their private key (.p12 and .pem files).

I have the file bob.lumreeker@gmail.com.crt for my intended recipient – matching the From: address in my file.

Inilah perintah untuk mengirim:

./sparkpostSMIME.py tests/declaration.eml --sign --encrypt --send_api


Oh, begitu:

Opened connection to https://api.sparkpost.com/api/v1 Sending tests/declaration.eml From: Steve <steve@thetucks.com> To: Bob <bob.lumreeker@gmail.com> OK - in 1.168 seconds

Email muncul di Thunderbird dengan ikon tanda tangan "titik merah" dan ikon terenkripsi "gembok".


You can send complex HTML-based email with links and images just as easily, such as the one shown in Part 1. Some clients such as Thunderbird ask for permission to display external links and images within encrypted S/MIME messages, but hanya ditandatangani messages display well in clients including Thunderbird and Gmail:


Perhatikan drop-down yang menunjukkan "Alamat email terverifikasi".


Further thoughts & things to be aware of

Alat ini mengambil pendekatan yang sangat sederhana untuk menarik kunci yang diperlukan - alat ini hanya mencari file bernama dalam direktori saat ini. Pengaturan yang lebih kompleks, seperti menyimpan semua kunci dalam database dapat dengan mudah ditambahkan, tetapi saya ingin kodenya sesederhana mungkin.

Anda dapat menyertakan penerima lain dengan Cc: dan Bcc: dan mereka akan dikirim; ini dapat berguna untuk tujuan pengarsipan. Pesan yang ditandatangani akan diterima dan dapat ditampilkan oleh penerima lain lengkap dengan tanda tangan. Alat ini menghilangkan header Bcc: dari pesan yang dikirim (seperti yang dilakukan oleh klien email desktop).

Untuk memastikan bahwa pesan yang melewati SparkPost tidak berubah (yang dapat merusak penandatanganan), alat ini menetapkan opsi API untuk pengiriman surat "transaksional", dengan pelacakan terbuka dan klik dinonaktifkan.

Jika Anda menggunakan enkripsi, ingatlah bahwa alat ini mengambil alamat tunggal To: untuk itu. Penerima lain dapat memecahkan kode isi pesan hanya jika mereka memiliki kunci pribadi penerima To:. Jika Anda hanya menggunakan penerima sekunder sebagai catatan pengiriman yang dilakukan, misalnya, hal ini tidak masalah.


Ditandatangani, disegel, dikirim... Aku milikmu

That’s our quick overview of how to sign, seal and deliver S/MIME messages through SparkPost. Quick reminder: the demo project is in Github here, I’ve tried to make it easy to install and use.


Fitur bonus: menampilkan bagian MIME dengan "mimeshow"

Internal file multipart MIME RFC822 cukup rumit untuk dibaca oleh manusia. Proyek ini menyertakan alat bantu mandiri untuk membuatnya lebih mudah, yang disebut mimeshow.


Ini mengambil semua file email yang Anda miliki (bukan hanya yang S/MIME) dan menunjukkan struktur internal. Berikut ini sebuah contoh:

./mimeshow.py testcases/img_and_attachment.eml


Kau akan lihat:



To Bob <bob.lumreeker@gmail.com>

From Steve <steve@thetucks.com> 

Subject Testing attachments etc 

MIME-Version 1.0

Content-Type multipart/mixed; boundary="------------7D48652042860D0098C65210"

Content-Language en-GB



 Content-Type multipart/alternative; boundary="------------58C0BF87598336550D70EB95" 



   Content-Type text/plain; charset=utf-8; format=flowed

   Content-Transfer-Encoding 7bit



   Content-Transfer-Encoding quoted-printable 

   Content-Type text/html; charset="utf-8"



 Content-Type application/pdf; name="sparkpost-datasheet-tam-technical-account-management.pdf" 

 Content-Transfer-Encoding base64

 Content-Disposition attachment; filename="sparkpost-datasheet-tam-technical-account-management.pdf"

You can also use as a filter to give a human-readable summary of sparkpostSMIME  output:

./sparkpostSMIME.py tests/declaration.eml --sign --encrypt | ./mimeshow.py


Kau akan lihat:

To Bob <bob.lumreeker@gmail.com> 

From Steve <steve@thetucks.com>

Subject Here is our declaration 

Content-Language en-GB

MIME-Version 1.0

Content-Type application/pkcs7-mime; smime-type=enveloped-data; name=smime.p7m

Content-Transfer-Encoding base64

Content-Disposition attachment; filename=smime.p7m


Akhirnya...

To recap – we’ve installed some simple command-line tools for signing and encrypting email (the Github repo is here, complete with installation instructions).


Kami mendapatkan kunci/sertifikat pengirim untuk penandatanganan, dan mengirimkan pesan yang telah ditandatangani melalui SparkPost. Kami mendapatkan sertifikat penerima untuk enkripsi, lalu mengirim pesan yang ditandatangani dan dienkripsi melalui SparkPost.


Terakhir, kami mencoba alat bantu mandiri "mimeshow" yang praktis untuk melihat bagian dalam file email.


Sekian dulu untuk saat ini! Sampai jumpa lagi!.

Your new standard in Marketing, Pay & Sales. It's Bird

The right message -> ke right person -> di right time.

By clicking "See Bird" you agree to Bird's Pemberitahuan Privasi.

Your new standard in Marketing, Pay & Sales. It's Bird

The right message -> ke right person -> di right time.

By clicking "See Bird" you agree to Bird's Pemberitahuan Privasi.