22
33import net .sharksystem .asap .ASAPException ;
44import net .sharksystem .asap .ASAPSecurityException ;
5- import net .sharksystem .crypto .BasisCryptoParameters ;
5+ import net .sharksystem .crypto .BasicCryptoParameters ;
66import net .sharksystem .crypto .ASAPCryptoAlgorithms ;
77import net .sharksystem .utils .Serialization ;
88
@@ -12,7 +12,7 @@ class ASAPCryptoMessage {
1212 private boolean encrypted ;
1313 private boolean sign ;
1414 private CharSequence recipient ;
15- private BasisCryptoParameters basisCryptoParameters ;
15+ private BasicCryptoParameters basicCryptoParameters ;
1616 private byte cmd ;
1717
1818 private OutputStream effectiveOS ;
@@ -21,26 +21,26 @@ class ASAPCryptoMessage {
2121 private InputStreamCopy inputStreamCopy ;
2222 private ASAPCryptoAlgorithms .EncryptedMessagePackage encryptedMessagePackage ;
2323
24- ASAPCryptoMessage (BasisCryptoParameters basisCryptoParameters ) {
25- this .basisCryptoParameters = basisCryptoParameters ;
24+ ASAPCryptoMessage (BasicCryptoParameters basicCryptoParameters ) {
25+ this .basicCryptoParameters = basicCryptoParameters ;
2626 }
2727
2828 ASAPCryptoMessage (byte cmd , OutputStream os , boolean sign , boolean encrypted ,
2929 CharSequence recipient ,
30- BasisCryptoParameters basisCryptoParameters )
30+ BasicCryptoParameters basicCryptoParameters )
3131 throws ASAPSecurityException {
3232
3333 this .cmd = cmd ;
3434 this .realOS = os ;
3535 this .effectiveOS = os ; // still this one
36- this .basisCryptoParameters = basisCryptoParameters ;
36+ this .basicCryptoParameters = basicCryptoParameters ;
3737 this .recipient = recipient ;
3838 this .encrypted = encrypted ;
3939 this .sign = sign ;
4040
4141 if (encrypted || sign ) {
4242 // we need some basic crypto parameters
43- if (basisCryptoParameters == null ) {
43+ if (basicCryptoParameters == null ) {
4444 throw new ASAPSecurityException ("cannot encrypt or sign without cryptp parameters / key store" );
4545 }
4646 this .setupCopyOutputStream ();
@@ -56,7 +56,7 @@ class ASAPCryptoMessage {
5656
5757 if (sign ) {
5858 // signing needs a private key - check of available
59- if (basisCryptoParameters .getPrivateKey () == null ) {
59+ if (basicCryptoParameters .getPrivateKey () == null ) {
6060 throw new ASAPSecurityException ("asap message is to be signed but no private key - fatal, give up" );
6161 }
6262 }
@@ -85,7 +85,7 @@ public void finish() throws ASAPSecurityException {
8585 // get message as bytes
8686 byte [] asapMessageAsBytes = this .outputStreamCopy .toByteArray ();
8787 // produce signature
88- byte [] signatureBytes = ASAPCryptoAlgorithms .sign (asapMessageAsBytes , this .basisCryptoParameters );
88+ byte [] signatureBytes = ASAPCryptoAlgorithms .sign (asapMessageAsBytes , this .basicCryptoParameters );
8989
9090 if (this .encrypted ) {
9191 // have to store it - message and signature will be encrypted
@@ -105,7 +105,7 @@ public void finish() throws ASAPSecurityException {
105105 byte [] asapMessageAsBytes = this .outputStreamCopy .toByteArray ();
106106
107107 ASAPCryptoAlgorithms .writeEncryptedMessagePackage (
108- asapMessageAsBytes , this .recipient , this .basisCryptoParameters , this .realOS );
108+ asapMessageAsBytes , this .recipient , this .basicCryptoParameters , this .realOS );
109109 }
110110 }
111111
@@ -159,7 +159,7 @@ public boolean verify(String sender, InputStream is) throws IOException, ASAPExc
159159 byte [] signatureBytes = Serialization .readByteArray (is );
160160 // debug break
161161 boolean wasVerified =
162- ASAPCryptoAlgorithms .verify (signedData , signatureBytes , sender , this .basisCryptoParameters );
162+ ASAPCryptoAlgorithms .verify (signedData , signatureBytes , sender , this .basicCryptoParameters );
163163
164164 return wasVerified ;
165165 }
@@ -179,30 +179,34 @@ public boolean verify(String sender, InputStream is) throws IOException, ASAPExc
179179 */
180180 public boolean initDecryption (byte cmd , InputStream is ) throws IOException , ASAPException {
181181 // make a copy of encrypted message - it is redundant. Same data in encryptedMessagePackage
182- InputStream copyStream = this .setupCopyInputStream (cmd , is );
182+ // InputStream copyStream = this.setupCopyInputStream(cmd, is);
183183
184184 this .encryptedMessagePackage =
185- ASAPCryptoAlgorithms .parseEncryptedMessagePackage (copyStream );
185+ ASAPCryptoAlgorithms .parseEncryptedMessagePackage (is );
186+ // ASAPCryptoAlgorithms.parseEncryptedMessagePackage(copyStream);
186187
187- if (this .basisCryptoParameters == null ) {
188+ if (this .basicCryptoParameters == null ) {
188189 System .out .println (this .getLogStart () + "no keystore set: cannot handle encrypted messages" );
189190 return false ;
190191 }
191192
192- if (this .basisCryptoParameters .isOwner (this .encryptedMessagePackage .getRecipient ())) {
193+ if (this .basicCryptoParameters .isOwner (this .encryptedMessagePackage .getRecipient ())) {
193194 return true ;
194195 }
195196
196197 return false ;
197198 }
198199
199- byte [] getEncryptedMessage () throws ASAPSecurityException {
200+ ASAPCryptoAlgorithms .EncryptedMessagePackage getEncryptedMessage () throws ASAPSecurityException {
201+ return this .encryptedMessagePackage ;
202+ /*
200203 if(this.inputStreamCopy == null) {
201204 throw new ASAPSecurityException(
202205 this.getLogStart() + "no copy made, maybe forgot to initialize decryption?");
203206 }
204207
205208 return this.inputStreamCopy.getCopy();
209+ */
206210 }
207211
208212 public InputStream doDecryption () throws ASAPSecurityException {
@@ -211,7 +215,7 @@ public InputStream doDecryption() throws ASAPSecurityException {
211215 }
212216
213217 byte [] decryptedBytes =
214- ASAPCryptoAlgorithms .decryptPackage (this .encryptedMessagePackage , this .basisCryptoParameters );
218+ ASAPCryptoAlgorithms .decryptPackage (this .encryptedMessagePackage , this .basicCryptoParameters );
215219
216220 return new ByteArrayInputStream (decryptedBytes );
217221 }
0 commit comments