File: onc_utils.h

package info (click to toggle)
chromium 139.0.7258.127-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 6,122,156 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (141 lines) | stat: -rw-r--r-- 6,400 bytes parent folder | download | duplicates (6)
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMEOS_COMPONENTS_ONC_ONC_UTILS_H_
#define CHROMEOS_COMPONENTS_ONC_ONC_UTILS_H_

#include <map>
#include <optional>
#include <string>

#include "base/component_export.h"
#include "base/values.h"
#include "components/onc/onc_constants.h"

namespace chromeos {

class VariableExpander;

namespace onc {

struct OncValueSignature;

using CertPEMsByGUIDMap = std::map<std::string, std::string>;

// Parses |json| according to the JSON format. If |json| is a JSON formatted
// dictionary, the function populates |dict| and returns true, otherwise returns
// false and |dict| is unchanged.
COMPONENT_EXPORT(CHROMEOS_ONC)
std::optional<base::Value::Dict> ReadDictionaryFromJson(std::string_view json);

// Decrypts the given EncryptedConfiguration |onc| (see the ONC specification)
// with a key derived from the ONC configuration's salt. The resulting
// UnencryptedConfiguration is returned. If an error occurs, returns nullopt.
//
// Note that because the key is derived from the salt only, and the salt is
// included in the clear in the ONC configuration, this provides no actual
// confidentiality.
COMPONENT_EXPORT(CHROMEOS_ONC)
std::optional<base::Value::Dict> Decrypt(const base::Value::Dict& onc);

// For logging only: strings not user facing.
COMPONENT_EXPORT(CHROMEOS_ONC)
std::string GetSourceAsString(::onc::ONCSource source);

// Replaces all expandable fields that are mentioned in the ONC
// specification. The object of |onc_object| is modified in place.
// The substitution is performed using the passed |variable_expander|, which
// defines the placeholder-value mapping.
COMPONENT_EXPORT(CHROMEOS_ONC)
void ExpandStringsInOncObject(const OncValueSignature& signature,
                              const VariableExpander& variable_expander,
                              base::Value::Dict* onc_object);

// Replaces expandable fields in the networks of |network_configs|, which must
// be a list of ONC NetworkConfigurations. See ExpandStringsInOncObject above.
COMPONENT_EXPORT(CHROMEOS_ONC)
void ExpandStringsInNetworks(const VariableExpander& variable_expander,
                             base::Value::List& network_configs);

// Fills in all missing CustomAPNList fields that are mentioned in the
// ONC specification with the value of |custom_apn_list|. The object of
// |onc_object| is modified in place.
COMPONENT_EXPORT(CHROMEOS_ONC)
void FillInCellularCustomAPNListFieldsInOncObject(
    const OncValueSignature& signature,
    base::Value::Dict& onc_object,
    const base::Value::List* custom_apn_list);

// Fills in all missing HexSSID fields that are mentioned in the ONC
// specification. The object of |onc_object| is modified in place.
COMPONENT_EXPORT(CHROMEOS_ONC)
void FillInHexSSIDFieldsInOncObject(const OncValueSignature& signature,
                                    base::Value::Dict& onc_object);

// If the SSID field is set, but HexSSID is not, converts the contents of the
// SSID field to UTF-8 encoding, creates the hex representation and assigns the
// result to HexSSID.
COMPONENT_EXPORT(CHROMEOS_ONC)
void FillInHexSSIDField(base::Value::Dict& wifi_fields);

// Sets missing HiddenSSID fields to default value that is specified in the ONC
// specification. The object of |onc_object| is modified in place.
COMPONENT_EXPORT(CHROMEOS_ONC)
void SetHiddenSSIDFieldInOncObject(const OncValueSignature& signature,
                                   base::Value::Dict& onc_object);

// If the HiddenSSID field is not set, sets it to default value(false). If the
// HiddenSSID field is set already, does nothing.
COMPONENT_EXPORT(CHROMEOS_ONC)
void SetHiddenSSIDField(base::Value::Dict& wifi_fields);

// Creates a copy of |onc_object| with all values of sensitive fields replaced
// by |mask|. To find sensitive fields, signature and field name are checked
// with the function FieldIsCredential().
COMPONENT_EXPORT(CHROMEOS_ONC)
base::Value::Dict MaskCredentialsInOncObject(
    const OncValueSignature& signature,
    const base::Value::Dict& onc_object,
    const std::string& mask);

// Decrypts |onc_blob| with an empty passphrase if necessary. Clears
// |network_configs|, |global_network_config| and |certificates| and fills them
// with the validated NetworkConfigurations, GlobalNetworkConfiguration and
// Certificates of |onc_blob|. Callers can pass nullptr as any of
// |network_configs|, |global_network_config|, |certificates| if they're not
// interested in the respective values. Returns false if any validation errors
// or warnings occurred in any segments (i.e. not only those requested by the
// caller). Even if false is returned, some configuration might be added to the
// output arguments and should be further processed by the caller.
COMPONENT_EXPORT(CHROMEOS_ONC)
bool ParseAndValidateOncForImport(const std::string& onc_blob,
                                  ::onc::ONCSource onc_source,
                                  base::Value::List* network_configs,
                                  base::Value::Dict* global_network_config,
                                  base::Value::List* certificates);

// Parse the given PEM encoded certificate |pem_encoded| and return the
// contained DER encoding. Returns an empty string on failure.
std::string DecodePEM(const std::string& pem_encoded);

// Replaces all references by GUID to Server or CA certs by their PEM
// encoding. Returns true if all references could be resolved. Otherwise returns
// false and network configurations with unresolvable references are removed
// from |network_configs|. |network_configs| must be a list of ONC
// NetworkConfiguration dictionaries.
COMPONENT_EXPORT(CHROMEOS_ONC)
bool ResolveServerCertRefsInNetworks(const CertPEMsByGUIDMap& certs_by_guid,
                                     base::Value::List& network_configs);

// Replaces all references by GUID to Server or CA certs by their PEM
// encoding. Returns true if all references could be resolved. |network_config|
// must be a ONC NetworkConfiguration.
COMPONENT_EXPORT(CHROMEOS_ONC)
bool ResolveServerCertRefsInNetwork(const CertPEMsByGUIDMap& certs_by_guid,
                                    base::Value::Dict& network_config);

}  // namespace onc
}  // namespace chromeos

#endif  // CHROMEOS_COMPONENTS_ONC_ONC_UTILS_H_