Select Java Card Applet and return 0x61XX rather than 0x9000 - javacard

I would like my java card applet to emulate our legacy non-java card (native OS) in our organization. The following is the targeted behaviour of the applet:
Select the applet (A4) and return 0x61XX.
Use GET RESPONSE (C0) to read the response
Protocol is T1.
My sample java card is from NXP compatible with JCRE 2.2.2. In my code,
//dataLen is 10 bytes
if (selectingApplet()){
apdu.setOutgoing();
apdu.setOutgoingLength((short)dataLen);
apdu.sendBytesLong(data, (short)0, dataLen);
ISOException.throwIt((short)(ISO7816.SW_BYTES_REMAINING_00 + dataLen)
}
I loaded my applet into the test card. The following is the result:
Select applet
Result: 0x610A
GET RESPONSE
Result: 0x6982
What could be wrong here ? What is the proper way of achieving this if this is even possible with java card ?

I don't think this is possible. The differences between T=0 and T=1 are handled by the Java card framework. GET RESPONSE is specific to T=0.
That means that the 61XX would be generated automatically when using T=0. And of course that the response of SELECT for INSTALL should be automatically returned - unless if the applet thrown an exception that generates a status word, in which case it is likely disregarded.
Similarly, I would expect the framework to catch the GET RESPONSE early, before you can do anything with it. The only thing you could try is to handle the GET RESPONSE yourself and hope the OS passes the APDU along.
But I think the best way of doing this is to configure the chip to use T=0. Then ISO case 4 commands (response and command data) should automatically use GET RESPONSE.

Related

Getting Data from PolarH10 via BLE

I have been trying to get data from my PolarH10 with my raspberry-pi. I have been successfully getting data through the commandline with bluez, but have been unable to reproduce that in python. I am using pygatt(gatttool bindings) and python3.
I have been closely following the examples provided on bitbucket and was able to detect my device and filter out it's MAC address by filtering it by name. I however was unable to get either of the "reading data asyncronously" examples to work.
#This doesnt work...
req = gattlib.GATTRequester(mymac)
response = gattlib.GATTResponse()
req.read_by_handle_async(0x15, response) # what does the 0x15 mean?
while not response.received():
time.sleep(0.1)
steps = response.received()[0]
...
#This doesn't work either
class NotifyYourName(gattlib.GATTResponse):
def on_response(self, data):
print("your data is: {}".format(data))
response = NotifyYourName()
req = gattlib.GATTRequester(mymac)
req.read_by_handle_async(0x15, response)
while True:
# here, do other interesting things
time.sleep(1)
I don't know and cannot extract from the "documentation(s)" how to subscribe to/read notifications from a characteristic(heart rate) of my sensor(PolarH10). The error I am getting is when calling GATTRequester.connect(True) is
RuntimeError: Channel or attrib not ready.
Please tell me how correctly connect to a BLE device via Python on Debian and how to programatically identify offered services and their characteristics and how to get their notifications asyncronously in python using gattlib(pygatt) or any other library. Thanks!
The answer is: Just use bleak.
I have a device that presents the same behavior. In my case, the problem was that it does not have a channel of type public, I should use random instead (like in gatttool -b BE:BA:CA:FE:BA:BE -I -t random).
Just calling the connect() method with the parameter channel_type to random could fix it:
requester.connect(True, channel_type="random")
PD: Sorry for the late response (maybe it will be helpful to others).

ONVIF PullMessages Fault

I understand that cameras that do not have WSBaseNotification feature do not support push-style notifications (Notify), so I have to do the pull-style way (CreatePullPointSubscription and PullMessages).
First I obtain the SubscriptionReference address from CreatePullPointSubscription and pass it to the "To" address in PullMessages. This has succeeded with one of the three cameras I have tested but failed with the other.
Here is a sample of response for CreatePullPointSubscription:
<SOAP-ENV:Header><wsa5:MessageID>urn:uuid:18764990-3fd8-4175-b074-bfdd6816d5a2</
wsa5:MessageID><wsa5:RelatesTo>urn:uuid:1adbe268-c822-eb58-8560-b07639671351</wsa5:RelatesTo><wsa5:To SOAP-
ENV:mustUnderstand="true">http://www.w3.org/2005/08/addressing/anonymous</wsa5:To><wsa5:Action SOAP-
ENV:mustUnderstand="true">http://www.onvif.org/ver10/events/wsdl/EventPortType/
CreatePullPointSubscriptionResponse</wsa5:Action></SOAP-ENV:Header><SOAP-
ENV:Body><tev:CreatePullPointSubscriptionResponse><tev:SubscriptionReference><wsa5:Address>http://172.22.22.35:80/
onvif/device_service?Idx=0</wsa5:Address></tev:SubscriptionReference><wsnt:CurrentTime>2015-11-26T17:05:55Z</
wsnt:CurrentTime><wsnt:TerminationTime>2038-01-19T03:14:07Z</wsnt:TerminationTime></
tev:CreatePullPointSubscriptionResponse></SOAP-ENV:Body></SOAP-ENV:Envelope>
And PulMessagesRequest:
<s:Header><wsa:To>http://172.22.22.35:80/onvi /device_service?Idx=0</wsa:To><wsse:Security><wsse:UsernameToken>
<wsse:Username>admin</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-
profile-1.0#PasswordDigest">XWhDcuw3cztspGCLlpQfVaqM1mU=</wsse:Password><wsse:Nonce>NTY1NmNiODFjYTk4MWZlNjFmNDA=</wsse:Nonce>
<wsu:Created>2015-11-26T09:06:09Z</wsu:Created></wsse:UsernameToken></wsse:Security></s:Header><s:Body><tev:PullMessages>
<tev:Timeout>PT5S</tev:Timeout><tev:MessageLimit>2</tev:MessageLimit></tev:PullMessages></s:Body></s:Envelope>
And PullMessagesResponse:
<SOAP-ENV:Header><wsa5:To SOAP-ENV:mustUnderstand="true">http://172.22.22.35:80/onvif
/device_service?Idx=0</wsa5:To></SOAP-ENV:Header><SOAP-ENV:Body><SOAP-ENV:Fault><SOAP-ENV:Code><SOAP-ENV:Value>SOAP-ENV:Sender</SOAP-ENV:Value>
<SOAP-ENV:Subcode><SOAP-ENV:Value>InvalidArgVal</SOAP-ENV:Value></SOAP-ENV:Subcode></SOAP-ENV:Code><SOAP-ENV:Reason><SOAP-ENV:Text
xml:lang="en">InvalidArgVal</SOAP-ENV:Text></SOAP-ENV:Reason><SOAP-
ENV:Detail>There is no subscribe.</SOAP-ENV:Detail></SOAP-ENV:Fault></SOAP-ENV:Body></SOAP-ENV:Envelope>
From the ONVIF core specs:
9.1.2 Pull messages
The device shall provide the following PullMessages command for all SubscriptionManager endpoints returned by the CreatePullPointSubscription command.
Therefore you need to pull the messages from the address returned int the CreatePullPointSubscription . Populating the wsa5:To field in the body of the request but using the URL of the event service is in general not enough.
You posted only the body of the soap requests and not the head, thus it's impossible to check the URL you're using.

Gmail IMAP via php ouath2 Zend_Mail_Protocol_Imap - getting the X-GM-THRID

I'm accessing GMail via IMAP using OAuth2 authentication and Zend_Mail_Protocol_Imap.
It all works great.
What I need to do is present emails in thread form just like the GMail interface. Google make this really easy because they have an X-GM-THRID header that links a conversation with a 64-bit unsigned integer.
My problem is: when presented with a single email, how do I find out what X-GM-THRID it belongs to?
First off Google says that there is a server extension X-GM-EXT-1 which is active. You can check it is there using the CAPABILITY command (and I have).
All the information suggests that if this is active then the X-GM-THRID will simply be returned as a header, but it isn't.
Perhaps I need to ask Google to return it via the fetch command. Google does describe a simple fetch process here:
https://developers.google.com/google-apps/gmail/imap_extensions
My code is sending TAG5 FETCH 3673 (FLAGS RFC822.HEADER X-GM-THRID) but the headers do not include an entry for X-GM-THRID.
I've even simplified it to TAG6 FETCH 3673 (X-GM-THRID) to be exactly as described in the google example. In this case no headers are returned.
I'm not massively familiar with IMAP commands and I'm not sure if Zend_Mail_Protocol_Imap is abstracting some handling which means this header is being removed.
But I do know that this is driving me mad.
Am I missing something? Is it not a header?
Okay, so it looks like it is not a header. It is an attribute in the IMAP command and response.
The standard fetch command sent by Zend_Mail_Protocol_Imap is "TAG5 FETCH 3673 (FLAGS RFC822.HEADER)"
The code that handles the response only expects to be dealing with 'FLAGS' and 'RFC822.HEADER'. It passes this information to a Zend_Mail_Message object which extends Zend_Mail_Part.
Zend_Mail_Part parses information about flag. It also parses the header.
The additional 'X-GM-THRID' attribute that I added does actually get a response. but since it is not passed back to Zend_Mail_Message there is no way for me to use it. It gets lost in the ether (at around line 171 of Zend_Mail_Storage_Imap in my Zend Library to be exact).
So I've hacked the core... Zend_Mail_Storage_Imap::getMessage now expects $data['X-GM-THRID'] and passes it to the constructor Zend_Mail_Part. And I now have a method Zend_Mail_Part::getXGmThrid which solves all my problems. I'll obviously refactor them into my own classes extending Zend_Mail_Storage_Imap and Zend_Mail_Part in the not too distant... but for now I know this works.

Execute AT commands in J2ME

I want to know how to execute AT commands inside a J2ME application. The approach that I am taking in brief is as below:
First get all the ports that are present in the phone by
String ports = System.getProperty("microedition.commports");
Now just try to write "AT" and wait for the response from each port (YES I said EACH!!!)
try{
commConnection = (CommConnection) Connector.open("comm:" + portsArr[i] + ";baudrate=19200");
} catch (IOException e) {
print("IOException:Port:" + portsArr[i] + "~Mess: " + e.getMessage());
}
Once I get an "OK" from some port I can execute my intended commands in the same way.
I am trying to execute this on two diffrent phones
Nokia SuperNova 7210
ports=USB1
When I try to write to the port nothing happens.
Nokia Xpress music
ports= USB2,COM1,IR1,USB1,BT1,BT2,BT3,BT4,BT5,BT6,BT7,BT8,BT9,BT10,BT11,BT12,BT13,BT14,BT15,BT16,BT17,BT18,BT19,BT20,BT21,BT22,BT23,BT24,BT25,BT26,BT27,BT28,BT29,BT30,BT31,BT32,BT33,BT34,BT35,BT36,BT37,BT38,BT39,BT40,BT41,BT42,BT43,BT44,BT45,BT46,BT47,BT48,BT49,BT50,BT51,BT52,BT53,BT54,BT55,BT56,BT57,BT58,BT59,BT60,BT61,BT62,BT63,BT64
When I try to write to USB2,COM1,BT1 port
IOException:Port:COM1~Mess: SymbianOS error = -1 : General:
System error
IOException:Port:USB1~Mess: SymbianOS error = -21 : General:
System error
IOException:Port:BT1~Mess: SymbianOS error = -44 : General:
System error
Is this a correct approach?
Smslib uses AT commands but I'm not understanding how do they execute AT commands or how they get the port on which to write the AT commands?
If not possible with J2ME I don't mind not writing the execution of AT commands in some other language as long as both are able to communicate and the solution will support a most of the vendors.
Related - https://stackoverflow.com/questions/3803508/can-i-use-at-commands-insider-j2me-app
What you are trying to achieve is absolutely not possible.
Your approach would only work if Java ME provided access to the GSM modem via COMM ports, which it does not!
(I suppose there could possibly be a device somewhere which offers this, anything's possible in Java ME land, but I have never seen or heard of this).
The library you are referring to runs on a PC which has a device connected to it via the COMM port, it does not work in a Java ME context.
I suspect that what you're really trying to do is access the handset's native SMS inbox via a MIDlet. I promise you, there is absolutely no way to do this!
If what you are trying to do is just send an SMS, maybe you can get to it using an APDU. It seems technically possible:
First you will need JSR 177 SATSA-APDU. Check Nokia devices that have support for it at http://www.developer.nokia.com/Community/Wiki/Java_ME_API_support_on_Nokia_devices
Then you will have to create an SMS APDU just like an STK Applet would do. Please check "Sending a message in the PDU mode" at http://www.dreamfabric.com/sms/
I did not try this, but this is the path I would go if I had to. If it does work with you, please share.

[Asterisk]Attended transfer using hook flash on a SIP channel

Within our organisation we use quite a few different models of telephone sets. The only thing they have in common, apart from the dialpad, is the ability to "send" hook flash. I prefer using this type of signaling for attended transfers above combinations of the usual dialpad keys to prevent the other end from receiving DTMF-tones (to prevent unwanted interactions with IVRs or bothering people on the other end).
2 questions:
How is a flash hook represented in features.conf? According to RFC2833 section 3.10 (DTMF Events) and this article (which is about a ZAP- instead of SIP-configuration, thus my doubt... see next question, also), it should be just "flash".
From my Google-quest I've learned that hook flash gets ignored by the PBX when using the SIP-protocol in Asterisk... I do get an error message when sending it: "WARNING[26159]: chan_sip.c:6487 sip_indicate: Don't know how to indicate condition 9". Is there a way to fix it/work around it?
Asterisk version: 1.8.3.2
Using "info" for dtmfmode
Tnx in advance!
In most cases you have in you adapter settings what to do with hook. IF you have, you can change that to transfer code.
Update: after code review i can say that DTMF 16 received ok and sended in 1.8.x. BUT features.c have no any action on flash(event 16)
So posible create audiohook application for asterisk to change that DTMF 16 to 2 DTMF values or invoke transfer. Will work for DTMF method SIPInfo, and such patch complexity is below-average(5-6 hours for expert)

Resources