Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2020 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | //! This crate implements AuthFS, a FUSE-based, non-generic filesystem where file access is |
| 18 | //! authenticated. This filesystem assumes the underlying layer is not trusted, e.g. file may be |
| 19 | //! provided by an untrusted host/VM, so that the content can't be simply trusted. However, with a |
| 20 | //! public key from a trusted party, this filesystem can still verify a (read-only) file signed by |
| 21 | //! the trusted party even if the host/VM as the blob provider is malicious. With the Merkle tree, |
| 22 | //! each read of file block can be verified individually only when needed. |
| 23 | //! |
| 24 | //! AuthFS only serve files that are specifically configured. A file configuration may include the |
| 25 | //! source (e.g. local file or remote file server), verification method (e.g. certificate for |
| 26 | //! fs-verity verification, or no verification if expected to mount over dm-verity), and file ID. |
| 27 | //! Regardless of the actual file name, the exposed file names through AuthFS are currently integer, |
| 28 | //! e.g. /mountpoint/42. |
| 29 | |
Andrew Walbran | cc09386 | 2021-03-05 16:59:35 +0000 | [diff] [blame] | 30 | use anyhow::{bail, Context, Result}; |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 31 | use std::collections::BTreeMap; |
| 32 | use std::fs::File; |
| 33 | use std::io::Read; |
Victor Hsieh | 6cf75b5 | 2021-04-01 12:45:49 -0700 | [diff] [blame] | 34 | use std::path::{Path, PathBuf}; |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 35 | use structopt::StructOpt; |
| 36 | |
| 37 | mod auth; |
| 38 | mod common; |
| 39 | mod crypto; |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 40 | mod file; |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 41 | mod fsverity; |
| 42 | mod fusefs; |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 43 | |
| 44 | use auth::FakeAuthenticator; |
Victor Hsieh | 6a47e7f | 2021-03-03 15:53:49 -0800 | [diff] [blame] | 45 | use file::{LocalFileReader, RemoteFileEditor, RemoteFileReader, RemoteMerkleTreeReader}; |
| 46 | use fsverity::{VerifiedFileEditor, VerifiedFileReader}; |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 47 | use fusefs::{FileConfig, Inode}; |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 48 | |
| 49 | #[derive(StructOpt)] |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 50 | struct Args { |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 51 | /// Mount point of AuthFS. |
| 52 | #[structopt(parse(from_os_str))] |
| 53 | mount_point: PathBuf, |
| 54 | |
Victor Hsieh | 2445e33 | 2021-06-04 16:44:53 -0700 | [diff] [blame] | 55 | /// CID of the VM where the service runs. |
| 56 | #[structopt(long)] |
| 57 | cid: Option<u32>, |
| 58 | |
Victor Hsieh | 4cc3b79 | 2021-08-04 12:00:04 -0700 | [diff] [blame^] | 59 | /// Extra options to FUSE |
| 60 | #[structopt(short = "o")] |
| 61 | extra_options: Option<String>, |
| 62 | |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 63 | /// A read-only remote file with integrity check. Can be multiple. |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 64 | /// |
| 65 | /// For example, `--remote-verified-file 5:10:1234:/path/to/cert` tells the filesystem to |
| 66 | /// associate entry 5 with a remote file 10 of size 1234 bytes, and need to be verified against |
| 67 | /// the /path/to/cert. |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 68 | #[structopt(long, parse(try_from_str = parse_remote_ro_file_option))] |
| 69 | remote_ro_file: Vec<OptionRemoteRoFile>, |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 70 | |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 71 | /// A read-only remote file without integrity check. Can be multiple. |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 72 | /// |
| 73 | /// For example, `--remote-unverified-file 5:10:1234` tells the filesystem to associate entry 5 |
| 74 | /// with a remote file 10 of size 1234 bytes. |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 75 | #[structopt(long, parse(try_from_str = parse_remote_ro_file_unverified_option))] |
| 76 | remote_ro_file_unverified: Vec<OptionRemoteRoFileUnverified>, |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 77 | |
Victor Hsieh | 6a47e7f | 2021-03-03 15:53:49 -0800 | [diff] [blame] | 78 | /// A new read-writable remote file with integrity check. Can be multiple. |
| 79 | /// |
| 80 | /// For example, `--remote-new-verified-file 12:34` tells the filesystem to associate entry 12 |
| 81 | /// with a remote file 34. |
| 82 | #[structopt(long, parse(try_from_str = parse_remote_new_rw_file_option))] |
| 83 | remote_new_rw_file: Vec<OptionRemoteRwFile>, |
| 84 | |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 85 | /// Debug only. A read-only local file with integrity check. Can be multiple. |
| 86 | #[structopt(long, parse(try_from_str = parse_local_file_ro_option))] |
| 87 | local_ro_file: Vec<OptionLocalFileRo>, |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 88 | |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 89 | /// Debug only. A read-only local file without integrity check. Can be multiple. |
| 90 | #[structopt(long, parse(try_from_str = parse_local_ro_file_unverified_ro_option))] |
| 91 | local_ro_file_unverified: Vec<OptionLocalRoFileUnverified>, |
Victor Hsieh | 9d0ab62 | 2021-04-26 17:07:02 -0700 | [diff] [blame] | 92 | |
| 93 | /// Enable debugging features. |
| 94 | #[structopt(long)] |
| 95 | debug: bool, |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 96 | } |
| 97 | |
Victor Hsieh | 9ab13e5 | 2021-06-29 09:23:29 -0700 | [diff] [blame] | 98 | impl Args { |
| 99 | fn has_remote_files(&self) -> bool { |
| 100 | !self.remote_ro_file.is_empty() |
| 101 | || !self.remote_ro_file_unverified.is_empty() |
| 102 | || !self.remote_new_rw_file.is_empty() |
| 103 | } |
| 104 | } |
| 105 | |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 106 | struct OptionRemoteRoFile { |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 107 | ino: Inode, |
| 108 | |
| 109 | /// ID to refer to the remote file. |
| 110 | remote_id: i32, |
| 111 | |
| 112 | /// Expected size of the remote file. Necessary for signature check and Merkle tree |
| 113 | /// verification. |
| 114 | file_size: u64, |
| 115 | |
| 116 | /// Certificate to verify the authenticity of the file's fs-verity signature. |
| 117 | /// TODO(170494765): Implement PKCS#7 signature verification. |
| 118 | _certificate_path: PathBuf, |
| 119 | } |
| 120 | |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 121 | struct OptionRemoteRoFileUnverified { |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 122 | ino: Inode, |
| 123 | |
| 124 | /// ID to refer to the remote file. |
| 125 | remote_id: i32, |
| 126 | |
| 127 | /// Expected size of the remote file. |
| 128 | file_size: u64, |
| 129 | } |
| 130 | |
Victor Hsieh | 6a47e7f | 2021-03-03 15:53:49 -0800 | [diff] [blame] | 131 | struct OptionRemoteRwFile { |
| 132 | ino: Inode, |
| 133 | |
| 134 | /// ID to refer to the remote file. |
| 135 | remote_id: i32, |
| 136 | } |
| 137 | |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 138 | struct OptionLocalFileRo { |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 139 | ino: Inode, |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 140 | |
| 141 | /// Local path of the backing file. |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 142 | file_path: PathBuf, |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 143 | |
| 144 | /// Local path of the backing file's fs-verity Merkle tree dump. |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 145 | merkle_tree_dump_path: PathBuf, |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 146 | |
| 147 | /// Local path of fs-verity signature for the backing file. |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 148 | signature_path: PathBuf, |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 149 | |
| 150 | /// Certificate to verify the authenticity of the file's fs-verity signature. |
| 151 | /// TODO(170494765): Implement PKCS#7 signature verification. |
| 152 | _certificate_path: PathBuf, |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 153 | } |
| 154 | |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 155 | struct OptionLocalRoFileUnverified { |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 156 | ino: Inode, |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 157 | |
| 158 | /// Local path of the backing file. |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 159 | file_path: PathBuf, |
| 160 | } |
| 161 | |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 162 | fn parse_remote_ro_file_option(option: &str) -> Result<OptionRemoteRoFile> { |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 163 | let strs: Vec<&str> = option.split(':').collect(); |
| 164 | if strs.len() != 4 { |
| 165 | bail!("Invalid option: {}", option); |
| 166 | } |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 167 | Ok(OptionRemoteRoFile { |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 168 | ino: strs[0].parse::<Inode>()?, |
| 169 | remote_id: strs[1].parse::<i32>()?, |
| 170 | file_size: strs[2].parse::<u64>()?, |
| 171 | _certificate_path: PathBuf::from(strs[3]), |
| 172 | }) |
| 173 | } |
| 174 | |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 175 | fn parse_remote_ro_file_unverified_option(option: &str) -> Result<OptionRemoteRoFileUnverified> { |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 176 | let strs: Vec<&str> = option.split(':').collect(); |
| 177 | if strs.len() != 3 { |
| 178 | bail!("Invalid option: {}", option); |
| 179 | } |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 180 | Ok(OptionRemoteRoFileUnverified { |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 181 | ino: strs[0].parse::<Inode>()?, |
| 182 | remote_id: strs[1].parse::<i32>()?, |
| 183 | file_size: strs[2].parse::<u64>()?, |
| 184 | }) |
| 185 | } |
| 186 | |
Victor Hsieh | 6a47e7f | 2021-03-03 15:53:49 -0800 | [diff] [blame] | 187 | fn parse_remote_new_rw_file_option(option: &str) -> Result<OptionRemoteRwFile> { |
| 188 | let strs: Vec<&str> = option.split(':').collect(); |
| 189 | if strs.len() != 2 { |
| 190 | bail!("Invalid option: {}", option); |
| 191 | } |
| 192 | Ok(OptionRemoteRwFile { |
| 193 | ino: strs[0].parse::<Inode>().unwrap(), |
| 194 | remote_id: strs[1].parse::<i32>().unwrap(), |
| 195 | }) |
| 196 | } |
| 197 | |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 198 | fn parse_local_file_ro_option(option: &str) -> Result<OptionLocalFileRo> { |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 199 | let strs: Vec<&str> = option.split(':').collect(); |
| 200 | if strs.len() != 5 { |
| 201 | bail!("Invalid option: {}", option); |
| 202 | } |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 203 | Ok(OptionLocalFileRo { |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 204 | ino: strs[0].parse::<Inode>()?, |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 205 | file_path: PathBuf::from(strs[1]), |
| 206 | merkle_tree_dump_path: PathBuf::from(strs[2]), |
| 207 | signature_path: PathBuf::from(strs[3]), |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 208 | _certificate_path: PathBuf::from(strs[4]), |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 209 | }) |
| 210 | } |
| 211 | |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 212 | fn parse_local_ro_file_unverified_ro_option(option: &str) -> Result<OptionLocalRoFileUnverified> { |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 213 | let strs: Vec<&str> = option.split(':').collect(); |
| 214 | if strs.len() != 2 { |
| 215 | bail!("Invalid option: {}", option); |
| 216 | } |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 217 | Ok(OptionLocalRoFileUnverified { |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 218 | ino: strs[0].parse::<Inode>()?, |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 219 | file_path: PathBuf::from(strs[1]), |
| 220 | }) |
| 221 | } |
| 222 | |
Victor Hsieh | 2445e33 | 2021-06-04 16:44:53 -0700 | [diff] [blame] | 223 | fn new_config_remote_verified_file( |
| 224 | service: file::VirtFdService, |
| 225 | remote_id: i32, |
| 226 | file_size: u64, |
| 227 | ) -> Result<FileConfig> { |
Andrew Walbran | cc09386 | 2021-03-05 16:59:35 +0000 | [diff] [blame] | 228 | let signature = service.readFsveritySignature(remote_id).context("Failed to read signature")?; |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 229 | |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 230 | let authenticator = FakeAuthenticator::always_succeed(); |
Chris Wailes | 68c39f8 | 2021-07-27 16:03:44 -0700 | [diff] [blame] | 231 | Ok(FileConfig::RemoteVerifiedReadonly { |
Victor Hsieh | 1bcf411 | 2021-03-19 14:26:57 -0700 | [diff] [blame] | 232 | reader: VerifiedFileReader::new( |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 233 | &authenticator, |
Victor Hsieh | c3d45b1 | 2021-06-30 09:16:41 -0700 | [diff] [blame] | 234 | RemoteFileReader::new(service.clone(), remote_id), |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 235 | file_size, |
| 236 | signature, |
Victor Hsieh | c3d45b1 | 2021-06-30 09:16:41 -0700 | [diff] [blame] | 237 | RemoteMerkleTreeReader::new(service.clone(), remote_id), |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 238 | )?, |
| 239 | file_size, |
Victor Hsieh | 1bcf411 | 2021-03-19 14:26:57 -0700 | [diff] [blame] | 240 | }) |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 241 | } |
| 242 | |
Victor Hsieh | 2445e33 | 2021-06-04 16:44:53 -0700 | [diff] [blame] | 243 | fn new_config_remote_unverified_file( |
| 244 | service: file::VirtFdService, |
| 245 | remote_id: i32, |
| 246 | file_size: u64, |
| 247 | ) -> Result<FileConfig> { |
Victor Hsieh | c3d45b1 | 2021-06-30 09:16:41 -0700 | [diff] [blame] | 248 | let reader = RemoteFileReader::new(service, remote_id); |
Chris Wailes | 68c39f8 | 2021-07-27 16:03:44 -0700 | [diff] [blame] | 249 | Ok(FileConfig::RemoteUnverifiedReadonly { reader, file_size }) |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 250 | } |
| 251 | |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 252 | fn new_config_local_ro_file( |
Victor Hsieh | 6cf75b5 | 2021-04-01 12:45:49 -0700 | [diff] [blame] | 253 | protected_file: &Path, |
| 254 | merkle_tree_dump: &Path, |
| 255 | signature: &Path, |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 256 | ) -> Result<FileConfig> { |
| 257 | let file = File::open(&protected_file)?; |
| 258 | let file_size = file.metadata()?.len(); |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 259 | let file_reader = LocalFileReader::new(file)?; |
| 260 | let merkle_tree_reader = LocalFileReader::new(File::open(merkle_tree_dump)?)?; |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 261 | let authenticator = FakeAuthenticator::always_succeed(); |
| 262 | let mut sig = Vec::new(); |
| 263 | let _ = File::open(signature)?.read_to_end(&mut sig)?; |
Victor Hsieh | 1bcf411 | 2021-03-19 14:26:57 -0700 | [diff] [blame] | 264 | let reader = |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 265 | VerifiedFileReader::new(&authenticator, file_reader, file_size, sig, merkle_tree_reader)?; |
Chris Wailes | 68c39f8 | 2021-07-27 16:03:44 -0700 | [diff] [blame] | 266 | Ok(FileConfig::LocalVerifiedReadonly { reader, file_size }) |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 267 | } |
| 268 | |
Victor Hsieh | 6cf75b5 | 2021-04-01 12:45:49 -0700 | [diff] [blame] | 269 | fn new_config_local_ro_file_unverified(file_path: &Path) -> Result<FileConfig> { |
Victor Hsieh | 1bcf411 | 2021-03-19 14:26:57 -0700 | [diff] [blame] | 270 | let reader = LocalFileReader::new(File::open(file_path)?)?; |
| 271 | let file_size = reader.len(); |
Chris Wailes | 68c39f8 | 2021-07-27 16:03:44 -0700 | [diff] [blame] | 272 | Ok(FileConfig::LocalUnverifiedReadonly { reader, file_size }) |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 273 | } |
| 274 | |
Victor Hsieh | 2445e33 | 2021-06-04 16:44:53 -0700 | [diff] [blame] | 275 | fn new_config_remote_new_verified_file( |
| 276 | service: file::VirtFdService, |
| 277 | remote_id: i32, |
| 278 | ) -> Result<FileConfig> { |
Victor Hsieh | c3d45b1 | 2021-06-30 09:16:41 -0700 | [diff] [blame] | 279 | let remote_file = RemoteFileEditor::new(service, remote_id); |
Chris Wailes | 68c39f8 | 2021-07-27 16:03:44 -0700 | [diff] [blame] | 280 | Ok(FileConfig::RemoteVerifiedNew { editor: VerifiedFileEditor::new(remote_file) }) |
Victor Hsieh | 6a47e7f | 2021-03-03 15:53:49 -0800 | [diff] [blame] | 281 | } |
| 282 | |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 283 | fn prepare_file_pool(args: &Args) -> Result<BTreeMap<Inode, FileConfig>> { |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 284 | let mut file_pool = BTreeMap::new(); |
| 285 | |
Victor Hsieh | 9ab13e5 | 2021-06-29 09:23:29 -0700 | [diff] [blame] | 286 | if args.has_remote_files() { |
| 287 | let service = file::get_binder_service(args.cid)?; |
Victor Hsieh | 2445e33 | 2021-06-04 16:44:53 -0700 | [diff] [blame] | 288 | |
Victor Hsieh | 9ab13e5 | 2021-06-29 09:23:29 -0700 | [diff] [blame] | 289 | for config in &args.remote_ro_file { |
| 290 | file_pool.insert( |
| 291 | config.ino, |
| 292 | new_config_remote_verified_file( |
| 293 | service.clone(), |
| 294 | config.remote_id, |
| 295 | config.file_size, |
| 296 | )?, |
| 297 | ); |
| 298 | } |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 299 | |
Victor Hsieh | 9ab13e5 | 2021-06-29 09:23:29 -0700 | [diff] [blame] | 300 | for config in &args.remote_ro_file_unverified { |
| 301 | file_pool.insert( |
| 302 | config.ino, |
| 303 | new_config_remote_unverified_file( |
| 304 | service.clone(), |
| 305 | config.remote_id, |
| 306 | config.file_size, |
| 307 | )?, |
| 308 | ); |
| 309 | } |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 310 | |
Victor Hsieh | 9ab13e5 | 2021-06-29 09:23:29 -0700 | [diff] [blame] | 311 | for config in &args.remote_new_rw_file { |
| 312 | file_pool.insert( |
| 313 | config.ino, |
| 314 | new_config_remote_new_verified_file(service.clone(), config.remote_id)?, |
| 315 | ); |
| 316 | } |
Victor Hsieh | 6a47e7f | 2021-03-03 15:53:49 -0800 | [diff] [blame] | 317 | } |
| 318 | |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 319 | for config in &args.local_ro_file { |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 320 | file_pool.insert( |
| 321 | config.ino, |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 322 | new_config_local_ro_file( |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 323 | &config.file_path, |
| 324 | &config.merkle_tree_dump_path, |
| 325 | &config.signature_path, |
| 326 | )?, |
| 327 | ); |
| 328 | } |
| 329 | |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 330 | for config in &args.local_ro_file_unverified { |
| 331 | file_pool.insert(config.ino, new_config_local_ro_file_unverified(&config.file_path)?); |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | Ok(file_pool) |
| 335 | } |
| 336 | |
| 337 | fn main() -> Result<()> { |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 338 | let args = Args::from_args(); |
Victor Hsieh | 9d0ab62 | 2021-04-26 17:07:02 -0700 | [diff] [blame] | 339 | |
| 340 | let log_level = if args.debug { log::Level::Debug } else { log::Level::Info }; |
| 341 | android_logger::init_once( |
| 342 | android_logger::Config::default().with_tag("authfs").with_min_level(log_level), |
| 343 | ); |
| 344 | |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 345 | let file_pool = prepare_file_pool(&args)?; |
Victor Hsieh | 4cc3b79 | 2021-08-04 12:00:04 -0700 | [diff] [blame^] | 346 | fusefs::loop_forever(file_pool, &args.mount_point, &args.extra_options)?; |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 347 | bail!("Unexpected exit after the handler loop") |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 348 | } |