Skip to content

Commit

Permalink
Separate host and port into separate strings
Browse files Browse the repository at this point in the history
Store host and port in separate strings internally and get rid of the
[host]:port representation where separate host and port would be
cleaner.  This includes the following user-visible changes:

-   Generated filenames that contain host and port, such as by -S and
    -F %d and %s, now use a host,port format instead of [host]:port.

-   Connect log now uses separate fields for host and port.

Issue:		#69 #74
Reported by:	Adam Jacob Muller
  • Loading branch information
droe committed Mar 15, 2015
1 parent a027fb6 commit 914360e
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 88 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
@@ -1,6 +1,9 @@

### SSLsplit develop

- Filenames generated by -S and -F %d and %s changed from [host]:port to
host,port format in order to be NTFS clean (partially fixes issue #69).
- Connect log format: host and port are now separate fields (issues #69 #74).
- Fix loading of certificate chains with OpenSSL 1.0.2 (issue #79).
- Removed the non-standard word "unmodified" from the 2-clause BSD license.
- Add options -w and -W to write generated leaf key, original and forged
Expand Down
42 changes: 29 additions & 13 deletions log.c
Expand Up @@ -335,7 +335,9 @@ log_content_split_pathspec(const char *path, char **lhs, char **rhs)
*/
#define PATH_BUF_INC 1024
static char * MALLOC NONNULL(1,2,3)
log_content_format_pathspec(const char *logspec, char *srcaddr, char *dstaddr,
log_content_format_pathspec(const char *logspec,
char *srchost, char *srcport,
char *dsthost, char *dstport,
char *exec_path, char *user, char *group)
{
/* set up buffer to hold our generated file path */
Expand All @@ -357,6 +359,7 @@ log_content_format_pathspec(const char *logspec, char *srcaddr, char *dstaddr,

const char iso8601[] = "%Y%m%dT%H%M%SZ";
char timebuf[24]; /* sized for ISO 8601 format */
char addrbuf[INET6_ADDRSTRLEN + 8]; /* [host]:port */

/* parse the format string and generate the next path element */
switch (*p) {
Expand All @@ -375,12 +378,22 @@ log_content_format_pathspec(const char *logspec, char *srcaddr, char *dstaddr,
elem_len = 1;
break;
case 'd':
elem = dstaddr;
elem_len = strlen(dstaddr);
if (snprintf(addrbuf, sizeof(addrbuf),
"%s,%s", dsthost, dstport) < 0) {
addrbuf[0] = '?';
addrbuf[1] = '\0';
}
elem = addrbuf;
elem_len = strlen(addrbuf);
break;
case 's':
elem = srcaddr;
elem_len = strlen(srcaddr);
if (snprintf(addrbuf, sizeof(addrbuf),
"%s,%s", srchost, srcport) < 0) {
addrbuf[0] = '?';
addrbuf[1] = '\0';
}
elem = addrbuf;
elem_len = strlen(addrbuf);
break;
case 'x':
if (exec_path) {
Expand Down Expand Up @@ -456,7 +469,8 @@ log_content_format_pathspec(const char *logspec, char *srcaddr, char *dstaddr,

int
log_content_open(log_content_ctx_t **pctx, opts_t *opts,
char *srcaddr, char *dstaddr,
char *srchost, char *srcport,
char *dsthost, char *dstport,
char *exec_path, char *user, char *group)
{
log_content_ctx_t *ctx;
Expand Down Expand Up @@ -489,8 +503,9 @@ log_content_open(log_content_ctx_t **pctx, opts_t *opts,
strerror(errno), errno);
goto errout;
}
if (asprintf(&ctx->u.dir.filename, "%s/%s-%s-%s.log",
opts->contentlog, timebuf, srcaddr, dstaddr) < 0) {
if (asprintf(&ctx->u.dir.filename, "%s/%s-%s,%s-%s,%s.log",
opts->contentlog, timebuf, srchost, srcport,
dsthost, dstport) < 0) {
log_err_printf("Failed to format filename: %s (%i)\n",
strerror(errno), errno);
goto errout;
Expand All @@ -499,19 +514,20 @@ log_content_open(log_content_ctx_t **pctx, opts_t *opts,
/* per-connection-file content log with logspec (-F) */
ctx->u.spec.filename = log_content_format_pathspec(
opts->contentlog,
srcaddr, dstaddr,
srchost, srcport,
dsthost, dstport,
exec_path, user, group);
if (!ctx->u.spec.filename) {
goto errout;
}
} else {
/* single-file content log (-L) */
if (asprintf(&ctx->u.file.header_req, "%s -> %s",
srcaddr, dstaddr) < 0) {
if (asprintf(&ctx->u.file.header_req, "[%s]:%s -> [%s]:%s",
srchost, srcport, dsthost, dstport) < 0) {
goto errout;
}
if (asprintf(&ctx->u.file.header_resp, "%s -> %s",
dstaddr, srcaddr) < 0) {
if (asprintf(&ctx->u.file.header_resp, "[%s]:%s -> [%s]:%s",
dsthost, dstport, srchost, srcport) < 0) {
free(ctx->u.file.header_req);
goto errout;
}
Expand Down
4 changes: 2 additions & 2 deletions log.h
Expand Up @@ -57,8 +57,8 @@ extern logger_t *connect_log;
logger_write_freebuf(connect_log, NULL, 0, (buf), (sz))

typedef struct log_content_ctx log_content_ctx_t;
int log_content_open(log_content_ctx_t **, opts_t *, char *, char *,
char *, char *, char *) NONNULL(1,2,3) WUNRES;
int log_content_open(log_content_ctx_t **, opts_t *, char *, char *, char *,
char *, char *, char *, char *) NONNULL(1,2,3) WUNRES;
int log_content_submit(log_content_ctx_t *, logbuf_t *, int)
NONNULL(1,2) WUNRES;
int log_content_close(log_content_ctx_t **) NONNULL(1) WUNRES;
Expand Down
44 changes: 32 additions & 12 deletions main.c
Expand Up @@ -153,8 +153,8 @@ main_usage(void)
" -S logdir content log: full data to separate files in dir (excludes -L/-F)\n"
" -F pathspec content log: full data to sep files with %% subst (excl. -L/-S):\n"
" %%T - initial connection time as an ISO 8601 UTC timestamp\n"
" %%d - dest address:port\n"
" %%s - source address:port\n"
" %%d - destination host and port\n"
" %%s - source host and port\n"
#ifdef HAVE_LOCAL_PROCINFO
" %%x - base name of local process (requires -i)\n"
" %%X - full path to local process (requires -i)\n"
Expand Down Expand Up @@ -810,14 +810,34 @@ main(int argc, char *argv[])
opts_proto_dbg_dump(opts);
log_dbg_printf("proxyspecs:\n");
for (proxyspec_t *spec = opts->spec; spec; spec = spec->next) {
char *lbuf, *cbuf = NULL;
lbuf = sys_sockaddr_str((struct sockaddr *)
&spec->listen_addr,
spec->listen_addrlen);
/* XXX refactor this into a proxyspec_str method */
char *lhbuf, *lpbuf;
char *cbuf = NULL;
if (sys_sockaddr_str((struct sockaddr *)
&spec->listen_addr,
spec->listen_addrlen,
&lhbuf, &lpbuf) != 0) {
fprintf(stderr, "%s: out of memory\n", argv0);
exit(EXIT_FAILURE);
}
if (spec->connect_addrlen) {
cbuf = sys_sockaddr_str((struct sockaddr *)
&spec->connect_addr,
spec->connect_addrlen);
char *chbuf, *cpbuf;
if (sys_sockaddr_str((struct sockaddr *)
&spec->connect_addr,
spec->connect_addrlen,
&chbuf, &cpbuf) != 0) {
fprintf(stderr, "%s: out of memory\n",
argv0);
exit(EXIT_FAILURE);
}
if (asprintf(&cbuf, "[%s]:%s",
chbuf, cpbuf) < 0) {
fprintf(stderr, "%s: out of memory\n",
argv0);
exit(EXIT_FAILURE);
}
free(chbuf);
free(cpbuf);
}
if (spec->sni_port) {
if (asprintf(&cbuf, "sni %i",
Expand All @@ -827,13 +847,13 @@ main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
}
log_dbg_printf("- %s %s %s %s\n", lbuf,
log_dbg_printf("- [%s]:%s %s %s %s\n", lhbuf, lpbuf,
(spec->ssl ? "ssl" : "tcp"),
(spec->http ? "http" : "plain"),
(spec->natengine ? spec->natengine
: cbuf));
if (lbuf)
free(lbuf);
free(lhbuf);
free(lpbuf);
if (cbuf)
free(cbuf);
}
Expand Down

0 comments on commit 914360e

Please sign in to comment.