Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Unified Diff: components/cronet/android/api/src/org/chromium/net/CronetUtil.java

Issue 1407263010: [Cronet] Public key pinning for Java API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added host name verification + review comments Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/cronet/android/api/src/org/chromium/net/CronetUtil.java
diff --git a/components/cronet/android/api/src/org/chromium/net/CronetUtil.java b/components/cronet/android/api/src/org/chromium/net/CronetUtil.java
new file mode 100644
index 0000000000000000000000000000000000000000..34b9bbc59520b83eb84a9f2c9b186acd98a4ce2b
--- /dev/null
+++ b/components/cronet/android/api/src/org/chromium/net/CronetUtil.java
@@ -0,0 +1,40 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+package org.chromium.net;
+
+import java.util.regex.Pattern;
+
+/**
+ * A set of generic utility methods.
+ */
+class CronetUtil {
+ private static final String VALID_IP_EXPR = "^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])"
mef 2015/11/09 16:59:28 I'm very skeptical about this.
kapishnikov 2015/11/09 19:14:20 I can add more tests to https://codereview.chromiu
+ + "\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])$";
+ private static final String VALID_HOST_EXPR = "^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*"
+ + "[a-zA-Z0-9])\\.)*([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9])$";
+ private static final Pattern VALID_IP_PATTERN = Pattern.compile(VALID_IP_EXPR);
+ private static final Pattern VALID_HOST_PATTERN = Pattern.compile(VALID_HOST_EXPR);
+
+ private CronetUtil() {}
+
+ /**
+ * Checks whether a given string that represents a host name is valid.
+ *
+ * @param hostName host name to check.
+ * @return true if the string is a valid host name.
+ */
+ static boolean isValidHostName(String hostName) {
+ return VALID_HOST_PATTERN.matcher(hostName).matches();
+ }
+
+ /**
+ * Checks whether a given string that represents an IPv4 address is valid.
+ *
+ * @param addr IPv4 address to check.
+ * @return true if the string is a valid IPv4 address.
+ */
+ static boolean isValidIPv4(String addr) {
+ return VALID_IP_PATTERN.matcher(addr).matches();
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698