Skip to content

Commit

Permalink
Merge pull request #28 from rodrigorato/intermediate
Browse files Browse the repository at this point in the history
Intermediate
  • Loading branch information
Gisson authored Dec 7, 2017
2 parents b4a69f4 + ed01a26 commit 421cf00
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 49 deletions.
107 changes: 66 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Once again, navigate to the ca folder, `cd ca`, then:
2. Verify the root CA information. *Make sure it is correct*:
`keytool -v -printcert -file yarfs-root.der`

3. Find out where the keystore for the trusted CAs is located in your system. It is probably located in the following file, owned by root:
3. Find out where the keystore for the trusted CAs is located in your system. It is probably located in the following file, owned by root. If not, find it with `find / -name cacert`, and then export the CACERTS variable to point to the cacerts file:
`export CACERTS=$JAVA_HOME/jre/lib/security/cacerts`

4. Create a backup of the trusted CA certificates keystore:
Expand All @@ -57,53 +57,78 @@ When you are done, restore the trusted certificates keystore ;) :
`cp -v ~/$(basename $CACERTS).bak $CACERTS`


====== HOW TO RUN ======

1. First of all, this project uses the /var/yarfs directory to store all it's files, so whenever a user wants to upload/download files to/from the server, that's where they should/will be.
- sudo mkdir -p /var/yarfs/server/files
- sudo mkdir -p /var/yarfs/client/files
- sudo mkdir -p /var/yarfs/client/.keys
- sudo chown -R $USER:$USER /var/yarfs

2. Generate Certificates and Key Stores with our script.
- Use password="password"

3. To use these certificates register `server.yarfs` and `ca.yarfs` in your /etc/hosts file (with the desired IP address - to run locally, 127.0.0.1 will do).

4. Add the Root CA certificate to your local Java list of trusted CAs as described in the README.md file.
- Find it with `find / | grep -i cacert`
- Mine (Arch Linux) was in /etc/ssl/certs/java/cacerts

5. Link/Copy the Server's Key Store in the server module's root directory ($YARFSROOT/server/).
- like so: `ln -s ../root-ca/yarfs-server.jks .`

6. You can now run the server like:
- `mvn clean compile exec:java -Dexec.args="31000 --ssl --listen=server.yarfs"`

7. Link/Copy the CA's Key Store in the CA module's root directory ($YARFSROOT/ca/).
- like so: `ln -s ../root-ca/yarfs-ca.jks .`

8. You can now run the CA like:
- `mvn clean compile exec:java -Dexec.args="https://server.yarfs:31000 --port=31001 --listen=ca.yarfs"`

9. Link/Copy the CA's certificate into the client module's root directory (~yarfsroot~/client/).
-like so: `ln -s ../root-ca/yarfs-ca.pem .`

10. Finally, to run the client, you can use the runclient.sh we included, as this module depends on the CA module and the compilation process is troublesome.


====== EXAMPLE USAGE ======

0. Check the available commands with:
- help
## HOW TO RUN
These are the instructions on how to test the project by running everything on
the same machine.
To use differente machine for the server, CA and client(s), the addresses need
to be changed and the certificates and keys need to be properly distributed.

1. First of all, this project uses the /var/yarfs directory to store all its files,
so whenever a user wants to upload/download files to/from the server, that's where
will look for or place them into. Create the necessary folder structure:
```
sudo mkdir -p /var/yarfs/server/files
sudo mkdir -p /var/yarfs/client/files
sudo mkdir -p /var/yarfs/client/.keys
sudo chown -R $USER:$USER /var/yarfs
```

2. Generate Certificates and Key Stores with our script, following the instructions in the HTTPS section above. Use password="password".

3. For these certificates to be valid, register *server.yarfs* and *ca.yarfs* in your /etc/hosts file (pointing to the desired IP address - to run locally, 127.0.0.1 will do).

4. Add the Root CA certificate to your local Java list of trusted CAs as described in the README.md file (section HTTPS/Client).

5. Link/Copy the Server's Key Store to the server module's root directory (YARFSROOT is the folder the README.md file is located):
```
cd $YARFSROOT/server/
ln -fs ../root-ca/yarfs-server.jks
```

6. You can now run the server:
```
mvn clean compile exec:java -Dexec.args="31000 --ssl --listen=server.yarfs"
```

7. On another shell, link/copy the CA's Key Store to the CA module's root directory:
```
cd $YARFSROOT/ca/
ln -fs ../root-ca/yarfs-ca.jks yarfs-ca.jks
```

8. You can now run the CA:
```
mvn clean compile exec:java -Dexec.args="https://server.yarfs:31000 --port=31001 --listen=ca.yarfs"
```

9. On another shell, Link/Copy the CA's certificate into the client module's root directory:
```
cd $YARFSROOT/ca/
ln -s ../root-ca/yarfs-ca.pem yarfs-ca.pem
```

10. Finally, to run the client, you can use the *runclient.sh* script we included,
as this module depends on the CA module and the compilation process is troublesome:
```
bash runclient.sh
```

### Example usage
Now that all three components of the application are running, you can try running
some commands in the client's shell.

0. Check the commands that are available in the client's shell use the help command.
The "yarfs $" is the prompt text which appears when the client shell is ready to
receive commands from the user:
`yarfs $ help`

1. Run a client and then:
- register mm ThisIsPassword

2. Run another client and then:
- register pa HackWall





Expand Down
2 changes: 1 addition & 1 deletion client/runclient.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ mvn compile package
mvn install:install-file -Dfile=target/ca-1.0-SNAPSHOT.jar -DgroupId=a16 -DartifactId=ca -Dversion=1.0-SNAPSHOT -Dpackaging=jar -DlocalRepositoryPath=../client/my-repo
popd
mvn dependency:purge-local-repository
mvn -U compile exec:java -Dexec.args="https://server.yarfs:31000 --ca-addr=ca.yarfs"
mvn -U compile exec:java -Dexec.args="https://server.yarfs:31001 --ca-addr=ca.yarfs"
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/
public class CommitCommand extends Command{
public CommitCommand(Shell sh, String name) {
super(sh, name, "Commit a change of existing file.");
super(sh, name, "commit a change of an existing file.");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
public class RefreshCommand extends Command{

public RefreshCommand(Shell sh, String name) {
super(sh, name, "Unable to refresh metadata from server.");
super(sh, name, "refreshes metadata from server.");
}

@Override
Expand All @@ -29,7 +29,7 @@ void execute(String[] args) {
service.execute();
List<String> newFiles = service.getNewFiles();
if( newFiles.size() == 0 ){
shell.println("No new files. All up to date!");
shell.println("No new files. ");
}else{
shell.println("New files were found.");
for(String filename : newFiles){
Expand Down
4 changes: 2 additions & 2 deletions client/src/main/java/a16/yarfs/client/presentation/Shell.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void execute(String[] args) {
Collections.sort(availableCmds);
for(String cmdName : availableCmds) {
Command c = getShell().getCommand(cmdName);
println(" " + whatIs(c));
println("\t" + whatIs(c));
}
} else {
String cmdName = args[0];
Expand All @@ -106,7 +106,7 @@ public String getUsage() {
}

protected String whatIs(Command cmd) {
return cmd.getName() + "\t\t" + cmd.getHelp();
return cmd.getName() + "\t\t\t" + cmd.getHelp();
}

public void println(String s) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class Unsharecommand extends Command{


public Unsharecommand(Shell sh, String name) {
super(sh, name, "Unshare a file with a user.");
super(sh, name, "unshare a file with a user.");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected JSONObject getResponse() throws IOException, NotExecutedException, Ser
*/
protected void assertExecuted() {
if (!_executed) {
throw new RuntimeException("Command was NOT executed!");
throw new RuntimeException("Service was NOT executed!");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public void execute() throws IOException, AlreadyExecutedException, ServiceExecu
super.execute();
} catch (IOException e) {
getLogger().warn("File not found. What now?");
throw new ServiceExecutionException("File not found. Use refresh first.");
}


Expand Down

0 comments on commit 421cf00

Please sign in to comment.