# Path: lib/crypto/packaged.py
# class SigningError(Exception):
# def sign_app(src, dest, ids, reviewer=False, local=False):
# def _sign_app(src, dest, ids, reviewer, tempname, local=False):
# def _get_endpoint(reviewer=False):
# def _no_sign(src, dst_path):
# def sign(version_id, reviewer=False, resign=False, **kw):
# 
# Path: lib/crypto/packaged.py
# class SigningError(Exception):
#     pass


import os
import socket
import StringIO
import tempfile
import time
import traceback
import commonware.log
import elasticsearch
import requests
        import M2Crypto  # NOQA
from django.conf import settings
from cache_nuggets.lib import memoize
from PIL import Image
from lib.crypto import packaged, receipt
from lib.crypto.packaged import SigningError as PackageSigningError
from lib.crypto.receipt import SigningError
from mkt.site.storage_utils import local_storage
    # Check that the certs used to sign the receipts are not about to expire.
    limit = now + (60 * 60 * 24)  # One day.
    if cert['exp'] < limit:
        msg = 'Cert will expire soon (%s)' % destination
        return msg, msg

    cert_err_msg = 'Error on checking public cert (%s): %s'
    location = cert['iss']
    try:
        resp = requests.get(location, timeout=5, stream=False)
    except Exception as err:
        msg = cert_err_msg % (location, err)
        return msg, msg

    if not resp.ok:
        msg = cert_err_msg % (location, resp.reason)
        return msg, msg

    cert_json = resp.json()
    if not cert_json or 'jwk' not in cert_json:
        msg = cert_err_msg % (location, 'Not valid JSON/JWK')
        return msg, msg

    return '', 'Signer working and up to date'


# Like the receipt signer above this asks the packaged app signing
# service to sign one for us.
@memoize('monitors-package-signer', time=60)
def package_signer():

# Path: lib/crypto/packaged.py
# class SigningError(Exception):
# def sign_app(src, dest, ids, reviewer=False, local=False):
# def _sign_app(src, dest, ids, reviewer, tempname, local=False):
# def _get_endpoint(reviewer=False):
# def _no_sign(src, dst_path):
# def sign(version_id, reviewer=False, resign=False, **kw):
# 
# Path: lib/crypto/packaged.py
# class SigningError(Exception):
#     pass


# Path: mkt/site/monitors.py
import os
import socket
import StringIO
import tempfile
import time
import traceback
import commonware.log
import elasticsearch
import requests
        import M2Crypto  # NOQA
from django.conf import settings
from cache_nuggets.lib import memoize
from PIL import Image
from lib.crypto import packaged, receipt
from lib.crypto.packaged import SigningError as PackageSigningError
from lib.crypto.receipt import SigningError
from mkt.site.storage_utils import local_storage

    # Check that the certs used to sign the receipts are not about to expire.
    limit = now + (60 * 60 * 24)  # One day.
    if cert['exp'] < limit:
        msg = 'Cert will expire soon (%s)' % destination
        return msg, msg

    cert_err_msg = 'Error on checking public cert (%s): %s'
    location = cert['iss']
    try:
        resp = requests.get(location, timeout=5, stream=False)
    except Exception as err:
        msg = cert_err_msg % (location, err)
        return msg, msg

    if not resp.ok:
        msg = cert_err_msg % (location, resp.reason)
        return msg, msg

    cert_json = resp.json()
    if not cert_json or 'jwk' not in cert_json:
        msg = cert_err_msg % (location, 'Not valid JSON/JWK')
        return msg, msg

    return '', 'Signer working and up to date'


# Like the receipt signer above this asks the packaged app signing
# service to sign one for us.
@memoize('monitors-package-signer', time=60)
def package_signer():

    destination = getattr(settings, 'SIGNED_APPS_SERVER', None)