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

[WIP] Allow trusted proxies to forward client certificate fingerprints (#1430) #1478

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

an-empty-string
Copy link
Contributor

@an-empty-string an-empty-string commented Dec 23, 2017

These changes allow trusted proxies to set a header overriding the detected client certificate fingerprint. This allows webadmin behind a HTTPS-supporting proxy to correctly work with the certauth module. This would fix #1430.

WIP because I'm really uncomfortable with the dynamic_cast that's used here. The alternatives are to change types in a bunch of other places, or just make Csock::GetPeerFingerprint virtual. I think the last one is the best solution, and if you agree I can get a PR off to CSocket and fix this one up.

Aside from the nasty dynamic_cast I'd be interested in any feedback.

@codecov
Copy link

codecov bot commented Dec 23, 2017

Codecov Report

Merging #1478 into master will decrease coverage by 1.09%.
The diff coverage is 3.22%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #1478     +/-   ##
=========================================
- Coverage   37.63%   36.54%   -1.1%     
=========================================
  Files         120      126      +6     
  Lines       23862    30838   +6976     
  Branches       93       93             
=========================================
+ Hits         8981    11270   +2289     
- Misses      14840    19527   +4687     
  Partials       41       41
Impacted Files Coverage Δ
include/znc/HTTPSock.h 100% <ø> (ø) ⬆️
modules/certauth.cpp 1.75% <0%> (-0.41%) ⬇️
include/znc/Socket.h 42.02% <0%> (-7%) ⬇️
src/HTTPSock.cpp 40.86% <5.26%> (-12.02%) ⬇️
include/znc/MD5.h 75% <0%> (-25%) ⬇️
modules/keepnick.cpp 40.16% <0%> (-16.16%) ⬇️
modules/samplewebapi.cpp 73.91% <0%> (-15.57%) ⬇️
src/Client.cpp 64.2% <0%> (-13.06%) ⬇️
src/WebModules.cpp 47.29% <0%> (-12.36%) ⬇️
... and 98 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 15ccaca...ec36715. Read the comment docs.

Copy link
Member

@DarthGandalf DarthGandalf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests? :)

@@ -86,6 +86,7 @@ class CHTTPSock : public CSocket {
const CString& GetURI() const;
const CString& GetURIPrefix() const;
bool IsPost() const;
long GetPeerFingerprint(CS_STRING& sResult) const override;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's CString here.

src/HTTPSock.cpp Outdated
@@ -181,6 +188,12 @@ void CHTTPSock::ReadLine(const CString& sData) {
// X-Forwarded-For list in both cases use it as the endpoind
m_sForwardedIP = sIP;
}
} else if (sName.Equals("X-Forwarded-CertFP:")) {
bool bTrusted = IsTrustedProxy(GetRemoteIP());
if(bTrusted) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space missing
you can use clang-format to fix style with a single keypress, and not care about indentation and other things manually

src/HTTPSock.cpp Outdated
@@ -181,6 +188,12 @@ void CHTTPSock::ReadLine(const CString& sData) {
// X-Forwarded-For list in both cases use it as the endpoind
m_sForwardedIP = sIP;
}
} else if (sName.Equals("X-Forwarded-CertFP:")) {
bool bTrusted = IsTrustedProxy(GetRemoteIP());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (IsTrusted...) is fine. The new variable doesn't add anything here.

src/HTTPSock.cpp Outdated
bool bTrusted = IsTrustedProxy(GetRemoteIP());
if(bTrusted) {
m_sForwardedCertFP = sLine.Token(1, true);
DEBUG("Got a forwarded CertFP '" << m_sForwardedCertFP << "'");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to output a socket name here.

@@ -181,6 +188,12 @@ void CHTTPSock::ReadLine(const CString& sData) {
// X-Forwarded-For list in both cases use it as the endpoind
m_sForwardedIP = sIP;
}
} else if (sName.Equals("X-Forwarded-CertFP:")) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't find anything about this name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it's not standardized anywhere. X-Forwarded-For is standardized by convention but as far as I know there isn't anything similar to TLS fingerprints, as this sort of thing isn't as widely done. This would have to go in documentation somewhere.

@an-empty-string
Copy link
Contributor Author

an-empty-string commented Dec 23, 2017

I'll work on a test later; I'm having some trouble figuring out a good strategy for testing this since things like GetRemoteIP are network-dependent.

@DarthGandalf
Copy link
Member

DarthGandalf commented Dec 24, 2017 via email

@an-empty-string
Copy link
Contributor Author

The hash algorithm is sha1 and it can't be changed, but this is the case with normal certauth currently also.

That's a good point about a compromised TrustedProxy. How about a global config flag that enables/disables this behavior?

I'll take a look at the integration test stuff, that sounds like what I want.

…#1430)

These changes allow trusted proxies to set a header overriding the
detected client certificate fingerprint. This allows webadmin behind a
HTTPS-supporting proxy to correctly work with the certauth module.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

certauth: Should accept authentication to webadmin through a trusted proxy
2 participants