1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef EXTENSIONS_COMMON_PERMISSIONS_SOCKET_PERMISSION_ENTRY_H_
#define EXTENSIONS_COMMON_PERMISSIONS_SOCKET_PERMISSION_ENTRY_H_
#include <string>
#include <tuple>
#include <vector>
#include "content/public/common/socket_permission_request.h"
#include "ipc/ipc_param_traits.h"
namespace ipc_fuzzer {
template <class T>
struct FuzzTraits;
template <class T>
struct GenerateTraits;
} // namespace ipc_fuzzer
namespace extensions {
// Internal representation of a socket permission for a specific operation, such
// as UDP "bind", host 127.0.0.1, port *.
class SocketPermissionEntry {
public:
enum HostType { ANY_HOST, HOSTS_IN_DOMAINS, SPECIFIC_HOSTS, };
SocketPermissionEntry();
~SocketPermissionEntry();
friend auto operator<=>(const SocketPermissionEntry& a,
const SocketPermissionEntry& b) {
return std::tie(a.pattern_.type, a.pattern_.host, a.match_subdomains_,
a.pattern_.port) <=>
std::tie(b.pattern_.type, b.pattern_.host, b.match_subdomains_,
b.pattern_.port);
}
friend bool operator==(const SocketPermissionEntry& a,
const SocketPermissionEntry& b) {
return std::tie(a.pattern_.type, a.pattern_.host, a.match_subdomains_,
a.pattern_.port) ==
std::tie(b.pattern_.type, b.pattern_.host, b.match_subdomains_,
b.pattern_.port);
}
bool Check(const content::SocketPermissionRequest& request) const;
// Parse a host:port pattern for a given operation type.
// <pattern> := '' |
// <host> |
// ':' <port> |
// <host> ':' <port> |
//
// <host> := '*' |
// '*.' <anychar except '/' and '*'>+ |
// <anychar except '/' and '*'>+
//
// <port> := '*' |
// <port number between 0 and 65535>)
static bool ParseHostPattern(
content::SocketPermissionRequest::OperationType type,
const std::string& pattern,
SocketPermissionEntry* entry);
static bool ParseHostPattern(
content::SocketPermissionRequest::OperationType type,
const std::vector<std::string>& pattern_tokens,
SocketPermissionEntry* entry);
// Returns true if the permission type can be bound to a host or port.
bool IsAddressBoundType() const;
std::string GetHostPatternAsString() const;
HostType GetHostType() const;
const content::SocketPermissionRequest& pattern() const { return pattern_; }
bool match_subdomains() const { return match_subdomains_; }
private:
// Friend so ParamTraits can serialize us.
friend struct IPC::ParamTraits<SocketPermissionEntry>;
friend struct ipc_fuzzer::FuzzTraits<SocketPermissionEntry>;
friend struct ipc_fuzzer::GenerateTraits<SocketPermissionEntry>;
// The permission type, host and port.
content::SocketPermissionRequest pattern_;
// True if there was a wildcard in the host name.
bool match_subdomains_;
};
} // namespace extensions
#endif // EXTENSIONS_COMMON_PERMISSIONS_SOCKET_PERMISSION_ENTRY_H_
|