<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:Wingdings;
panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
{mso-style-priority:34;
margin-top:0in;
margin-right:0in;
margin-bottom:0in;
margin-left:.5in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Arial",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;
mso-fareast-language:EN-US;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
/* List Definitions */
@list l0
{mso-list-id:1569918033;
mso-list-type:hybrid;
mso-list-template-ids:1034159458 134807567 134807555 134807557 134807553 134807555 134807557 134807553 134807555 134807557;}
@list l0:level1
{mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;}
@list l0:level2
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;
font-family:"Courier New";}
@list l0:level3
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;
font-family:Wingdings;}
@list l0:level4
{mso-level-number-format:bullet;
mso-level-text:\F0B7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;
font-family:Symbol;}
@list l0:level5
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;
font-family:"Courier New";}
@list l0:level6
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;
font-family:Wingdings;}
@list l0:level7
{mso-level-number-format:bullet;
mso-level-text:\F0B7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;
font-family:Symbol;}
@list l0:level8
{mso-level-number-format:bullet;
mso-level-text:o;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;
font-family:"Courier New";}
@list l0:level9
{mso-level-number-format:bullet;
mso-level-text:\F0A7;
mso-level-tab-stop:none;
mso-level-number-position:left;
text-indent:-.25in;
font-family:Wingdings;}
ol
{margin-bottom:0in;}
ul
{margin-bottom:0in;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-family:"Arial",sans-serif">Hi,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial",sans-serif">I am trying to implement a client server program over SSL through systemd.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial",sans-serif">Here I have a TCP systemd socket (listening on a predefined port) and its associated service.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial",sans-serif">systemd socket file:-<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""># cat /usr/lib/systemd/system/test_ssl.socket<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">[Unit]<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">Description=Test socket<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">[Socket]<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">ListenStream=2000<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">Accept=true<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">MaxConnections=900<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">[Install]<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">WantedBy=sockets.target<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial",sans-serif">systemd service file:-<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""># cat /usr/lib/systemd/system/test_ssl@.service<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">[Unit]<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">Description= Test Service<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">Requires=test_ssl.socket<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">[Service]<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">ExecStart=/home/SSL/server
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">StandardInput=socket<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">KillMode=process<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">[Install]<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">WantedBy=multi-user.target<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal">The service file invoke the binary /home/SSL/server.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Here is it a very simple client server program, where<o:p></o:p></p>
<p class="MsoListParagraph" style="text-indent:-.25in;mso-list:l0 level1 lfo1"><![if !supportLists]><span style="mso-list:Ignore">1.<span style="font:7.0pt "Times New Roman"">
</span></span><![endif]>Server binds and listens on a port number.<o:p></o:p></p>
<p class="MsoListParagraph" style="text-indent:-.25in;mso-list:l0 level1 lfo1"><![if !supportLists]><span style="mso-list:Ignore">2.<span style="font:7.0pt "Times New Roman"">
</span></span><![endif]>Client first connects to server with normal connect (server will do accept)<o:p></o:p></p>
<p class="MsoListParagraph" style="text-indent:-.25in;mso-list:l0 level1 lfo1"><![if !supportLists]><span style="mso-list:Ignore">3.<span style="font:7.0pt "Times New Roman"">
</span></span><![endif]>Once it gets the fd, client does the SSL_connect over same connection. (server will do SSL_accept)<o:p></o:p></p>
<p class="MsoListParagraph" style="text-indent:-.25in;mso-list:l0 level1 lfo1"><![if !supportLists]><span style="mso-list:Ignore">4.<span style="font:7.0pt "Times New Roman"">
</span></span><![endif]>After that it will be SSL_read & SSL_write.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Once, I start the systemd socket I can see the systemd starts listening on port 2000.<o:p></o:p></p>
<p class="MsoNormal"><span style="font-family:"Courier New""># systemctl start test_ssl.socket<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""># netstat -an | grep 2000<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">tcp6 0 0 :::2000 :::* LISTEN<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal">Post than when executing client, SSL_conect fails.<o:p></o:p></p>
<p class="MsoNormal"><span style="font-family:"Courier New""># ./client localhost 2000<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">OpenConnection succedeed. << normal connect succeeds.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">SSL_connect failed.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">140691172779952:error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number:s3_pkt.c:365:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><o:p></o:p></span></p>
<p class="MsoNormal">Here client is able to do normal connect, post that SSL_connect fails.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">This client server program works well outside of systemd.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Do I need to add some extra steps to get this working?<o:p></o:p></p>
<p class="MsoNormal">Any help or reference would be appreciated.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks & Regards,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-family:"Courier New""><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Arial",sans-serif"><o:p> </o:p></span></p>
</div>
</body>
</html>