2003-07-23 12:12:24 -04:00
|
|
|
require 'openssl'
|
2007-12-24 02:31:23 -05:00
|
|
|
require 'optparse'
|
2003-07-23 12:12:24 -04:00
|
|
|
|
2007-12-24 02:31:23 -05:00
|
|
|
options = ARGV.getopts("c:k:r:")
|
2003-07-23 12:12:24 -04:00
|
|
|
|
2007-12-24 02:31:23 -05:00
|
|
|
cert_file = options["c"]
|
|
|
|
key_file = options["k"]
|
|
|
|
rcpt_file = options["r"]
|
2003-07-23 12:12:24 -04:00
|
|
|
|
2021-02-25 02:49:11 -05:00
|
|
|
cert = OpenSSL::X509::Certificate.new(File::read(cert_file))
|
|
|
|
key = OpenSSL::PKey::read(File::read(key_file))
|
2003-07-23 12:12:24 -04:00
|
|
|
|
|
|
|
data = "Content-Type: text/plain\r\n"
|
|
|
|
data << "\r\n"
|
|
|
|
data << "This is a clear-signed message.\r\n"
|
|
|
|
|
2021-02-25 02:49:11 -05:00
|
|
|
p7sig = OpenSSL::PKCS7::sign(cert, key, data, [], OpenSSL::PKCS7::DETACHED)
|
|
|
|
smime0 = OpenSSL::PKCS7::write_smime(p7sig)
|
2003-07-23 12:12:24 -04:00
|
|
|
|
2021-02-25 02:49:11 -05:00
|
|
|
rcpt = OpenSSL::X509::Certificate.new(File::read(rcpt_file))
|
|
|
|
p7enc = OpenSSL::PKCS7::encrypt([rcpt], smime0)
|
|
|
|
print OpenSSL::PKCS7::write_smime(p7enc)
|