X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=crypt_common.c;h=08361b27104d6a4658e151259ba6f0ae585205c0;hp=b39ee5e4cb6fce2b28a3b87034350f321d7cd75d;hb=a35c113e0bb9fa9ac02b77eb01dd32f49cd5c8d0;hpb=0b6e7a20c19d642f9d8e65683e1525c91dd3de39 diff --git a/crypt_common.c b/crypt_common.c index b39ee5e4..08361b27 100644 --- a/crypt_common.c +++ b/crypt_common.c @@ -1,8 +1,4 @@ -/* - * Copyright (C) 2005 Andre Noll - * - * Licensed under the GPL v2. For licencing details see COPYING. - */ +/* Copyright (C) 2005 Andre Noll , see file COPYING. */ /** \file crypt_common.c Crypto functions independent of openssl/libgcrypt. */ @@ -13,6 +9,7 @@ #include "string.h" #include "crypt.h" #include "crypt_backend.h" +#include "portable_io.h" /** If the key begins with this text, we treat it as an ssh key. */ #define KEY_TYPE_TXT "ssh-rsa" @@ -45,29 +42,6 @@ size_t is_ssh_rsa_key(char *data, size_t size) return cp - data; } -/** - * Read a 4-byte number from a buffer in big-endian format. - * - * \param vp The buffer. - * - * The byte-order of the buffer is expected to be big-endian, unlike read_u32() - * of portable_io.h which expects little endian. - * - * \return The 32 bit number given by \a vp. - */ -uint32_t read_ssh_u32(const void *vp) -{ - const unsigned char *p = (const unsigned char *)vp; - uint32_t v; - - v = (uint32_t)p[0] << 24; - v |= (uint32_t)p[1] << 16; - v |= (uint32_t)p[2] << 8; - v |= (uint32_t)p[3]; - - return v; -} - /** * Sanity checks for the header of an ssh key. * @@ -88,7 +62,7 @@ int check_ssh_key_header(const unsigned char *blob, int blen) if (p + 4 > end) return -E_SSH_KEY_HEADER; - rlen = read_ssh_u32(p); + rlen = read_u32_be(p); p += 4; if (p + rlen < p) return -E_SSH_KEY_HEADER; @@ -96,32 +70,29 @@ int check_ssh_key_header(const unsigned char *blob, int blen) return -E_SSH_KEY_HEADER; if (rlen < strlen(KEY_TYPE_TXT)) return -E_SSH_KEY_HEADER; - PARA_DEBUG_LOG("type: %s, rlen: %d\n", p, rlen); + PARA_DEBUG_LOG("type: %s, rlen: %u\n", p, rlen); if (strncmp((char *)p, KEY_TYPE_TXT, strlen(KEY_TYPE_TXT))) return -E_SSH_KEY_HEADER; return 4 + rlen; } /** - * Check existence and permissions of a key file. + * Check existence and permissions of a private key file. * * \param file The path of the key file. - * \param private_key Whether this is a private key. * - * This checks whether the file exists. If it is a private key, we additionally - * check that the permissions are restrictive enough. It is considered an error - * if we own the file and it is readable for others. + * This checks whether the file exists and its permissions are restrictive + * enough. It is considered an error if we own the file and it is readable for + * others. * * \return Standard. */ -int check_key_file(const char *file, bool private_key) +int check_private_key_file(const char *file) { struct stat st; if (stat(file, &st) != 0) return -ERRNO_TO_PARA_ERROR(errno); - if (!private_key) - return 0; if ((st.st_uid == getuid()) && (st.st_mode & 077) != 0) return -E_KEY_PERM; return 1;