예제 #1
0
파일: test_sysca.py 프로젝트: markokr/sysca
def test_write_key():
    fd, name = tempfile.mkstemp()
    os.close(fd)
    try:
        # ec key, unencrypted
        key = sysca.new_ec_key()
        open(name, 'wb').write(sysca.key_to_pem(key))
        key2 = sysca.load_key(name)
        assert_true(sysca.same_pubkey(key, key2))

        # ec key, encrypted
        key = sysca.new_ec_key()
        open(name, 'wb').write(sysca.key_to_pem(key, 'password'))
        assert_raises(TypeError, sysca.load_key, name)
        assert_raises(ValueError, sysca.load_key, name, 'wrong')
        key2 = sysca.load_key(name, 'password')
        assert_true(sysca.same_pubkey(key, key2))

        # rsa key, unencrypted
        key = sysca.new_rsa_key()
        open(name, 'wb').write(sysca.key_to_pem(key))
        key2 = sysca.load_key(name)
        assert_true(sysca.same_pubkey(key, key2))

        # rsa key, encrypted
        key = sysca.new_rsa_key()
        open(name, 'wb').write(sysca.key_to_pem(key, 'password'))
        assert_raises(TypeError, sysca.load_key, name)
        assert_raises(ValueError, sysca.load_key, name, 'wrong')
        key2 = sysca.load_key(name, 'password')
        assert_true(sysca.same_pubkey(key, key2))
    finally:
        os.unlink(name)
예제 #2
0
def test_same_pubkey():
    k1 = sysca.new_ec_key()
    k2 = sysca.new_ec_key()
    k3 = sysca.new_rsa_key()
    k4 = sysca.new_rsa_key()
    assert sysca.same_pubkey(k1, k1)
    assert sysca.same_pubkey(k2, k2)
    assert sysca.same_pubkey(k3, k3)
    assert sysca.same_pubkey(k4, k4)
    assert not sysca.same_pubkey(k1, k2)
    assert not sysca.same_pubkey(k1, k3)
    assert not sysca.same_pubkey(k3, k1)
    assert not sysca.same_pubkey(k3, k4)
예제 #3
0
파일: test_sysca.py 프로젝트: markokr/sysca
def test_same_pubkey():
    k1 = sysca.new_ec_key()
    k2 = sysca.new_ec_key()
    k3 = sysca.new_rsa_key()
    k4 = sysca.new_rsa_key()
    assert_true(sysca.same_pubkey(k1, k1))
    assert_true(sysca.same_pubkey(k2, k2))
    assert_true(sysca.same_pubkey(k3, k3))
    assert_true(sysca.same_pubkey(k4, k4))
    assert_false(sysca.same_pubkey(k1, k2))
    assert_false(sysca.same_pubkey(k1, k3))
    assert_false(sysca.same_pubkey(k3, k1))
    assert_false(sysca.same_pubkey(k3, k4))
예제 #4
0
def test_write_key():
    fd, name = tempfile.mkstemp()
    os.close(fd)
    try:
        # ec key, unencrypted
        key = sysca.new_ec_key()
        open(name, 'wb').write(sysca.key_to_pem(key))
        key2 = sysca.load_key(name)
        assert sysca.same_pubkey(key, key2)

        # ec key, encrypted
        key = sysca.new_ec_key()
        open(name, 'wb').write(sysca.key_to_pem(key, 'password'))
        with pytest.raises(TypeError):
            sysca.load_key(name)
        with pytest.raises(ValueError):
            sysca.load_key(name, 'wrong')
        key2 = sysca.load_key(name, 'password')
        assert sysca.same_pubkey(key, key2)

        # rsa key, unencrypted
        key = sysca.new_rsa_key()
        open(name, 'wb').write(sysca.key_to_pem(key))
        key2 = sysca.load_key(name)
        assert sysca.same_pubkey(key, key2)

        # rsa key, encrypted
        key = sysca.new_rsa_key()
        open(name, 'wb').write(sysca.key_to_pem(key, 'password'))
        with pytest.raises(TypeError):
            sysca.load_key(name)
        with pytest.raises(ValueError):
            sysca.load_key(name, 'wrong')
        key2 = sysca.load_key(name, 'password')
        assert sysca.same_pubkey(key, key2)
    finally:
        os.unlink(name)
예제 #5
0
def test_sysca():
    # create ca key and cert
    ca_key = sysca.new_ec_key()
    ca_pub_key = ca_key.public_key()
    ca_info = sysca.CertInfo(subject={'CN': 'TestCA'}, ca=True)
    ca_cert = sysca.create_x509_cert(ca_key, ca_pub_key, ca_info, ca_info, 365)

    # srv key
    srv_key = sysca.new_rsa_key()
    srv_info = sysca.CertInfo(subject={'CN': 'Server1'})
    srv_req = sysca.create_x509_req(srv_key, srv_info)

    # ca signs
    srv_info2 = sysca.CertInfo(load=srv_req)
    srv_cert = sysca.create_x509_cert(ca_key, srv_req.public_key(), srv_info2, ca_info, 365)
예제 #6
0
파일: test_sysca.py 프로젝트: markokr/sysca
def test_sysca():
    # create ca key and cert
    ca_key = sysca.new_ec_key()
    ca_pub_key = ca_key.public_key()
    ca_info = sysca.CertInfo(subject={'CN': 'TestCA'}, ca=True)
    ca_cert = sysca.create_x509_cert(ca_key, ca_pub_key, ca_info, ca_info, 365)

    # srv key
    srv_key = sysca.new_rsa_key()
    srv_info = sysca.CertInfo(subject={'CN': 'Server1'})
    srv_req = sysca.create_x509_req(srv_key, srv_info)

    # ca signs
    srv_info2 = sysca.CertInfo(load=srv_req)
    srv_cert = sysca.create_x509_cert(ca_key, srv_req.public_key(), srv_info2, ca_info, 365)
    eq_(1, 1)