Skip to content

Commit

Permalink
Merge pull request #3 from SendSafely/v3.1
Browse files Browse the repository at this point in the history
Updates for v3.1 release
  • Loading branch information
SendSafely-GitHub committed Jan 10, 2019
2 parents c876df8 + 197e795 commit 999443d
Show file tree
Hide file tree
Showing 25 changed files with 693 additions and 112 deletions.
20 changes: 20 additions & 0 deletions SendSafelyAPI/src/com/sendsafely/Privatekey.java
@@ -0,0 +1,20 @@
package com.sendsafely;

public class Privatekey {

private String privateKey;
private String publicKeyId;

public String getArmoredKey() {
return privateKey;
}
public void setArmoredKey(String privateKey) {
this.privateKey = privateKey;
}
public String getPublicKeyId() {
return publicKeyId;
}
public void setPublicKeyId(String publicKeyId) {
this.publicKeyId = publicKeyId;
}
}
19 changes: 19 additions & 0 deletions SendSafelyAPI/src/com/sendsafely/Recipient.java
Expand Up @@ -16,6 +16,8 @@ public class Recipient {
private String recipientId;
private String email;
private boolean needsApproval;
private List<String> approvers;
private List<Phonenumber> phonenumbers;
private List<Confirmation> confirmations = new ArrayList<Confirmation>();
private String role;

Expand Down Expand Up @@ -103,5 +105,22 @@ public String getRole() {
public void setRole(String roleName) {
this.role = roleName;
}

public List<String> getApprovers() {
return approvers;
}

public void setApprovers(List<String> approvers) {
this.approvers = approvers;
}

public List<Phonenumber> getPhonenumbers() {
return phonenumbers;
}

public void setPhonenumbers(List<Phonenumber> phonenumbers) {
this.phonenumbers = phonenumbers;
}


}
84 changes: 84 additions & 0 deletions SendSafelyAPI/src/com/sendsafely/SendSafely.java
Expand Up @@ -2,16 +2,19 @@

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.NoSuchAlgorithmException;
import java.security.Security;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.openpgp.PGPException;

import com.google.gson.Gson;
import com.sendsafely.connection.ConnectionFactory;
Expand All @@ -23,6 +26,7 @@
import com.sendsafely.dto.EnterpriseInfo;
import com.sendsafely.dto.FileInfo;
import com.sendsafely.dto.PackageURL;
import com.sendsafely.dto.RecipientHistory;
import com.sendsafely.dto.UserInformation;
import com.sendsafely.dto.request.AddContactGroupAsRecipientRequest;
import com.sendsafely.dto.request.AddDropzoneRecipientRequest;
Expand Down Expand Up @@ -57,12 +61,14 @@
import com.sendsafely.exceptions.FinalizePackageFailedException;
import com.sendsafely.exceptions.GetActivityLogException;
import com.sendsafely.exceptions.GetContactGroupsFailedException;
import com.sendsafely.exceptions.GetKeycodeFailedException;
import com.sendsafely.exceptions.GetPackagesException;
import com.sendsafely.exceptions.InvalidCredentialsException;
import com.sendsafely.exceptions.LimitExceededException;
import com.sendsafely.exceptions.MessageException;
import com.sendsafely.exceptions.PackageInformationFailedException;
import com.sendsafely.exceptions.PasswordRequiredException;
import com.sendsafely.exceptions.PublicKeysFailedException;
import com.sendsafely.exceptions.RecipientFailedException;
import com.sendsafely.exceptions.RemoveContactGroupAsRecipientFailedException;
import com.sendsafely.exceptions.RemoveContactGroupFailedException;
Expand All @@ -88,6 +94,8 @@
import com.sendsafely.handlers.DeleteDirectoryHandler;
import com.sendsafely.handlers.DeleteFileHandler;
import com.sendsafely.handlers.DeletePackageHandler;
import com.sendsafely.handlers.RevokePublicKey;
import com.sendsafely.handlers.DeleteTempPackageHandler;
import com.sendsafely.handlers.DownloadAndDecryptFileHandler;
import com.sendsafely.handlers.EnterpriseInfoHandler;
import com.sendsafely.handlers.FileInformationHandler;
Expand All @@ -96,10 +104,12 @@
import com.sendsafely.handlers.GetContactGroupsHandler;
import com.sendsafely.handlers.GetDirectoryHandler;
import com.sendsafely.handlers.GetDropzoneRecipientHandler;
import com.sendsafely.handlers.GetKeycode;
import com.sendsafely.handlers.GetMessageHandler;
import com.sendsafely.handlers.GetOrganizationPackagesHandler;
import com.sendsafely.handlers.GetPackagesHandler;
import com.sendsafely.handlers.GetRecipientHandler;
import com.sendsafely.handlers.GetRecipientHistoryHandler;
import com.sendsafely.handlers.HandlerFactory;
import com.sendsafely.handlers.MoveDirectoryHandler;
import com.sendsafely.handlers.MoveFileHandler;
Expand All @@ -114,6 +124,7 @@
import com.sendsafely.handlers.UpdatePackageDescriptorHandler;
import com.sendsafely.handlers.UpdatePackageLifeHandler;
import com.sendsafely.handlers.UpdateRecipientHandler;
import com.sendsafely.handlers.UploadPublicKey;
import com.sendsafely.handlers.UserInformationHandler;
import com.sendsafely.handlers.VerifyCredentialsHandler;
import com.sendsafely.handlers.VerifyVersionHandler;
Expand All @@ -122,6 +133,8 @@
import com.sendsafely.upload.DefaultUploadManager;
import com.sendsafely.upload.UploadFactory;
import com.sendsafely.upload.UploadManager;
import com.sendsafely.utils.CryptoUtil;
import com.sendsafely.utils.Keypair;

/**
* @description The main SendSafely API. Use this API to create packages and append files and recipients.
Expand Down Expand Up @@ -442,6 +455,18 @@ public java.io.File downloadFile(String packageId, String fileId, String keyCode
return handler.makeRequest(packageId, null, fileId, keyCode, progress, null);
}

/*
* @ description Gets a list of Recipient History information.
* @ param recipientEmail
* @ returnType List<RecipientHistory>
* @ return a List<RecipientHistory> object containing a list of all recipient history items.
* @ throws RecipientFailedException
*/
public List<RecipientHistory> getRecipientHistory(String recipientEmail) throws RecipientFailedException{
GetRecipientHistoryHandler handler = ((GetRecipientHistoryHandler)HandlerFactory.getInstance(uploadManager, Endpoint.RECIPIENT_HISTORY));
return handler.makeRequest(recipientEmail);
}

/**
* @description Downloads a file from the server and decrypts it.
* @param packageId The unique package id of the package for the file download operation.
Expand Down Expand Up @@ -542,6 +567,17 @@ public File encryptAndUploadFile(String packageId, String keyCode, FileManager f
return handler.makeRequest(packageId, keyCode, file, progress);
}

/**
* @description Deletes a package given a package ID.
* @param packageId The unique package id of the package for the delete temporary package operation.
* @throws DeletePackageException
*/
public void deleteTempPackage(String packageId) throws DeletePackageException
{
DeleteTempPackageHandler handler = (DeleteTempPackageHandler)HandlerFactory.getInstance(uploadManager, Endpoint.DELETE_TEMP_PACKAGE);
handler.makeRequest(packageId);
}

/**
* @description Encrypt and upload a new file. The file will be encrypted before being uploaded to the server. The function will block until the file is uploaded.
* @param packageId The packageId to attach the file to.
Expand All @@ -561,6 +597,17 @@ public File encryptAndUploadFile(String packageId, String keyCode, String server
return handler.makeRequest(packageId, null, keyCode, serverSecret, file, progress);
}

/**
* @description Get all received packages
* @return List<String> a list of all received package IDs.
* @throws GetPackagesException
*/
public List<PackageReference> getReceivedPackages() throws GetPackagesException
{
GetPackagesHandler handler = (GetPackagesHandler)HandlerFactory.getInstance(uploadManager, Endpoint.RECEIVED_PACKAGES);
return handler.makeRequest();
}

/**
* @description Encrypt and upload a new file to a directory in a Workspace package. The file will be encrypted before being uploaded to the server. The function will block until the file is uploaded.
* @param packageId The unique package id of the package for the file upload operation.
Expand Down Expand Up @@ -844,6 +891,43 @@ public EnterpriseInfo getEnterpriseInfo() throws EnterpriseInfoFailedException
return handler.makeRequest();
}

/**
* @description Generates a new RSA Key pair used to encrypt keycodes. The private key as well as an identifier associating the public Key is returned to the user. The public key is uploaded and stored on the SendSafely servers.
* @param description The description used for generating the key pair.
* @returnType Privatekey
* @return Returns a Private Key containing the armored private key and a Public Key ID associating a public key to the private key.
* @throws NoSuchAlgorithmException
* @throws PublicKeysFailedException
* @throws IOException
* @throws PGPException
*/
public Privatekey generateKeyPair(String description) throws NoSuchAlgorithmException, PublicKeysFailedException, PGPException, IOException{

UploadPublicKey handler = new UploadPublicKey(uploadManager);
Keypair kp = CryptoUtil.GenerateKeyPair();
String publicKeyId = handler.makeRequest(kp.getPublicKey(), description);
Privatekey privateKey = new Privatekey();
privateKey.setPublicKeyId(publicKeyId);
privateKey.setArmoredKey(kp.getPrivateKey());
return privateKey;
}

public String getKeycode(String packageId, Privatekey privateKey) throws GetKeycodeFailedException{
GetKeycode handler = new GetKeycode(uploadManager);
return handler.get(packageId, privateKey);
}

/**
* @description Revokes a public key from the server. Only call this if the private key has been deleted and should not be used anymore.
* @param publicKeyId The public key id to revoke.
* @throws PublicKeysFailedException
*/
public void revokePublicKey(String publicKeyId) throws PublicKeysFailedException{
RevokePublicKey handler = new RevokePublicKey(uploadManager);
handler.makeRequest(publicKeyId);
}


/**
* @description Retrieves meta data about a file in a Workspace package.
* @param packageId The unique package id of the package for the get file information operation.
Expand Down
110 changes: 110 additions & 0 deletions SendSafelyAPI/src/com/sendsafely/dto/RecipientHistory.java
@@ -0,0 +1,110 @@
package com.sendsafely.dto;

import java.util.Date;
import java.util.Set;

import com.sendsafely.Recipient;

public class RecipientHistory {

private String packageId;
private String packageUserName;
private String packageUserId;
private int packageState;
private String packageStateStr;
private String packageStateColor;
private int packageLife;
private String packageUpdateTimestampStr;
private Date packageUpdateTimestamp;
private String packageCode;
private String packageOS;
private Recipient packageRecipientResponse;
private Set<String> filenames;
private boolean packageContainsMessage;
public String getPackageId() {
return packageId;
}
public void setPackageId(String packageId) {
this.packageId = packageId;
}
public String getPackageUserName() {
return packageUserName;
}
public void setPackageUserName(String packageUserName) {
this.packageUserName = packageUserName;
}
public String getPackageUserId() {
return packageUserId;
}
public void setPackageUserId(String packageUserId) {
this.packageUserId = packageUserId;
}
public int getPackageState() {
return packageState;
}
public void setPackageState(int packageState) {
this.packageState = packageState;
}
public String getPackageStateStr() {
return packageStateStr;
}
public void setPackageStateStr(String packageStateStr) {
this.packageStateStr = packageStateStr;
}
public String getPackageStateColor() {
return packageStateColor;
}
public void setPackageStateColor(String packageStateColor) {
this.packageStateColor = packageStateColor;
}
public int getPackageLife() {
return packageLife;
}
public void setPackageLife(int packageLife) {
this.packageLife = packageLife;
}
public String getPackageUpdateTimestampStr() {
return packageUpdateTimestampStr;
}
public void setPackageUpdateTimestampStr(String packageUpdateTimestampStr) {
this.packageUpdateTimestampStr = packageUpdateTimestampStr;
}
public Date getPackageUpdateTimestamp() {
return packageUpdateTimestamp;
}
public void setPackageUpdateTimestamp(Date packageUpdateTimestamp) {
this.packageUpdateTimestamp = packageUpdateTimestamp;
}
public String getPackageCode() {
return packageCode;
}
public void setPackageCode(String packageCode) {
this.packageCode = packageCode;
}
public String getPackageOS() {
return packageOS;
}
public void setPackageOS(String packageOS) {
this.packageOS = packageOS;
}
public Recipient getPackageRecipientResponse() {
return packageRecipientResponse;
}
public void setPackageRecipientResponse(Recipient packageRecipientResponse) {
this.packageRecipientResponse = packageRecipientResponse;
}
public Set<String> getFilenames() {
return filenames;
}
public void setFilenames(Set<String> filenames) {
this.filenames = filenames;
}
public boolean isPackageContainsMessage() {
return packageContainsMessage;
}
public void setPackageContainsMessage(boolean packageContainsMessage) {
this.packageContainsMessage = packageContainsMessage;
}


}
@@ -0,0 +1,25 @@
package com.sendsafely.dto.request;

import com.sendsafely.enums.HTTPMethod;
import com.sendsafely.json.JsonManager;

public class AddPublicKeyRequest extends BaseRequest
{

private HTTPMethod method = HTTPMethod.PUT;
private String path = "/public-key/";

public AddPublicKeyRequest(JsonManager jsonManager) {
initialize(jsonManager, method, path);
}

public void setPublicKey(String publicKey)
{
super.setPostParam("publicKey", publicKey);
}

public void setDescription(String description){
super.setPostParam("description", description);
}

}
@@ -0,0 +1,21 @@
package com.sendsafely.dto.request;

import com.sendsafely.enums.GetParam;
import com.sendsafely.enums.HTTPMethod;
import com.sendsafely.json.JsonManager;

public class DeleteTempPackageRequest extends BaseRequest
{

private HTTPMethod method = HTTPMethod.DELETE;
private String path = "/package/" + GetParam.PACKAGE_ID + "/temp/";

public DeleteTempPackageRequest(JsonManager jsonManager) {
initialize(jsonManager, method, path);
}

public void setPackageId(String packageId)
{
super.setGetParam(GetParam.PACKAGE_ID, packageId);
}
}

0 comments on commit 999443d

Please sign in to comment.