2
2
3
3
import java .io .BufferedReader ;
4
4
import java .io .DataOutputStream ;
5
+ import java .io .IOException ;
5
6
import java .io .InputStream ;
6
7
import java .io .InputStreamReader ;
7
8
import java .net .HttpURLConnection ;
8
9
import java .net .URL ;
10
+ import java .security .NoSuchAlgorithmException ;
9
11
import java .security .Security ;
10
12
import java .util .Date ;
11
13
import java .util .List ;
12
14
import java .util .Map ;
13
15
14
16
import org .bouncycastle .jce .provider .BouncyCastleProvider ;
17
+ import org .bouncycastle .openpgp .PGPException ;
15
18
16
19
import com .google .gson .Gson ;
17
20
import com .sendsafely .connection .ConnectionFactory ;
23
26
import com .sendsafely .dto .EnterpriseInfo ;
24
27
import com .sendsafely .dto .FileInfo ;
25
28
import com .sendsafely .dto .PackageURL ;
29
+ import com .sendsafely .dto .RecipientHistory ;
26
30
import com .sendsafely .dto .UserInformation ;
27
31
import com .sendsafely .dto .request .AddContactGroupAsRecipientRequest ;
28
32
import com .sendsafely .dto .request .AddDropzoneRecipientRequest ;
57
61
import com .sendsafely .exceptions .FinalizePackageFailedException ;
58
62
import com .sendsafely .exceptions .GetActivityLogException ;
59
63
import com .sendsafely .exceptions .GetContactGroupsFailedException ;
64
+ import com .sendsafely .exceptions .GetKeycodeFailedException ;
60
65
import com .sendsafely .exceptions .GetPackagesException ;
61
66
import com .sendsafely .exceptions .InvalidCredentialsException ;
62
67
import com .sendsafely .exceptions .LimitExceededException ;
63
68
import com .sendsafely .exceptions .MessageException ;
64
69
import com .sendsafely .exceptions .PackageInformationFailedException ;
65
70
import com .sendsafely .exceptions .PasswordRequiredException ;
71
+ import com .sendsafely .exceptions .PublicKeysFailedException ;
66
72
import com .sendsafely .exceptions .RecipientFailedException ;
67
73
import com .sendsafely .exceptions .RemoveContactGroupAsRecipientFailedException ;
68
74
import com .sendsafely .exceptions .RemoveContactGroupFailedException ;
88
94
import com .sendsafely .handlers .DeleteDirectoryHandler ;
89
95
import com .sendsafely .handlers .DeleteFileHandler ;
90
96
import com .sendsafely .handlers .DeletePackageHandler ;
97
+ import com .sendsafely .handlers .RevokePublicKey ;
98
+ import com .sendsafely .handlers .DeleteTempPackageHandler ;
91
99
import com .sendsafely .handlers .DownloadAndDecryptFileHandler ;
92
100
import com .sendsafely .handlers .EnterpriseInfoHandler ;
93
101
import com .sendsafely .handlers .FileInformationHandler ;
96
104
import com .sendsafely .handlers .GetContactGroupsHandler ;
97
105
import com .sendsafely .handlers .GetDirectoryHandler ;
98
106
import com .sendsafely .handlers .GetDropzoneRecipientHandler ;
107
+ import com .sendsafely .handlers .GetKeycode ;
99
108
import com .sendsafely .handlers .GetMessageHandler ;
100
109
import com .sendsafely .handlers .GetOrganizationPackagesHandler ;
101
110
import com .sendsafely .handlers .GetPackagesHandler ;
102
111
import com .sendsafely .handlers .GetRecipientHandler ;
112
+ import com .sendsafely .handlers .GetRecipientHistoryHandler ;
103
113
import com .sendsafely .handlers .HandlerFactory ;
104
114
import com .sendsafely .handlers .MoveDirectoryHandler ;
105
115
import com .sendsafely .handlers .MoveFileHandler ;
114
124
import com .sendsafely .handlers .UpdatePackageDescriptorHandler ;
115
125
import com .sendsafely .handlers .UpdatePackageLifeHandler ;
116
126
import com .sendsafely .handlers .UpdateRecipientHandler ;
127
+ import com .sendsafely .handlers .UploadPublicKey ;
117
128
import com .sendsafely .handlers .UserInformationHandler ;
118
129
import com .sendsafely .handlers .VerifyCredentialsHandler ;
119
130
import com .sendsafely .handlers .VerifyVersionHandler ;
122
133
import com .sendsafely .upload .DefaultUploadManager ;
123
134
import com .sendsafely .upload .UploadFactory ;
124
135
import com .sendsafely .upload .UploadManager ;
136
+ import com .sendsafely .utils .CryptoUtil ;
137
+ import com .sendsafely .utils .Keypair ;
125
138
126
139
/**
127
140
* @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
442
455
return handler .makeRequest (packageId , null , fileId , keyCode , progress , null );
443
456
}
444
457
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
+
445
470
/**
446
471
* @description Downloads a file from the server and decrypts it.
447
472
* @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
542
567
return handler .makeRequest (packageId , keyCode , file , progress );
543
568
}
544
569
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
+
545
581
/**
546
582
* @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.
547
583
* @param packageId The packageId to attach the file to.
@@ -561,6 +597,17 @@ public File encryptAndUploadFile(String packageId, String keyCode, String server
561
597
return handler .makeRequest (packageId , null , keyCode , serverSecret , file , progress );
562
598
}
563
599
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
+
564
611
/**
565
612
* @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.
566
613
* @param packageId The unique package id of the package for the file upload operation.
@@ -844,6 +891,43 @@ public EnterpriseInfo getEnterpriseInfo() throws EnterpriseInfoFailedException
844
891
return handler .makeRequest ();
845
892
}
846
893
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
+
847
931
/**
848
932
* @description Retrieves meta data about a file in a Workspace package.
849
933
* @param packageId The unique package id of the package for the get file information operation.
0 commit comments