LCOV - code coverage report
Current view: top level - shishi/lib - encticketpart.c (source / functions) Hit Total Coverage
Test: GNU Shishi Lines: 38 102 37.3 %
Date: 2010-05-20 Functions: 6 14 42.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 12 42 28.6 %

           Branch data     Line data    Source code
       1                 :            : /* encticketpart.c --- Encrypted ticket part handling.
       2                 :            :  * Copyright (C) 2002, 2003, 2004, 2007  Simon Josefsson
       3                 :            :  *
       4                 :            :  * This file is part of Shishi.
       5                 :            :  *
       6                 :            :  * Shishi is free software; you can redistribute it and/or modify it
       7                 :            :  * under the terms of the GNU General Public License as published by
       8                 :            :  * the Free Software Foundation; either version 3 of the License, or
       9                 :            :  * (at your option) any later version.
      10                 :            :  *
      11                 :            :  * Shishi is distributed in the hope that it will be useful, but
      12                 :            :  * WITHOUT ANY WARRANTY; without even the implied warranty of
      13                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14                 :            :  * GNU General Public License for more details.
      15                 :            :  *
      16                 :            :  * You should have received a copy of the GNU General Public License
      17                 :            :  * along with Shishi; if not, see http://www.gnu.org/licenses or write
      18                 :            :  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
      19                 :            :  * Floor, Boston, MA 02110-1301, USA
      20                 :            :  *
      21                 :            :  */
      22                 :            : 
      23                 :            : #include "internal.h"
      24                 :            : 
      25                 :            : Shishi_asn1
      26                 :          2 : shishi_encticketpart (Shishi * handle)
      27                 :            : {
      28                 :            :   Shishi_asn1 node;
      29                 :            :   int res;
      30                 :            : 
      31                 :          2 :   node = shishi_asn1_encticketpart (handle);
      32                 :            : 
      33                 :          2 :   res = shishi_asn1_write (handle, node, "starttime", NULL, 0);
      34         [ -  + ]:          2 :   if (res != SHISHI_OK)
      35                 :            :     {
      36                 :          0 :       shishi_asn1_done (handle, node);
      37                 :          0 :       return NULL;
      38                 :            :     }
      39                 :            : 
      40                 :          2 :   res = shishi_asn1_write (handle, node, "renew-till", NULL, 0);
      41         [ -  + ]:          2 :   if (res != SHISHI_OK)
      42                 :            :     {
      43                 :          0 :       shishi_asn1_done (handle, node);
      44                 :          0 :       return NULL;
      45                 :            :     }
      46                 :            : 
      47                 :          2 :   res = shishi_asn1_write (handle, node, "caddr", NULL, 0);
      48         [ -  + ]:          2 :   if (res != SHISHI_OK)
      49                 :            :     {
      50                 :          0 :       shishi_asn1_done (handle, node);
      51                 :          0 :       return NULL;
      52                 :            :     }
      53                 :            : 
      54                 :          2 :   res = shishi_asn1_write (handle, node, "authorization-data", NULL, 0);
      55         [ -  + ]:          2 :   if (res != SHISHI_OK)
      56                 :            :     {
      57                 :          0 :       shishi_asn1_done (handle, node);
      58                 :          0 :       return NULL;
      59                 :            :     }
      60                 :            : 
      61                 :          2 :   res = shishi_encticketpart_flags_set (handle, node, 0);
      62         [ -  + ]:          2 :   if (res != SHISHI_OK)
      63                 :            :     {
      64                 :          0 :       shishi_asn1_done (handle, node);
      65                 :          0 :       return NULL;
      66                 :            :     }
      67                 :            : 
      68                 :          2 :   return node;
      69                 :            : }
      70                 :            : 
      71                 :            : /**
      72                 :            :  * shishi_encticketpart_get_key:
      73                 :            :  * @handle: shishi handle as allocated by shishi_init().
      74                 :            :  * @encticketpart: input EncTicketPart variable.
      75                 :            :  * @key: newly allocated key.
      76                 :            :  *
      77                 :            :  * Extract the session key in the Ticket.
      78                 :            :  *
      79                 :            :  * Return value: Returns %SHISHI_OK iff successful.
      80                 :            :  **/
      81                 :            : int
      82                 :          0 : shishi_encticketpart_get_key (Shishi * handle,
      83                 :            :                               Shishi_asn1 encticketpart, Shishi_key ** key)
      84                 :            : {
      85                 :            :   int res;
      86                 :            :   char *buf;
      87                 :            :   size_t buflen;
      88                 :            :   int32_t keytype;
      89                 :            : 
      90                 :          0 :   res = shishi_asn1_read_int32 (handle, encticketpart,
      91                 :            :                                 "key.keytype", &keytype);
      92         [ #  # ]:          0 :   if (res != SHISHI_OK)
      93                 :          0 :     return res;
      94                 :            : 
      95                 :          0 :   res = shishi_asn1_read (handle, encticketpart, "key.keyvalue",
      96                 :            :                           &buf, &buflen);
      97         [ #  # ]:          0 :   if (res != SHISHI_OK)
      98                 :          0 :     return res;
      99                 :            : 
     100                 :          0 :   res = shishi_key_from_value (handle, keytype, buf, key);
     101                 :          0 :   free (buf);
     102         [ #  # ]:          0 :   if (res != SHISHI_OK)
     103                 :          0 :     return res;
     104                 :            : 
     105                 :          0 :   return SHISHI_OK;
     106                 :            : }
     107                 :            : 
     108                 :            : /**
     109                 :            :  * shishi_encticketpart_key_set:
     110                 :            :  * @handle: shishi handle as allocated by shishi_init().
     111                 :            :  * @encticketpart: input EncTicketPart variable.
     112                 :            :  * @key: key handle with information to store in encticketpart.
     113                 :            :  *
     114                 :            :  * Set the EncTicketPart.key field to key type and value of supplied
     115                 :            :  * key.
     116                 :            :  *
     117                 :            :  * Return value: Returns %SHISHI_OK iff successful.
     118                 :            :  **/
     119                 :            : int
     120                 :          2 : shishi_encticketpart_key_set (Shishi * handle,
     121                 :            :                               Shishi_asn1 encticketpart, Shishi_key * key)
     122                 :            : {
     123                 :            :   int res;
     124                 :            :   int keytype;
     125                 :            : 
     126                 :          2 :   keytype = shishi_key_type (key);
     127                 :          2 :   res = shishi_asn1_write_uint32 (handle, encticketpart,
     128                 :            :                                   "key.keytype", keytype);
     129         [ -  + ]:          2 :   if (res != SHISHI_OK)
     130                 :          0 :     return res;
     131                 :            : 
     132                 :          2 :   res = shishi_asn1_write (handle, encticketpart, "key.keyvalue",
     133                 :            :                            shishi_key_value (key), shishi_key_length (key));
     134         [ -  + ]:          2 :   if (res != SHISHI_OK)
     135                 :          0 :     return res;
     136                 :            : 
     137                 :          2 :   return SHISHI_OK;
     138                 :            : }
     139                 :            : 
     140                 :            : /**
     141                 :            :  * shishi_encticketpart_flags_set:
     142                 :            :  * @handle: shishi handle as allocated by shishi_init().
     143                 :            :  * @encticketpart: input EncTicketPart variable.
     144                 :            :  * @flags: flags to set in encticketpart.
     145                 :            :  *
     146                 :            :  * Set the EncTicketPart.flags to supplied value.
     147                 :            :  *
     148                 :            :  * Return value: Returns %SHISHI_OK iff successful.
     149                 :            :  **/
     150                 :            : int
     151                 :          4 : shishi_encticketpart_flags_set (Shishi * handle,
     152                 :            :                                 Shishi_asn1 encticketpart, int flags)
     153                 :            : {
     154                 :            :   int res;
     155                 :            : 
     156                 :          4 :   res = shishi_asn1_write_bitstring (handle, encticketpart, "flags", flags);
     157         [ -  + ]:          4 :   if (res != SHISHI_OK)
     158                 :          0 :     return res;
     159                 :            : 
     160                 :          4 :   return SHISHI_OK;
     161                 :            : }
     162                 :            : 
     163                 :            : int
     164                 :          0 : shishi_encticketpart_crealm (Shishi * handle,
     165                 :            :                              Shishi_asn1 encticketpart,
     166                 :            :                              char **crealm, size_t * crealmlen)
     167                 :            : {
     168                 :          0 :   return shishi_asn1_read (handle, encticketpart, "crealm",
     169                 :            :                            crealm, crealmlen);
     170                 :            : }
     171                 :            : 
     172                 :            : /**
     173                 :            :  * shishi_encticketpart_crealm_set:
     174                 :            :  * @handle: shishi handle as allocated by shishi_init().
     175                 :            :  * @encticketpart: input EncTicketPart variable.
     176                 :            :  * @realm: input array with name of realm.
     177                 :            :  *
     178                 :            :  * Set the realm field in the KDC-REQ.
     179                 :            :  *
     180                 :            :  * Return value: Returns SHISHI_OK iff successful.
     181                 :            :  **/
     182                 :            : int
     183                 :          0 : shishi_encticketpart_crealm_set (Shishi * handle,
     184                 :            :                                  Shishi_asn1 encticketpart, const char *realm)
     185                 :            : {
     186                 :            :   int res;
     187                 :            : 
     188                 :          0 :   res = shishi_asn1_write (handle, encticketpart, "crealm", realm, 0);
     189         [ #  # ]:          0 :   if (res != SHISHI_OK)
     190                 :          0 :     return res;
     191                 :            : 
     192                 :          0 :   return SHISHI_OK;
     193                 :            : }
     194                 :            : 
     195                 :            : /**
     196                 :            :  * shishi_encticketpart_cname_set:
     197                 :            :  * @handle: shishi handle as allocated by shishi_init().
     198                 :            :  * @encticketpart: input EncTicketPart variable.
     199                 :            :  * @name_type: type of principial, see Shishi_name_type, usually
     200                 :            :  *             SHISHI_NT_UNKNOWN.
     201                 :            :  * @principal: input array with principal name.
     202                 :            :  *
     203                 :            :  * Set the client name field in the EncTicketPart.
     204                 :            :  *
     205                 :            :  * Return value: Returns SHISHI_OK iff successful.
     206                 :            :  **/
     207                 :            : int
     208                 :          0 : shishi_encticketpart_cname_set (Shishi * handle,
     209                 :            :                                 Shishi_asn1 encticketpart,
     210                 :            :                                 Shishi_name_type name_type,
     211                 :            :                                 const char *principal)
     212                 :            : {
     213                 :            :   int res;
     214                 :            : 
     215                 :          0 :   res = shishi_asn1_write_uint32 (handle, encticketpart,
     216                 :            :                                   "cname.name-type", name_type);
     217         [ #  # ]:          0 :   if (res != SHISHI_OK)
     218                 :          0 :     return res;
     219                 :            : 
     220                 :          0 :   res = shishi_asn1_write (handle, encticketpart,
     221                 :            :                            "cname.name-string", NULL, 0);
     222         [ #  # ]:          0 :   if (res != SHISHI_OK)
     223                 :          0 :     return res;
     224                 :            : 
     225                 :          0 :   res = shishi_asn1_write (handle, encticketpart,
     226                 :            :                            "cname.name-string", "NEW", 1);
     227         [ #  # ]:          0 :   if (res != SHISHI_OK)
     228                 :          0 :     return res;
     229                 :            : 
     230                 :          0 :   res = shishi_asn1_write (handle, encticketpart,
     231                 :            :                            "cname.name-string.?1",
     232                 :            :                            principal, strlen (principal));
     233         [ #  # ]:          0 :   if (res != SHISHI_OK)
     234                 :          0 :     return res;
     235                 :            : 
     236                 :          0 :   return SHISHI_OK;
     237                 :            : }
     238                 :            : 
     239                 :            : /**
     240                 :            :  * shishi_encticketpart_transited_set:
     241                 :            :  * @handle: shishi handle as allocated by shishi_init().
     242                 :            :  * @encticketpart: input EncTicketPart variable.
     243                 :            :  * @trtype: transitedencoding type, e.g. SHISHI_TR_DOMAIN_X500_COMPRESS.
     244                 :            :  * @trdata: actual transited realm data.
     245                 :            :  * @trdatalen: length of actual transited realm data.
     246                 :            :  *
     247                 :            :  * Set the EncTicketPart.transited field to supplied value.
     248                 :            :  *
     249                 :            :  * Return value: Returns %SHISHI_OK iff successful.
     250                 :            :  **/
     251                 :            : int
     252                 :          2 : shishi_encticketpart_transited_set (Shishi * handle,
     253                 :            :                                     Shishi_asn1 encticketpart,
     254                 :            :                                     int32_t trtype,
     255                 :            :                                     const char *trdata, size_t trdatalen)
     256                 :            : {
     257                 :            :   int res;
     258                 :            : 
     259                 :          2 :   res = shishi_asn1_write_int32 (handle, encticketpart,
     260                 :            :                                  "transited.tr-type", trtype);
     261         [ -  + ]:          2 :   if (res != SHISHI_OK)
     262                 :          0 :     return res;
     263                 :            : 
     264                 :          2 :   res = shishi_asn1_write (handle, encticketpart,
     265                 :            :                            "transited.contents", trdata, trdatalen);
     266         [ -  + ]:          2 :   if (res != SHISHI_OK)
     267                 :          0 :     return res;
     268                 :            : 
     269                 :          2 :   return SHISHI_OK;
     270                 :            : }
     271                 :            : 
     272                 :            : /**
     273                 :            :  * shishi_encticketpart_authtime_set:
     274                 :            :  * @handle: shishi handle as allocated by shishi_init().
     275                 :            :  * @encticketpart: input EncTicketPart variable.
     276                 :            :  * @authtime: character buffer containing a generalized time string.
     277                 :            :  *
     278                 :            :  * Set the EncTicketPart.authtime to supplied value.
     279                 :            :  *
     280                 :            :  * Return value: Returns %SHISHI_OK iff successful.
     281                 :            :  **/
     282                 :            : int
     283                 :          2 : shishi_encticketpart_authtime_set (Shishi * handle,
     284                 :            :                                    Shishi_asn1 encticketpart,
     285                 :            :                                    const char *authtime)
     286                 :            : {
     287                 :            :   int res;
     288                 :            : 
     289                 :          2 :   res = shishi_asn1_write (handle, encticketpart, "authtime",
     290                 :            :                            authtime, SHISHI_GENERALIZEDTIME_LENGTH);
     291         [ -  + ]:          2 :   if (res != SHISHI_OK)
     292                 :          0 :     return SHISHI_ASN1_ERROR;
     293                 :            : 
     294                 :          2 :   return SHISHI_OK;
     295                 :            : }
     296                 :            : 
     297                 :            : /**
     298                 :            :  * shishi_encticketpart_endtime_set:
     299                 :            :  * @handle: shishi handle as allocated by shishi_init().
     300                 :            :  * @encticketpart: input EncTicketPart variable.
     301                 :            :  * @endtime: character buffer containing a generalized time string.
     302                 :            :  *
     303                 :            :  * Set the EncTicketPart.endtime to supplied value.
     304                 :            :  *
     305                 :            :  * Return value: Returns %SHISHI_OK iff successful.
     306                 :            :  **/
     307                 :            : int
     308                 :          2 : shishi_encticketpart_endtime_set (Shishi * handle,
     309                 :            :                                   Shishi_asn1 encticketpart,
     310                 :            :                                   const char *endtime)
     311                 :            : {
     312                 :            :   int res;
     313                 :            : 
     314                 :          2 :   res = shishi_asn1_write (handle, encticketpart, "endtime",
     315                 :            :                            endtime, SHISHI_GENERALIZEDTIME_LENGTH);
     316         [ -  + ]:          2 :   if (res != SHISHI_OK)
     317                 :          0 :     return res;
     318                 :            : 
     319                 :          2 :   return SHISHI_OK;
     320                 :            : }
     321                 :            : 
     322                 :            : int
     323                 :          0 : shishi_encticketpart_authtime (Shishi * handle,
     324                 :            :                                Shishi_asn1 encticketpart,
     325                 :            :                                char *authtime, size_t * authtimelen)
     326                 :            : {
     327                 :          0 :   return shishi_asn1_read_inline (handle, encticketpart, "authtime",
     328                 :            :                                   authtime, authtimelen);
     329                 :            : }
     330                 :            : 
     331                 :            : time_t
     332                 :          0 : shishi_encticketpart_authctime (Shishi * handle, Shishi_asn1 encticketpart)
     333                 :            : {
     334                 :            :   char authtime[SHISHI_GENERALIZEDTIME_LENGTH + 1];
     335                 :            :   size_t authtimelen;
     336                 :            :   time_t t;
     337                 :            :   int res;
     338                 :            : 
     339                 :          0 :   authtimelen = sizeof (authtime);
     340                 :          0 :   res = shishi_encticketpart_authtime (handle, encticketpart,
     341                 :            :                                        authtime, &authtimelen);
     342         [ #  # ]:          0 :   if (res != SHISHI_OK)
     343                 :          0 :     return (time_t) - 1;
     344                 :            : 
     345                 :          0 :   authtime[SHISHI_GENERALIZEDTIME_LENGTH] = '\0';
     346                 :            : 
     347                 :          0 :   t = shishi_generalize_ctime (handle, authtime);
     348                 :            : 
     349                 :          0 :   return t;
     350                 :            : }
     351                 :            : 
     352                 :            : /**
     353                 :            :  * shishi_encticketpart_client:
     354                 :            :  * @handle: Shishi library handle create by shishi_init().
     355                 :            :  * @encticketpart: EncTicketPart variable to get client name from.
     356                 :            :  * @client: pointer to newly allocated zero terminated string containing
     357                 :            :  *   principal name.  May be %NULL (to only populate @clientlen).
     358                 :            :  * @clientlen: pointer to length of @client on output, excluding terminating
     359                 :            :  *   zero.  May be %NULL (to only populate @client).
     360                 :            :  *
     361                 :            :  * Represent client principal name in EncTicketPart as zero-terminated
     362                 :            :  * string.  The string is allocate by this function, and it is the
     363                 :            :  * responsibility of the caller to deallocate it.  Note that the
     364                 :            :  * output length @clientlen does not include the terminating zero.
     365                 :            :  *
     366                 :            :  * Return value: Returns SHISHI_OK iff successful.
     367                 :            :  **/
     368                 :            : int
     369                 :          0 : shishi_encticketpart_client (Shishi * handle,
     370                 :            :                              Shishi_asn1 encticketpart,
     371                 :            :                              char **client, size_t * clientlen)
     372                 :            : {
     373                 :          0 :   return shishi_principal_name (handle, encticketpart, "cname",
     374                 :            :                                 client, clientlen);
     375                 :            : }
     376                 :            : 
     377                 :            : /**
     378                 :            :  * shishi_encticketpart_clientrealm:
     379                 :            :  * @handle: Shishi library handle create by shishi_init().
     380                 :            :  * @encticketpart: EncTicketPart variable to get client name and realm from.
     381                 :            :  * @client: pointer to newly allocated zero terminated string containing
     382                 :            :  *   principal name and realm.  May be %NULL (to only populate @clientlen).
     383                 :            :  * @clientlen: pointer to length of @client on output, excluding terminating
     384                 :            :  *   zero.  May be %NULL (to only populate @client).
     385                 :            :  *
     386                 :            :  * Convert cname and realm fields from EncTicketPart to printable
     387                 :            :  * principal name format.  The string is allocate by this function,
     388                 :            :  * and it is the responsibility of the caller to deallocate it.  Note
     389                 :            :  * that the output length @clientlen does not include the terminating
     390                 :            :  * zero.
     391                 :            :  *
     392                 :            :  * Return value: Returns SHISHI_OK iff successful.
     393                 :            :  **/
     394                 :            : int
     395                 :          0 : shishi_encticketpart_clientrealm (Shishi * handle,
     396                 :            :                                   Shishi_asn1 encticketpart,
     397                 :            :                                   char **client, size_t * clientlen)
     398                 :            : {
     399                 :          0 :   return shishi_principal_name_realm (handle,
     400                 :            :                                       encticketpart, "cname",
     401                 :            :                                       encticketpart, "crealm",
     402                 :            :                                       client, clientlen);
     403                 :            : }

Generated by: LCOV version 1.8