22
33import java .io .BufferedReader ;
44import java .io .DataOutputStream ;
5+ import java .io .IOException ;
56import java .io .InputStream ;
67import java .io .InputStreamReader ;
78import java .net .HttpURLConnection ;
89import java .net .URL ;
10+ import java .security .NoSuchAlgorithmException ;
911import java .security .Security ;
1012import java .util .Date ;
1113import java .util .List ;
1214import java .util .Map ;
1315
1416import org .bouncycastle .jce .provider .BouncyCastleProvider ;
17+ import org .bouncycastle .openpgp .PGPException ;
1518
1619import com .google .gson .Gson ;
1720import com .sendsafely .connection .ConnectionFactory ;
2326import com .sendsafely .dto .EnterpriseInfo ;
2427import com .sendsafely .dto .FileInfo ;
2528import com .sendsafely .dto .PackageURL ;
29+ import com .sendsafely .dto .RecipientHistory ;
2630import com .sendsafely .dto .UserInformation ;
2731import com .sendsafely .dto .request .AddContactGroupAsRecipientRequest ;
2832import com .sendsafely .dto .request .AddDropzoneRecipientRequest ;
5761import com .sendsafely .exceptions .FinalizePackageFailedException ;
5862import com .sendsafely .exceptions .GetActivityLogException ;
5963import com .sendsafely .exceptions .GetContactGroupsFailedException ;
64+ import com .sendsafely .exceptions .GetKeycodeFailedException ;
6065import com .sendsafely .exceptions .GetPackagesException ;
6166import com .sendsafely .exceptions .InvalidCredentialsException ;
6267import com .sendsafely .exceptions .LimitExceededException ;
6368import com .sendsafely .exceptions .MessageException ;
6469import com .sendsafely .exceptions .PackageInformationFailedException ;
6570import com .sendsafely .exceptions .PasswordRequiredException ;
71+ import com .sendsafely .exceptions .PublicKeysFailedException ;
6672import com .sendsafely .exceptions .RecipientFailedException ;
6773import com .sendsafely .exceptions .RemoveContactGroupAsRecipientFailedException ;
6874import com .sendsafely .exceptions .RemoveContactGroupFailedException ;
8894import com .sendsafely .handlers .DeleteDirectoryHandler ;
8995import com .sendsafely .handlers .DeleteFileHandler ;
9096import com .sendsafely .handlers .DeletePackageHandler ;
97+ import com .sendsafely .handlers .RevokePublicKey ;
98+ import com .sendsafely .handlers .DeleteTempPackageHandler ;
9199import com .sendsafely .handlers .DownloadAndDecryptFileHandler ;
92100import com .sendsafely .handlers .EnterpriseInfoHandler ;
93101import com .sendsafely .handlers .FileInformationHandler ;
96104import com .sendsafely .handlers .GetContactGroupsHandler ;
97105import com .sendsafely .handlers .GetDirectoryHandler ;
98106import com .sendsafely .handlers .GetDropzoneRecipientHandler ;
107+ import com .sendsafely .handlers .GetKeycode ;
99108import com .sendsafely .handlers .GetMessageHandler ;
100109import com .sendsafely .handlers .GetOrganizationPackagesHandler ;
101110import com .sendsafely .handlers .GetPackagesHandler ;
102111import com .sendsafely .handlers .GetRecipientHandler ;
112+ import com .sendsafely .handlers .GetRecipientHistoryHandler ;
103113import com .sendsafely .handlers .HandlerFactory ;
104114import com .sendsafely .handlers .MoveDirectoryHandler ;
105115import com .sendsafely .handlers .MoveFileHandler ;
114124import com .sendsafely .handlers .UpdatePackageDescriptorHandler ;
115125import com .sendsafely .handlers .UpdatePackageLifeHandler ;
116126import com .sendsafely .handlers .UpdateRecipientHandler ;
127+ import com .sendsafely .handlers .UploadPublicKey ;
117128import com .sendsafely .handlers .UserInformationHandler ;
118129import com .sendsafely .handlers .VerifyCredentialsHandler ;
119130import com .sendsafely .handlers .VerifyVersionHandler ;
122133import com .sendsafely .upload .DefaultUploadManager ;
123134import com .sendsafely .upload .UploadFactory ;
124135import 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.
0 commit comments