gnokii-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] libgnokii and core programs branch, master, updated. rel_0_6_29-33


From: Pawel Kot
Subject: [SCM] libgnokii and core programs branch, master, updated. rel_0_6_29-336-g9e5af7f
Date: Fri, 23 Dec 2011 21:36:29 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "libgnokii and core programs".

The branch, master has been updated
       via  9e5af7fa0566ac8b66db8caed89995699340c7a3 (commit)
      from  3d85042c5a5bee3ff8e9a2383db91c53db98da0b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/gnokii.git/commit/?id=9e5af7fa0566ac8b66db8caed89995699340c7a3


commit 9e5af7fa0566ac8b66db8caed89995699340c7a3
Author: Pawel Kot <address@hidden>
Date:   Tue Dec 20 15:56:48 2011 +0100

    Optional authentication for AT driver
    
    These changes support devices that need authentication process when
    initializing.  Support is provided just for AT driver.
    
    The following methods of authentication are supported.
    
    text
    It is used for regular PIN/PUK authentication (ascii text data). Security
    code will be read from the file or from the interactive prompt.  The file
    format looks as follows:
     PIN:1234
     PUK:12345678
     PIN2:5678
     PUK2:0987654321
     SEC:12345
    gnokii will issue:
     AT+CPIN?
    Depending on the outcome different actions will be taken.
     +CPIN: READY - no action
     +CPIN: SIM PIN - authenticate using PIN
     +CPIN: SIM PUK - authenticate using PUK
     +CPIN: SIM PIN2 - authenticate using PIN2
     +CPIN: SIM PUK2 - authenticate using PUK2
    
    interactive
    It allows program that uses libgnokii to register own authentication code.
    The indented use case is for interactive entering PIN, PUK or other security
    code.  The registered function should determine on its own whether any
    security code is expected and if so, which one.
    
    binary
    For future use. Intended usage is for any binary data authentication.
    
    Authentication type and path to the relevant file are stored in gnokii
    config.  It can be used either in [global] section or in [phone_*] sections.

diff --git a/ChangeLog b/ChangeLog
index a7e771a..b7f3b1a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -5,6 +5,8 @@
  * libgnokii updates
     o replace gethostbyname (deprecated) with getaddrinfo in tcp
       driver                                            (Paweł Kot)
+    o add optional authentication during the initialization phase
+                                                        (Paweł Kot)
  * at driver updates
     o in the default case autodetect if PDU SMS starts with SMSC
                                                     (Daniele Forsi)
@@ -12,6 +14,8 @@
                                                         (Paweł Kot)
     o fix sending sms with Nokia Cellular Data Adapter; thanks to
       Tristan Drinkwater for patient testing            (Paweł Kot)
+    o add optional authentication during the initialization phase
+                                                        (Paweł Kot)
  * fake driver updates
     o always autodetect if PDU SMS starts with SMSC (Daniele Forsi)
  * Documentation updates
diff --git a/Docs/sample/gnokiirc b/Docs/sample/gnokiirc
index 3b5aaaa..6bd9b9a 100644
--- a/Docs/sample/gnokiirc
+++ b/Docs/sample/gnokiirc
@@ -5,7 +5,6 @@
 # $HOME/.config/gnokii/config in most cases) and change port, connection and
 # model settings following the comments below.  See
 # http://wiki.gnokii.org/index.php/Config for working examples.
-#
 
 [global]
 
@@ -169,11 +168,53 @@ serial_baudrate = 19200
 # (sm_retry = 0)
 #sm_retry = 1
 
-# Run the specified script(s) right after opening and initializing the device
-# and before any communication (right before closing for disconnect_script).
-# You may find handy to use it to connect your modem to SMS Center
-# when using BIP or CIMD protocols
-# Non-absolute path is relative to the specific directory where gnokii is run!
+# The following settings allow to choose an authentication method upon the
+# initialization of the phone. It is effective only for AT driver.
+# Authentication type: none, interactive, text, binary, script
+authentication_type = none
+#   When 'none' type is selected, no additional action on initialization is
+#   taken
+#authentication_type = interactive
+#   When 'interactive' type is selected it allows the application to
+#   implement own authentication method.  When no authentication is
+#   implemented by the application, the type 'text' is assumed.
+#authentication_type = text
+#   When 'pin' type is selected gnokii will issue:
+#    AT+CPIN?
+#   Depending on the outcome different actions will be taken.
+#    +CPIN: READY - no action
+#    +CPIN: SIM PIN - authenticate using PIN
+#    +CPIN: SIM PUK - authenticate using PUK
+#    +CPIN: SIM PIN2 - authenticate using PIN2
+#    +CPIN: SIM PUK2 - authenticate using PUK2
+#   PIN/PUK will be read from the file pointed out by 'auth_file' variable.
+#   File must not be world or group readable/writable/exacutable.
+#   The syntax of the file is (see also Docs/sample/pin file):
+#    PIN:1234
+#    PUK:12345678
+#    PIN2:5678
+#    PUK2:0987654321
+#    SEC:12345
+#   Supported code types are: PIN, PIN2, PUK, PUK2, SEC
+#   If the path variable is empty or points to non existent file or to the
+#   file with wrong permissions, PIN/PUK will be read from the interactive
+#   prompt (stdin).
+#authentication_type = binary
+#   For future use. Reads binary authentication information from the file
+#   pointed out by 'auth_file' variable. Currently does nothing.
+
+# Location of the file that includes authentication information. Used by
+# authentication types text and binary.
+#auth_file = 
+
+# Location of the scripts to be run at specified moments.
+# connect_script: right after establishing connection with the device
+# disconnect_script: right before closing the connection
+# auth_script: right after establishing the connection with the device
+# You may find handy to use connect_script
+# or disconnect_script to connect your modem to SMS Center when using BIP or
+# CIMD protocols. Non-absolute path is relative to the specific directory
+# where gnokii is run!
 #connect_script = /absolute/path/to/gnokii/Docs/sample/cimd-connect
 #disconnect_script =
 
@@ -249,6 +290,7 @@ TELEPHONE = 12345678
 
 [disconnect_script]
 
+[auth_script]
 
 # The following parameters control how libgnokii handles the debugging 
messages.
 # Currently there are three categories: "debug" controls the libgnokii
@@ -266,6 +308,10 @@ rlpdebug = off
 # where to log X debug output (on: stderr, off: /dev/null)
 xdebug = off
 
+# In [phone_*] sections you can use all variables that were used in [global]
+# section.  Only the following sections are global: [flags], [gnokii],
+# [xgnokii], [gnokiid], [logging].
+
 # Fake-phone can be used for testing Gnokii functionality without
 # having a physical phone connected.
 # Example usage:
diff --git a/Docs/sample/pin b/Docs/sample/pin
new file mode 100644
index 0000000..b12fa3a
--- /dev/null
+++ b/Docs/sample/pin
@@ -0,0 +1,5 @@
+PIN:1234
+PUK:12345678
+PIN2:5678
+PUK2:0987654321
+SEC:12345
diff --git a/common/Makefile.am b/common/Makefile.am
index e8a04ee..597ba7d 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -50,7 +50,8 @@ libgnokii_la_SOURCES = \
        misc.c \
        snprintf.c \
        localcharset.c \
-       map.c
+       map.c \
+       gsm-auth.c
 
 libgnokii_la_LIBADD = \
        $(top_builddir)/common/phones/libPHONES.la \
diff --git a/common/cfgreader.c b/common/cfgreader.c
index 90e6678..6b02da4 100644
--- a/common/cfgreader.c
+++ b/common/cfgreader.c
@@ -860,6 +860,27 @@ static gn_error cfg_psection_load(gn_config *cfg, const 
char *section, const gn_
                cfg->use_locking = def->use_locking;
        }
 
+       if (!(val = gn_cfg_get(gn_cfg_info, section, "authentication_type")))
+               cfg->auth_type = GN_AUTH_TYPE_NONE;
+       else if (!strcasecmp(val, "text"))
+               cfg->auth_type = GN_AUTH_TYPE_TEXT;
+       else if (!strcasecmp(val, "interactive"))
+               cfg->auth_type = GN_AUTH_TYPE_INTERACTIVE;
+       else if (!strcasecmp(val, "binary"))
+               cfg->auth_type = GN_AUTH_TYPE_BINARY;
+       else if (!strcasecmp(val, "none"))
+               cfg->auth_type = GN_AUTH_TYPE_NONE;
+       else {
+               fprintf(stderr, _("Unsupported [%s] %s value \"%s\"\n"), 
section, "authentication_type", val);
+               fprintf(stderr, _("Assuming: %s\n"), "none");
+               cfg->auth_type = def->auth_type;
+       }
+
+       if (!(val = gn_cfg_get(gn_cfg_info, section, "auth_file")))
+               snprintf(cfg->auth_file, sizeof(cfg->auth_file), "%s", 
def->auth_file);
+       else
+               snprintf(cfg->auth_file, sizeof(cfg->auth_file), "%s", val);
+
        return GN_ERR_NONE;
 }
 
@@ -1213,6 +1234,8 @@ static gn_error cfg_file_or_memory_read(const char *file, 
const char **lines)
        gn_config_default.rfcomm_cn = 0;
        gn_config_default.sm_retry = 0;
        gn_config_default.use_locking = 0;
+       gn_config_default.auth_type = GN_AUTH_TYPE_NONE;
+       gn_config_default.auth_file[0] = 0;
 
        if ((error = cfg_psection_load(&gn_config_global, "global", 
&gn_config_default)) != GN_ERR_NONE)
                return error;
diff --git a/common/gsm-auth.c b/common/gsm-auth.c
new file mode 100644
index 0000000..6d96c85
--- /dev/null
+++ b/common/gsm-auth.c
@@ -0,0 +1,208 @@
+/*
+
+  G N O K I I
+
+  A Linux/Unix toolset and driver for the mobile phones.
+
+  This file is part of gnokii.
+
+  Copyright (C) 2011 Paweł Kot
+  
+  Functions for initialization authentication.
+
+*/
+
+#include "config.h"
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "gnokii-internal.h"
+#include "gnokii.h"
+
+static int get_password(const char *prompt, char *pass, int length)
+{
+       int fd = fileno(stdin);
+       int count;
+
+       if (isatty(fd)) {
+#ifdef HAVE_GETPASS
+               const char *s;
+
+               /* FIXME: man getpass says it was removed in POSIX.1-2001 */
+               s = getpass(prompt);
+               if (s) {
+                       strncpy(pass, s, length - 1);
+                       pass[length - 1] = '\0';
+
+                       return strlen(pass);
+               }
+               return -1;
+#else
+               fprintf(stdout, "%s", prompt);
+#endif
+       }
+       if (fgets(pass, length, stdin)) {
+               /* Strip trailing newline like getpass() would do */
+               for (count = 0; pass[count] && pass[count] != '\n'; count++)
+                       ;
+               pass[count] = '\0';
+
+               return count;
+       }
+       return -1;
+}
+
+/* This function is called only by auth_pin(). No need for any sanity checks 
here */
+static gn_error auth_pin_interactive(gn_data *data, struct gn_statemachine 
*state)
+{
+       gn_security_code *security_code = data->security_code;
+
+       memset(&security_code->code, 0, sizeof(security_code->code));
+       switch (security_code->type) {
+       case GN_SCT_Pin:
+               get_password(_("Enter your PIN code: "), security_code->code, 
sizeof(security_code->code));
+               break;
+       case GN_SCT_Puk:
+               get_password(_("Enter your PUK code: "), security_code->code, 
sizeof(security_code->code));
+               break;
+       case GN_SCT_Pin2:
+               get_password(_("Enter your PIN2 code: "), security_code->code, 
sizeof(security_code->code));
+               break;
+       case GN_SCT_Puk2:
+               get_password(_("Enter your PUK2 code: "), security_code->code, 
sizeof(security_code->code));
+               break;
+       case GN_SCT_SecurityCode:
+               get_password(_("Enter your security code: "), 
security_code->code, sizeof(security_code->code));
+               break;
+       default:
+               return GN_ERR_NOTSUPPORTED;
+       }
+
+       return gn_sm_functions(GN_OP_EnterSecurityCode, data, state);
+}
+
+static int read_security_code_from_file(const char *path, gn_security_code *sc)
+{
+       FILE *f;
+       char line[32];
+       int cnt = 0;
+
+       f = fopen(path, "r");
+       while (fgets(line, sizeof(line), f) != NULL) {
+               switch (sc->type) {
+               case GN_SCT_SecurityCode:
+                       cnt = sscanf(line, "SEC:%s", sc->code);
+                       break;
+               case GN_SCT_Pin:
+                       cnt = sscanf(line, "PIN:%s", sc->code);
+                       break;
+               case GN_SCT_Pin2:
+                       cnt = sscanf(line, "PIN2:%s", sc->code);
+                       break;
+               case GN_SCT_Puk:
+                       cnt = sscanf(line, "PUK:%s", sc->code);
+                       break;
+               case GN_SCT_Puk2:
+                       cnt = sscanf(line, "PUK2:%s", sc->code);
+                       break;
+               default:
+                       break;
+               }
+               if (cnt == 1)
+                       break;
+       }
+       fclose(f);
+       return cnt;
+}
+
+static gn_error auth_pin(struct gn_statemachine *state)
+{
+       struct stat buf;
+       gn_error err;
+       char *str;
+       gn_data *data;
+       gn_security_code sc;
+       const char *path = state->config.auth_file;
+
+       data = calloc(1, sizeof(gn_data));
+       data->security_code = &sc;
+
+       err = gn_sm_functions(GN_OP_GetSecurityCodeStatus, data, state);
+       if (err != GN_ERR_NONE)
+               goto out;
+
+       switch (sc.type) {
+       case GN_SCT_SecurityCode:
+               str = "SEC";
+               break;
+       case GN_SCT_Pin:
+               str = "PIN";
+               break;
+       case GN_SCT_Pin2:
+               str = "PIN2";
+               break;
+       case GN_SCT_Puk:
+               str = "PUK";
+               break;
+       case GN_SCT_Puk2:
+               str = "PUK2";
+               break;
+       case GN_SCT_None:
+               /* err is GN_ERR_NONE but this is to make it explicit */
+               err = GN_ERR_NONE;
+               goto out;
+       default:
+               err = GN_ERR_NOTSUPPORTED;
+               goto out;
+       }
+
+       /* file handling */
+       if (stat(path, &buf) != 0) {
+               dprintf("File with the security code not found.\n");
+               dprintf("Falling back to interactive mode.\n");
+               err = auth_pin_interactive(data, state);
+               goto out;
+       }
+       if ((buf.st_mode & S_IRWXG) != 0 || (buf.st_mode & S_IRWXO) != 0) {
+               dprintf("File with the security code cannot be world or group 
readable.\n");
+               dprintf("Falling back to interactive mode\n");
+               err = auth_pin_interactive(data, state);
+               goto out;
+       }
+
+       if (!read_security_code_from_file(path, data->security_code)) {
+               dprintf("Could not find %s in file %s.\n", str, path);
+               dprintf("Falling back to interactive mode.\n");
+               err = auth_pin_interactive(data, state);
+               goto out;
+       }
+
+       err = gn_sm_functions(GN_OP_EnterSecurityCode, data, state);
+out:
+       free(data);
+       return err;
+}
+
+gn_error do_auth(gn_auth_type auth_type, struct gn_statemachine *state)
+{
+       switch (auth_type) {
+       case GN_AUTH_TYPE_TEXT:
+               return auth_pin(state);
+       case GN_AUTH_TYPE_INTERACTIVE:
+               if (!state->callbacks.auth_interactive)
+                       return auth_pin(state);
+               else
+                       return state->callbacks.auth_interactive(state);
+       case GN_AUTH_TYPE_NONE:
+       case GN_AUTH_TYPE_BINARY:
+               return GN_ERR_NONE;
+       default:
+               return GN_ERR_NOTSUPPORTED;
+       }
+}
+
+void gn_auth_interactive_register(gn_auth_interactive_func_t auth_func, struct 
gn_statemachine *state)
+{
+       state->callbacks.auth_interactive = auth_func;
+}
diff --git a/common/phones/atgen.c b/common/phones/atgen.c
index 7d4f12a..a706f2e 100644
--- a/common/phones/atgen.c
+++ b/common/phones/atgen.c
@@ -3301,6 +3301,12 @@ static gn_error Initialise(gn_data *setupdata, struct 
gn_statemachine *state)
        SetEcho(&data, state);
        SetExtendedError(&data, state);
 
+       if (state->config.auth_type != GN_AUTH_TYPE_NONE)
+               ret = do_auth(state->config.auth_type, state);
+
+       if (ret)
+               goto out;
+
        /*
         * detect manufacturer and model for further initialization
         */
diff --git a/include/Makefile.am b/include/Makefile.am
index d552e8c..89a9fc3 100644
--- a/include/Makefile.am
+++ b/include/Makefile.am
@@ -16,7 +16,8 @@ EXTRA_HEADERS =                               \
                 pkt.h                  \
                 sms-nokia.h            \
                 localcharset.h         \
-                map.h
+                map.h                  \
+                gsm-auth.h
 
 CLEANFILES = gnokii.h
 
diff --git a/include/gnokii-internal.h b/include/gnokii-internal.h
index 0b8b1b0..cf53384 100644
--- a/include/gnokii-internal.h
+++ b/include/gnokii-internal.h
@@ -22,7 +22,6 @@
 
 #include "compat.h"
 #include "misc.h"
-
 #if !defined(GNOKII_DEPRECATED)
 #  define GNOKII_DEPRECATED /* do not warn about deprecated functions here */
 #endif
@@ -176,4 +175,7 @@ int utf8_base64_encode(char *dest, int destlen, const char 
*src, int inlen);
 int add_slashes(char *dest, char *src, int maxlen, int len);
 int strip_slashes(char *dest, const char *src, int maxlen, int len);
 
+/* authentication for at driver */
+gn_error do_auth(gn_auth_type auth_type, struct gn_statemachine *state);
+
 #endif /* _gnokii_internal_h */
diff --git a/include/gnokii.h.in b/include/gnokii.h.in
index 08cf1d7..100339e 100644
--- a/include/gnokii.h.in
+++ b/include/gnokii.h.in
@@ -338,6 +338,9 @@ GNOKII_API gn_error gn_mms_convert(const gn_mms 
*source_mms, gn_mms *dest_mms);
 GNOKII_API gn_error gn_call_dial(int *call_id, gn_data *data, struct 
gn_statemachine *state);
 GNOKII_API gn_error gn_call_check_active(struct gn_statemachine *state);
 
+/* Callback registration */
+GNOKII_API void gn_auth_interactive_register(gn_auth_interactive_func_t 
auth_func, struct gn_statemachine *state);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/gnokii/common.h b/include/gnokii/common.h
index 10eeee8..34fe7dc 100644
--- a/include/gnokii/common.h
+++ b/include/gnokii/common.h
@@ -883,4 +883,11 @@ typedef struct {
        int size;
 } gn_file_list;
 
+typedef enum {
+       GN_AUTH_TYPE_NONE = 0,
+       GN_AUTH_TYPE_INTERACTIVE,
+       GN_AUTH_TYPE_TEXT,
+       GN_AUTH_TYPE_BINARY
+} gn_auth_type;
+
 #endif /* _gnokii_common_h */
diff --git a/include/gnokii/data.h b/include/gnokii/data.h
index a14b363..fa51d34 100644
--- a/include/gnokii/data.h
+++ b/include/gnokii/data.h
@@ -153,14 +153,16 @@ typedef struct {
        int hardware_handshake;                         /* Select between 
hardware and software handshake */
        int require_dcd;                                /* DCD signal check */
        int smsc_timeout;                               /* How many seconds 
should we wait for the SMSC response, defaults to 10 seconds */
-       char connect_script[256];                       /* Script to run when 
device connection established */
-       char disconnect_script[256];                    /* Script to run when 
device connection closed */
        uint8_t rfcomm_cn;                              /* RFCOMM channel 
number to connect */
        unsigned int sm_retry;                          /* Indicates whether 
statemachine should do retries. Defaults to off. */
                                                        /* Use with caution -- 
may break newer DCT4 phones */
-
        unsigned int use_locking;                       /* Should we use 
locking system or not */
        int set_dtr_rts;                                /* Should we set DTR 
and RTS bits on the serial line */
+       gn_auth_type auth_type;                         /* Type of the 
initialization authentication for the AT driver */
+       char auth_file[256];                            /* Location of the 
authentication information file */
+       char connect_script[256];                       /* Script to run when 
device connection established */
+       char disconnect_script[256];                    /* Script to run when 
device connection closed */
+       char auth_script[256];                          /* Script to run after 
device connection established */
        /* do not change the following values from userspace */
        char m_model[GN_MODEL_MAX_LENGTH];
        char m_manufacturer[GN_MANUFACTURER_MAX_LENGTH];
@@ -168,6 +170,11 @@ typedef struct {
        char m_imei[GN_IMEI_MAX_LENGTH];
 } gn_config;
 
+typedef gn_error (*gn_auth_interactive_func_t)(struct gn_statemachine *state);
+typedef struct {
+       gn_auth_interactive_func_t auth_interactive;
+} gn_callback;
+
 typedef struct {
        int fd;
        gn_connection_type type;
diff --git a/include/gnokii/statemachine.h b/include/gnokii/statemachine.h
index 3da11c3..61cef77 100644
--- a/include/gnokii/statemachine.h
+++ b/include/gnokii/statemachine.h
@@ -58,6 +58,7 @@ struct gn_statemachine {
        gn_link link;
        gn_driver driver;
        char *lockfile;
+       gn_callback callbacks;  /* We store all callbacks in here */
        
        /* Store last message for resend purposes */
        unsigned char last_msg_type;

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog                     |    4 +
 Docs/sample/gnokiirc          |   58 ++++++++++-
 Docs/sample/pin               |    5 +
 common/Makefile.am            |    3 +-
 common/cfgreader.c            |   23 +++++
 common/gsm-auth.c             |  208 +++++++++++++++++++++++++++++++++++++++++
 common/phones/atgen.c         |    6 +
 include/Makefile.am           |    3 +-
 include/gnokii-internal.h     |    4 +-
 include/gnokii.h.in           |    3 +
 include/gnokii/common.h       |    7 ++
 include/gnokii/data.h         |   13 ++-
 include/gnokii/statemachine.h |    1 +
 13 files changed, 326 insertions(+), 12 deletions(-)
 create mode 100644 Docs/sample/pin
 create mode 100644 common/gsm-auth.c


hooks/post-receive
-- 
libgnokii and core programs



reply via email to

[Prev in Thread] Current Thread [Next in Thread]