kafka_neu-1778570057504.zip-extract/kafka-4.2.0-src/release/gpg.py

Path
kafka_neu-1778570057504.zip-extract/kafka-4.2.0-src/release/gpg.py
Status
scanned
Type
file
Name
gpg.py
Extension
.py
Programming language
Python
Mime type
text/x-script.python
File type
Python script, ASCII text executable
Tag

      
    
Rootfs path

      
    
Size
2628 (2.6 KB)
MD5
de0fdc3209577d714fd6793f14f3a7f9
SHA1
6d6bb6b6127624b1b5a9765e76638c416d597086
SHA256
5d5286357837351cfa5d0143d00ede931c47e63c3de32fd0a7ae81079398e8f1
SHA512

      
    
SHA1_git
347389e308942266f50541bb3e83cf437a9fc629
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
gpg.py | 2.6 KB |

# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # """ Auxiliary functions to interact with GNU Privacy Guard (GPG). """ import hashlib import subprocess import tempfile from runtime import execute def key_exists(key_id): """ Checks whether the specified GPG key exists locally. """ try: execute(f"gpg --list-keys {key_id}") except Exception: return False return True def agent_kill(): """ Tries to kill the GPG agent process. """ try: execute("gpgconf --kill gpg-agent") except FileNotFoundError as e: if e.filename != 'gpgconf': raise e def sign(key_id, passphrase, content, target): """ Generates a GPG signature, using the given key and passphrase, of the specified content into the target path. """ execute(f"gpg --passphrase-fd 0 -u {key_id} --armor --output {target} --detach-sig {content}", input=passphrase.encode()) def verify(content, signature): """ Verify the given GPG signature for the specified content. """ execute(f"gpg --verify {signature} {content}") def valid_passphrase(key_id, passphrase): """ Checks whether the given passphrase is workable for the given key. """ with tempfile.TemporaryDirectory() as tmpdir: content = __file__ signature = tmpdir + '/sig.asc' # if the agent is running, the supplied passphrase may be ignored agent_kill() try: sign(key_id, passphrase, content, signature) verify(content, signature) except subprocess.CalledProcessError: return False return True def key_pass_id(key_id, passphrase): """ Generates a deterministic identifier for the key and passphrase combination. """ h = hashlib.sha512() h.update(key_id.encode()) h.update(passphrase.encode()) return h.hexdigest()
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
34.9
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9