Keeping certs in config file
I'd like to keep everything an openvpn client needs in one configuration file, so it's easy to move around. Included a working implementation, but I could rewrite it to work some other way to get it included in main openvpn distribution.
Currently it works like:
ca \
"---- BEGIN CERT .. \
etc. \
--- END CERT .."
I hardcoded it as max. 10240 bytes for now. Buffers can't be grown dynamically?
options.c +38 -6
@@ -1901,7 +1901,7 @@bool backslash = false;char in, out; -char parm[256 ]; +char parm[10240 ];unsigned int parm_len =0 ; do
@@ -2028,6 +2028,7 @@ struct env_set *es) {const int max_recursive_levels =10 ; +struct buffer full_line =alloc_buf (10240 );FILE *fp;int line_num;char line[256 ];
@@ -2044,16 +2045,47 @@while (fgets (line,sizeof (line), fp)) {char *p[MAX_PARMS ]; -CLEAR (p); +int len =strlen (line); + +if (len >0 && line[len-1 ] =='\n' ) + len--; +if (len >0 && line[len-1 ] =='\r' ) + len--; + ++line_num; -if (parse_line (line, p,SIZE (p), file, line_num, msglevel, &options->gc)) +if (len >0 && line[len-1 ] =='\\' ) { -if (strlen (p[0 ]) >=3 && !strncmp (p[0 ],"--" ,2 )) - p[0 ] +=2 ; -add_option (options,0 , p, file, line_num, level, msglevel, permission_mask, option_types_found, es); +/* multiline value */ +if (!buf_write (&full_line, line, len -1 ) || + !buf_write (&full_line,"\n" ,1 )) +msg (M_ERR ,"In %s:%d: Multiline value is too large" , top_file, top_line); + } +else + { +char *pline; + +CLEAR (p); +if (BLEN (&full_line) ==0 ) + pline = line; +else + { +if (!buf_write (&full_line, line, len) || + !buf_write (&full_line,"\n" ,2 )) +msg (M_ERR ,"In %s:%d: Multiline value is too large" , top_file, top_line); + pline =BSTR (&full_line); + } + +if (parse_line (pline, p,SIZE (p), file, line_num, msglevel, &options->gc)) + { +if (strlen (p[0 ]) >=3 && !strncmp (p[0 ],"--" ,2 )) + p[0 ] +=2 ; +add_option (options,0 , p, file, line_num, level, msglevel, permission_mask, option_types_found, es); + } +buf_init (&full_line,0 ); } }fclose (fp); +free_buf (&full_line); }void
ssl.c +74 -19
112 lines not on this page · raw message