decryption test after keygen
This commit is contained in:
11
ChangeLog
11
ChangeLog
@@ -1,12 +1,19 @@
|
|||||||
2012-06-28 Niibe Yutaka <gniibe@fsij.org>
|
2012-06-28 Niibe Yutaka <gniibe@fsij.org>
|
||||||
|
|
||||||
|
* test/features/204_decryption.feature: New.
|
||||||
|
* test/features/203_compute_signature.feature: New.
|
||||||
|
* test/features/202_keygen.feature: New.
|
||||||
|
* test/features/201_setup_passphrase.feature: New.
|
||||||
|
* test/features/200_key_removal.feature: New.
|
||||||
|
|
||||||
|
* test/rsa_keys.py (verify_signature): New.
|
||||||
|
(encrypt_with_pubkey): New.
|
||||||
|
|
||||||
* test/gnuk.py (gnuk_token): New method: increment_seq.
|
* test/gnuk.py (gnuk_token): New method: increment_seq.
|
||||||
(gnuk_token.icc_send_cmd): Handle timeout.
|
(gnuk_token.icc_send_cmd): Handle timeout.
|
||||||
(gnuk_token.cmd_genkey): New.
|
(gnuk_token.cmd_genkey): New.
|
||||||
(gnuk_token.cmd_get_public_key): New.
|
(gnuk_token.cmd_get_public_key): New.
|
||||||
|
|
||||||
* test/rsa_keys.py (verify_signature): New.
|
|
||||||
|
|
||||||
2012-06-27 Niibe Yutaka <gniibe@fsij.org>
|
2012-06-27 Niibe Yutaka <gniibe@fsij.org>
|
||||||
|
|
||||||
* test/features/101_decryption.feature: New.
|
* test/features/101_decryption.feature: New.
|
||||||
|
|||||||
19
test/features/204_decryption.feature
Normal file
19
test/features/204_decryption.feature
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
@keygen
|
||||||
|
Feature: decryption
|
||||||
|
In order to use a token
|
||||||
|
A token should decrypt encrypted data
|
||||||
|
|
||||||
|
Scenario: decrypt by OPENPGP.2 key (1)
|
||||||
|
Given a plain text "This is a test message."
|
||||||
|
And a public key from token for OPENPGP.2
|
||||||
|
And encrypt it on host
|
||||||
|
And let a token decrypt encrypted data
|
||||||
|
Then decrypted data should be same as a plain text
|
||||||
|
|
||||||
|
Scenario: decrypt by OPENPGP.2 key (2)
|
||||||
|
Given a plain text "RSA decryption is as easy as pie."
|
||||||
|
And a public key from token for OPENPGP.2
|
||||||
|
And encrypt it on host
|
||||||
|
And let a token decrypt encrypted data
|
||||||
|
Then decrypted data should be same as a plain text
|
||||||
|
|
||||||
@@ -95,11 +95,15 @@ def compute_signature_on_host(keyno_str):
|
|||||||
def set_plaintext(content_str_repr):
|
def set_plaintext(content_str_repr):
|
||||||
scc.plaintext = ast.literal_eval(content_str_repr)
|
scc.plaintext = ast.literal_eval(content_str_repr)
|
||||||
|
|
||||||
@Given("encrypt it on host with RSA key pair (.*)")
|
@Given("encrypt it on host with RSA key pair (.*)$")
|
||||||
def encrypt_on_host(keyno_str):
|
def encrypt_on_host(keyno_str):
|
||||||
keyno = int(keyno_str)
|
keyno = int(keyno_str)
|
||||||
scc.ciphertext = rsa_keys.encrypt(keyno, scc.plaintext)
|
scc.ciphertext = rsa_keys.encrypt(keyno, scc.plaintext)
|
||||||
|
|
||||||
|
@Given("encrypt it on host$")
|
||||||
|
def encrypt_on_host_public_key():
|
||||||
|
scc.ciphertext = rsa_keys.encrypt_with_pubkey(scc.pubkey_info, scc.plaintext)
|
||||||
|
|
||||||
@Given("let a token decrypt encrypted data")
|
@Given("let a token decrypt encrypted data")
|
||||||
def decrypt():
|
def decrypt():
|
||||||
scc.result = ftc.token.cmd_pso_longdata(0x80, 0x86, scc.ciphertext)
|
scc.result = ftc.token.cmd_pso_longdata(0x80, 0x86, scc.ciphertext)
|
||||||
|
|||||||
@@ -138,6 +138,12 @@ def encrypt(keyno, plaintext):
|
|||||||
m = pkcs1_pad_for_crypt(plaintext)
|
m = pkcs1_pad_for_crypt(plaintext)
|
||||||
return '\x00' + integer_to_bytes(pow(m, e, n))
|
return '\x00' + integer_to_bytes(pow(m, e, n))
|
||||||
|
|
||||||
|
def encrypt_with_pubkey(pubkey_info, plaintext):
|
||||||
|
n = int(hexlify(pubkey_info[0]), 16)
|
||||||
|
e = int(hexlify(pubkey_info[1]), 16)
|
||||||
|
m = pkcs1_pad_for_crypt(plaintext)
|
||||||
|
return '\x00' + integer_to_bytes(pow(m, e, n))
|
||||||
|
|
||||||
def verify_signature(pubkey_info, digestinfo, sig):
|
def verify_signature(pubkey_info, digestinfo, sig):
|
||||||
n = int(hexlify(pubkey_info[0]), 16)
|
n = int(hexlify(pubkey_info[0]), 16)
|
||||||
e = int(hexlify(pubkey_info[1]), 16)
|
e = int(hexlify(pubkey_info[1]), 16)
|
||||||
|
|||||||
Reference in New Issue
Block a user