Returns True if the file is signed with authenticode
551472
def is_authenticode_signed(filename):
    """"""
    with open(filename, 'rb') as fp:
        fp.seek(0)
        magic = fp.read(2)
        if magic != b'MZ':
            return False

        # First grab the pointer to the coff_header, which is at offset 60
        fp.seek(60)
        coff_header_offset = struct.unpack('<L', fp.read(4))[0]

        # Check the COFF magic
        fp.seek(coff_header_offset)
        magic = fp.read(4)
        if magic != b'PE\x00\x00':
            return False

        # Get the PE type
        fp.seek(coff_header_offset + 0x18)
        pe_type = struct.unpack('<h', fp.read(2))[0]

        if pe_type == 0x10b:
            # PE32 file (32-bit apps)
            number_of_data_dirs_offset = coff_header_offset + 0x74
        elif pe_type == 0x20b:
            # PE32+ files (64-bit apps)
            # PE32+ files have slightly larger fields in the header
            number_of_data_dirs_offset = coff_header_offset + 0x74 + 16
        else:
            return False

        fp.seek(number_of_data_dirs_offset)
        num_data_dirs = struct.unpack('<L', fp.read(4))[0]

        if num_data_dirs < 5:
            # Probably shouldn't happen, but just in case
            return False

        cert_table_offset = number_of_data_dirs_offset + 4*8 + 4
        fp.seek(cert_table_offset)
        addr, size = struct.unpack('<LL', fp.read(8))
        if not addr or not size:
            return False
        # Check that addr is inside the file
        fp.seek(addr)
        if fp.tell() != addr:
            return False
        cert = fp.read(size)
        if len(cert) != size:
            return False
        return True
841635
def signed?
            begin
                self.Catalog.AcroForm.is_a?(Dictionary) and
                self.Catalog.AcroForm.SigFlags.is_a?(Integer) and
                (self.Catalog.AcroForm.SigFlags & InteractiveForm::SigFlags::SIGNATURES_EXIST != 0)
            rescue InvalidReferenceError
                false
            end
        end
1118481
def _prefix_is_authorized(self, path):
        
        path = os.path.abspath(path)
        while True:
            if path in self._prefixes:
                return True
            if path == '/':
                break
            path = os.path.dirname(path)
        return False
782769
public boolean signatureCoversWholeDocument(String name) {
        getSignatureNames();
        name = getTranslatedFieldName(name);
        if (!sigNames.containsKey(name))
            return false;
        return ((int[])sigNames.get(name))[0] == reader.getFileLength();
    }
67043
private void maybeInstantiateVerifier() throws IOException {
        if (jv != null) {
            return;
        }

        if (verify) {
            String[] names = getMetaInfEntryNames();
            if (names != null) {
                for (int i = 0; i < names.length; i++) {
                    String name = names[i].toUpperCase(Locale.ENGLISH);
                    if (name.endsWith(".DSA") ||
                        name.endsWith(".RSA") ||
                        name.endsWith(".EC") ||
                        name.endsWith(".SF")) {
                        // Assume since we found a signature-related file
                        // that the jar is signed and that we therefore
                        // need a JarVerifier and Manifest
                        getManifest();
                        return;
                    }
                }
            }
            // No signature-related files; don't instantiate a
            // verifier
            verify = false;
        }
    }
1303670
def _is_valid_file(self, path):
        """"""
        return isinstance(path, basestring) and os.path.isfile(path)
969649
def verify(self, data, signature=None, keyrings=None, homedir=None):
        '''
        
        '''

        if isinstance(data, six.text_type):
            data = data.encode('utf-8')

        tmpdir = tempfile.mkdtemp()
        data_file, data_path = tempfile.mkstemp(dir=tmpdir)
        data_file = os.fdopen(data_file, 'wb')
        data_file.write(data)
        data_file.close()
        if signature:
            sig_file, sig_path = tempfile.mkstemp(dir=tmpdir)
            sig_file = os.fdopen(sig_file, 'wb')
            sig_file.write(signature)
            sig_file.close()
        else:
            sig_path = None
        try:
            return self.verify_from_file(
                data_path,
                sig_path=sig_path,
                keyrings=keyrings,
                homedir=homedir
            )
        finally:
            shutil.rmtree(tmpdir)
684378
private boolean authorizedPath(AuthContext context, Path path, String action) {
        Decision evaluate = context.evaluate(
                resourceForPath(path),
                action,
                environmentForPath(path)
        );
        return evaluate.isAuthorized();
    }
173432
def validate_signature(self, filename):
        """"""

        if not GPG_PRESENT:
            return False

        sigfilename = filename + '.sig'

        try:
            with open(sigfilename):
                pass

        except IOError:
            # Signature file does not exist
            return False

        # Check if the sig is valid for the sigfile
        # TODO: Check for whitespace in filepaths
        return verify(sigfilename, filename)
1279080
def signed_raw(self) -> str:
        
        if not isinstance(self.identity, Identity):
            raise MalformedDocumentError("Can not return full revocation document created from inline")

        raw = self.raw()
        signed = "\n".join(self.signatures)
        signed_raw = raw + signed + "\n"
        return signed_raw
12553
private static boolean verifySignature(String content, String secret, String signature) throws InvalidTokenException{
        try {
            SecretKey secretKey = new SecretKeySpec(secret.getBytes(), ALG_HMACSHA256);
            Mac mac = Mac.getInstance(ALG_HMACSHA256);
            mac.init(secretKey);
            byte[] bytes = mac.doFinal(content.getBytes());
            String base64 = base64UrlEncode(bytes);
            return  Strings.equals(base64,signature);
        } catch (Exception e) {
            throw new RuntimeException("Verify signature error", e);
        }
    }
192272
public static boolean verify(byte[] data, byte[] signature, byte[] pub) {
        return verify(data, ECDSASignature.decodeFromDER(signature), pub);
    }
447451
public static boolean authenticate(String userName, String userPassword) {
        LOGGER.entering(userName, StringUtils.isBlank(userPassword) ? userPassword : userPassword.replaceAll(".", "*"));
        boolean validLogin = false;
        byte[] currentAuthData;
        byte[] hashedInputData;
        if (StringUtils.isBlank(userName) || StringUtils.isBlank(userPassword)) {
            return validLogin;
        }
        try {
            File authFile = new File(AUTH_FILE_LOCATION);
            if (!authFile.exists()) {
                authFile.createNewFile();
                createAuthFile(authFile, DEFAULT_USERNAME, DEFAULT_PASSWORD);
            }
            currentAuthData = getBytesFromFile(authFile);
            hashedInputData = hashData(userName, userPassword);
            validLogin = Arrays.equals(currentAuthData, hashedInputData);
        } catch (Exception e) {
            validLogin = false;
        }
        LOGGER.exiting(validLogin);
        return validLogin;
    }
1058880
public static boolean ensureSameSignature(Context context, String targetPackageName) {
        return ensureSameSignature(context, targetPackageName, getSignatureHexCode(context));
    }
239474
def verifyChainFromCAFile(self, cafile, untrusted_file=None):
        
        try:
            f = open(cafile, "rb")
            ca_certs = f.read()
            f.close()
        except Exception:
            raise Exception("Could not read from cafile")

        anchors = [Cert(c) for c in split_pem(ca_certs)]

        untrusted = None
        if untrusted_file:
            try:
                f = open(untrusted_file, "rb")
                untrusted_certs = f.read()
                f.close()
            except Exception:
                raise Exception("Could not read from untrusted_file")
            untrusted = [Cert(c) for c in split_pem(untrusted_certs)]

        return self.verifyChain(anchors, untrusted)
961745
def crypto_sign_open(signed, vk):
    """"""
    if len(vk) != PUBLICKEYBYTES:
        raise ValueError("Bad verifying key length %d" % len(vk))
    rc = djbec.checkvalid(signed[:SIGNATUREBYTES], signed[SIGNATUREBYTES:], vk)
    if not rc:
        raise ValueError("rc != True", rc)
    return signed[SIGNATUREBYTES:]
530570
private boolean isAuthenticated() {
        Authentication existingAuth = SecurityContextHolder.getContext().getAuthentication();
        return !(!(existingAuth != null && existingAuth.isAuthenticated()) || existingAuth instanceof SSOAuthentication);
    }