Beispiel #1
0
    def test_new_rsa_raises(vectors):
        with pytest.raises(WolfCryptError):
            RsaPrivate(vectors[RsaPrivate].key[:-1])  # invalid key length

        with pytest.raises(WolfCryptError):
            RsaPublic(vectors[RsaPublic].key[:-1])  # invalid key length

        if _lib.KEYGEN_ENABLED:
            with pytest.raises(WolfCryptError):  # invalid key size
                RsaPrivate.make_key(16384)
Beispiel #2
0
def signature_vectors():
    TestVector = namedtuple(
        "TestVector", """data signature hash_cls pub_key
                                             priv_key""")
    TestVector.__new__.__defaults__ = (None, ) * len(TestVector._fields)

    vectors = []

    with open(os.path.join(certs_dir, "server-keyPub.pem"), "rb") as f:
        pub_key_pem = f.read()
    with open(os.path.join(certs_dir, "server-key.pem"), "rb") as f:
        priv_key_pem = f.read()

    # Signature computed with:
    # echo -n "wolfcrypt is the best crypto around" | \
    # openssl dgst -hex -sha256 -sign tests/certs/server-key.pem
    if _lib.ASN_ENABLED and _lib.SHA256_ENABLED and _lib.RSA_ENABLED:
        vectors.append(
            TestVector(
                data="wolfcrypt is the best crypto around",
                signature=h2b(
                    "1d65f21df8fdc9f3c2351792840423481c6b0f2332105abd9248"
                    "9e0dc8f6f8c740e267cf49f522f771eabd484f961eaf9f907c97"
                    "b513bb9de7411b508c4e7ab7dc4438890ca161a9e24addaffd3c"
                    "86821f2431f55fde5d131dfbe5805dea74e8882bfbfbf451f809"
                    "ed792dfb0b17c799e6a39f866ed9cf613138c9e5e99f757ea13a"
                    "2b9c167c294cd89f38365ab40175d4e29c24d672cd5ad2d57fec"
                    "e9ea2b29c1866235c791ec5b635b858512c2b832b1b8f1dc6854"
                    "cd4927df5519eefee439848c7f109548b3a3c8265658e009899a"
                    "51a4edaf9f1199f93e448482f27c43a53e0bc65b04e9848128e3"
                    "60314e864190e6bb9812bfbf4b40994f2c1d4ca7aad9"),
                hash_cls=Sha256,
                pub_key=RsaPublic.from_pem(pub_key_pem),
                priv_key=RsaPrivate.from_pem(priv_key_pem)))

    return vectors
Beispiel #3
0
 def rsa_private_pem(vectors):
     with open(vectors[RsaPrivate].pem, "rb") as f:
         pem = f.read()
     return RsaPrivate.from_pem(pem)
Beispiel #4
0
 def rsa_private_pkcs8(vectors):
     return RsaPrivate(vectors[RsaPrivate].pkcs8_key)
Beispiel #5
0
 def rsa_private_pss(vectors):
     return RsaPrivate(vectors[RsaPrivate].key, hash_type=HASH_TYPE_SHA256)
Beispiel #6
0
 def rsa_private(vectors):
     return RsaPrivate(vectors[RsaPrivate].key)
def test_new_rsa_raises(vectors):
    with pytest.raises(WolfCryptError):
        RsaPrivate(vectors[RsaPrivate].key[:-1])  # invalid key length

    with pytest.raises(WolfCryptError):
        RsaPublic(vectors[RsaPublic].key[:-1])  # invalid key length
Beispiel #8
0
           "F18623C84EEB8F568E8FF5BFF1F72BB5CC3DC657390C1B54410241009D7E05DE" +
           "EDF4B7B2FBFC304B551DE32F0147966905CD0E2E2CBD8363B6AB7CB76DCA5B64" +
           "A7CEBE86DF3B53DE61D21EEBA5F637EDACAB78D94CE755FBD71199C102401898" +
           "1829E61E2739702168AC0A2FA172C121869538C65890A0579CBAE3A7B115C8DE" +
           "F61BC2612376EFB09D1C44BE1343396717C89DCAFBF545648B38822CF2810240" +
           "3989E59C195530BAB7488C48140EF49F7E779743E1B419353123759C3B44AD69" +
           "1256EE0061641666D37C742B15B4A2FEBF086B1A5D3F9012B105863129DBD9E2")

public = (
    "30819F300D06092A864886F70D010101050003818D0030818902818100BC730E" +
    "A849F374A2A9EF18A5DA559921F9C8ECB36D48E53535757737ECD161905F3ED9" +
    "E4D5DF94CAC1A9D719DA86C9E84DC4613682FEABAD7E7725BB8D11A5BC623AA8" +
    "38CC39A20466B4F7F7F3AADA4D020EBB5E8D6948DC77C9280E22E96BA426BA4C" +
    "E8C1FD4A6F2B1FEF8AAEF69062E5641EEB2B3C67C8DC2700F6916865A90203010001")

prv = RsaPrivate(h2b(private))
pub = RsaPublic(h2b(public))

plaintext = "AgentBlueServer: :GetActiveHosts:JU13Tm0jqU1V2YAs:e9a7d3a0b6381315900b6539078a106e966c14c14e3006912260aa6572110d0a"
ciphertext = pub.encrypt(plaintext)
deciphertext = prv.decrypt(ciphertext)
print(deciphertext.decode("utf-8"), end="\n\n")

print(deciphertext.hex(), end="\n\n")
print(bytes.fromhex(deciphertext.hex()).decode("utf-8"), end="\n\n")

# signature = prv.sign(plaintext)

# print(signature, end='\n\n')
# print(signature.hex(), end='\n\n')
# print(bytes.fromhex(signature.hex()), end='\n\n')