Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch for v1.2.12 #5

Open
wants to merge 1 commit into
base: origin-v1.2.12-1733754081
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions src/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1158,9 +1158,35 @@ relpTcpGetCN(relpTcp_t *pThis, gnutls_x509_crt_t cert, char *namebuf, int lenNam
return r;
}


/* helper to consistently add names to error message buffer */
static int
relpTcpAddToCertNamesBuffer(relpTcp_t *const pThis,
char *const buf,
const size_t buflen,
int *p_currIdx,
const char *const certName)
{
int r = 0;
assert(buf != NULL);
assert(p_currIdx != NULL);
const int currIdx = *p_currIdx;
const int n = snprintf(buf + currIdx, buflen - currIdx,
"DNSname: %s; ", certName);
if(n < 0 || n >= (int) (buflen - currIdx)) {
callOnAuthErr(pThis, "", "certificate validation failed, names "
"inside certifcate are way to long (> 32KiB)",
RELP_RET_AUTH_CERT_INVL);
r = GNUTLS_E_CERTIFICATE_ERROR;
} else {
*p_currIdx += n;
}
return r;
}

/* Check the peer's ID in name auth mode. */
static int
relpTcpChkPeerName(relpTcp_t *pThis, gnutls_x509_crt_t cert)
relpTcpChkPeerName(relpTcp_t *const pThis, gnutls_x509_crt_t cert)
{
int r = 0;
int ret;
Expand Down Expand Up @@ -1199,8 +1225,9 @@ relpTcpChkPeerName(relpTcp_t *pThis, gnutls_x509_crt_t cert)
break;
else if(gnuRet == GNUTLS_SAN_DNSNAME) {
pThis->pEngine->dbgprint("librelp: subject alt dnsName: '%s'\n", szAltName);
iAllNames += snprintf(allNames+iAllNames, sizeof(allNames)-iAllNames,
"DNSname: %s; ", szAltName);
r = relpTcpAddToCertNamesBuffer(pThis, allNames, sizeof(allNames),
&iAllNames, szAltName);
if(r != 0) goto done;
relpTcpChkOnePeerName(pThis, szAltName, &bFoundPositiveMatch);
/* do NOT break, because there may be multiple dNSName's! */
}
Expand All @@ -1211,8 +1238,9 @@ relpTcpChkPeerName(relpTcp_t *pThis, gnutls_x509_crt_t cert)
/* if we did not succeed so far, we try the CN part of the DN... */
if(relpTcpGetCN(pThis, cert, cnBuf, sizeof(cnBuf)) == 0) {
pThis->pEngine->dbgprint("librelp: relpTcp now checking auth for CN '%s'\n", cnBuf);
iAllNames += snprintf(allNames+iAllNames, sizeof(allNames)-iAllNames,
"CN: %s; ", cnBuf);
r = relpTcpAddToCertNamesBuffer(pThis, allNames, sizeof(allNames),
&iAllNames, cnBuf);
if(r != 0) goto done;
relpTcpChkOnePeerName(pThis, cnBuf, &bFoundPositiveMatch);
}
}
Expand Down
Loading