Esempio n. 1
0
        public Scp03Session(Session session, ushort key_id, Session auth_session, ushort auth_key_id)
        {
            var host_chal = auth_session.SendCmd(new GetChallengeReq {
                key_id = auth_key_id
            });

            if (host_chal[0] != 38)
            {
                throw new IOException($"Unknown host challenge algorithm: {host_chal[0]}");
            }
            var create_req = new CreateSessionReq
            {
                key_id    = key_id,
                host_chal = host_chal.Slice(1).ToArray()
            };
            var create_resp = session.SendCmd(create_req);

            session_id = create_resp[0];
            var card_chal   = create_resp.Slice(1, 8);
            var card_crypto = create_resp.Slice(1 + 8, 8);

            var client_auth = new ClientAuthReq
            {
                key_id      = auth_key_id,
                host_chal   = host_chal.Slice(1).ToArray(),
                card_chal   = card_chal.ToArray(),
                card_crypto = card_crypto.ToArray()
            };
            var auth_resp = auth_session.SendCmd(client_auth).ToArray();

            key_enc = new KeyParameter(auth_resp, 0, 16);
            var key_mac     = new KeyParameter(auth_resp, 16, 16);
            var key_rmac    = new KeyParameter(auth_resp, 32, 16);
            var host_crypto = auth_resp.AsMemory(48, 8);

            this.session = new Scp03CMacSession(cmac, session, key_mac, key_rmac, new byte[16]);

            var auth_req = new AuthenticateSessionReq
            {
                session_id  = session_id,
                host_crypto = host_crypto
            };

            this.session.SendCmd(auth_req);
        }
Esempio n. 2
0
        public Scp11Session(Session session, ushort key_id, Session auth_session, ushort auth_key_id)
        {
            var epk_oce = auth_session.SendCmd(new GetChallengeReq {
                key_id = auth_key_id
            }).ToArray();

            if (epk_oce[0] != 49)
            {
                throw new IOException($"Unknown ephemeral key algorithm: {epk_oce[0]}");
            }
            epk_oce[0] = 0x04;

            var req = new CreateSessionReq
            {
                key_id    = key_id,
                host_chal = epk_oce
            };
            var resp = session.SendCmd(req);

            session_id = resp[0];
            var epk_sd  = resp.Slice(1, 65).ToArray();
            var receipt = resp.Slice(1 + 65, 16).ToArray();

            var client_auth = new ClientAuthReq
            {
                key_id      = auth_key_id,
                host_chal   = epk_oce,
                card_chal   = epk_sd,
                card_crypto = receipt
            };
            var auth_resp = auth_session.SendCmd(client_auth).ToArray();

            key_enc = new KeyParameter(auth_resp, 0, 16);
            var key_mac  = new KeyParameter(auth_resp, 16, 16);
            var key_rmac = new KeyParameter(auth_resp, 32, 16);

            this.session = new Scp03CMacSession(cmac, session, key_mac, key_rmac, receipt);
        }