Skip to content

Commit 4e20cff

Browse files
authored
Merge pull request #60 from wolfgangkarall/tls-chain
Add support for --tls-chain
2 parents cebcebb + 31dec62 commit 4e20cff

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

doc/base.pod

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ Tell Swaks to use the system-default method of determining the current user's us
483483

484484
These are options related to encrypting the transaction. These have been tested and confirmed to work with all three transport methods. The L<Net::SSLeay> module is used to perform encryption when it is requested. If this module is not loadable Swaks will either ignore the TLS request or error out, depending on whether the request was optional. STARTTLS is defined as an extension in the ESMTP protocol and will be unavailable if C<--protocol> is set to a variation of plain SMTP. Because it is not defined in the protocol itself, C<--tls-on-connect> is available for any protocol type if the target supports it.
485485

486-
A local certificate is not required for a TLS connection to be negotiated. However, some servers use client certificate checking to verify that the client is allowed to connect. Swaks can be told to use a specific local certificate using the C<--tls-cert> and C<--tls-key> options.
486+
A local certificate is not required for a TLS connection to be negotiated. However, some servers use client certificate checking to verify that the client is allowed to connect. Swaks can be told to use a specific local certificate using the C<--tls-cert> and C<--tls-key> options, and optionally to use a certificate chain using the C<--tls-chain> option.
487487

488488
=over 4
489489

@@ -545,6 +545,10 @@ Provide a path to a file containing the local certificate Swaks should use if TL
545545

546546
Provide a path to a file containing the local private key Swaks should use if TLS is negotiated. The file path argument is required. As currently implemented the certificate in the file must be in PEM format. Contact the author if there's a compelling need for ASN1. If this option is set, C<--tls-cert> is also required. (Arg-Required)
547547

548+
=item --tls-chain <chain-file>
549+
550+
Provide a path to a file containing the local certificate chain (starting with the certificate followed by the necessary intermediate CA certificates) Swaks should use if TLS is negotiated. The file path argument is required. As currently implemented the certificate in the file must be in PEM format. Contact the author if there's a compelling need for ASN1. If this option is set, C<--tls-cert> and C<--tls-key> are also required. (Arg-Required)
551+
548552
=item --tls-get-peer-cert [<output-file>]
549553

550554
Get a copy of the TLS peer's certificate. If no argument is given, it will be displayed to C<STDOUT>. If an argument is given it is assumed to be a filesystem path specifying where the certificate should be written. The saved certificate can then be examined using standard tools such as the openssl command. If a file is specified its contents will be overwritten. (Arg-Optional)

swaks

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,13 @@ sub start_tls {
536536
}
537537
}
538538
if ($G::tls_cert && $G::tls_key) {
539+
if ($G::tls_chain) {
540+
if (!Net::SSLeay::CTX_use_certificate_chain_file($t{con}, $G::tls_chain)) {
541+
$t{res} = "Unable to set chain file $G::tls_chain to SSL CTX: "
542+
. Net::SSLeay::ERR_error_string(Net::SSLeay::ERR_get_error());
543+
return(0);
544+
}
545+
}
539546
if (!Net::SSLeay::CTX_use_certificate_file($t{con}, $G::tls_cert, &Net::SSLeay::FILETYPE_PEM)) {
540547
$t{res} = "Unable to add cert file $G::tls_cert to SSL CTX: "
541548
. Net::SSLeay::ERR_error_string(Net::SSLeay::ERR_get_error());
@@ -1975,6 +1982,10 @@ sub get_option_struct {
19751982
{ opts => ['tls-key'], suffix => '=s',
19761983
cfgs => OP_ARG_REQ,
19771984
okey => 'tls_key', type => 'scalar', },
1985+
# local chain to present to server
1986+
{ opts => ['tls-chain'], suffix => '=s',
1987+
cfgs => OP_ARG_REQ,
1988+
okey => 'tls_chain', type => 'scalar', },
19781989
# tls protocol to use
19791990
{ opts => ['tls-protocol', 'tlsp'], suffix => '=s',
19801991
cfgs => OP_ARG_REQ,
@@ -3362,11 +3373,16 @@ sub process_args {
33623373
$G::tls_sni_hostname = get_arg('tls_sni_hostname', $o);
33633374
$G::tls_cipher = get_arg('tls_cipher', $o);
33643375
$G::tls_cert = get_arg('tls_cert', $o);
3376+
$G::tls_chain = get_arg('tls_chain', $o);
33653377
$G::tls_key = get_arg('tls_key', $o);
33663378
if (($G::tls_cert || $G::tls_key) && !($G::tls_cert && $G::tls_key)) {
33673379
ptrans(12, "--tls-cert and --tls-key require each other. Exiting");
33683380
exit(1);
33693381
}
3382+
if (($G::tls_chain) && !($G::tls_cert && $G::tls_key)) {
3383+
ptrans(12, "--tls-chain requires also --tls-cert and --tls-key. Exiting");
3384+
exit(1);
3385+
}
33703386
if (($G::tls_ca_path = get_arg('tls_ca_path', $o)) && !-f $G::tls_ca_path && !-d $G::tls_ca_path) {
33713387
ptrans(12, "--tls-ca-path: $G::tls_ca_path is not a valid file or directory. Exiting.");
33723388
exit(1);
@@ -3892,6 +3908,7 @@ sub get_running_state {
38923908
" peer cert = $G::tls_get_peer_cert",
38933909
" local cert = $G::tls_cert",
38943910
" local key = $G::tls_key",
3911+
" local chain = $G::tls_chain",
38953912
" local cipher list = $G::tls_cipher",
38963913
" ca path = $G::tls_ca_path",
38973914
" sni string = $G::tls_sni_hostname",

0 commit comments

Comments
 (0)