Commit c3734bb1 authored by Alberto Inch's avatar Alberto Inch
Browse files

Agregando función para desbloquear token.

parent 694e1f20
......@@ -15,7 +15,8 @@ class Token
CK_SLOT_ID_PTR slots();
CK_SESSION_HANDLE open(CK_SLOT_ID slot);
void close(CK_SESSION_HANDLE hSession);
void changePin(CK_SESSION_HANDLE hSession, const char* oldPin, const char* newPin);
void changePin(CK_SESSION_HANDLE hSession, const char* oldPin, const char* newPin);
void unlock(CK_SESSION_HANDLE hSession, const char* soPin, const char* newPin);
virtual ~Token();
protected:
......
......@@ -28,3 +28,31 @@ JNIEXPORT jstring JNICALL Java_bo_firmadigital_token_ChangePinJNI_changePin
}
return env->NewStringUTF(res);
}
JNIEXPORT jstring JNICALL Java_bo_firmadigital_token_ChangePinJNI_unlock
(JNIEnv* env, jobject thisObject, jstring lib, jint slot, jstring osPin, jstring newPin) {
const char* res = "Ok";
try {
Token *token = new Token(env->GetStringUTFChars(lib, NULL));
int nroSlots = token->nroSlots();
if (nroSlots > 0) {
try {
CK_SESSION_HANDLE hSession = token->open(slot);
try {
token->unlock(hSession, env->GetStringUTFChars(osPin, NULL), env->GetStringUTFChars(newPin, NULL));
} catch (const std::runtime_error& error) {
res = "No se pudo cambiar la contraseña.";
}
token->close(hSession);
} catch (const std::runtime_error& error) {
res = "No se encontró el slot especificado.";
}
} else {
res = "No se encontró ningún token conectado.";
}
token->~Token();
} catch (const std::runtime_error& error) {
res = "No se pudo cargar el controlador.";
}
return env->NewStringUTF(res);
}
......@@ -15,6 +15,14 @@ extern "C" {
JNIEXPORT jstring JNICALL Java_bo_firmadigital_token_ChangePinJNI_changePin
(JNIEnv *, jobject, jstring, jint, jstring, jstring);
/*
* Class: bo_firmadigital_token_ChangePinJNI
* Method: unlock
* Signature: (Ljava/lang/String;ILjava/lang/String;Ljava/lang/String;)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_bo_firmadigital_token_ChangePinJNI_unlock
(JNIEnv *, jobject, jstring, jint, jstring, jstring);
#ifdef __cplusplus
}
#endif
......
......@@ -69,6 +69,24 @@ void Token::changePin(CK_SESSION_HANDLE hSession, const char* oldPin, const char
newPin = newBuf;
CK_RV rv = functionList->C_SetPIN(hSession, (CK_UTF8CHAR *)oldBuf, strlen(oldBuf), (CK_UTF8CHAR *)newBuf, strlen(newBuf));
error(rv);
}
void Token::unlock(CK_SESSION_HANDLE hSession, const char* soPin, const char* newPin) {
char soBuf[21], newBuf[21];
strcpy(soBuf, soPin);
soPin = soBuf;
CK_RV rv = functionList->C_Login(hSession, CKU_SO, (CK_UTF8CHAR *)soBuf, strlen(soBuf));
error(rv);
strcpy(newBuf, newPin);
newPin = newBuf;
rv = functionList->C_InitPIN(hSession, (CK_UTF8CHAR *)newBuf, strlen(newBuf));
if (rv == CKR_OK) {
rv = functionList->C_Logout(hSession);
error(rv);
} else {
functionList->C_Logout(hSession);
error(rv);
}
}
char* Token::byteToHex(CK_BYTE_PTR bytes, int l) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment