2018-07-20 20:56:59 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								import ./make-test.nix ({ ... }:
							 | 
						
					
						
							
								
									
										
										
										
											2016-07-13 01:47:49 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								{
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  name = "ecryptfs";
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2018-07-20 20:56:59 +00:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  machine = { pkgs, ... }: {
							 | 
						
					
						
							
								
									
										
										
										
											2016-07-13 01:47:49 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    imports = [ ./common/user-account.nix ];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    boot.kernelModules = [ "ecryptfs" ];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    security.pam.enableEcryptfs = true;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    environment.systemPackages = with pkgs; [ keyutils ];
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  };
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  testScript = ''
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    $machine->waitForUnit("default.target");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    # Set alice up with a password and a home
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    $machine->succeed("(echo foobar; echo foobar) | passwd alice");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    $machine->succeed("chown -R alice.users ~alice");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    # Migrate alice's home
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    my $out = $machine->succeed("echo foobar | ecryptfs-migrate-home -u alice");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    $machine->log("ecryptfs-migrate-home said: $out");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    # Log alice in (ecryptfs passwhrase is wrapped during first login)
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-01 09:04:35 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    $machine->waitUntilTTYMatches(1, "login: ");
							 | 
						
					
						
							
								
									
										
										
										
											2016-07-13 01:47:49 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    $machine->sendChars("alice\n");
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-01 09:04:35 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    $machine->waitUntilTTYMatches(1, "Password: ");
							 | 
						
					
						
							
								
									
										
										
										
											2016-07-13 01:47:49 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    $machine->sendChars("foobar\n");
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-01 09:04:35 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    $machine->waitUntilTTYMatches(1, "alice\@machine");
							 | 
						
					
						
							
								
									
										
										
										
											2016-07-13 01:47:49 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    $machine->sendChars("logout\n");
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-01 09:04:35 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    $machine->waitUntilTTYMatches(1, "login: ");
							 | 
						
					
						
							
								
									
										
										
										
											2016-07-13 01:47:49 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    # Why do I need to do this??
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-16 02:46:13 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    $machine->succeed("su alice -c ecryptfs-umount-private || true");
							 | 
						
					
						
							
								
									
										
										
										
											2016-07-13 01:47:49 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    $machine->sleep(1);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    $machine->fail("mount | grep ecryptfs"); # check that encrypted home is not mounted
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    # Show contents of the user keyring
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    my $out = $machine->succeed("su - alice -c 'keyctl list \@u'");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    $machine->log("keyctl unlink said: " . $out);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    # Log alice again
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-01 09:04:35 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    $machine->waitUntilTTYMatches(1, "login: ");
							 | 
						
					
						
							
								
									
										
										
										
											2016-07-13 01:47:49 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    $machine->sendChars("alice\n");
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-01 09:04:35 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    $machine->waitUntilTTYMatches(1, "Password: ");
							 | 
						
					
						
							
								
									
										
										
										
											2016-07-13 01:47:49 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    $machine->sendChars("foobar\n");
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-01 09:04:35 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    $machine->waitUntilTTYMatches(1, "alice\@machine");
							 | 
						
					
						
							
								
									
										
										
										
											2016-07-13 01:47:49 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    # Create some files in encrypted home
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    $machine->succeed("su alice -c 'touch ~alice/a'");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    $machine->succeed("su alice -c 'echo c > ~alice/b'");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    # Logout
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    $machine->sendChars("logout\n");
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-01 09:04:35 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    $machine->waitUntilTTYMatches(1, "login: ");
							 | 
						
					
						
							
								
									
										
										
										
											2016-07-13 01:47:49 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    # Why do I need to do this??
							 | 
						
					
						
							
								
									
										
										
										
											2016-08-16 02:46:13 +01:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    $machine->succeed("su alice -c ecryptfs-umount-private || true");
							 | 
						
					
						
							
								
									
										
										
										
											2016-07-13 01:47:49 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    $machine->sleep(1);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    # Check that the filesystem is not accessible
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    $machine->fail("mount | grep ecryptfs");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    $machine->succeed("su alice -c 'test \! -f ~alice/a'");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    $machine->succeed("su alice -c 'test \! -f ~alice/b'");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    # Log alice once more
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-01 09:04:35 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    $machine->waitUntilTTYMatches(1, "login: ");
							 | 
						
					
						
							
								
									
										
										
										
											2016-07-13 01:47:49 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    $machine->sendChars("alice\n");
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-01 09:04:35 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    $machine->waitUntilTTYMatches(1, "Password: ");
							 | 
						
					
						
							
								
									
										
										
										
											2016-07-13 01:47:49 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    $machine->sendChars("foobar\n");
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-01 09:04:35 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    $machine->waitUntilTTYMatches(1, "alice\@machine");
							 | 
						
					
						
							
								
									
										
										
										
											2016-07-13 01:47:49 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    # Check that the files are there
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    $machine->sleep(1);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    $machine->succeed("su alice -c 'test -f ~alice/a'");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    $machine->succeed("su alice -c 'test -f ~alice/b'");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    $machine->succeed(qq%test "\$(cat ~alice/b)" = "c"%);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-07-13 01:59:47 +02:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    # Catch https://github.com/NixOS/nixpkgs/issues/16766
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    $machine->succeed("su alice -c 'ls -lh ~alice/'");
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2016-07-13 01:47:49 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    $machine->sendChars("logout\n");
							 | 
						
					
						
							
								
									
										
										
										
											2016-12-01 09:04:35 -05:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    $machine->waitUntilTTYMatches(1, "login: ");
							 | 
						
					
						
							
								
									
										
										
										
											2016-07-13 01:47:49 +02:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  '';
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								})
							 |