This file is indexed.

/usr/share/hplip/base/validation.py is in hplip-data 3.14.3-0ubuntu3.4.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
# -*- coding: utf-8 -*-
#
# (c) Copyright 2014 Hewlett-Packard Development Company, L.P.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
#
# Author: Amarnath Chitumalla
#
#Global imports
import os

#Local imports
from base import utils
from base.g import *


# GPGP validation errors
DIGSIG_ERROR_NONE = 0
DIGSIG_ERROR_FILE_NOT_FOUND = 1
DIGSIG_ERROR_DIGITAL_SIGN_NOT_FOUND = 2
DIGSIG_ERROR_DIGITAL_SIGN_BAD = 3
DIGSIG_ERROR_UNABLE_TO_RECV_KEYS = 4
DIGSIG_ERROR_GPG_CMD_NOT_FOUND = 5
DIGSIG_ERROR_INCORRECT_PASSWORD = 6


DIGSIG_ERROR_GPG_CMD_NOT_FOUND_STR ="GPG Command Not Found"

class DigiSign_Verification(object):
    def __init__(self):
        pass

    def validate(self):
        pass


class GPG_Verification(DigiSign_Verification):
    def __init__(self, pgp_site = 'pgp.mit.edu', key = 0x4ABA2F66DBD5A95894910E0673D770CDA59047B9):
        self.__pgp_site = pgp_site
        self.__key = key
        self.__gpg = utils.which('gpg',True)
        if not self.__gpg:
            raise Exception(DIGSIG_ERROR_GPG_CMD_NOT_FOUND_STR)


    def __gpg_check(self, hplip_package, hplip_digsig, passwordObj):
        cmd = '%s --no-permission-warning --verify %s %s' % (self.__gpg, hplip_digsig, hplip_package)
        cmd = passwordObj.getAuthCmd()%cmd
        log.debug("Verifying file %s with digital keys: %s" % (hplip_package,cmd))

        status, output = utils.run(cmd, passwordObj)
        log.debug("%s status: %d  output:%s" % (self.__gpg, status,output))
        return status


    def acquire_gpg_key(self, passwordObj):
        cmd = '%s --no-permission-warning --keyserver %s --recv-keys 0x%X' \
              % (self.__gpg, self.__pgp_site, self.__key)

        cmd = passwordObj.getAuthCmd()%cmd
        log.info("Receiving digital keys: %s" % cmd)

        status, output = utils.run(cmd, passwordObj)
        log.debug(output)
        return status 


    def validate(self, hplip_package, hplip_digsig, passwordObj):
        if not os.path.exists(hplip_package):
            log.error("%s file doesn't exists." %(hplip_package))
            return DIGSIG_ERROR_FILE_NOT_FOUND

        if not os.path.exists(hplip_digsig):
            log.warn("%s file doesn't exists." %(hplip_digsig))
            return DIGSIG_ERROR_DIGITAL_SIGN_NOT_FOUND

        log.info(log.bold("\n\nNeed authentication to validate HPLIP package."))
        if not passwordObj.getPassword():
            return DIGSIG_ERROR_INCORRECT_PASSWORD

        status = self.acquire_gpg_key(passwordObj)
        if status != 0:
            return DIGSIG_ERROR_UNABLE_TO_RECV_KEYS

        status = self.__gpg_check(hplip_package, hplip_digsig, passwordObj)
        if status != 0:
            return DIGSIG_ERROR_DIGITAL_SIGN_BAD
        else:
            return DIGSIG_ERROR_NONE