Skip to content

Commit 999443d

Browse files
Merge pull request #3 from SendSafely/v3.1
Updates for v3.1 release
2 parents c876df8 + 197e795 commit 999443d

25 files changed

+693
-112
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.sendsafely;
2+
3+
public class Privatekey {
4+
5+
private String privateKey;
6+
private String publicKeyId;
7+
8+
public String getArmoredKey() {
9+
return privateKey;
10+
}
11+
public void setArmoredKey(String privateKey) {
12+
this.privateKey = privateKey;
13+
}
14+
public String getPublicKeyId() {
15+
return publicKeyId;
16+
}
17+
public void setPublicKeyId(String publicKeyId) {
18+
this.publicKeyId = publicKeyId;
19+
}
20+
}

SendSafelyAPI/src/com/sendsafely/Recipient.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public class Recipient {
1616
private String recipientId;
1717
private String email;
1818
private boolean needsApproval;
19+
private List<String> approvers;
20+
private List<Phonenumber> phonenumbers;
1921
private List<Confirmation> confirmations = new ArrayList<Confirmation>();
2022
private String role;
2123

@@ -103,5 +105,22 @@ public String getRole() {
103105
public void setRole(String roleName) {
104106
this.role = roleName;
105107
}
108+
109+
public List<String> getApprovers() {
110+
return approvers;
111+
}
112+
113+
public void setApprovers(List<String> approvers) {
114+
this.approvers = approvers;
115+
}
116+
117+
public List<Phonenumber> getPhonenumbers() {
118+
return phonenumbers;
119+
}
120+
121+
public void setPhonenumbers(List<Phonenumber> phonenumbers) {
122+
this.phonenumbers = phonenumbers;
123+
}
124+
106125

107126
}

SendSafelyAPI/src/com/sendsafely/SendSafely.java

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@
22

33
import java.io.BufferedReader;
44
import java.io.DataOutputStream;
5+
import java.io.IOException;
56
import java.io.InputStream;
67
import java.io.InputStreamReader;
78
import java.net.HttpURLConnection;
89
import java.net.URL;
10+
import java.security.NoSuchAlgorithmException;
911
import java.security.Security;
1012
import java.util.Date;
1113
import java.util.List;
1214
import java.util.Map;
1315

1416
import org.bouncycastle.jce.provider.BouncyCastleProvider;
17+
import org.bouncycastle.openpgp.PGPException;
1518

1619
import com.google.gson.Gson;
1720
import com.sendsafely.connection.ConnectionFactory;
@@ -23,6 +26,7 @@
2326
import com.sendsafely.dto.EnterpriseInfo;
2427
import com.sendsafely.dto.FileInfo;
2528
import com.sendsafely.dto.PackageURL;
29+
import com.sendsafely.dto.RecipientHistory;
2630
import com.sendsafely.dto.UserInformation;
2731
import com.sendsafely.dto.request.AddContactGroupAsRecipientRequest;
2832
import com.sendsafely.dto.request.AddDropzoneRecipientRequest;
@@ -57,12 +61,14 @@
5761
import com.sendsafely.exceptions.FinalizePackageFailedException;
5862
import com.sendsafely.exceptions.GetActivityLogException;
5963
import com.sendsafely.exceptions.GetContactGroupsFailedException;
64+
import com.sendsafely.exceptions.GetKeycodeFailedException;
6065
import com.sendsafely.exceptions.GetPackagesException;
6166
import com.sendsafely.exceptions.InvalidCredentialsException;
6267
import com.sendsafely.exceptions.LimitExceededException;
6368
import com.sendsafely.exceptions.MessageException;
6469
import com.sendsafely.exceptions.PackageInformationFailedException;
6570
import com.sendsafely.exceptions.PasswordRequiredException;
71+
import com.sendsafely.exceptions.PublicKeysFailedException;
6672
import com.sendsafely.exceptions.RecipientFailedException;
6773
import com.sendsafely.exceptions.RemoveContactGroupAsRecipientFailedException;
6874
import com.sendsafely.exceptions.RemoveContactGroupFailedException;
@@ -88,6 +94,8 @@
8894
import com.sendsafely.handlers.DeleteDirectoryHandler;
8995
import com.sendsafely.handlers.DeleteFileHandler;
9096
import com.sendsafely.handlers.DeletePackageHandler;
97+
import com.sendsafely.handlers.RevokePublicKey;
98+
import com.sendsafely.handlers.DeleteTempPackageHandler;
9199
import com.sendsafely.handlers.DownloadAndDecryptFileHandler;
92100
import com.sendsafely.handlers.EnterpriseInfoHandler;
93101
import com.sendsafely.handlers.FileInformationHandler;
@@ -96,10 +104,12 @@
96104
import com.sendsafely.handlers.GetContactGroupsHandler;
97105
import com.sendsafely.handlers.GetDirectoryHandler;
98106
import com.sendsafely.handlers.GetDropzoneRecipientHandler;
107+
import com.sendsafely.handlers.GetKeycode;
99108
import com.sendsafely.handlers.GetMessageHandler;
100109
import com.sendsafely.handlers.GetOrganizationPackagesHandler;
101110
import com.sendsafely.handlers.GetPackagesHandler;
102111
import com.sendsafely.handlers.GetRecipientHandler;
112+
import com.sendsafely.handlers.GetRecipientHistoryHandler;
103113
import com.sendsafely.handlers.HandlerFactory;
104114
import com.sendsafely.handlers.MoveDirectoryHandler;
105115
import com.sendsafely.handlers.MoveFileHandler;
@@ -114,6 +124,7 @@
114124
import com.sendsafely.handlers.UpdatePackageDescriptorHandler;
115125
import com.sendsafely.handlers.UpdatePackageLifeHandler;
116126
import com.sendsafely.handlers.UpdateRecipientHandler;
127+
import com.sendsafely.handlers.UploadPublicKey;
117128
import com.sendsafely.handlers.UserInformationHandler;
118129
import com.sendsafely.handlers.VerifyCredentialsHandler;
119130
import com.sendsafely.handlers.VerifyVersionHandler;
@@ -122,6 +133,8 @@
122133
import com.sendsafely.upload.DefaultUploadManager;
123134
import com.sendsafely.upload.UploadFactory;
124135
import com.sendsafely.upload.UploadManager;
136+
import com.sendsafely.utils.CryptoUtil;
137+
import com.sendsafely.utils.Keypair;
125138

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

458+
/*
459+
* @ description Gets a list of Recipient History information.
460+
* @ param recipientEmail
461+
* @ returnType List<RecipientHistory>
462+
* @ return a List<RecipientHistory> object containing a list of all recipient history items.
463+
* @ throws RecipientFailedException
464+
*/
465+
public List<RecipientHistory> getRecipientHistory(String recipientEmail) throws RecipientFailedException{
466+
GetRecipientHistoryHandler handler = ((GetRecipientHistoryHandler)HandlerFactory.getInstance(uploadManager, Endpoint.RECIPIENT_HISTORY));
467+
return handler.makeRequest(recipientEmail);
468+
}
469+
445470
/**
446471
* @description Downloads a file from the server and decrypts it.
447472
* @param packageId The unique package id of the package for the file download operation.
@@ -542,6 +567,17 @@ public File encryptAndUploadFile(String packageId, String keyCode, FileManager f
542567
return handler.makeRequest(packageId, keyCode, file, progress);
543568
}
544569

570+
/**
571+
* @description Deletes a package given a package ID.
572+
* @param packageId The unique package id of the package for the delete temporary package operation.
573+
* @throws DeletePackageException
574+
*/
575+
public void deleteTempPackage(String packageId) throws DeletePackageException
576+
{
577+
DeleteTempPackageHandler handler = (DeleteTempPackageHandler)HandlerFactory.getInstance(uploadManager, Endpoint.DELETE_TEMP_PACKAGE);
578+
handler.makeRequest(packageId);
579+
}
580+
545581
/**
546582
* @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.
547583
* @param packageId The packageId to attach the file to.
@@ -561,6 +597,17 @@ public File encryptAndUploadFile(String packageId, String keyCode, String server
561597
return handler.makeRequest(packageId, null, keyCode, serverSecret, file, progress);
562598
}
563599

600+
/**
601+
* @description Get all received packages
602+
* @return List<String> a list of all received package IDs.
603+
* @throws GetPackagesException
604+
*/
605+
public List<PackageReference> getReceivedPackages() throws GetPackagesException
606+
{
607+
GetPackagesHandler handler = (GetPackagesHandler)HandlerFactory.getInstance(uploadManager, Endpoint.RECEIVED_PACKAGES);
608+
return handler.makeRequest();
609+
}
610+
564611
/**
565612
* @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.
566613
* @param packageId The unique package id of the package for the file upload operation.
@@ -844,6 +891,43 @@ public EnterpriseInfo getEnterpriseInfo() throws EnterpriseInfoFailedException
844891
return handler.makeRequest();
845892
}
846893

894+
/**
895+
* @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.
896+
* @param description The description used for generating the key pair.
897+
* @returnType Privatekey
898+
* @return Returns a Private Key containing the armored private key and a Public Key ID associating a public key to the private key.
899+
* @throws NoSuchAlgorithmException
900+
* @throws PublicKeysFailedException
901+
* @throws IOException
902+
* @throws PGPException
903+
*/
904+
public Privatekey generateKeyPair(String description) throws NoSuchAlgorithmException, PublicKeysFailedException, PGPException, IOException{
905+
906+
UploadPublicKey handler = new UploadPublicKey(uploadManager);
907+
Keypair kp = CryptoUtil.GenerateKeyPair();
908+
String publicKeyId = handler.makeRequest(kp.getPublicKey(), description);
909+
Privatekey privateKey = new Privatekey();
910+
privateKey.setPublicKeyId(publicKeyId);
911+
privateKey.setArmoredKey(kp.getPrivateKey());
912+
return privateKey;
913+
}
914+
915+
public String getKeycode(String packageId, Privatekey privateKey) throws GetKeycodeFailedException{
916+
GetKeycode handler = new GetKeycode(uploadManager);
917+
return handler.get(packageId, privateKey);
918+
}
919+
920+
/**
921+
* @description Revokes a public key from the server. Only call this if the private key has been deleted and should not be used anymore.
922+
* @param publicKeyId The public key id to revoke.
923+
* @throws PublicKeysFailedException
924+
*/
925+
public void revokePublicKey(String publicKeyId) throws PublicKeysFailedException{
926+
RevokePublicKey handler = new RevokePublicKey(uploadManager);
927+
handler.makeRequest(publicKeyId);
928+
}
929+
930+
847931
/**
848932
* @description Retrieves meta data about a file in a Workspace package.
849933
* @param packageId The unique package id of the package for the get file information operation.
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package com.sendsafely.dto;
2+
3+
import java.util.Date;
4+
import java.util.Set;
5+
6+
import com.sendsafely.Recipient;
7+
8+
public class RecipientHistory {
9+
10+
private String packageId;
11+
private String packageUserName;
12+
private String packageUserId;
13+
private int packageState;
14+
private String packageStateStr;
15+
private String packageStateColor;
16+
private int packageLife;
17+
private String packageUpdateTimestampStr;
18+
private Date packageUpdateTimestamp;
19+
private String packageCode;
20+
private String packageOS;
21+
private Recipient packageRecipientResponse;
22+
private Set<String> filenames;
23+
private boolean packageContainsMessage;
24+
public String getPackageId() {
25+
return packageId;
26+
}
27+
public void setPackageId(String packageId) {
28+
this.packageId = packageId;
29+
}
30+
public String getPackageUserName() {
31+
return packageUserName;
32+
}
33+
public void setPackageUserName(String packageUserName) {
34+
this.packageUserName = packageUserName;
35+
}
36+
public String getPackageUserId() {
37+
return packageUserId;
38+
}
39+
public void setPackageUserId(String packageUserId) {
40+
this.packageUserId = packageUserId;
41+
}
42+
public int getPackageState() {
43+
return packageState;
44+
}
45+
public void setPackageState(int packageState) {
46+
this.packageState = packageState;
47+
}
48+
public String getPackageStateStr() {
49+
return packageStateStr;
50+
}
51+
public void setPackageStateStr(String packageStateStr) {
52+
this.packageStateStr = packageStateStr;
53+
}
54+
public String getPackageStateColor() {
55+
return packageStateColor;
56+
}
57+
public void setPackageStateColor(String packageStateColor) {
58+
this.packageStateColor = packageStateColor;
59+
}
60+
public int getPackageLife() {
61+
return packageLife;
62+
}
63+
public void setPackageLife(int packageLife) {
64+
this.packageLife = packageLife;
65+
}
66+
public String getPackageUpdateTimestampStr() {
67+
return packageUpdateTimestampStr;
68+
}
69+
public void setPackageUpdateTimestampStr(String packageUpdateTimestampStr) {
70+
this.packageUpdateTimestampStr = packageUpdateTimestampStr;
71+
}
72+
public Date getPackageUpdateTimestamp() {
73+
return packageUpdateTimestamp;
74+
}
75+
public void setPackageUpdateTimestamp(Date packageUpdateTimestamp) {
76+
this.packageUpdateTimestamp = packageUpdateTimestamp;
77+
}
78+
public String getPackageCode() {
79+
return packageCode;
80+
}
81+
public void setPackageCode(String packageCode) {
82+
this.packageCode = packageCode;
83+
}
84+
public String getPackageOS() {
85+
return packageOS;
86+
}
87+
public void setPackageOS(String packageOS) {
88+
this.packageOS = packageOS;
89+
}
90+
public Recipient getPackageRecipientResponse() {
91+
return packageRecipientResponse;
92+
}
93+
public void setPackageRecipientResponse(Recipient packageRecipientResponse) {
94+
this.packageRecipientResponse = packageRecipientResponse;
95+
}
96+
public Set<String> getFilenames() {
97+
return filenames;
98+
}
99+
public void setFilenames(Set<String> filenames) {
100+
this.filenames = filenames;
101+
}
102+
public boolean isPackageContainsMessage() {
103+
return packageContainsMessage;
104+
}
105+
public void setPackageContainsMessage(boolean packageContainsMessage) {
106+
this.packageContainsMessage = packageContainsMessage;
107+
}
108+
109+
110+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.sendsafely.dto.request;
2+
3+
import com.sendsafely.enums.HTTPMethod;
4+
import com.sendsafely.json.JsonManager;
5+
6+
public class AddPublicKeyRequest extends BaseRequest
7+
{
8+
9+
private HTTPMethod method = HTTPMethod.PUT;
10+
private String path = "/public-key/";
11+
12+
public AddPublicKeyRequest(JsonManager jsonManager) {
13+
initialize(jsonManager, method, path);
14+
}
15+
16+
public void setPublicKey(String publicKey)
17+
{
18+
super.setPostParam("publicKey", publicKey);
19+
}
20+
21+
public void setDescription(String description){
22+
super.setPostParam("description", description);
23+
}
24+
25+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.sendsafely.dto.request;
2+
3+
import com.sendsafely.enums.GetParam;
4+
import com.sendsafely.enums.HTTPMethod;
5+
import com.sendsafely.json.JsonManager;
6+
7+
public class DeleteTempPackageRequest extends BaseRequest
8+
{
9+
10+
private HTTPMethod method = HTTPMethod.DELETE;
11+
private String path = "/package/" + GetParam.PACKAGE_ID + "/temp/";
12+
13+
public DeleteTempPackageRequest(JsonManager jsonManager) {
14+
initialize(jsonManager, method, path);
15+
}
16+
17+
public void setPackageId(String packageId)
18+
{
19+
super.setGetParam(GetParam.PACKAGE_ID, packageId);
20+
}
21+
}

0 commit comments

Comments
 (0)