LCOV - code coverage report
Current view: top level - pkcs11/rpc-layer - gkm-rpc-util.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 0.0 % 46 0
Test Date: 2024-05-07 18:02:03 Functions: 0.0 % 7 0

            Line data    Source code
       1              : /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
       2              : /* p11-rpc-util.c - utilities for module and dispatcher
       3              : 
       4              :    Copyright (C) 2008, Stef Walter
       5              : 
       6              :    The Gnome Keyring Library is free software; you can redistribute it and/or
       7              :    modify it under the terms of the GNU Library General Public License as
       8              :    published by the Free Software Foundation; either version 2 of the
       9              :    License, or (at your option) any later version.
      10              : 
      11              :    The Gnome Keyring Library is distributed in the hope that it will be useful,
      12              :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      13              :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      14              :    Library General Public License for more details.
      15              : 
      16              :    You should have received a copy of the GNU Library General Public
      17              :    License along with the Gnome Library; see the file COPYING.LIB.  If not,
      18              :    <http://www.gnu.org/licenses/>.
      19              : 
      20              :    Author: Stef Walter <stef@memberwebs.com>
      21              : */
      22              : 
      23              : #include "config.h"
      24              : 
      25              : #include "gkm-rpc-layer.h"
      26              : #include "gkm-rpc-private.h"
      27              : 
      28              : #include <stdarg.h>
      29              : #include <string.h>
      30              : #include <stdio.h>
      31              : 
      32              : static void
      33            0 : do_log (const char *pref, const char *msg, va_list va)
      34              : {
      35              :         char buffer[1024];
      36            0 :         size_t len = 0;
      37              : 
      38            0 :         if (pref) {
      39            0 :                 snprintf (buffer, sizeof (buffer), "%s: ", pref);
      40            0 :                 len = strlen (buffer);
      41              :         }
      42              : 
      43            0 :         vsnprintf (buffer + len, sizeof (buffer) - len, msg, va);
      44            0 :         gkm_rpc_log (buffer);
      45            0 : }
      46              : 
      47              : void
      48            0 : gkm_rpc_warn (const char* msg, ...)
      49              : {
      50              :         va_list va;
      51            0 :         va_start (va, msg);
      52            0 :         do_log ("WARNING: gnome-keyring:", msg, va);
      53            0 :         va_end (va);
      54            0 : }
      55              : 
      56              : void
      57            0 : gkm_rpc_debug (const char* msg, ...)
      58              : {
      59              :         va_list va;
      60            0 :         va_start (va, msg);
      61            0 :         do_log ("DEBUG: gnome-keyring:", msg, va);
      62            0 :         va_end (va);
      63            0 : }
      64              : 
      65              : int
      66            0 : gkm_rpc_mechanism_is_supported (CK_MECHANISM_TYPE mech)
      67              : {
      68            0 :         if (gkm_rpc_mechanism_has_no_parameters (mech) ||
      69            0 :             gkm_rpc_mechanism_has_sane_parameters (mech))
      70            0 :                 return 1;
      71            0 :         return 0;
      72              : }
      73              : void
      74            0 : gkm_rpc_mechanism_list_purge (CK_MECHANISM_TYPE_PTR mechs, CK_ULONG* n_mechs)
      75              : {
      76              :         int i;
      77              : 
      78            0 :         assert (mechs);
      79            0 :         assert (n_mechs);
      80              : 
      81            0 :         for (i = 0; i < (int)(*n_mechs); ++i) {
      82            0 :                 if (!gkm_rpc_mechanism_has_no_parameters (mechs[i]) &&
      83            0 :                     !gkm_rpc_mechanism_has_sane_parameters (mechs[i])) {
      84            0 :                         if (*n_mechs - i - 1 > 0) {
      85              :                                 /* Remove the mechanism from the list */
      86            0 :                                 memmove (&mechs[i], &mechs[i + 1], (*n_mechs - i - 1) * sizeof (CK_MECHANISM_TYPE));
      87              :                         }
      88              : 
      89            0 :                         --(*n_mechs);
      90            0 :                         --i;
      91              :                 }
      92              :         }
      93            0 : }
      94              : 
      95              : int
      96            0 : gkm_rpc_mechanism_has_sane_parameters (CK_MECHANISM_TYPE type)
      97              : {
      98              :         /* This list is incomplete */
      99            0 :         switch (type) {
     100            0 :         case CKM_RSA_PKCS_OAEP:
     101              :         case CKM_RSA_PKCS_PSS:
     102            0 :                 return 1;
     103            0 :         default:
     104            0 :                 return 0;
     105              :         }
     106              : }
     107              : 
     108              : int
     109            0 : gkm_rpc_mechanism_has_no_parameters (CK_MECHANISM_TYPE mech)
     110              : {
     111              :         /* This list is incomplete */
     112              : 
     113            0 :         switch (mech) {
     114            0 :         case CKM_RSA_PKCS_KEY_PAIR_GEN:
     115              :         case CKM_RSA_X9_31_KEY_PAIR_GEN:
     116              :         case CKM_RSA_PKCS:
     117              :         case CKM_RSA_9796:
     118              :         case CKM_RSA_X_509:
     119              :         case CKM_RSA_X9_31:
     120              :         case CKM_MD2_RSA_PKCS:
     121              :         case CKM_MD5_RSA_PKCS:
     122              :         case CKM_SHA1_RSA_PKCS:
     123              :         case CKM_SHA256_RSA_PKCS:
     124              :         case CKM_SHA384_RSA_PKCS:
     125              :         case CKM_SHA512_RSA_PKCS:
     126              :         case CKM_RIPEMD128_RSA_PKCS:
     127              :         case CKM_RIPEMD160_RSA_PKCS:
     128              :         case CKM_SHA1_RSA_X9_31:
     129              :         case CKM_DSA_KEY_PAIR_GEN:
     130              :         case CKM_DSA_PARAMETER_GEN:
     131              :         case CKM_DSA:
     132              :         case CKM_DSA_SHA1:
     133              :         case CKM_FORTEZZA_TIMESTAMP:
     134              :         case CKM_EC_KEY_PAIR_GEN:
     135              :         case CKM_ECDSA:
     136              :         case CKM_ECDSA_SHA1:
     137              :         case CKM_DH_PKCS_KEY_PAIR_GEN:
     138              :         case CKM_DH_PKCS_PARAMETER_GEN:
     139              :         case CKM_X9_42_DH_KEY_PAIR_GEN:
     140              :         case CKM_X9_42_DH_PARAMETER_GEN:
     141              :         case CKM_KEA_KEY_PAIR_GEN:
     142              :         case CKM_GENERIC_SECRET_KEY_GEN:
     143              :         case CKM_RC2_KEY_GEN:
     144              :         case CKM_RC4_KEY_GEN:
     145              :         case CKM_RC4:
     146              :         case CKM_RC5_KEY_GEN:
     147              :         case CKM_AES_KEY_GEN:
     148              :         case CKM_AES_ECB:
     149              :         case CKM_AES_MAC:
     150              :         case CKM_DES_KEY_GEN:
     151              :         case CKM_DES2_KEY_GEN:
     152              :         case CKM_DES3_KEY_GEN:
     153              :         case CKM_CDMF_KEY_GEN:
     154              :         case CKM_CAST_KEY_GEN:
     155              :         case CKM_CAST3_KEY_GEN:
     156              :         case CKM_CAST128_KEY_GEN:
     157              :         case CKM_IDEA_KEY_GEN:
     158              :         case CKM_SSL3_PRE_MASTER_KEY_GEN:
     159              :         case CKM_TLS_PRE_MASTER_KEY_GEN:
     160              :         case CKM_SKIPJACK_KEY_GEN:
     161              :         case CKM_BATON_KEY_GEN:
     162              :         case CKM_JUNIPER_KEY_GEN:
     163              :         case CKM_RC2_ECB:
     164              :         case CKM_DES_ECB:
     165              :         case CKM_DES3_ECB:
     166              :         case CKM_CDMF_ECB:
     167              :         case CKM_CAST_ECB:
     168              :         case CKM_CAST3_ECB:
     169              :         case CKM_CAST128_ECB:
     170              :         case CKM_RC5_ECB:
     171              :         case CKM_IDEA_ECB:
     172              :         case CKM_RC2_MAC:
     173              :         case CKM_DES_MAC:
     174              :         case CKM_DES3_MAC:
     175              :         case CKM_CDMF_MAC:
     176              :         case CKM_CAST_MAC:
     177              :         case CKM_CAST3_MAC:
     178              :         case CKM_RC5_MAC:
     179              :         case CKM_IDEA_MAC:
     180              :         case CKM_SSL3_MD5_MAC:
     181              :         case CKM_SSL3_SHA1_MAC:
     182              :         case CKM_SKIPJACK_WRAP:
     183              :         case CKM_BATON_WRAP:
     184              :         case CKM_JUNIPER_WRAP:
     185              :         case CKM_MD2:
     186              :         case CKM_MD2_HMAC:
     187              :         case CKM_MD5:
     188              :         case CKM_MD5_HMAC:
     189              :         case CKM_SHA_1:
     190              :         case CKM_SHA_1_HMAC:
     191              :         case CKM_SHA256:
     192              :         case CKM_SHA256_HMAC:
     193              :         case CKM_SHA384:
     194              :         case CKM_SHA384_HMAC:
     195              :         case CKM_SHA512:
     196              :         case CKM_SHA512_HMAC:
     197              :         case CKM_FASTHASH:
     198              :         case CKM_RIPEMD128:
     199              :         case CKM_RIPEMD128_HMAC:
     200              :         case CKM_RIPEMD160:
     201              :         case CKM_RIPEMD160_HMAC:
     202              :         case CKM_KEY_WRAP_LYNKS:
     203            0 :                 return 1;
     204            0 :         default:
     205            0 :                 return 0;
     206              :         };
     207              : }
        

Generated by: LCOV version 2.0-1