Exemplo n.º 1
0
def gen_dsa_pub_key(dsa_key, old_key):

    der = base64.b64decode(old_key)

    cert = asn1.DerSequence()
    cert.decode(der)

    y_asn = asn1.DerInteger()
    y_asn.decode(cert[1][4:])
    y = y_asn.value

    pubkeyInfo = asn1.DerSequence()
    pubkeyInfo.decode(cert[0])

    pubkeys = asn1.DerSequence()
    pubkeys[:] = [dsa_key.p, dsa_key.q, dsa_key.g]

    pubkeyInfo[1] = pubkeys.encode()

    y_asn = asn1.DerInteger(dsa_key.y).encode()
    y_asn_prefix = struct.pack('BBBB', 3, 0x81, len(y_asn) + 1, 0)
    cert[:] = [pubkeyInfo.encode(), y_asn_prefix + y_asn]

    return base64.b64encode(cert.encode())
Exemplo n.º 2
0
def load_dsa_key(pub_key):
    der = base64.b64decode(pub_key)

    cert = asn1.DerSequence()
    cert.decode(der)

    y_asn = asn1.DerInteger()
    y_asn.decode(cert[1][4:])
    y = y_asn.value

    pubkeyInfo = asn1.DerSequence()
    pubkeyInfo.decode(cert[0])

    pubkeys = asn1.DerSequence()
    pubkeys.decode(pubkeyInfo[1])
    p, q, g = pubkeys[:]

    return DSA.construct((y, g, p, q))
Exemplo n.º 3
0
def decode_int(data):
    der = asn1.DerInteger()
    der.decode(data)
    return der.value