99
1010import com .atakmap .comms .CommsMapComponent ;
1111import com .atakmap .coremap .cot .event .CotEvent ;
12- import com .paulmandal .atak .libcotshrink .pub .api .CotShrinker ;
1312
1413import com .atakmap .android .aprstak .plugin .PluginLifecycle ;
14+ import com .siemens .ct .exi .core .EXIFactory ;
15+ import com .siemens .ct .exi .core .helpers .DefaultEXIFactory ;
16+ import com .siemens .ct .exi .main .api .sax .EXIResult ;
1517
18+ import org .xml .sax .InputSource ;
19+ import org .xml .sax .XMLReader ;
20+
21+ import java .io .ByteArrayOutputStream ;
22+ import java .io .StringReader ;
1623import java .nio .ByteBuffer ;
1724import java .security .MessageDigest ;
1825import java .security .SecureRandom ;
1926
2027import javax .crypto .Cipher ;
2128import javax .crypto .spec .IvParameterSpec ;
2229import javax .crypto .spec .SecretKeySpec ;
30+ import javax .xml .parsers .SAXParser ;
31+ import javax .xml .parsers .SAXParserFactory ;
2332
2433import utils .AprsUtility ;
2534
2635public class APRSMessageHandler implements CommsMapComponent .PreSendProcessor {
2736
2837 private static final String TAG = "APRSMessageHandler" ;
29- private final CotShrinker cotShrinker ;
3038
31- public APRSMessageHandler (CotShrinker cotShrinker ) {
39+ private Context context ;
40+
41+ public APRSMessageHandler (Context context ) {
3242 CommsMapComponent .getInstance ().registerPreSendProcessor (this );
33- this .cotShrinker = cotShrinker ;
43+ this .context = context ;
3444 }
3545
3646 @ Override
3747 public void processCotEvent (CotEvent cotEvent , String [] toUIDs ) {
3848 if (cotEvent .toString ().contains ("All Chat Rooms" )) {
39- byte [] cotBytes = cotShrinker .toByteArrayLossy (cotEvent );
40- String encodedString ;
49+ byte [] cotAsBytes ;
50+
51+ try {
52+ EXIFactory exiFactory = DefaultEXIFactory .newInstance ();
53+ ByteArrayOutputStream osEXI = new ByteArrayOutputStream ();
54+ EXIResult exiResult = new EXIResult (exiFactory );
55+ exiResult .setOutputStream (osEXI );
56+ SAXParserFactory saxParserFactory = SAXParserFactory .newInstance ();
57+ SAXParser newSAXParser = saxParserFactory .newSAXParser ();
58+ XMLReader xmlReader = newSAXParser .getXMLReader ();
59+ xmlReader .setContentHandler (exiResult .getHandler ());
60+ InputSource stream = new InputSource (new StringReader (cotEvent .toString ()));
61+ xmlReader .parse (stream ); // parse XML input
62+ cotAsBytes = osEXI .toByteArray ();
63+ osEXI .close ();
64+ } catch (Exception e ) {
65+ e .printStackTrace ();
66+ return ;
67+ }
68+
69+ Log .d (TAG , "Size: " + cotAsBytes .length ); String encodedString ;
70+
4171 if (AprsUtility .usePSK ) {
4272 com .atakmap .coremap .log .Log .i (TAG , "PSK enabled" );
4373 ByteBuffer payload ;
4474 byte [] PSKhash , cipherText ;
45- SharedPreferences sharedPref = PluginLifecycle . activity .getSharedPreferences ("aprs-prefs" , Context .MODE_PRIVATE );
75+ SharedPreferences sharedPref = context .getSharedPreferences ("aprs-prefs" , Context .MODE_PRIVATE );
4676 String psk = sharedPref .getString ("PSKText" , "atakatak" );
4777 try {
4878 MessageDigest digest = MessageDigest .getInstance ("MD5" );
@@ -57,7 +87,7 @@ public void processCotEvent(CotEvent cotEvent, String[] toUIDs) {
5787 Cipher cipher = Cipher .getInstance ("AES/CBC/PKCS5Padding" );
5888 SecretKeySpec key = new SecretKeySpec (PSKhash , "AES" );
5989 cipher .init (Cipher .ENCRYPT_MODE , key , new IvParameterSpec (iv ));
60- cipherText = cipher .doFinal (cotBytes );
90+ cipherText = cipher .doFinal (cotAsBytes );
6191 // set the iv+cipherText as the payload
6292 payload = ByteBuffer .allocate (iv .length + cipherText .length );
6393 payload .put (iv );
@@ -68,13 +98,13 @@ public void processCotEvent(CotEvent cotEvent, String[] toUIDs) {
6898 }
6999 encodedString = Base64 .encodeToString (payload .array (), Base64 .NO_WRAP );
70100 } else {
71- encodedString = Base64 .encodeToString (cotBytes , Base64 .NO_WRAP );
101+ encodedString = Base64 .encodeToString (cotAsBytes , Base64 .NO_WRAP );
72102 }
73103
74104 Log .d (TAG , "Base64 string len: " + encodedString .length ());
75105 Intent i = new Intent ("org.aprsdroid.app.SEND_PACKET" ).setPackage ("org.aprsdroid.app" );
76106 i .putExtra ("data" , ">M," + encodedString );
77- PluginLifecycle . activity .getApplicationContext ().startForegroundService (i );
107+ context .getApplicationContext ().startForegroundService (i );
78108 }
79109 }
80110}
0 commit comments