LCOV - code coverage report
Current view: top level - src - letsencrypt.c (source / functions) Hit Total Coverage
Test: deployctl-0.3.15.2.96a2d Code Coverage Lines: 24 32 75.0 %
Date: 2018-06-22 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :   letsencrypt.c
       3             :   Created by Danny Goossen, Gioxa Ltd on 22/3/17.
       4             : 
       5             : MIT License
       6             : 
       7             : Copyright (c) 2017 deployctl, Gioxa Ltd.
       8             : 
       9             : Permission is hereby granted, free of charge, to any person obtaining a copy
      10             : of this software and associated documentation files (the "Software"), to deal
      11             : in the Software without restriction, including without limitation the rights
      12             : to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
      13             : copies of the Software, and to permit persons to whom the Software is
      14             : furnished to do so, subject to the following conditions:
      15             : 
      16             : The above copyright notice and this permission notice shall be included in all
      17             : copies or substantial portions of the Software.
      18             : 
      19             : THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      20             : IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      21             : FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      22             : AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      23             : LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      24             : OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
      25             : SOFTWARE.
      26             : 
      27             : */
      28             : 
      29             : #include "deployd.h"
      30             : 
      31             : /*----------------------------------------------------------------------------------
      32             :  * letsencrypt the DEPLOY_DOMAIN with GITLAB_USER_EMAIL
      33             :  * exec /bin/sh certbot .....
      34             :  * returns 0 on success
      35             :  *-----------------------------------------------------------------------------------*/
      36           2 : int letsencrypt(void * opaque, char * domain,char * email)
      37             : {
      38           2 :    int exitcode=0;
      39           2 :    struct trace_Struct *trace=((data_exchange_t *)opaque)->trace;
      40             :    char command[4096]; // temporary string
      41             :    char dir[1024];
      42             : 
      43           2 :    ((data_exchange_t *)opaque)->needenvp=0;
      44           2 :    sprintf((char *)dir,"/opt/deploy/.acme.sh/%s/fullchain.cer",domain);
      45           2 :         debug("check %s\n",dir );
      46           2 :    if( access( dir, F_OK ) == -1 )
      47             :    {
      48           2 :       const char * testpref=((data_exchange_t *)opaque)->parameters->testprefix;
      49           2 :       int snres=snprintf((char *)command,4096,"%s/opt/deploy/.acme.sh/acme.sh --issue --keylength 4096 --home %s/opt/deploy/.acme.sh -w %s/opt/deploy/var -d %s",testpref,testpref,testpref,domain); //--email %s
      50           2 :       if (snres>=4096)
      51             :       {
      52           0 :          Write_dyn_trace(trace, red,"ERROR: command exeeds max length\n");
      53           0 :          exitcode=1;
      54           0 :          return(exitcode);
      55             :       }
      56           2 :       Write_dyn_trace(trace, none,"+ %s \n",command);
      57           2 :       update_details(trace);
      58           2 :       debug("cmd: %s\n",command);
      59           2 :       ((data_exchange_t *)opaque)->shellcommand=command;
      60           2 :       exitcode=exec_color(opaque);
      61           2 :       if (exitcode) {debug("ERROR: Failed to create certificates\n");}
      62             :       // check if certs
      63           2 :       sprintf((char *)dir,"%s/opt/deploy/.acme.sh/%s/fullchain.cer",((data_exchange_t *)opaque)->parameters->testprefix ,domain);
      64           2 :       if (!exitcode && access( dir, F_OK ) == -1 )
      65             :       {
      66           1 :          debug("ERROR: certificate missing\n");
      67           1 :          Write_dyn_trace(trace, red,"ERROR: certificate missing\n");
      68           1 :          exitcode=1;
      69             :       }
      70           2 :       sprintf((char *)dir,"%s/opt/deploy/.acme.sh/%s/%s.key",((data_exchange_t *)opaque)->parameters->testprefix,domain,domain);
      71           2 :       if (!exitcode && access( dir, F_OK ) == -1 )
      72             :       {
      73           0 :          debug("ERROR: priv key missing\n");
      74           0 :          Write_dyn_trace(trace, red,"ERROR: priv key missing\n");
      75           0 :          exitcode=1;
      76             :       }
      77             : 
      78             :    }else
      79             :    {
      80           0 :       Write_dyn_trace_pad(trace, none,75,"+ SSL config already exists...");
      81           0 :    Write_dyn_trace(trace, green,"[OK]\n");
      82             :    }
      83           2 :    return(exitcode);
      84             : }

Generated by: LCOV version 1.10