to read the packet data from a cap file - udp

i need to read the payload information from a udp packet which is in pcap file.
tshark -x -c 10 -r traces/trace.pcap udp
0000 00 22 4d a8 1f 7f 80 3f 5d 08 52 35 08 00 45 00 ."M....?].R5..E.
0010 05 94 03 e6 40 00 40 11 3b 46 c0 a8 ba 6c c0 a8 ....#.#.;F...l..
0020 ba 6f d4 80 05 dc 05 80 4e 9e 00 00 80 25 1b 3a .o......N....%.:
0030 fd 9e 00 00 00 01 00 00 00 06 5b 29 c2 5b 78 ed ..........[).[x.
0040 00 00 1b 6f c2 5b 78 ed 00 00 1e c4 30 5b 00 00 ...o.[x.....0[..
0050 00 00 85 c7 09 00 00 00 00 00 01 00 00 00 06 00 ................
0060 00 00 c0 07 1c 00 00 00 00 00 c0 07 3c 00 00 00 ............<...
0070 00 00 c0 07 3c 00 00 00 00 00 78 78 78 78 78 78 ....<.....xxxxxx
i get the above output from tshark but the payload consists of packet arrival and departure time from a udp server how i need to retrieve arrival and departure time from above information.

To print both the packet as hex (-x) and the summary with the timestamp in tshark add the -P option. To get the timestamp as absolute instead of relative value add the -ta option. For more information see the documentation.

Related

Can't visit https://gentoo.org when connected over NAT

I have NAT configured on desktop for laptop to use. All is working except one thing: I cannot open https://gentoo.org. In links it hangs at "SSL negotiation. So, I guess this strange issue is related to SSL. All other HTTPS sites work fine.
NAT configuration on desktop:
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o wg0 -j MASQUERADE
iptables -A FORWARD -i eth1 -j ACCEPT
wg0: Internet interface of desktop
eth1: laptop is connected to this interface
openssl s_client -connect www.gentoo.org:443 -prexit -debug shows:
CONNECTED(00000003)
write to 0x557ba3f68e50 [0x557ba3f78d70] (316 bytes => 316 (0x13C))
0000 - 16 03 01 01 37 01 00 01-33 03 03 ca da b4 c8 0d ....7...3.......
0010 - 7a 15 7b dc 4b cc 1b f9-1f 28 93 31 53 6b 6e 6f z.{.K....(.1Skno
0020 - 56 1d c2 df 06 b2 eb 35-a9 e8 56 20 c4 85 26 09 V......5..V ..&.
0030 - 1c 4b 8f d2 52 cb 76 a5-2c 06 2a da d8 a0 83 e2 .K..R.v.,.*.....
0040 - 64 53 87 5e ba 63 d1 d8-0e 25 24 d1 00 3e 13 02 dS.^.c...%$..>..
0050 - 13 03 13 01 c0 2c c0 30-00 9f cc a9 cc a8 cc aa .....,.0........
0060 - c0 2b c0 2f 00 9e c0 24-c0 28 00 6b c0 23 c0 27 .+./...$.(.k.#.'
0070 - 00 67 c0 0a c0 14 00 39-c0 09 c0 13 00 33 00 9d .g.....9.....3..
0080 - 00 9c 00 3d 00 3c 00 35-00 2f 00 ff 01 00 00 ac ...=.<.5./......
0090 - 00 00 00 13 00 11 00 00-0e 77 77 77 2e 67 65 6e .........www.gen
00a0 - 74 6f 6f 2e 6f 72 67 00-0b 00 04 03 00 01 02 00 too.org.........
00b0 - 0a 00 0c 00 0a 00 1d 00-17 00 1e 00 19 00 18 00 ................
00c0 - 23 00 00 00 16 00 00 00-17 00 00 00 0d 00 30 00 #.............0.
00d0 - 2e 04 03 05 03 06 03 08-07 08 08 08 09 08 0a 08 ................
00e0 - 0b 08 04 08 05 08 06 04-01 05 01 06 01 03 03 02 ................
00f0 - 03 03 01 02 01 03 02 02-02 04 02 05 02 06 02 00 ................
0100 - 2b 00 09 08 03 04 03 03-03 02 03 01 00 2d 00 02 +............-..
0110 - 01 01 00 33 00 26 00 24-00 1d 00 20 95 79 e4 57 ...3.&.$... .y.W
0120 - 04 d6 24 e3 cd 64 f7 16-89 f7 41 da dc 4d 12 45 ..$..d....A..M.E
0130 - 14 02 b5 b5 92 d0 f8 30-7a e0 cf 64 .......0z..d
and hangs.
Tried to debug using openssl s_client -connect

red5pro SSL with AWS EC2

I have successfully installed the red5pro server at my AWS EC2 instance. Works with http. To allow the access to my webcam I need to install an SSL certificate. I have set all inbound ports required for red5pro to work with SSL at my EC2 instance.
I have followed this guide from red5pro docs to get my certificate with letsencrypt. I have all the files mentioned there:
sudo ls /etc/letsencrypt/live/stream.gettoworkout-live.de/
cert.pem fullchain_and_key.p12 keystore.jks tomcat.cer
chain.pem fullchain.pem privkey.pem truststore.jks
After configuring red5pro to work with SSL (making said changes in red5.properties etc) I have tested my configuration with the mentioned open SSL test:
openssl s_client -connect stream.gettoworkout-live.de:443
The console output is:
CONNECTED(00000003)
After setting the debug option:
CONNECTED(00000003)
write to 0xed22d0 [0xed2350] (305 bytes => 305 (0x131))
0000 - 16 03 01 01 2c 01 00 01-28 03 03 c9 07 ca 58 2d ....,...(.....X-
0010 - 6f 9f b2 24 d6 6c af 3a-ad 2f 44 c1 54 18 9e 14 o..$.l.:./D.T...
0020 - b8 57 5a 53 b0 23 eb 0b-fd 03 1d 00 00 aa c0 30 .WZS.#.........0
0030 - c0 2c c0 28 c0 24 c0 14-c0 0a 00 a5 00 a3 00 a1 .,.(.$..........
0040 - 00 9f 00 6b 00 6a 00 69-00 68 00 39 00 38 00 37 ...k.j.i.h.9.8.7
0050 - 00 36 00 88 00 87 00 86-00 85 c0 32 c0 2e c0 2a .6.........2...*
0060 - c0 26 c0 0f c0 05 00 9d-00 3d 00 35 00 84 c0 2f .&.......=.5.../
0070 - c0 2b c0 27 c0 23 c0 13-c0 09 00 a4 00 a2 00 a0 .+.'.#..........
0080 - 00 9e 00 67 00 40 00 3f-00 3e 00 33 00 32 00 31 ...g.#.?.>.3.2.1
0090 - 00 30 00 9a 00 99 00 98-00 97 00 45 00 44 00 43 .0.........E.D.C
00a0 - 00 42 c0 31 c0 2d c0 29-c0 25 c0 0e c0 04 00 9c .B.1.-.).%......
00b0 - 00 3c 00 2f 00 96 00 41-c0 11 c0 07 c0 0c c0 02 .<./...A........
00c0 - 00 05 00 04 c0 12 c0 08-00 16 00 13 00 10 00 0d ................
00d0 - c0 0d c0 03 00 0a 00 ff-01 00 00 55 00 0b 00 04 ...........U....
00e0 - 03 00 01 02 00 0a 00 1c-00 1a 00 17 00 19 00 1c ................
00f0 - 00 1b 00 18 00 1a 00 16-00 0e 00 0d 00 0b 00 0c ................
0100 - 00 09 00 0a 00 23 00 00-00 0d 00 20 00 1e 06 01 .....#..... ....
0110 - 06 02 06 03 05 01 05 02-05 03 04 01 04 02 04 03 ................
0120 - 03 01 03 02 03 03 02 01-02 02 02 03 00 0f 00 01 ................
0130 - 01
Nothing more. No success or error message. Could somebody help?
UPDATE:
This is the Output after -state -nbio:
SSL_connect:before/connect initialization
SSL_connect:SSLv2/v3 write client hello A
SSL_connect:error in SSLv2/v3 read server hello A
EDIT 2:
I have found out that my red5.log says
"o.r.n.w.SecureWebSocketConfiguration - Keystore or Truststore file does not exist"
I have installed red5pro in
/usr/local/red5pro
My keystore + truststore files are in
/etc/letsencrypt/live/stream.gettoworkout-live.de/
I reference the files in red5.properties with:
/etc/letsencrypt/live/stream.gettoworkout-live.de/truststore.jks
/etc/letsencrypt/live/stream.gettoworkout-live.de/keystore.jks

OpenSSL ClientHello fails in latest version

I need to connect to an SSL server. When I connect using OpenSSL 1.0.1r it works fine:
CONNECTED(00000304)
write to 0x6e13e8 [0x730a98] (297 bytes => 297 (0x129))
0000 - 16 03 01 01 24 01 00 01-20 03 03 16 f2 71 5f 26 ....$... ....q_&
0010 - a5 9b 64 cb 8f 0b 27 65-8d a3 54 e6 de a5 18 7a ..d...'e..T....z
0020 - 3c 5a e4 08 ab ff 6a 92-d7 45 f3 00 00 8a c0 30 <Z....j..E.....0
0030 - c0 2c c0 28 c0 24 c0 14-c0 0a 00 a3 00 9f 00 6b .,.(.$.........k
0040 - 00 6a 00 39 00 38 00 88-00 87 c0 32 c0 2e c0 2a .j.9.8.....2...*
0050 - c0 26 c0 0f c0 05 00 9d-00 3d 00 35 00 84 c0 2f .&.......=.5.../
0060 - c0 2b c0 27 c0 23 c0 13-c0 09 00 a2 00 9e 00 67 .+.'.#.........g
0070 - 00 40 00 33 00 32 00 9a-00 99 00 45 00 44 c0 31 .#.3.2.....E.D.1
0080 - c0 2d c0 29 c0 25 c0 0e-c0 04 00 9c 00 3c 00 2f .-.).%.......<./
0090 - 00 96 00 41 00 07 c0 11-c0 07 c0 0c c0 02 00 05 ...A............
00a0 - 00 04 c0 12 c0 08 00 16-00 13 c0 0d c0 03 00 0a ................
00b0 - 00 15 00 12 00 09 00 ff-01 00 00 6d 00 0b 00 04 ...........m....
00c0 - 03 00 01 02 00 0a 00 34-00 32 00 0e 00 0d 00 19 .......4.2......
00d0 - 00 0b 00 0c 00 18 00 09-00 0a 00 16 00 17 00 08 ................
00e0 - 00 06 00 07 00 14 00 15-00 04 00 05 00 12 00 13 ................
00f0 - 00 01 00 02 00 03 00 0f-00 10 00 11 00 23 00 00 .............#..
0100 - 00 0d 00 20 00 1e 06 01-06 02 06 03 05 01 05 02 ... ............
0110 - 05 03 04 01 04 02 04 03-03 01 03 02 03 03 02 01 ................
0120 - 02 02 02 03 00 0f 00 01-01 .........
>>> TLS 1.2 Handshake [length 0124], ClientHello
01 00 01 20 03 03 16 f2 71 5f 26 a5 9b 64 cb 8f
0b 27 65 8d a3 54 e6 de a5 18 7a 3c 5a e4 08 ab
ff 6a 92 d7 45 f3 00 00 8a c0 30 c0 2c c0 28 c0
24 c0 14 c0 0a 00 a3 00 9f 00 6b 00 6a 00 39 00
38 00 88 00 87 c0 32 c0 2e c0 2a c0 26 c0 0f c0
05 00 9d 00 3d 00 35 00 84 c0 2f c0 2b c0 27 c0
23 c0 13 c0 09 00 a2 00 9e 00 67 00 40 00 33 00
32 00 9a 00 99 00 45 00 44 c0 31 c0 2d c0 29 c0
25 c0 0e c0 04 00 9c 00 3c 00 2f 00 96 00 41 00
07 c0 11 c0 07 c0 0c c0 02 00 05 00 04 c0 12 c0
08 00 16 00 13 c0 0d c0 03 00 0a 00 15 00 12 00
09 00 ff 01 00 00 6d 00 0b 00 04 03 00 01 02 00
0a 00 34 00 32 00 0e 00 0d 00 19 00 0b 00 0c 00
18 00 09 00 0a 00 16 00 17 00 08 00 06 00 07 00
14 00 15 00 04 00 05 00 12 00 13 00 01 00 02 00
03 00 0f 00 10 00 11 00 23 00 00 00 0d 00 20 00
1e 06 01 06 02 06 03 05 01 05 02 05 03 04 01 04
02 04 03 03 01 03 02 03 03 02 01 02 02 02 03 00
0f 00 01 01
read from 0x6e13e8 [0x735ff8] (7 bytes => 7 (0x7))
0000 - 16 03 03 00 57 02 ....W.
0007 - <SPACES/NULS>
read from 0x6e13e8 [0x736002] (85 bytes => 85 (0x55))
0000 - 00 53 03 03 56 bb 11 21-1a ac 49 84 2d be 94 ad .S..V..!..I.-...
0010 - a0 c4 57 46 bc 70 d0 84-95 ce 96 c6 8c 92 07 2e ..WF.p..........
0020 - 4e 13 d6 f3 20 aa d7 86-ca 48 5e 01 a1 8c d3 f1 N... ....H^.....
0030 - d7 74 f9 2c 84 48 7d c1-95 6d 22 81 ff 53 ab d3 .t.,.H}..m"..S..
0040 - 0c 89 81 7d a2 00 3d 00-00 0b 00 0b 00 02 01 00 ...}..=.........
0050 - ff 01 00 01 ....
0055 - <SPACES/NULS>
<<< TLS 1.2 Handshake [length 0057], ServerHello
02 00 00 53 03 03 56 bb 11 21 1a ac 49 84 2d be
94 ad a0 c4 57 46 bc 70 d0 84 95 ce 96 c6 8c 92
07 2e 4e 13 d6 f3 20 aa d7 86 ca 48 5e 01 a1 8c
d3 f1 d7 74 f9 2c 84 48 7d c1 95 6d 22 81 ff 53
ab d3 0c 89 81 7d a2 00 3d 00 00 0b 00 0b 00 02
01 00 ff 01 00 01 00
read from 0x6e13e8 [0x735ffb] (5 bytes => 5 (0x5))
// etc.
However when I connect using OpenSSL 1.0.2f, the server closes the connection immediately:
CONNECTED(00000300)
write to 0x7812d0 [0x7ceef0] (317 bytes => 317 (0x13D))
0000 - 16 03 01 01 38 01 00 01-34 03 03 45 1c 09 c2 2e ....8...4..E....
0010 - 46 06 85 a1 01 fd 0a 2c-bb 6f 15 10 42 74 b3 bf F......,.o..Bt..
0020 - 9f 2e 5c 00 9f f2 93 8e-c0 18 9c 00 00 b6 c0 30 ..\............0
0030 - c0 2c c0 28 c0 24 c0 14-c0 0a 00 a5 00 a3 00 a1 .,.(.$..........
0040 - 00 9f 00 6b 00 6a 00 69-00 68 00 39 00 38 00 37 ...k.j.i.h.9.8.7
0050 - 00 36 00 88 00 87 00 86-00 85 c0 32 c0 2e c0 2a .6.........2...*
0060 - c0 26 c0 0f c0 05 00 9d-00 3d 00 35 00 84 c0 2f .&.......=.5.../
0070 - c0 2b c0 27 c0 23 c0 13-c0 09 00 a4 00 a2 00 a0 .+.'.#..........
0080 - 00 9e 00 67 00 40 00 3f-00 3e 00 33 00 32 00 31 ...g.#.?.>.3.2.1
0090 - 00 30 00 9a 00 99 00 98-00 97 00 45 00 44 00 43 .0.........E.D.C
00a0 - 00 42 c0 31 c0 2d c0 29-c0 25 c0 0e c0 04 00 9c .B.1.-.).%......
00b0 - 00 3c 00 2f 00 96 00 41-00 07 c0 11 c0 07 c0 0c .<./...A........
00c0 - c0 02 00 05 00 04 c0 12-c0 08 00 16 00 13 00 10 ................
00d0 - 00 0d c0 0d c0 03 00 0a-00 15 00 12 00 0f 00 0c ................
00e0 - 00 09 00 ff 01 00 00 55-00 0b 00 04 03 00 01 02 .......U........
00f0 - 00 0a 00 1c 00 1a 00 17-00 19 00 1c 00 1b 00 18 ................
0100 - 00 1a 00 16 00 0e 00 0d-00 0b 00 0c 00 09 00 0a ................
0110 - 00 23 00 00 00 0d 00 20-00 1e 06 01 06 02 06 03 .#..... ........
0120 - 05 01 05 02 05 03 04 01-04 02 04 03 03 01 03 02 ................
0130 - 03 03 02 01 02 02 02 03-00 0f 00 01 01 .............
>>> TLS 1.2 [length 0005]
16 03 01 01 38
>>> TLS 1.2 Handshake [length 0138], ClientHello
01 00 01 34 03 03 45 1c 09 c2 2e 46 06 85 a1 01
fd 0a 2c bb 6f 15 10 42 74 b3 bf 9f 2e 5c 00 9f
f2 93 8e c0 18 9c 00 00 b6 c0 30 c0 2c c0 28 c0
24 c0 14 c0 0a 00 a5 00 a3 00 a1 00 9f 00 6b 00
6a 00 69 00 68 00 39 00 38 00 37 00 36 00 88 00
87 00 86 00 85 c0 32 c0 2e c0 2a c0 26 c0 0f c0
05 00 9d 00 3d 00 35 00 84 c0 2f c0 2b c0 27 c0
23 c0 13 c0 09 00 a4 00 a2 00 a0 00 9e 00 67 00
40 00 3f 00 3e 00 33 00 32 00 31 00 30 00 9a 00
99 00 98 00 97 00 45 00 44 00 43 00 42 c0 31 c0
2d c0 29 c0 25 c0 0e c0 04 00 9c 00 3c 00 2f 00
96 00 41 00 07 c0 11 c0 07 c0 0c c0 02 00 05 00
04 c0 12 c0 08 00 16 00 13 00 10 00 0d c0 0d c0
03 00 0a 00 15 00 12 00 0f 00 0c 00 09 00 ff 01
00 00 55 00 0b 00 04 03 00 01 02 00 0a 00 1c 00
1a 00 17 00 19 00 1c 00 1b 00 18 00 1a 00 16 00
0e 00 0d 00 0b 00 0c 00 09 00 0a 00 23 00 00 00
0d 00 20 00 1e 06 01 06 02 06 03 05 01 05 02 05
03 04 01 04 02 04 03 03 01 03 02 03 03 02 01 02
02 02 03 00 0f 00 01 01
read from 0x7812d0 [0x7d4450] (7 bytes => 0 (0x0))
10124:error:140790E5:SSL routines:ssl23_write:ssl handshake failure:.\ssl\s23_lib.c:177:
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 0 bytes and written 317 bytes
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
Protocol : TLSv1.2
Cipher : 0000
Session-ID:
Session-ID-ctx:
Master-Key:
Key-Arg : None
PSK identity: None
PSK identity hint: None
SRP username: None
Start Time: 1455100247
Timeout : 300 (sec)
Verify return code: 0 (ok)
---
I don't suppose anyone speaks ClientHello sufficiently well to tell me what the difference is, and how to get OpenSSL 1.0.2f to behave like the old version (even if it is insecure; I don't control the server).
I checked both traces with Wireshark, and the only significant differences I can see are that OpenSSL 1.0.2's ClientHello packet is identified as "SSL" by Wireshark, and the record layer is SSL:
Whereas OpenSSL 1.0.1 is identified as TLS 1.2. It also has fewer cypher suites (I guess they removed some insecure ones?).
I've tried the following combinations, and these are how Wireshark labels them in the "Protocol" column:
1.0.1: <no options>=TLSv1.2; -ssl2=SSLv2; -ssl3=SSLv3; -tls1_2=TLSv1.2
1.0.2: <no options>=SSL; -ssl2=SSLv2; -ssl3=SSLv3; -tls1_2=SSL
Any ideas about:
Why Wireshark decodes 1.0.1 and 1.0.2 differently?
Why the connection is failing with 1.0.2?
How I can get OpenSSL 1.0.2 to behave like 1.0.1?
Why Wireshark decodes 1.0.1 and 1.0.2 differently?
See SSL Record Layer vs SSLv3 Record Layer on the Wireshark Q&A bulletin board and Secure Socket Layer (SSL) on the Wireshark wiki.
Why the connection is failing with 1.0.2?
Looks like a buggy server that's rejecting a record layer that's not an early one, like one used in SSLv3.
The record layer is just that... It specifies the version of the record layer, which is simply the framing of SSL/TLS protocol messages. It is not a MIN-TLS-VERSION as many people think.
The TLS protocol version is just that... It specifies the version of the SSL/TLS protocol. It is not a MAX-TLS-VERSION as many people think.
How I can get OpenSSL 1.0.2 to behave like 1.0.1?
Use the following in your client, but its not exactly the same. The OpenSSL client will do the right thing and select TLS 1.2 if its available:
/* Uses the early record layer for downlevel servers */
const SSL_METHOD* method = SSLv23_method();
if(NULL == method) handleFailure();
ctx = SSL_CTX_new(method);
if(ctx == NULL) handleFailure();
/* Cannot fail ??? */
const long flags = SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3 | SSL_OP_NO_TLSv1 | SSL_OP_NO_TLSv1_1 | SSL_OP_NO_COMPRESSION;
SSL_CTX_set_options(ctx, flags);
I checked OpenSSL 1.0.2's ssl/ssl.h, and both SSL_OP_NO_TLSv1 and SSL_OP_NO_TLSv1_1 are available.
There's a different way to do it for OpenSSL Master (a.k.a, OpenSSL 1.1.0 and above); see Working around servers requiring SSL 2/3 record layer, and using TLS 1.2?
... [OpenSSL 1.0.2] also has fewer cipher suites (I guess they removed some insecure ones?).
You should not leave cipher suites to chance. You should do something like the following:
const char* const PREFERRED_CIPHERS = "HIGH:!aNULL:!kRSA:!PSK:!SRP:!MD5:!RC4";
res = SSL_set_cipher_list(ssl, PREFERRED_CIPHERS);
if(res != 1) handleFailure();
The !PSK and !SRP simply removes cipher suites that are not usually used. !MD5 and !RC4 are removed for servers to help avoid the Obsolete cryptography warning from Browser.
You could even do the following:
const char* const PREFERRED_CIPHERS =
"ECDHE-ECDSA-AES256-GCM-SHA384:"
"ECDHE-RSA-AES256-GCM-SHA384:"
"ECDHE-ECDSA-AES128-GCM-SHA256:"
"ECDHE-RSA-AES128-GCM-SHA256:"
"DHE-DSS-AES256-GCM-SHA384:"
"DHE-RSA-AES256-GCM-SHA384:"
"DHE-DSS-AES128-GCM-SHA256:"
"DHE-RSA-AES128-GCM-SHA256";
res = SSL_set_cipher_list(ssl, PREFERRED_CIPHERS);
if(res != 1) handleFailure();
Be sure to always offer a AES/GCM cipher suite because as server configurations move to a TLS 1.2-only configuration, that's the cipher suite they usually choose.
Also, each cipher suite takes up to bytes in the ClientHello, and you want to minimize the number of them. You want to minimize them because some older Proxies and Interception boxes use a fixed size buffer for the client's ClientHello, and they can't handle the proliferation of cipher suite options available in TLS 1.2. The older boxes include F5 and Ironport middleware.
Why Wireshark decodes 1.0.1 and 1.0.2 differently?
No idea.
Why the connection is failing with 1.0.2?
Hard to tell but I've seen several servers having problems with some ciphers added to OpenSSL 1.0.2 or that too much ciphers were given or similar. I've seen similar problems with recent LibreSSL versions. In this case the servers have obviously broken TLS stacks.
How I can get OpenSSL 1.0.2 to behave like 1.0.1?
You can try to reduce the cipher set so that it only uses the same ciphers as OpenSSL 1.0.1. Notable I've seen servers croak ChaCha20-Poly1305 was inside the cipher set, probably they did not understand what kind of cipher this is.

How can I check INITIALIZE UPDATE and EXTERNAL AUTHENTICATE correctness?

I sent 80 50 00 00 08 00 00 00 00 00 00 00 00 [INITILIZE UPDATE Command] via opensc-tool to my java card and received 00 00 11 60 01 00 8A 79 0A F9 FF 02 00 11 79 11 36 5D 71 00 A5 A5 EC 63 BB DC 05 CC [Init Response] as its response from the card.
As you see:
In the command,I send 00 00 00 00 00 00 00 00 as Host Challenge, And in the response :
00 00 11 60 01 00 8A 79 0A F9 = Key diversification data
FF 02 = Key information
00 11 79 11 36 5D 71 00 = Card challenge
A5 A5 EC 63 BB DC 05 CC = Card cryptogram
Now I want to check myself,if the card cryptogram is OK or not. How I can do it? for example I encrypt 00 00 00 00 00 00 00 00 in this site under a 3DES cryptography algorithm [with keys of my card = 4041...4F], but the output is not equal with card cryptogram that I wrote above. Why?
And the next question is, if I want to send EXTERNAL AUTHENTICATION command to the card, what is its data field (after the above INITILIZE UPDATE)?
Update:
This is GPJ output :
C:\Users\ghasemi\Desktop\gpj-20120310>GPJ
C:\Users\ghasemi\Desktop\gpj-20120310>java -jar gpj.jar
Found terminals: [PC/SC terminal ACS CCID USB Reader 0]
Found card in terminal: ACS CCID USB Reader 0
ATR: 3B 68 00 00 00 73 C8 40 12 00 90 00
.
.
.
DEBUG: Command APDU: 00 A4 04 00 08 A0 00 00 00 03 00 00 00
DEBUG: Response APDU: 6F 10 84 08 A0 00 00 00 03 00 00 00 A5 04 9F 65 01 FF 90 00
Successfully selected Security Domain OP201a A0 00 00 00 03 00 00 00
DEBUG: Command APDU: 80 50 00 00 08 7F 41 A9 E7 19 37 83 FA
DEBUG: Response APDU: 00 00 11 60 01 00 8A 79 0A F9 FF 02 00 1B 9B 95 B9 5E 5E BC BA 51 34 84 D9 C1 B9 6E 90 00
DEBUG: Command APDU: 84 82 00 00 10 13 3B 4E C5 2C 9E D8 24 50 71 83 3A 78 AE 75 23
DEBUG: Response APDU: 90 00
DEBUG: Command APDU: 84 82 00 00 08 13 3B 4E C5 2C 9E D8 24
DEBUG: Response APDU: 90 00
C:\Users\ghasemi\Desktop\gpj-20120310>
So :
Host_Challenge :: 7F41A9E7193783FA
Diversification_Data :: 0000116001008A790AF9
Key_Information :: FF02
Sequence_Counter :: 001B
Card_Challenge :: 9B95B95E5EBC
Card_Cryptogram :: BA513484D9C1B96E
Host_Cryptogram[16,24] = 13 3B 4E C5 2C 9E D8 24
Now,lets make our Host_Cryptogram Manually :
Derivation_data=derivation_const_ENC|sequence_counter|0000 0000 0000 0000 0000 0000
Derivation_Data = 0182001B000000000000000000000000
k_ENC :: 404142434445464748494A4B4C4D4E4F
IV = 00 00 00 00 00 00 00 00
S_ENC = encrypt(TDES_CBC, K_ENC, IV, derivation_data)
So :
I used http://tripledes.online-domain-tools.com/ and its output for above values was :
S_ENC = 448b0a5967ca246d058703ff0c694f15
And :
Padding_DES = 80 00 00 00 00 00 00 00
Host_auth_data = sequence_counter | card_challenge | host_challenge | padding_DES
IV = Card_Cryptogram :: BA513484D9C1B96E
host_cryptogram = encrypt(TDES_CBC, S_ENC, IV, host_auth_data)
So :
Host_Authentication_Data : 001B9B95B95E5EBC7F41A9E7193783FA8000000000000000
Again, I used http://tripledes.online-domain-tools.com/
and :
Host_Cryptogram : 3587b531db71ac52392493c08cff189ce7b9061029c63b62
So :
Host_Cryptogram[16,24] = e7b9061029c63b62
Why these two way [manually and GPJ output] give us two host cryptogram?
From the INITIALIZE UPDATE command you send, you get
host_challenge = 00 00 00 00 00 00 00 00
In response to the INITIALIZE UPDATE command, you get
diversification_data = 00 00 11 60 01 00 8A 79 0A F9
key_information = FF 02
sequence_counter = 00 11
card_challenge = 79 11 36 5D 71 00
card_cryptogram = A5 A5 EC 63 BB DC 05 CC
The key information indicates SCP02 (02). The key diversification data may be used to derive the card-specific K_ENC. Lets assume we have a K_ENC like this
K_ENC = 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
We can then derive the session encryption key like this
derivation_const_ENC = 01 82
derivation_data = derivation_const_ENC | sequence_counter | 00 00 00 00 00 00 00 00 00 00 00 00
IV = 00 00 00 00 00 00 00 00
S_ENC = encrypt(TDES_CBC, K_ENC, IV, derivation_data)
Next, we can assemble the authentication data used to calculate the host cryptogram:
padding_DES = 80 00 00 00 00 00 00 00
host_auth_data = sequence_counter | card_challenge | host_challenge | padding_DES
Then we can use the session encryption key to encrypt the authentication data:
IV = 00 00 00 00 00 00 00 00
host_cryptogram = encrypt(TDES_CBC, S_ENC, IV, host_auth_data)
The last 8 bytes of the encrypted authentication data are the actual host cryptogram that we would send to the card:
EXTERNAL_AUTHENTICATE_data = host_cryptogram[16, 24]
Now we can assemble the EXTERNAL AUTHENTICATE command:
EXTERNAL_AUTHENTICATE = 84 82 03 00 08 | EXTERNAL_AUTHENTICATE_data
We can then calculate the S_MAC key (analoguous to getting the S_ENC above) and the MAC over that command and append it to the command data to get the full EXTERNAL AUTHENTICATE command that can be sent to the card:
EXTERNAL_AUTHENTICATE = 84 82 03 00 10 | EXTERNAL_AUTHENTICATE_data | MAC
Update
Using http://tripledes.online-domain-tools.com/ to reproduce the results of GPJ
Your K_ENC is 404142434445464748494A4B4C4D4E4F. The online tools does not properly support 2-key-3DES, so you have to convert the key into its 3-key form first:
K_ENC = 404142434445464748494A4B4C4D4E4F4041424344454647
Use this key and a zero IV to encrypt the derivation data (0182001B000000000000000000000000). You get
S_ENC = fb063cc2e17b979b10e22f82110234b4
In 3-key notation, this is
S_ENC = fb063cc2e17b979b10e22f82110234b4fb063cc2e17b979b
Use this key and a zero IV to encrypt the host authentication data (001b9b95b95e5ebc7f41a9e7193783fa8000000000000000):
HOST_CRYPTOGRAM = 773e790c91acce3167d99f92c60e2afd133b4ec52c9ed824

Calculate time duration using awk [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How to calculate time duration by using awk for the following file:
02 0F 00 80 C9 CD AB 00 00 48 CF 00 00 00 00 00 00 6B E7 01 07 1A 16 1B 36 00 with Timestamp2014-03-12 18:46:59.986000
02 0F 00 80 CA CD AB 00 00 48 CF 00 00 00 00 00 00 6B E7 01 07 1A 14 DB 39 00 with Timestamp2014-03-12 18:47:02.446279
02 13 23 C8 B0 CD AB 00 00 FF FF E2 75 AC 21 4E 83 00 00 01 83 6C E7 01 11 1A 36 DD 39 00 with Timestamp2014-03-12 18:47:02.455278
02 03 12 00 B0 6B E7 01 03 1A FF FF FF FF with Timestamp2014-03-12 18:47:02.457279
02 17 00 80 CB CD AB 00 00 48 CF 00 10 E2 75 AC 21 4E 83 00 00 00 00 00 00 6B E6 01 07 1A 10 9B 3D 00 with Timestamp2014-03-12 18:47:06.196279
02 10 63 C8 B1 CD AB 00 00 E2 75 AC 21 4E 83 00 00 04 6A E6 01 0F 1A 14 9D 3D 00 with Timestamp2014-03-12 18:47:06.205278
02 03 12 00 B1 6C E6 01 03 1A FF FF FF FF with Timestamp2014-03-12 18:47:06.206279
In other words, last line timestamp value minus first line timestamp values.
Is this what you want (using GNU awk for mktime())?
$ cat tst.awk
sub(/.*Timestamp/,"") {
split($0,t,/[-:. ]/)
time[++nr] = mktime(t[1]" "t[2]" "t[3]" "t[4]" "t[5]" "t[6]) "." t[7]
}
END { print time[nr] - time[1] }
$ awk -f tst.awk file
6.22028
Thanks a lot #Ed Morton; it is not working with this example:
Number of saved packets= 373
Protocol: IEEE 802.15.4
Packet #0 :02 0F 00 80 C9 CD AB 00 00 48 CF 00 00 00 00 00 00 6B E7 01 07 1A 16 1B 36 00 with Timestamp2014-03-12 18:46:59.986000
###################################################################################
Packet #1 :02 0F 00 80 CA CD AB 00 00 48 CF 00 00 00 00 00 00 6B E7 01 07 1A 14 DB 39 00 with Timestamp2014-03-12 18:47:02.446279
###################################################################################
Packet #2 :02 13 23 C8 B0 CD AB 00 00 FF FF E2 75 AC 21 4E 83 00 00 01 83 6C E7 01 11 1A 36 DD 39 00 with Timestamp2014-03-12 18:47:02.455278
###################################################################################
Packet #3 :02 03 12 00 B0 6B E7 01 03 1A FF FF FF FF with Timestamp2014-03-12 18:47:02.457279
###################################################################################
Packet #4 :02 17 00 80 CB CD AB 00 00 48 CF 00 10 E2 75 AC 21 4E 83 00 00 00 00 00 00 6B E6 01 07 1A 10 9B 3D 00 with Timestamp2014-03-12 18:47:06.196279
###################################################################################
Packet #5 :02 10 63 C8 B1 CD AB 00 00 E2 75 AC 21 4E 83 00 00 04 6A E6 01 0F 1A 14 9D 3D 00 with Timestamp2014-03-12 18:47:06.205278
###################################################################################
Packet #6 :02 03 12 00 B1 6C E6 01 03 1A FF FF FF FF with Timestamp2014-03-12 18:47:06.206279