authenticationobject.js
Summary
AuthenticationObject - Password, PIN or key container for external authentication
Class Summary
|
AuthenticationObject |
Class implementing authentication objects like PINs, PACE passwords or keys
|
function AuthenticationObject(name, type, id, value) {
FileSystemIdObject.call(this, name, id);
this.type = type;
this.value = value;
this.retrycounter = 3;
this.initialretrycounter = 3;
this.usecounter = -1;
this.resetcounter = -1;
this.minLength = 4;
this.isActive = true;
this.isEnabled = true;
this.isTransport = false;
this.isTerminated = false;
this.allowActivate = false;
this.allowDeactivate = false;
this.allowEnable = false;
this.allowDisable = false;
this.allowResetRetryCounter = false;
this.allowResetValue = false;
this.allowTerminate = false;
this.unsuspendAuthenticationObject = null;
this.unblockAuthenticationObject = null;
}
AuthenticationObject.prototype = new FileSystemIdObject();
AuthenticationObject.prototype.constructor = AuthenticationObject;
AuthenticationObject.TYPE_PACE = "pace";
AuthenticationObject.TYPE_PIN = "pin";
AuthenticationObject.prototype.getType = function() {
return this.type;
}
AuthenticationObject.prototype.isBlocked = function() {
return ((this.initialretrycounter != 0) && (this.retrycounter == 0));
}
AuthenticationObject.prototype.isSuspended = function() {
return ((this.initialretrycounter != 0) && (this.retrycounter == 1));
}
AuthenticationObject.prototype.activate = function() {
if (!this.allowActivate) {
throw new GPError("AuthenticationObject", GPError.INVALID_DATA, APDU.SW_CONDOFUSENOTSAT, "Activate not allowed for authentication object");
}
this.isActive = true;
}
AuthenticationObject.prototype.deactivate = function() {
if (!this.allowDeactivate) {
throw new GPError("AuthenticationObject", GPError.INVALID_DATA, APDU.SW_CONDOFUSENOTSAT, "Deactivate not allowed for authentication object");
}
this.isActive = false;
}
AuthenticationObject.prototype.resetRetryCounter = function(newValue) {
if (!this.allowResetRetryCounter) {
throw new GPError("AuthenticationObject", GPError.INVALID_DATA, APDU.SW_CONDOFUSENOTSAT, "Reset retry counter not allowed for authentication object");
}
if (newValue && !this.allowResetValue) {
throw new GPError("AuthenticationObject", GPError.INVALID_DATA, APDU.SW_CONDOFUSENOTSAT, "Reset retry counter not allowed with new value for authentication object");
}
if (this.resetcounter != -1) {
if (this.resetcounter == 0) {
throw new GPError("AuthenticationObject", GPError.INVALID_DATA, APDU.SW_CONDOFUSENOTSAT, "Reset retry counter is 0");
}
this.resetcounter--;
}
if (newValue && (newValue.length < this.minLength)) {
throw new GPError("AuthenticationObject", GPError.INVALID_DATA, APDU.SW_WRONGLENGTH, "New reference data too short");
}
this.retrycounter = this.initialretrycounter;
this.isActive = true;
if (this.initialretrycounter) {
this.retrycounter = this.initialretrycounter;
}
if (newValue) {
this.isTransport = false;
this.value = newValue;
}
}
AuthenticationObject.prototype.changeReferenceData = function(qualifier, value) {
if (!this.allowChangeReferenceData) {
throw new GPError("AuthenticationObject", GPError.INVALID_DATA, APDU.SW_CONDOFUSENOTSAT, "Change reference data not allowed for authentication object");
}
if (qualifier == 0x01) {
if (!this.isTerminated) {
throw new GPError("AuthenticationObject", GPError.INVALID_DATA, APDU.SW_CONDOFUSENOTSAT, "Change reference data with P1=01 not allowed non terminated authentication object");
}
if (this.associatedKey && !this.associatedKey.isTerminated) {
throw new GPError("AuthenticationObject", GPError.INVALID_DATA, APDU.SW_REFDATANOTUSABLE, "Associated key is not terminated");
}
}
if ((qualifier == 0x00) && (value.length <= this.value.length)) {
throw new GPError("AuthenticationObject", GPError.INVALID_DATA, APDU.SW_INVDATA, "Command data does not contain a new PIN value for P1=00");
}
if (qualifier == 0x00) {
this.verify(value.left(this.value.length));
value = value.bytes(this.value.length);
}
if (value.length < this.minLength) {
throw new GPError("AuthenticationObject", GPError.INVALID_DATA, APDU.SW_WRONGLENGTH, "New reference data too short");
}
this.value = value;
this.isTerminated = false;
}
AuthenticationObject.prototype.verify = function(value) {
if (this.isBlocked()) {
throw new GPError("AuthenticationObject", GPError.INVALID_DATA, APDU.SW_AUTHMETHLOCKED, "Authentication method blocked");
}
if (this.isTerminated) {
throw new GPError("AuthenticationObject", GPError.INVALID_DATA, APDU.SW_REFDATANOTUSABLE, "Authentication method terminated");
}
this.decreaseRetryCounter();
if (!this.value.equals(value)) {
var sw = APDU.SW_WARNINGCOUNT | this.retrycounter;
throw new GPError("AuthenticationObject", GPError.INVALID_DATA, sw, "Authentication failed");
}
this.restoreRetryCounter();
}
AuthenticationObject.prototype.decreaseRetryCounter = function() {
if (this.initialretrycounter) {
this.retrycounter--;
}
}
AuthenticationObject.prototype.restoreRetryCounter = function() {
if (this.initialretrycounter) {
this.retrycounter = this.initialretrycounter;
}
}
AuthenticationObject.prototype.terminate = function() {
if (!this.allowTerminate) {
throw new GPError("AuthenticationObject", GPError.INVALID_DATA, APDU.SW_CONDOFUSENOTSAT, "Terminate not allowed for authentication object");
}
this.isTerminated = true;
}
AuthenticationObject.prototype.toString = function() {
var state = "";
if (this.isBlocked()) {
state += "blocked ";
} else if (this.isTerminated) {
state += "terminated ";
} else {
if (this.isActive) {
state += "active ";
}
if (this.isActive) {
state += "enabled ";
} else {
state += "disabled ";
}
if (this.isTransport) {
state += "transport ";
}
}
var str = this.type + ":" + this.name + "(" + this.id + ") is " + state;
if (this.initialretrycounter) {
str += " RC=" + this.retrycounter;
}
return str;
}
Documentation generated by
JSDoc on Tue Sep 3 22:29:41 2013