Skip to content

Verify SAN with multiple values, support verifying URI type in SAN#559

Merged
mattklein123 merged 5 commits intoenvoyproxy:masterfrom
myidpt:verify_san
Mar 11, 2017
Merged

Verify SAN with multiple values, support verifying URI type in SAN#559
mattklein123 merged 5 commits intoenvoyproxy:masterfrom
myidpt:verify_san

Conversation

@myidpt
Copy link
Copy Markdown
Contributor

@myidpt myidpt commented Mar 10, 2017

Enable Envoy to verify certificate SAN field against multiple values (set through config).
In config, modify the type of verify_subject_alt_name field to an array.
Support verifying URI type in certificate SAN. The exact match is checked.

This is part of Istio work.

fixes #515

@myidpt myidpt changed the title Verify SAN with multiple values, support verifying SAN type in URI Verify SAN with multiple values, support verifying URI type in SAN Mar 10, 2017
@myidpt myidpt closed this Mar 10, 2017
@myidpt myidpt reopened this Mar 10, 2017
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

generally looks good, a few comments/questions.

std::string cert_chain_file_;
std::string private_key_file_;
std::string verify_subject_alt_name_;
std::vector<std::string> verify_subject_alt_name_;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: verify_subject_alt_names_ or verify_subject_alt_name_list_

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

verify_subject_alt_name_list_ sounds good :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good point.


ContextManagerImpl& parent_;
SslCtxPtr ctx_;
std::string verify_subject_alt_name_;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

same nit above

}

TEST(SslContextImplTest, TestVerifySubjectAltNameDNSMatched) {
FILE* fp = fopen("test/common/ssl/test_data/san_dns.crt", "r");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

close fp here and in other test functions.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure.

}

bool ContextImpl::verifySubjectAltName(X509* cert, const std::string& subject_alt_name) {
bool ContextImpl::verifySubjectAltName(X509* cert,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I assume we have 100% coverage on this function now? Can you please get someone else who is familiar with TLS to give a +1 on the TLS part. I'm really not familiar with this stuff and don't feel comfortable approving the actual crypto aspect.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, 100% unit test coverage. I can get Tao Li in the loop as well.

std::string cert_chain_file_;
std::string private_key_file_;
std::string verify_subject_alt_name_;
std::vector<std::string> verify_subject_alt_name_;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good point.

for (auto& config_san : subject_alt_names) {
if (dNSNameMatch(config_san, dns_name)) {
verified = true;
break;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This break will only jump out the for loop in line 266, but not the one in line 260, which will change the existing behavior.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe you can free altnames here and return true.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Thanks!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@wattli yes, great catch. @myidpt can we make sure to have a test case that would have caught this bug.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@mattklein123 , this is not a bug, it's just about efficiency since 'verified' will never be set to 'false' explicitly.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ah ok, cool, thanks. Didn't look carefully.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Adding "&& !verified" in the loop condition should do the work.

for (auto& config_san : subject_alt_names) {
if (config_san.compare(crt_san) == 0) {
verified = true;
break;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same thing here. Should return immediately once a match found.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Acked.

@mattklein123 mattklein123 merged commit 9dcac8c into envoyproxy:master Mar 11, 2017
@myidpt myidpt deleted the verify_san branch March 13, 2017 03:58
lookuptable added a commit to lookuptable/envoy that referenced this pull request Mar 14, 2017
mattklein123 pushed a commit that referenced this pull request Mar 15, 2017
jplevyak pushed a commit to istio/envoy that referenced this pull request Jul 9, 2020
jpsim pushed a commit that referenced this pull request Nov 28, 2022
This archive is actually a zip containing the produced aar, so this
makes that a bit less confusing.

Signed-off-by: Keith Smiley <[email protected]>
Signed-off-by: JP Simard <[email protected]>
jpsim pushed a commit that referenced this pull request Nov 29, 2022
This archive is actually a zip containing the produced aar, so this
makes that a bit less confusing.

Signed-off-by: Keith Smiley <[email protected]>
Signed-off-by: JP Simard <[email protected]>
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.

Update verify_subject_alt_name from string to array

3 participants