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