Skip to content

Commit b04afe0

Browse files
Review comments.
Review comments.
1 parent 66d4b8f commit b04afe0

File tree

18 files changed

+205
-585
lines changed

18 files changed

+205
-585
lines changed

presto-client/src/main/java/com/facebook/presto/client/okhttp3/internal/tls/DistinguishedNameParser.java

Lines changed: 111 additions & 160 deletions
Large diffs are not rendered by default.

presto-client/src/main/java/com/facebook/presto/client/okhttp3/internal/tls/LegacyHostnameVerifier.java

Lines changed: 16 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
import java.util.Locale;
3131
import java.util.regex.Pattern;
3232

33+
/**
34+
* The type Legacy hostname verifier.
35+
*/
3336
public class LegacyHostnameVerifier
3437
implements HostnameVerifier
3538
{
@@ -38,6 +41,9 @@ public class LegacyHostnameVerifier
3841
private static final Pattern VERIFY_AS_IP_ADDRESS = Pattern.compile(
3942
"([0-9a-fA-F]*:[0-9a-fA-F:.]*)|([\\d.]+)");
4043

44+
/**
45+
* The constant INSTANCE.
46+
*/
4147
public static final HostnameVerifier INSTANCE = new LegacyHostnameVerifier();
4248

4349
private LegacyHostnameVerifier()
@@ -51,23 +57,19 @@ public boolean verify(String host, SSLSession session)
5157
return true;
5258
}
5359

54-
// the CN cannot be used with IP addresses
5560
if (verifyAsIpAddress(host)) {
5661
return false;
5762
}
5863

59-
// try to verify using the legacy CN rules
6064
try {
6165
Certificate[] certificates = session.getPeerCertificates();
6266
X509Certificate certificate = (X509Certificate) certificates[0];
6367

64-
// only use CN if there are no alt names
6568
if (!allSubjectAltNames(certificate).isEmpty()) {
6669
return false;
6770
}
6871

6972
X500Principal principal = certificate.getSubjectX500Principal();
70-
// RFC 2818 advises using the most specific name for matching.
7173
String cn = new DistinguishedNameParser(principal).findMostSpecific("cn");
7274
if (cn != null) {
7375
return verifyHostName(host, cn);
@@ -80,49 +82,23 @@ public boolean verify(String host, SSLSession session)
8082
}
8183
}
8284

85+
/**
86+
* Verify as ip address boolean.
87+
*
88+
* @param host the host
89+
* @return the boolean
90+
*/
8391
static boolean verifyAsIpAddress(String host)
8492
{
8593
return VERIFY_AS_IP_ADDRESS.matcher(host).matches();
8694
}
8795

8896
/**
89-
* Returns true if {@code certificate} matches {@code ipAddress}.
97+
* All subject alt names list.
98+
*
99+
* @param certificate the certificate
100+
* @return the list
90101
*/
91-
private boolean verifyIpAddress(String ipAddress, X509Certificate certificate)
92-
{
93-
List<String> altNames = getSubjectAltNames(certificate, ALT_IPA_NAME);
94-
for (int i = 0, size = altNames.size(); i < size; i++) {
95-
if (ipAddress.equalsIgnoreCase(altNames.get(i))) {
96-
return true;
97-
}
98-
}
99-
return false;
100-
}
101-
102-
private boolean verifyHostName(String hostName, X509Certificate certificate)
103-
{
104-
hostName = hostName.toLowerCase(Locale.US);
105-
boolean hasDns = false;
106-
List<String> altNames = getSubjectAltNames(certificate, ALT_DNS_NAME);
107-
for (int i = 0, size = altNames.size(); i < size; i++) {
108-
hasDns = true;
109-
if (verifyHostName(hostName, altNames.get(i))) {
110-
return true;
111-
}
112-
}
113-
114-
if (!hasDns) {
115-
X500Principal principal = certificate.getSubjectX500Principal();
116-
// RFC 2818 advises using the most specific name for matching.
117-
String cn = new DistinguishedNameParser(principal).findMostSpecific("cn");
118-
if (cn != null) {
119-
return verifyHostName(hostName, cn);
120-
}
121-
}
122-
123-
return false;
124-
}
125-
126102
public static List<String> allSubjectAltNames(X509Certificate certificate)
127103
{
128104
List<String> altIpaNames = getSubjectAltNames(certificate, ALT_IPA_NAME);
@@ -173,90 +149,50 @@ private static List<String> getSubjectAltNames(X509Certificate certificate, int
173149
*/
174150
private boolean verifyHostName(String hostName, String pattern)
175151
{
176-
// Basic sanity checks
177-
// Check length == 0 instead of .isEmpty() to support Java 5.
178152
if ((hostName == null) || (hostName.length() == 0) || (hostName.startsWith("."))
179153
|| (hostName.endsWith(".."))) {
180-
// Invalid domain name
181154
return false;
182155
}
183156
if ((pattern == null) || (pattern.length() == 0) || (pattern.startsWith("."))
184157
|| (pattern.endsWith(".."))) {
185-
// Invalid pattern/domain name
186158
return false;
187159
}
188160

189-
// Normalize hostName and pattern by turning them into absolute domain names if they are not
190-
// yet absolute. This is needed because server certificates do not normally contain absolute
191-
// names or patterns, but they should be treated as absolute. At the same time, any hostName
192-
// presented to this method should also be treated as absolute for the purposes of matching
193-
// to the server certificate.
194-
// www.android.com matches www.android.com
195-
// www.android.com matches www.android.com.
196-
// www.android.com. matches www.android.com.
197-
// www.android.com. matches www.android.com
198161
if (!hostName.endsWith(".")) {
199162
hostName += '.';
200163
}
201164
if (!pattern.endsWith(".")) {
202165
pattern += '.';
203166
}
204-
// hostName and pattern are now absolute domain names.
205167

206168
pattern = pattern.toLowerCase(Locale.US);
207-
// hostName and pattern are now in lower case -- domain names are case-insensitive.
208169

209170
if (!pattern.contains("*")) {
210-
// Not a wildcard pattern -- hostName and pattern must match exactly.
211171
return hostName.equals(pattern);
212172
}
213-
// Wildcard pattern
214-
215-
// WILDCARD PATTERN RULES:
216-
// 1. Asterisk (*) is only permitted in the left-most domain name label and must be the
217-
// only character in that label (i.e., must match the whole left-most label).
218-
// For example, *.example.com is permitted, while *a.example.com, a*.example.com,
219-
// a*b.example.com, a.*.example.com are not permitted.
220-
// 2. Asterisk (*) cannot match across domain name labels.
221-
// For example, *.example.com matches test.example.com but does not match
222-
// sub.test.example.com.
223-
// 3. Wildcard patterns for single-label domain names are not permitted.
224173

225174
if ((!pattern.startsWith("*.")) || (pattern.indexOf('*', 1) != -1)) {
226-
// Asterisk (*) is only permitted in the left-most domain name label and must be the only
227-
// character in that label
228175
return false;
229176
}
230177

231-
// Optimization: check whether hostName is too short to match the pattern. hostName must be at
232-
// least as long as the pattern because asterisk must match the whole left-most label and
233-
// hostName starts with a non-empty label. Thus, asterisk has to match one or more characters.
234178
if (hostName.length() < pattern.length()) {
235-
// hostName too short to match the pattern.
236179
return false;
237180
}
238181

239182
if ("*.".equals(pattern)) {
240-
// Wildcard pattern for single-label domain name -- not permitted.
241183
return false;
242184
}
243185

244-
// hostName must end with the region of pattern following the asterisk.
245186
String suffix = pattern.substring(1);
246187
if (!hostName.endsWith(suffix)) {
247-
// hostName does not end with the suffix
248188
return false;
249189
}
250190

251-
// Check that asterisk did not match across domain name labels.
252191
int suffixStartIndexInHostName = hostName.length() - suffix.length();
253192
if ((suffixStartIndexInHostName > 0)
254193
&& (hostName.lastIndexOf('.', suffixStartIndexInHostName - 1) != -1)) {
255-
// Asterisk is matching across domain name labels -- not permitted.
256194
return false;
257195
}
258-
259-
// hostName matches pattern
260196
return true;
261197
}
262198
}

presto-common/src/main/java/com/facebook/presto/common/TelemetryConfig.java

Lines changed: 6 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import static java.util.Objects.requireNonNull;
2020

2121
/**
22-
* The type TelemetryConfig to store all the values in telemetry.properties.
22+
* The type TelemetryConfig to store the values from telemetry-tracing.properties.
2323
*/
2424
public class TelemetryConfig
2525
{
@@ -31,11 +31,11 @@ public class TelemetryConfig
3131
private Integer exporterTimeout;
3232
private Integer scheduleDelay;
3333
private Double samplingRatio;
34-
private Boolean tracingEnabled = false;
35-
private Boolean spanSampling = false;
34+
private boolean tracingEnabled;
35+
private boolean spanSampling;
3636

3737
/**
38-
* The type Telemetry config constants.
38+
* The type TelemetryConfigConstants to store constants.
3939
*/
4040
public static class TelemetryConfigConstants
4141
{
@@ -54,7 +54,7 @@ private TelemetryConfig()
5454
}
5555

5656
/**
57-
* Gets telemetry config.
57+
* Gets the singleton telemetryConfig.
5858
*
5959
* @return the telemetry config
6060
*/
@@ -65,7 +65,7 @@ public static TelemetryConfig getTelemetryConfig()
6565
}
6666

6767
/**
68-
* Sets telemetry properties.
68+
* Sets telemetry properties from the input.
6969
*
7070
* @param telemetryProperties the telemetry properties
7171
*/
@@ -91,91 +91,46 @@ public void setTracingEnabled(Boolean tracingEnabled)
9191
getTelemetryConfig().tracingEnabled = tracingEnabled;
9292
}
9393

94-
/**
95-
* Sets span sampling.
96-
*
97-
* @param spanSampling the span sampling
98-
*/
9994
public void setSpanSampling(Boolean spanSampling)
10095
{
10196
getTelemetryConfig().spanSampling = spanSampling;
10297
}
10398

104-
/**
105-
* Gets exporter endpoint.
106-
*
107-
* @return the exporter endpoint
108-
*/
10999
public String getTracingBackendUrl()
110100
{
111101
return this.tracingBackendUrl;
112102
}
113103

114-
/**
115-
* Gets max exporter batch size.
116-
*
117-
* @return the max exporter batch size
118-
*/
119104
public Integer getMaxExporterBatchSize()
120105
{
121106
return this.maxExporterBatchSize;
122107
}
123108

124-
/**
125-
* Gets max queue size.
126-
*
127-
* @return the max queue size
128-
*/
129109
public Integer getMaxQueueSize()
130110
{
131111
return this.maxQueueSize;
132112
}
133113

134-
/**
135-
* Gets exporter timeout.
136-
*
137-
* @return the exporter timeout
138-
*/
139114
public Integer getExporterTimeout()
140115
{
141116
return this.exporterTimeout;
142117
}
143118

144-
/**
145-
* Gets schedule delay.
146-
*
147-
* @return the schedule delay
148-
*/
149119
public Integer getScheduleDelay()
150120
{
151121
return this.scheduleDelay;
152122
}
153123

154-
/**
155-
* Gets sampling ratio.
156-
*
157-
* @return the sampling ratio
158-
*/
159124
public Double getSamplingRatio()
160125
{
161126
return this.samplingRatio;
162127
}
163128

164-
/**
165-
* Gets tracing enabled.
166-
*
167-
* @return the tracing enabled
168-
*/
169129
public static Boolean getTracingEnabled()
170130
{
171131
return getTelemetryConfig().tracingEnabled;
172132
}
173133

174-
/**
175-
* Gets span sampling.
176-
*
177-
* @return the span sampling
178-
*/
179134
public static Boolean getSpanSampling()
180135
{
181136
return getTelemetryConfig().spanSampling;

presto-common/src/main/java/com/facebook/presto/common/TracingConfig.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import javax.annotation.concurrent.Immutable;
2020

2121
/**
22-
* The type Tracing config.
22+
* POJO to use with TelemetryResource for the dynamically enable/disable the trace endpoint.
2323
*/
2424
@Immutable
2525
public class TracingConfig
@@ -38,11 +38,6 @@ public TracingConfig(
3838
this.tracingEnabled = tracingEnabled;
3939
}
4040

41-
/**
42-
* Is tracing enabled boolean.
43-
*
44-
* @return the boolean
45-
*/
4641
@JsonProperty
4742
public boolean isTracingEnabled()
4843
{

presto-main/src/main/java/com/facebook/presto/Session.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import com.facebook.presto.sql.analyzer.CTEInformationCollector;
4040
import com.facebook.presto.sql.planner.optimizations.OptimizerInformationCollector;
4141
import com.facebook.presto.sql.planner.optimizations.OptimizerResultCollector;
42-
import com.facebook.presto.telemetry.TracingManager;
4342
import com.facebook.presto.transaction.TransactionManager;
4443
import com.google.common.collect.ImmutableMap;
4544
import com.google.common.collect.ImmutableSet;
@@ -67,6 +66,8 @@
6766
import static com.facebook.presto.spi.ConnectorId.createInformationSchemaConnectorId;
6867
import static com.facebook.presto.spi.ConnectorId.createSystemTablesConnectorId;
6968
import static com.facebook.presto.spi.StandardErrorCode.NOT_FOUND;
69+
import static com.facebook.presto.telemetry.TracingManager.getInvalidSpan;
70+
import static com.facebook.presto.telemetry.TracingManager.spanString;
7071
import static com.facebook.presto.util.Failures.checkCondition;
7172
import static com.google.common.base.MoreObjects.toStringHelper;
7273
import static com.google.common.base.Preconditions.checkArgument;
@@ -530,7 +531,7 @@ public String toString()
530531
{
531532
return toStringHelper(this)
532533
.add("queryId", queryId)
533-
.add("querySpan", TracingManager.spanString(querySpan).orElse(null))
534+
.add("querySpan", spanString(querySpan).orElse(null))
534535
.add("rootSpan", rootSpan.toString())
535536
.add("transactionId", transactionId)
536537
.add("user", getUser())
@@ -563,8 +564,8 @@ public static SessionBuilder builder(Session session)
563564
public static class SessionBuilder
564565
{
565566
private QueryId queryId;
566-
private BaseSpan querySpan = TracingManager.getInvalidSpan(); //do not initialize with null
567-
private BaseSpan rootSpan = TracingManager.getInvalidSpan(); //do not initialize with null
567+
private BaseSpan querySpan = getInvalidSpan(); //do not initialize with null
568+
private BaseSpan rootSpan = getInvalidSpan(); //do not initialize with null
568569
private TransactionId transactionId;
569570
private boolean clientTransactionSupport;
570571
private Identity identity;

presto-main/src/main/java/com/facebook/presto/telemetry/TelemetryModule.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919

2020
import static org.weakref.jmx.guice.ExportBinder.newExporter;
2121

22-
/**
23-
* The type Telemetry module.
24-
*/
2522
public class TelemetryModule
2623
implements Module
2724
{

0 commit comments

Comments
 (0)