Skip to content

Commit 2f87d7d

Browse files
authored
Merge pull request #86 from canokeys/feature/openpgp_get_challenge
add GET_CHALLENGE for openpgp
2 parents 609b490 + 6d0b5a2 commit 2f87d7d

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

applets/openpgp/openpgp.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ static const uint8_t extended_length_info[] = {0x02, 0x02, HI(APDU_BUFFER_SIZE),
7878
0x02, 0x02, HI(APDU_BUFFER_SIZE), LO(APDU_BUFFER_SIZE)};
7979

8080
static const uint8_t extended_capabilities[] = {
81-
0x34, // Support key import, pw1 status change, and algorithm attributes changes
81+
0x74, // Support get challenge, key import, pw1 status change, and algorithm attributes changes
8282
0x00, // No SM algorithm
83-
0x00,
84-
0x00, // No challenge support
83+
HI(APDU_BUFFER_SIZE),
84+
LO(APDU_BUFFER_SIZE), // Challenge size
8585
HI(MAX_CERT_LENGTH),
8686
LO(MAX_CERT_LENGTH), // Cert length
8787
HI(MAX_DO_LENGTH),
@@ -1201,6 +1201,14 @@ static int openpgp_activate(const CAPDU *capdu, RAPDU *rapdu) {
12011201
return openpgp_install(1);
12021202
}
12031203

1204+
static int openpgp_get_challenge(const CAPDU *capdu, RAPDU *rapdu) {
1205+
if (P1 != 0x00 || P2 != 0x00) EXCEPT(SW_WRONG_P1P2);
1206+
if (LE > APDU_BUFFER_SIZE) EXCEPT(SW_WRONG_LENGTH);
1207+
random_buffer(RDATA, LE);
1208+
LL = LE;
1209+
return 0;
1210+
}
1211+
12041212
int openpgp_process_apdu(const CAPDU *capdu, RAPDU *rapdu) {
12051213
LL = 0;
12061214
SW = SW_NO_ERROR;
@@ -1287,6 +1295,9 @@ int openpgp_process_apdu(const CAPDU *capdu, RAPDU *rapdu) {
12871295
ret = openpgp_sign_or_auth(capdu, rapdu, false);
12881296
stop_blinking();
12891297
break;
1298+
case OPENPGP_INS_GET_CHALLENGE:
1299+
ret = openpgp_get_challenge(capdu, rapdu);
1300+
break;
12901301
case OPENPGP_INS_TERMINATE:
12911302
ret = openpgp_terminate(capdu, rapdu);
12921303
break;

include/openpgp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define OPENPGP_INS_GENERATE_ASYMMETRIC_KEY_PAIR 0x47
1919
#define OPENPGP_INS_TERMINATE 0xE6
2020
#define OPENPGP_INS_ACTIVATE 0x44
21+
#define OPENPGP_INS_GET_CHALLENGE 0x84
2122

2223
#define TAG_AID 0x4F
2324
#define TAG_LOGIN 0x5E

test-via-pcsc/openpgp_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ func TestOpenPGPApplet(t *testing.T) {
107107
So(res, ShouldResemble, []byte{2, 2, 0x05, 0x3C, 2, 2, 0x05, 0x3C}) // 1340 bytes
108108
})
109109

110+
Convey("Get challenge", func(ctx C) {
111+
res, code, err := app.Send([]byte{0x00, 0x84, 0x00, 0x00, 0x00, 0x05, 0x3C})
112+
So(err, ShouldBeNil)
113+
So(code, ShouldEqual, 0x9000)
114+
So(len(res), ShouldEqual, 0x53C) // 1340 bytes
115+
})
116+
110117
Convey("Admin PIN retry times", func(ctx C) {
111118
_, code, err := app.Send([]byte{0x00, 0x20, 0x00, 0x83})
112119
So(err, ShouldBeNil)

0 commit comments

Comments
 (0)