From: James Prestwood <james.prestwood@linux.intel.com>
To: ofono@ofono.org
Subject: [PATCHv2 02/11] simutil: Added authenticate builder/parser API
Date: Tue, 10 Oct 2017 14:36:11 -0700 [thread overview]
Message-ID: <1507671380-7625-2-git-send-email-james.prestwood@linux.intel.com> (raw)
In-Reply-To: <1507671380-7625-1-git-send-email-james.prestwood@linux.intel.com>
[-- Attachment #1: Type: text/plain, Size: 3855 bytes --]
Used to compose/parse non-TLV formatted authenticate commands
for GSM and UMTS authentication.
---
src/simutil.c | 130 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/simutil.h | 14 +++++++
2 files changed, 144 insertions(+)
diff --git a/src/simutil.c b/src/simutil.c
index f43c2c2..69783bd 100644
--- a/src/simutil.c
+++ b/src/simutil.c
@@ -1609,3 +1609,133 @@ error:
return NULL;
}
+
+static int build_authenticate(unsigned char *buffer, const unsigned char *rand,
+ const unsigned char *autn)
+{
+ int pos = 0;
+
+ buffer[pos++] = 0x00;
+ buffer[pos++] = 0x88;
+ buffer[pos++] = 0x00;
+ buffer[pos++] = autn ? 0x81 : 0x80;
+ buffer[pos++] = autn ? 0x22 : 0x11;
+ buffer[pos++] = 0x10;
+ memcpy(buffer + pos, rand, 16);
+ pos += 16;
+
+ if (autn) {
+ buffer[pos++] = 0x10;
+ memcpy(buffer + pos, autn, 16);
+ pos += 16;
+ buffer[pos++] = 0x00;
+ }
+
+ return pos;
+}
+
+int sim_build_umts_authenticate(unsigned char *buffer, int len,
+ const unsigned char *rand, const unsigned char *autn)
+{
+ if (len < 40 || !rand || !autn)
+ return FALSE;
+
+ return build_authenticate(buffer, rand, autn);
+}
+
+int sim_build_gsm_authenticate(unsigned char *buffer, int len,
+ const unsigned char *rand)
+{
+ if (len < 22 || !rand)
+ return FALSE;
+
+ return build_authenticate(buffer, rand, NULL);
+}
+
+#include <stdio.h>
+
+gboolean sim_parse_umts_authenticate(const unsigned char *buffer,
+ int len, const unsigned char **res, const unsigned char **ck,
+ const unsigned char **ik, const unsigned char **auts,
+ const unsigned char **kc)
+{
+ if (len < 18 || !buffer)
+ return FALSE;
+
+ switch (buffer[0]) {
+ case 0xdb:
+ /* 'DB' + '08' + RES(16) + '10' + CK(32) + '10' + IK(32) = 43 */
+ if (len < 43)
+ goto umts_end;
+
+ /* success */
+ if (buffer[1] != 0x08)
+ goto umts_end;
+
+ *res = buffer + 2;
+
+ if (buffer[10] != 0x10)
+ goto umts_end;
+
+ *ck = buffer + 11;
+
+ if (buffer[27] != 0x10)
+ goto umts_end;
+
+ *ik = buffer + 28;
+
+ if (len >= 53 && kc) {
+ if (buffer[44] != 0x08)
+ goto umts_end;
+
+ *kc = buffer + 45;
+ } else {
+ *kc = NULL;
+ }
+
+ *auts = NULL;
+
+ break;
+ case 0xdc:
+ /* 'DB' + '10' + AUTS(16) = 18 */
+ if (len < 18)
+ goto umts_end;
+
+ /* sync error */
+ if (buffer[1] != 0x10)
+ goto umts_end;
+
+ *auts = buffer + 2;
+
+ break;
+ default:
+ goto umts_end;
+ }
+
+ return TRUE;
+
+umts_end:
+ return FALSE;
+}
+
+gboolean sim_parse_gsm_authenticate(const unsigned char *buffer, int len,
+ const unsigned char **sres, const unsigned char **kc)
+{
+ if (len < 14 || !buffer)
+ goto gsm_end;
+
+ if (buffer[0] != 0x04)
+ goto gsm_end;
+
+ *sres = buffer + 1;
+
+ if (buffer[5] != 0x08)
+ goto gsm_end;
+
+ *kc = buffer + 6;
+
+ return TRUE;
+
+gsm_end:
+ return FALSE;
+}
diff --git a/src/simutil.h b/src/simutil.h
index 9984b2c..ece5145 100644
--- a/src/simutil.h
+++ b/src/simutil.h
@@ -507,3 +507,17 @@ gboolean sim_cphs_is_active(unsigned char *service_cphs,
enum sim_cphs_service index);
GSList *sim_parse_app_template_entries(const unsigned char *buffer, int len);
+
+int sim_build_umts_authenticate(unsigned char *buffer, int len,
+ const unsigned char *rand, const unsigned char *autn);
+
+int sim_build_gsm_authenticate(unsigned char *buffer, int len,
+ const unsigned char *rand);
+
+gboolean sim_parse_umts_authenticate(const unsigned char *buffer,
+ int len, const unsigned char **res, const unsigned char **ck,
+ const unsigned char **ik, const unsigned char **auts,
+ const unsigned char **kc);
+
+gboolean sim_parse_gsm_authenticate(const unsigned char *buffer, int len,
+ const unsigned char **sres, const unsigned char **kc);
--
2.7.4
next prev parent reply other threads:[~2017-10-10 21:36 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-10-10 21:36 [PATCHv2 01/11] simutil: Added app type to application parser James Prestwood
2017-10-10 21:36 ` James Prestwood [this message]
2017-10-11 15:30 ` [PATCHv2 02/11] simutil: Added authenticate builder/parser API Denis Kenzior
2017-10-10 21:36 ` [PATCHv2 03/11] unit: add gsm and umts parse/build unit tests James Prestwood
2017-10-10 21:36 ` [PATCHv2 04/11] sim: new API to check for a UST service only James Prestwood
2017-10-11 15:34 ` Denis Kenzior
2017-10-10 21:36 ` [PATCHv2 05/11] sim-auth: prep simauth/dbus headers James Prestwood
2017-10-11 15:39 ` Denis Kenzior
2017-10-10 21:36 ` [PATCHv2 06/11] sim-auth: implementation of core sim-auth atom James Prestwood
2017-10-10 21:36 ` [PATCHv2 07/11] atmodem: implemented sim-auth functionality in atmodem James Prestwood
2017-10-10 21:36 ` [PATCHv2 08/11] xmm7xxx: add sim-auth driver to xmm7xxx plugin James Prestwood
2017-10-10 21:36 ` [PATCHv2 09/11] phonesim: Added sim-auth to phonesim plugin James Prestwood
2017-10-10 21:36 ` [PATCHv2 10/11] test: added tests for GSM/UMTS auth algorithms James Prestwood
2017-10-10 21:36 ` [PATCHv2 11/11] doc: documentation for SimAuth dbus interfaces James Prestwood
2017-10-11 15:57 ` Denis Kenzior
2017-10-11 15:29 ` [PATCHv2 01/11] simutil: Added app type to application parser Denis Kenzior
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1507671380-7625-2-git-send-email-james.prestwood@linux.intel.com \
--to=james.prestwood@linux.intel.com \
--cc=ofono@ofono.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox