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 | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 59 | /// A read-only remote file with integrity check. Can be multiple. |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 60 | /// |
| 61 | /// For example, `--remote-verified-file 5:10:1234:/path/to/cert` tells the filesystem to |
| 62 | /// associate entry 5 with a remote file 10 of size 1234 bytes, and need to be verified against |
| 63 | /// the /path/to/cert. |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 64 | #[structopt(long, parse(try_from_str = parse_remote_ro_file_option))] |
| 65 | remote_ro_file: Vec<OptionRemoteRoFile>, |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 66 | |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 67 | /// A read-only remote file without integrity check. Can be multiple. |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 68 | /// |
| 69 | /// For example, `--remote-unverified-file 5:10:1234` tells the filesystem to associate entry 5 |
| 70 | /// with a remote file 10 of size 1234 bytes. |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 71 | #[structopt(long, parse(try_from_str = parse_remote_ro_file_unverified_option))] |
| 72 | remote_ro_file_unverified: Vec<OptionRemoteRoFileUnverified>, |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 73 | |
Victor Hsieh | 6a47e7f | 2021-03-03 15:53:49 -0800 | [diff] [blame] | 74 | /// A new read-writable remote file with integrity check. Can be multiple. |
| 75 | /// |
| 76 | /// For example, `--remote-new-verified-file 12:34` tells the filesystem to associate entry 12 |
| 77 | /// with a remote file 34. |
| 78 | #[structopt(long, parse(try_from_str = parse_remote_new_rw_file_option))] |
| 79 | remote_new_rw_file: Vec<OptionRemoteRwFile>, |
| 80 | |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 81 | /// Debug only. A read-only local file with integrity check. Can be multiple. |
| 82 | #[structopt(long, parse(try_from_str = parse_local_file_ro_option))] |
| 83 | local_ro_file: Vec<OptionLocalFileRo>, |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 84 | |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 85 | /// Debug only. A read-only local file without integrity check. Can be multiple. |
| 86 | #[structopt(long, parse(try_from_str = parse_local_ro_file_unverified_ro_option))] |
| 87 | local_ro_file_unverified: Vec<OptionLocalRoFileUnverified>, |
Victor Hsieh | 9d0ab62 | 2021-04-26 17:07:02 -0700 | [diff] [blame] | 88 | |
| 89 | /// Enable debugging features. |
| 90 | #[structopt(long)] |
| 91 | debug: bool, |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 92 | } |
| 93 | |
Victor Hsieh | 9ab13e5 | 2021-06-29 09:23:29 -0700 | [diff] [blame] | 94 | impl Args { |
| 95 | fn has_remote_files(&self) -> bool { |
| 96 | !self.remote_ro_file.is_empty() |
| 97 | || !self.remote_ro_file_unverified.is_empty() |
| 98 | || !self.remote_new_rw_file.is_empty() |
| 99 | } |
| 100 | } |
| 101 | |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 102 | struct OptionRemoteRoFile { |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 103 | ino: Inode, |
| 104 | |
| 105 | /// ID to refer to the remote file. |
| 106 | remote_id: i32, |
| 107 | |
| 108 | /// Expected size of the remote file. Necessary for signature check and Merkle tree |
| 109 | /// verification. |
| 110 | file_size: u64, |
| 111 | |
| 112 | /// Certificate to verify the authenticity of the file's fs-verity signature. |
| 113 | /// TODO(170494765): Implement PKCS#7 signature verification. |
| 114 | _certificate_path: PathBuf, |
| 115 | } |
| 116 | |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 117 | struct OptionRemoteRoFileUnverified { |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 118 | ino: Inode, |
| 119 | |
| 120 | /// ID to refer to the remote file. |
| 121 | remote_id: i32, |
| 122 | |
| 123 | /// Expected size of the remote file. |
| 124 | file_size: u64, |
| 125 | } |
| 126 | |
Victor Hsieh | 6a47e7f | 2021-03-03 15:53:49 -0800 | [diff] [blame] | 127 | struct OptionRemoteRwFile { |
| 128 | ino: Inode, |
| 129 | |
| 130 | /// ID to refer to the remote file. |
| 131 | remote_id: i32, |
| 132 | } |
| 133 | |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 134 | struct OptionLocalFileRo { |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 135 | ino: Inode, |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 136 | |
| 137 | /// Local path of the backing file. |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 138 | file_path: PathBuf, |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 139 | |
| 140 | /// Local path of the backing file's fs-verity Merkle tree dump. |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 141 | merkle_tree_dump_path: PathBuf, |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 142 | |
| 143 | /// Local path of fs-verity signature for the backing file. |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 144 | signature_path: PathBuf, |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 145 | |
| 146 | /// Certificate to verify the authenticity of the file's fs-verity signature. |
| 147 | /// TODO(170494765): Implement PKCS#7 signature verification. |
| 148 | _certificate_path: PathBuf, |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 149 | } |
| 150 | |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 151 | struct OptionLocalRoFileUnverified { |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 152 | ino: Inode, |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 153 | |
| 154 | /// Local path of the backing file. |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 155 | file_path: PathBuf, |
| 156 | } |
| 157 | |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 158 | fn parse_remote_ro_file_option(option: &str) -> Result<OptionRemoteRoFile> { |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 159 | let strs: Vec<&str> = option.split(':').collect(); |
| 160 | if strs.len() != 4 { |
| 161 | bail!("Invalid option: {}", option); |
| 162 | } |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 163 | Ok(OptionRemoteRoFile { |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 164 | ino: strs[0].parse::<Inode>()?, |
| 165 | remote_id: strs[1].parse::<i32>()?, |
| 166 | file_size: strs[2].parse::<u64>()?, |
| 167 | _certificate_path: PathBuf::from(strs[3]), |
| 168 | }) |
| 169 | } |
| 170 | |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 171 | fn parse_remote_ro_file_unverified_option(option: &str) -> Result<OptionRemoteRoFileUnverified> { |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 172 | let strs: Vec<&str> = option.split(':').collect(); |
| 173 | if strs.len() != 3 { |
| 174 | bail!("Invalid option: {}", option); |
| 175 | } |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 176 | Ok(OptionRemoteRoFileUnverified { |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 177 | ino: strs[0].parse::<Inode>()?, |
| 178 | remote_id: strs[1].parse::<i32>()?, |
| 179 | file_size: strs[2].parse::<u64>()?, |
| 180 | }) |
| 181 | } |
| 182 | |
Victor Hsieh | 6a47e7f | 2021-03-03 15:53:49 -0800 | [diff] [blame] | 183 | fn parse_remote_new_rw_file_option(option: &str) -> Result<OptionRemoteRwFile> { |
| 184 | let strs: Vec<&str> = option.split(':').collect(); |
| 185 | if strs.len() != 2 { |
| 186 | bail!("Invalid option: {}", option); |
| 187 | } |
| 188 | Ok(OptionRemoteRwFile { |
| 189 | ino: strs[0].parse::<Inode>().unwrap(), |
| 190 | remote_id: strs[1].parse::<i32>().unwrap(), |
| 191 | }) |
| 192 | } |
| 193 | |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 194 | fn parse_local_file_ro_option(option: &str) -> Result<OptionLocalFileRo> { |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 195 | let strs: Vec<&str> = option.split(':').collect(); |
| 196 | if strs.len() != 5 { |
| 197 | bail!("Invalid option: {}", option); |
| 198 | } |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 199 | Ok(OptionLocalFileRo { |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 200 | ino: strs[0].parse::<Inode>()?, |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 201 | file_path: PathBuf::from(strs[1]), |
| 202 | merkle_tree_dump_path: PathBuf::from(strs[2]), |
| 203 | signature_path: PathBuf::from(strs[3]), |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 204 | _certificate_path: PathBuf::from(strs[4]), |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 205 | }) |
| 206 | } |
| 207 | |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 208 | fn parse_local_ro_file_unverified_ro_option(option: &str) -> Result<OptionLocalRoFileUnverified> { |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 209 | let strs: Vec<&str> = option.split(':').collect(); |
| 210 | if strs.len() != 2 { |
| 211 | bail!("Invalid option: {}", option); |
| 212 | } |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 213 | Ok(OptionLocalRoFileUnverified { |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 214 | ino: strs[0].parse::<Inode>()?, |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 215 | file_path: PathBuf::from(strs[1]), |
| 216 | }) |
| 217 | } |
| 218 | |
Victor Hsieh | 2445e33 | 2021-06-04 16:44:53 -0700 | [diff] [blame] | 219 | fn new_config_remote_verified_file( |
| 220 | service: file::VirtFdService, |
| 221 | remote_id: i32, |
| 222 | file_size: u64, |
| 223 | ) -> Result<FileConfig> { |
Andrew Walbran | cc09386 | 2021-03-05 16:59:35 +0000 | [diff] [blame] | 224 | let signature = service.readFsveritySignature(remote_id).context("Failed to read signature")?; |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 225 | |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 226 | let authenticator = FakeAuthenticator::always_succeed(); |
Victor Hsieh | 1bcf411 | 2021-03-19 14:26:57 -0700 | [diff] [blame] | 227 | Ok(FileConfig::RemoteVerifiedReadonlyFile { |
| 228 | reader: VerifiedFileReader::new( |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 229 | &authenticator, |
Victor Hsieh | c3d45b1 | 2021-06-30 09:16:41 -0700 | [diff] [blame] | 230 | RemoteFileReader::new(service.clone(), remote_id), |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 231 | file_size, |
| 232 | signature, |
Victor Hsieh | c3d45b1 | 2021-06-30 09:16:41 -0700 | [diff] [blame] | 233 | RemoteMerkleTreeReader::new(service.clone(), remote_id), |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 234 | )?, |
| 235 | file_size, |
Victor Hsieh | 1bcf411 | 2021-03-19 14:26:57 -0700 | [diff] [blame] | 236 | }) |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 237 | } |
| 238 | |
Victor Hsieh | 2445e33 | 2021-06-04 16:44:53 -0700 | [diff] [blame] | 239 | fn new_config_remote_unverified_file( |
| 240 | service: file::VirtFdService, |
| 241 | remote_id: i32, |
| 242 | file_size: u64, |
| 243 | ) -> Result<FileConfig> { |
Victor Hsieh | c3d45b1 | 2021-06-30 09:16:41 -0700 | [diff] [blame] | 244 | let reader = RemoteFileReader::new(service, remote_id); |
Victor Hsieh | 1bcf411 | 2021-03-19 14:26:57 -0700 | [diff] [blame] | 245 | Ok(FileConfig::RemoteUnverifiedReadonlyFile { reader, file_size }) |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 246 | } |
| 247 | |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 248 | fn new_config_local_ro_file( |
Victor Hsieh | 6cf75b5 | 2021-04-01 12:45:49 -0700 | [diff] [blame] | 249 | protected_file: &Path, |
| 250 | merkle_tree_dump: &Path, |
| 251 | signature: &Path, |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 252 | ) -> Result<FileConfig> { |
| 253 | let file = File::open(&protected_file)?; |
| 254 | let file_size = file.metadata()?.len(); |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 255 | let file_reader = LocalFileReader::new(file)?; |
| 256 | let merkle_tree_reader = LocalFileReader::new(File::open(merkle_tree_dump)?)?; |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 257 | let authenticator = FakeAuthenticator::always_succeed(); |
| 258 | let mut sig = Vec::new(); |
| 259 | let _ = File::open(signature)?.read_to_end(&mut sig)?; |
Victor Hsieh | 1bcf411 | 2021-03-19 14:26:57 -0700 | [diff] [blame] | 260 | let reader = |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 261 | VerifiedFileReader::new(&authenticator, file_reader, file_size, sig, merkle_tree_reader)?; |
Victor Hsieh | 1bcf411 | 2021-03-19 14:26:57 -0700 | [diff] [blame] | 262 | Ok(FileConfig::LocalVerifiedReadonlyFile { reader, file_size }) |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 263 | } |
| 264 | |
Victor Hsieh | 6cf75b5 | 2021-04-01 12:45:49 -0700 | [diff] [blame] | 265 | fn new_config_local_ro_file_unverified(file_path: &Path) -> Result<FileConfig> { |
Victor Hsieh | 1bcf411 | 2021-03-19 14:26:57 -0700 | [diff] [blame] | 266 | let reader = LocalFileReader::new(File::open(file_path)?)?; |
| 267 | let file_size = reader.len(); |
| 268 | Ok(FileConfig::LocalUnverifiedReadonlyFile { reader, file_size }) |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 269 | } |
| 270 | |
Victor Hsieh | 2445e33 | 2021-06-04 16:44:53 -0700 | [diff] [blame] | 271 | fn new_config_remote_new_verified_file( |
| 272 | service: file::VirtFdService, |
| 273 | remote_id: i32, |
| 274 | ) -> Result<FileConfig> { |
Victor Hsieh | c3d45b1 | 2021-06-30 09:16:41 -0700 | [diff] [blame] | 275 | let remote_file = RemoteFileEditor::new(service, remote_id); |
Victor Hsieh | 1bcf411 | 2021-03-19 14:26:57 -0700 | [diff] [blame] | 276 | Ok(FileConfig::RemoteVerifiedNewFile { editor: VerifiedFileEditor::new(remote_file) }) |
Victor Hsieh | 6a47e7f | 2021-03-03 15:53:49 -0800 | [diff] [blame] | 277 | } |
| 278 | |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 279 | fn prepare_file_pool(args: &Args) -> Result<BTreeMap<Inode, FileConfig>> { |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 280 | let mut file_pool = BTreeMap::new(); |
| 281 | |
Victor Hsieh | 9ab13e5 | 2021-06-29 09:23:29 -0700 | [diff] [blame] | 282 | if args.has_remote_files() { |
| 283 | let service = file::get_binder_service(args.cid)?; |
Victor Hsieh | 2445e33 | 2021-06-04 16:44:53 -0700 | [diff] [blame] | 284 | |
Victor Hsieh | 9ab13e5 | 2021-06-29 09:23:29 -0700 | [diff] [blame] | 285 | for config in &args.remote_ro_file { |
| 286 | file_pool.insert( |
| 287 | config.ino, |
| 288 | new_config_remote_verified_file( |
| 289 | service.clone(), |
| 290 | config.remote_id, |
| 291 | config.file_size, |
| 292 | )?, |
| 293 | ); |
| 294 | } |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 295 | |
Victor Hsieh | 9ab13e5 | 2021-06-29 09:23:29 -0700 | [diff] [blame] | 296 | for config in &args.remote_ro_file_unverified { |
| 297 | file_pool.insert( |
| 298 | config.ino, |
| 299 | new_config_remote_unverified_file( |
| 300 | service.clone(), |
| 301 | config.remote_id, |
| 302 | config.file_size, |
| 303 | )?, |
| 304 | ); |
| 305 | } |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 306 | |
Victor Hsieh | 9ab13e5 | 2021-06-29 09:23:29 -0700 | [diff] [blame] | 307 | for config in &args.remote_new_rw_file { |
| 308 | file_pool.insert( |
| 309 | config.ino, |
| 310 | new_config_remote_new_verified_file(service.clone(), config.remote_id)?, |
| 311 | ); |
| 312 | } |
Victor Hsieh | 6a47e7f | 2021-03-03 15:53:49 -0800 | [diff] [blame] | 313 | } |
| 314 | |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 315 | for config in &args.local_ro_file { |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 316 | file_pool.insert( |
| 317 | config.ino, |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 318 | new_config_local_ro_file( |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 319 | &config.file_path, |
| 320 | &config.merkle_tree_dump_path, |
| 321 | &config.signature_path, |
| 322 | )?, |
| 323 | ); |
| 324 | } |
| 325 | |
Victor Hsieh | 09e2626 | 2021-03-03 16:00:55 -0800 | [diff] [blame] | 326 | for config in &args.local_ro_file_unverified { |
| 327 | 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] | 328 | } |
| 329 | |
| 330 | Ok(file_pool) |
| 331 | } |
| 332 | |
| 333 | fn main() -> Result<()> { |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 334 | let args = Args::from_args(); |
Victor Hsieh | 9d0ab62 | 2021-04-26 17:07:02 -0700 | [diff] [blame] | 335 | |
| 336 | let log_level = if args.debug { log::Level::Debug } else { log::Level::Info }; |
| 337 | android_logger::init_once( |
| 338 | android_logger::Config::default().with_tag("authfs").with_min_level(log_level), |
| 339 | ); |
| 340 | |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 341 | let file_pool = prepare_file_pool(&args)?; |
| 342 | fusefs::loop_forever(file_pool, &args.mount_point)?; |
Victor Hsieh | f01f323 | 2020-12-11 13:31:31 -0800 | [diff] [blame] | 343 | bail!("Unexpected exit after the handler loop") |
Victor Hsieh | 88ac6ca | 2020-11-13 15:20:24 -0800 | [diff] [blame] | 344 | } |