Skip to content

Commit

Permalink
library: Add token_version and uses_pin to struct token_info
Browse files Browse the repository at this point in the history
uses_pin may be needed by some callers to figure out whether to
concatenate a PIN.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
  • Loading branch information
cernekee committed Jul 19, 2014
1 parent ed9bc7b commit c966d3e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
2 changes: 2 additions & 0 deletions java/src/org/stoken/LibStoken.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public static class StokenInfo {
public String serial;
public long unixExpDate;
public int interval;
public int tokenVersion;
public boolean usesPin;
};

/* public APIs */
Expand Down
15 changes: 14 additions & 1 deletion src/jni.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ static int set_long(struct libctx *ctx, jobject jobj, const char *name, uint64_t
return 0;
}

static int set_bool(struct libctx *ctx, jobject jobj, const char *name, int value)
{
jclass jcls = (*ctx->jenv)->GetObjectClass(ctx->jenv, jobj);
jfieldID jfld = (*ctx->jenv)->GetFieldID(ctx->jenv, jcls, name, "Z");

if (!jfld)
return -1;
(*ctx->jenv)->SetBooleanField(ctx->jenv, jobj, jfld, value);
return 0;
}

static jstring dup_to_jstring(JNIEnv *jenv, const char *in)
{
/*
Expand Down Expand Up @@ -238,7 +249,9 @@ JNIEXPORT jobject JNICALL Java_org_stoken_LibStoken_getInfo(

if (set_string(ctx, jobj, "serial", info->serial) ||
set_long(ctx, jobj, "unixExpDate", info->exp_date) ||
set_int(ctx, jobj, "interval", info->interval))
set_int(ctx, jobj, "interval", info->interval) ||
set_int(ctx, jobj, "tokenVersion", info->token_version) ||
set_bool(ctx, jobj, "usesPin", info->uses_pin))
return NULL;

return jobj;
Expand Down
4 changes: 4 additions & 0 deletions src/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,13 @@ struct stoken_info *stoken_get_info(struct stoken_ctx *ctx)
struct stoken_info *info = calloc(1, sizeof(*info));
if (!info)
return NULL;

strncpy(info->serial, ctx->t->serial, sizeof(info->serial) - 1);
info->exp_date = securid_unix_exp_date(ctx->t);
info->interval = securid_token_interval(ctx->t);
info->token_version = ctx->t->version;
info->uses_pin = securid_pin_required(ctx->t);

return info;
}

Expand Down
11 changes: 10 additions & 1 deletion src/stoken.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ struct stoken_info {
char serial[16];
time_t exp_date;
int interval;
int token_version;
int uses_pin;
};

/*
Expand Down Expand Up @@ -105,7 +107,14 @@ struct stoken_info *stoken_get_info(struct stoken_ctx *ctx);
*/
void stoken_pin_range(struct stoken_ctx *ctx, int *min_pin, int *max_pin);

/* returns nonzero if the token in CTX requires a PIN */
/*
* Returns nonzero if the token in CTX requires a PIN, and doesn't have one
* saved (i.e. you need to prompt for it). stoken_info->uses_pin returns
* nonzero if a PIN is used in the calculation. If stoken_info->uses_pin is
* 0, a PIN is not needed to generate the tokencode but you may need to
* request and concatenate a PIN in order to log in to a protected resource:
* PASSCODE = PIN + TOKENCODE
*/
int stoken_pin_required(struct stoken_ctx *ctx);

/* returns nonzero if the token in CTX needs a password to decrypt the seed */
Expand Down

0 comments on commit c966d3e

Please sign in to comment.