示例#1
0
def _generateAndSaveKeys(registry=None):
    registry = registry or Registry_Base_URL
    k = rsa.generate_private_key(public_exponent=65537,
                                 key_size=2048,
                                 backend=default_backend())
    privatekey_pem = k.private_bytes(serialization.Encoding.PEM,
                                     serialization.PrivateFormat.PKCS8,
                                     serialization.NoEncryption())

    pubkey_pem = k.public_key().public_bytes(
        serialization.Encoding.PEM,
        serialization.PublicFormat.SubjectPublicKeyInfo)

    if _isPublicRegistry(registry):
        settings.setProperty('keys', 'private', privatekey_pem.decode('ascii'))
        settings.setProperty('keys', 'public', pubkey_pem.decode('ascii'))
    else:
        sources = _getSources()
        keys = None
        for s in sources:
            if _sourceMatches(s, registry):
                if not 'keys' in s:
                    s['keys'] = dict()
                keys = s['keys']
                break
        if keys is None:
            keys = dict()
            sources.append({'type': 'registry', 'url': registry, 'keys': keys})
        keys['private'] = privatekey_pem.decode('ascii')
        keys['public'] = pubkey_pem.decode('ascii')
        settings.set('sources', sources)
    return pubkey_pem, privatekey_pem
示例#2
0
def _generateAndSaveKeys(registry=None):
    registry = registry or Registry_Base_URL
    k = rsa.generate_private_key(public_exponent=65537, key_size=2048, backend=default_backend())
    privatekey_pem = k.private_bytes(
        serialization.Encoding.PEM, serialization.PrivateFormat.PKCS8, serialization.NoEncryption()
    )

    pubkey_pem = k.public_key().public_bytes(
        serialization.Encoding.PEM, serialization.PublicFormat.SubjectPublicKeyInfo
    )

    if _isPublicRegistry(registry):
        settings.setProperty("keys", "private", privatekey_pem.decode("ascii"))
        settings.setProperty("keys", "public", pubkey_pem.decode("ascii"))
    else:
        sources = _getSources()
        keys = None
        for s in sources:
            if _sourceMatches(s, registry):
                if not "keys" in s:
                    s["keys"] = dict()
                keys = s["keys"]
                break
        if keys is None:
            keys = dict()
            sources.append({"type": "registry", "url": registry, "keys": keys})
        keys["private"] = privatekey_pem.decode("ascii")
        keys["public"] = pubkey_pem.decode("ascii")
        settings.set("sources", sources)
    return pubkey_pem, privatekey_pem
示例#3
0
def _generateAndSaveKeys():
    k = RSA.generate(2048)
    privatekey_hex = binascii.hexlify(k.exportKey('DER'))
    settings.setProperty('keys', 'private', privatekey_hex)
    pubkey_hex = binascii.hexlify(k.publickey().exportKey('DER'))
    settings.setProperty('keys', 'public', pubkey_hex)
    return pubkey_hex, privatekey_hex
示例#4
0
文件: auth.py 项目: aewp2/yotta
def _pollForAuth(registry=None):
    tokens = registry_access.getAuthData(registry=registry)
    if tokens:
        if "github" in tokens:
            settings.setProperty("github", "authtoken", tokens["github"])
        # mbed login doesn't send us a token
        return True
    return False
示例#5
0
def _pollForAuth(registry=None):
    tokens = registry_access.getAuthData(registry=registry)
    if tokens:
        if 'github' in tokens:
            settings.setProperty('github', 'authtoken', tokens['github'])
        # mbed login doesn't send us a token
        return True
    return False
示例#6
0
def _generateAndSaveKeys():
    k = RSA.generate(2048)
    privatekey_hex = binascii.hexlify(k.exportKey('DER')).decode('ascii')
    settings.setProperty('keys', 'private', privatekey_hex)
    pubkey_hex = binascii.hexlify(
        k.publickey().exportKey('DER')).decode('ascii')
    settings.setProperty('keys', 'public', pubkey_hex)
    return pubkey_hex, privatekey_hex
示例#7
0
文件: auth.py 项目: stevenewey/yotta
def _pollForAuth(registry=None):
    tokens = registry_access.getAuthData(registry=registry)
    if tokens:
        if 'github' in tokens:
            settings.setProperty('github', 'authtoken', tokens['github'])
        # mbed login doesn't send us a token
        return True
    return False
示例#8
0
def _pollForAuth(registry=None):
    tokens = registry_access.getAuthData(registry=registry)
    if tokens:
        if 'github' in tokens:
            settings.setProperty('github', 'authtoken', tokens['github'])
        if 'mbed' in tokens:
            settings.setProperty('mbed', 'authtoken', tokens['mbed'])
        return True
    return False
示例#9
0
文件: auth.py 项目: headlessme/yotta
def _pollForAuth(registry=None):
    tokens = registry_access.getAuthData(registry=registry)
    if tokens:
        if 'github' in tokens:
            settings.setProperty('github', 'authtoken', tokens['github'])
        if 'mbed' in tokens:
            settings.setProperty('mbed', 'authtoken', tokens['mbed'])
        return True
    return False
示例#10
0
def getPublicKey():
    ''' Return the user's public key (generating and saving a new key pair if necessary) '''
    pubkey_hex = settings.getProperty('keys', 'public')
    if not pubkey_hex:
        k = RSA.generate(2048)
        settings.setProperty('keys', 'private', binascii.hexlify(k.exportKey('DER')))
        pubkey_hex = binascii.hexlify(k.publickey().exportKey('DER'))
        settings.setProperty('keys', 'public', pubkey_hex)
        pubkey_hex, privatekey_hex = _generateAndSaveKeys()
    return _pubkeyWireFormat(RSA.importKey(binascii.unhexlify(pubkey_hex)))
示例#11
0
def getPublicKey():
    ''' Return the user's public key (generating and saving a new key pair if necessary) '''
    pubkey_hex = settings.getProperty('keys', 'public')
    if not pubkey_hex:
        k = RSA.generate(2048)
        settings.setProperty('keys', 'private',
                             binascii.hexlify(k.exportKey('DER')))
        pubkey_hex = binascii.hexlify(k.publickey().exportKey('DER'))
        settings.setProperty('keys', 'public', pubkey_hex)
        pubkey_hex, privatekey_hex = _generateAndSaveKeys()
    return _pubkeyWireFormat(RSA.importKey(binascii.unhexlify(pubkey_hex)))
示例#12
0
def _generateAndSaveKeys(registry=None):
    registry = registry or Registry_Base_URL
    k = rsa.generate_private_key(
        public_exponent=65537, key_size=2048, backend=default_backend()
    )
    privatekey_pem = k.private_bytes(
        serialization.Encoding.PEM,
        serialization.PrivateFormat.PKCS8,
        serialization.NoEncryption()
    )

    pubkey_pem = k.public_key().public_bytes(
        serialization.Encoding.PEM,
        serialization.PublicFormat.SubjectPublicKeyInfo
    )

    if _isPublicRegistry(registry):
        settings.setProperty('keys', 'private', privatekey_pem.decode('ascii'))
        settings.setProperty('keys', 'public', pubkey_pem.decode('ascii'))
    else:
        sources = _getSources()
        keys = None
        for s in sources:
            if _sourceMatches(s, registry):
                if not 'keys' in s:
                    s['keys'] = dict()
                keys = s['keys']
                break
        if keys is None:
            keys = dict()
            sources.append({
               'type':'registry',
                'url':registry,
               'keys':keys
            })
        keys['private'] = privatekey_pem.decode('ascii')
        keys['public']  = pubkey_pem.decode('ascii')
        settings.set('sources', sources)
    return pubkey_pem, privatekey_pem
示例#13
0
def deauthorize():
    if settings.getProperty('github', 'authtoken'):
        settings.setProperty('github', 'authtoken', '')
示例#14
0
def deauthorize():
    if settings.getProperty('keys', 'private'):
        settings.setProperty('keys', 'private', '')
    if settings.getProperty('keys', 'public'):
        settings.setProperty('keys', 'public', '')
示例#15
0
def _pollForAuth():
    tokens = registry_access.getAuthData()
    if tokens and 'github' in tokens:
        settings.setProperty('github', 'authtoken', tokens['github'])
        return True
    return False
示例#16
0
def deauthorize():
    if settings.getProperty('keys', 'private'):
        settings.setProperty('keys', 'private', '')
    if settings.getProperty('keys', 'public'):
        settings.setProperty('keys', 'public', '')
示例#17
0
文件: auth.py 项目: jason790/yotta
def deauthorize():
    if settings.getProperty('github', 'authtoken'):
        settings.setProperty('github', 'authtoken', '')
    if settings.getProperty('mbed', 'authtoken'):
        settings.setProperty('mbed', 'authtoken', '')
示例#18
0
def _pollForAuth():
    tokens = registry_access.getAuthData()
    if tokens and 'github' in tokens:
        settings.setProperty('github', 'authtoken', tokens['github'])
        return True
    return False