You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@trafficserver.apache.org by GitBox <gi...@apache.org> on 2021/03/15 22:01:37 UTC

[GitHub] [trafficserver] ywkaras commented on a change in pull request #7598: Add client_allow_list.so experimental plugin.

ywkaras commented on a change in pull request #7598:
URL: https://github.com/apache/trafficserver/pull/7598#discussion_r594713463



##########
File path: plugins/experimental/client_allow_list/client_allow_list.h
##########
@@ -0,0 +1,301 @@
+/** @file
+
+  SSL client certificate verification plugin, header file.
+
+  Checks for specificate names in the client provided certificate and
+  fails the handshake if none of the good names are present
+
+  @section license License
+
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+ */
+
+#pragma once
+
+#include <vector>
+#include <string>
+#include <unordered_map>
+#include <utility>
+#include <algorithm>
+
+#include <pcre.h>
+
+#if defined(CLIENT_ALLOW_LIST_UNIT_TEST)
+
+struct ClientAllowListUTException {
+};
+
+#else
+
+#include <ts/ts.h>
+
+#endif
+
+#include <string_view>
+
+#define PN "client_allow_list"
+
+namespace client_allow_list_plugin
+{
+struct cname_matcher {
+  std::string _CName;
+  pcre *_compiled_RE = nullptr;
+
+  cname_matcher() = default;
+
+  // No copying.
+  //
+  cname_matcher(cname_matcher const &) = delete;
+  cname_matcher &operator=(cname_matcher const &) = delete;
+
+  // Must be moveable to be able to make a vector of these.
+  //
+  cname_matcher(cname_matcher &&that)
+  {
+    _CName            = std::move(that._CName);
+    _compiled_RE      = that._compiled_RE;
+    that._compiled_RE = nullptr;
+  }
+  cname_matcher &
+  operator=(cname_matcher &&that)
+  {
+    this->~cname_matcher();
+    ::new (this) cname_matcher(std::move(that));
+    return *this;
+  }
+
+  ~cname_matcher()
+  {
+    if (_compiled_RE != nullptr) {
+      pcre_free(_compiled_RE);
+    }
+  }
+};
+
+// Matchers for cert subject/associated names.
+//
+extern std::vector<cname_matcher> matcher;
+
+// Indexes into matcher vector of matchers to use if there is no list of matchers to use specific to the
+// SNI server name.
+//
+extern std::vector<unsigned> other_matcher_idxs;
+
+// Indexes into matcher vector of matchers to use if there is no list of matchers to use specific to the
+// SNI server name.
+//
+extern std::vector<unsigned> none_matcher_idxs;
+
+// Lookup table from C strings to vectors of unsigned.  Comparison of string keys is case-insensitive.
+//
+class MapCStrToUVec
+{
+public:
+  MapCStrToUVec() {}
+
+  // Adds a new entry.  Saves a copy of the key string, returns a pointer to the new, empty vector.
+  // Returns nullptr if there is already an entry for key.
+  //
+  std::vector<unsigned> *add(std::string_view key);
+
+  // Returns nullptr if no entry with given key.
+  //
+  std::vector<unsigned> const *find(char const *key);
+
+  std::size_t
+  size() const
+  {
+    return _map.size();
+  }
+
+  ~MapCStrToUVec();
+
+  // No copying.
+  //
+  MapCStrToUVec(MapCStrToUVec const &) = delete;
+  MapCStrToUVec &operator=(MapCStrToUVec const &) = delete;
+
+private:
+  struct _Hash {
+    std::size_t operator()(char const *key) const;
+  };
+
+  struct _Eq {
+    bool operator()(char const *lhs, char const *rhs) const;
+  };
+
+  std::unordered_map<char const *, std::vector<unsigned>, _Hash, _Eq> _map;
+};
+
+class HashFnv1a32

Review comment:
       Seems like we should move it to ts/util from tscore it we're going to use it in plugins.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org