| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
import tlslite.X509 as X509 |
|---|
| 6 |
import tlslite.utils.keyfactory as keyfactory |
|---|
| 7 |
import array |
|---|
| 8 |
|
|---|
| 9 |
def readPEM(fname): |
|---|
| 10 |
f = open (fname, 'r') |
|---|
| 11 |
lines = f.readlines() |
|---|
| 12 |
f.close() |
|---|
| 13 |
return ''.join(lines) |
|---|
| 14 |
|
|---|
| 15 |
if __name__ == '__main__': |
|---|
| 16 |
s = readPEM('clientX509Cert.pem') |
|---|
| 17 |
x = X509.X509() |
|---|
| 18 |
cert = x.parse(s) |
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
data = array.array('B', '\x01\x02\x03\x04' * 5) |
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
encData = cert.publicKey.encrypt(data) |
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
s = readPEM('clientX509Key.pem') |
|---|
| 28 |
privateKey = keyfactory.parsePEMKey(s, True, False) |
|---|
| 29 |
decData = privateKey.decrypt(encData) |
|---|
| 30 |
|
|---|
| 31 |
if data == decData: |
|---|
| 32 |
print 'ok' |
|---|
| 33 |
else: |
|---|
| 34 |
print 'ng' |
|---|