eidaccesscontroller.js
Summary
Access controller for eID card
load("../cardsim/accesscontroller.js");
function MFAccessController() {
AccessController.call(this);
this.name = "MFAccessController";
}
MFAccessController.prototype = new AccessController();
MFAccessController.constructor = MFAccessController;
MFAccessController.prototype.checkFileReadAccess = function(ci, apdu, node) {
var fid = node.getFCP().fid.toUnsigned();
if ((fid == 0x011C) || (fid == 0x2F01)) {
return true;
}
if (!apdu.isSecureMessaging()) {
GPSystem.trace("Read access not allowed without secure messaging");
return false;
}
if (!ci.isAuthenticatedTerminal()) {
GPSystem.trace("Must have passed terminal authentication");
return false;
}
if (fid == 0x011b) {
return this.checkRight(ci, apdu, 3);
}
return true;
}
MFAccessController.prototype.checkRight = function(ci, apdu, bit) {
if (!apdu.isSecureMessaging()) {
GPSystem.trace("Special functions can only be performed with secure messaging");
return false;
}
if (!ci.isAuthenticatedTerminal()) {
GPSystem.trace("Must have passed terminal authentication");
return false;
}
if (!ci.getTerminalRole().equals(new ByteString("id-AT", OID))) {
GPSystem.trace("No access to roles other than id-AT");
return false;
}
var mask = ByteString.valueOf(1 << bit, 5);
print("EffRights:" + ci.effectiveRights);
print("ReqRights:" + mask);
print(mask.and(ci.effectiveRights));
return ci.effectiveRights.and(mask).right(4).toUnsigned() > 0;
}
function ePassAccessController() {
AccessController.call(this);
this.name = "ePassAccessController";
}
ePassAccessController.prototype = new AccessController();
ePassAccessController.constructor = ePassAccessController;
ePassAccessController.prototype.checkFileReadAccess = function(ci, apdu, node) {
if (!apdu.isSecureMessaging()) {
GPSystem.trace("Read access not allowed without secure messaging");
return false;
}
if (ci.isAuthenticatedTerminal()) {
if (!ci.getTerminalRole().equals(new ByteString("id-IS", OID))) {
GPSystem.trace("No access to roles other than id-IS");
return false;
}
}
var fid = node.getFCP().fid.toUnsigned();
if ((fid != 0x0103) && (fid != 0x0104)) {
return true;
}
if (!ci.isAuthenticatedTerminal()) {
GPSystem.trace("Must have passed terminal authentication");
return false;
}
var mask = ByteString.valueOf(0x01 << ((fid & 0xFF) - 3), 1);
print("EffRights:" + ci.effectiveRights);
print("ReqRights:" + mask);
print(mask.and(ci.effectiveRights));
return ci.effectiveRights.and(mask).toUnsigned() > 0;
}
ePassAccessController.prototype.checkRight = function(ci, apdu, bit) {
return false;
}
ePassAccessController.prototype.checkCommandAccess = function(ci, apdu) {
if ((apdu.getINS() == 0xA4) && (apdu.getP1() != 0x04)) {
return apdu.isSecureMessaging();
}
return true;
}
function eIDAccessController() {
AccessController.call(this);
this.name = "eIDAccessController";
}
eIDAccessController.prototype = new AccessController();
eIDAccessController.constructor = eIDAccessController;
eIDAccessController.prototype.checkBasicAccess = function(ci, apdu) {
if (!apdu.isSecureMessaging()) {
GPSystem.trace("Read access not allowed without secure messaging");
return false;
}
if (!ci.isAuthenticatedTerminal()) {
GPSystem.trace("No access to unauthenticated terminal");
false;
}
if (ci.paceao.id == 3) {
return true;
}
if (!ci.getTerminalRole().equals(new ByteString("id-AT", OID))) {
return true;
}
if (!this.checkBit(ci, apdu, 4)) {
print("CAN allowed right not granted");
return false;
}
if (ci.paceao.id != 2) {
print("CAN allowed only effective for PACE with CAN");
return false;
}
return true;
}
eIDAccessController.prototype.checkFileReadAccess = function(ci, apdu, node) {
if (!this.checkBasicAccess(ci, apdu)) {
return false;
}
var fid = node.getFCP().fid;
if ((fid.byteAt(0) != 0x01) || (fid.byteAt(1) < 0x01) || (fid.byteAt(1) > 0x15)) {
GPSystem.trace("FID " + fid + " out of defined range");
return false;
}
if ((ci.getTerminalRole().equals(new ByteString("id-IS", OID)) && ci.chat)) {
return true;
}
if (!ci.getTerminalRole().equals(new ByteString("id-AT", OID))) {
GPSystem.trace("No access to roles other than id-AT");
return false;
}
var mask = ByteString.valueOf(0x0100 << (fid.byteAt(1) - 1), 5);
print("EffRights:" + ci.effectiveRights);
print("ReqRights:" + mask);
print(mask.and(ci.effectiveRights));
return ci.effectiveRights.and(mask).toUnsigned() > 0;
}
eIDAccessController.prototype.checkFileWriteAccess = function(ci, apdu, node) {
if (!this.checkBasicAccess(ci, apdu)) {
return false;
}
var fid = node.getFCP().fid;
if ((fid.byteAt(0) != 0x01) || (fid.byteAt(1) < 0x11) || (fid.byteAt(1) > 0x15)) {
GPSystem.trace("FID out of defined range");
return false;
}
if (!ci.getTerminalRole().equals(new ByteString("id-AT", OID))) {
GPSystem.trace("No access to roles other than id-AT");
return false;
}
var mask = ByteString.valueOf(0x20000000 >> (fid.byteAt(1) - 17), 4);
mask = mask.concat(new ByteString.valueOf(0, 1));
print("EffRights:" + ci.effectiveRights);
print("ReqRights:" + mask);
print(mask.and(ci.effectiveRights));
return ci.effectiveRights.and(mask).left(4).toUnsigned() > 0;
}
eIDAccessController.prototype.checkBit = function(ci, apdu, bit) {
var mask = ByteString.valueOf(1 << bit, 5);
print("EffRights:" + ci.effectiveRights);
print("ReqRights:" + mask);
print(mask.and(ci.effectiveRights));
return ci.effectiveRights.and(mask).right(4).toUnsigned() > 0;
}
eIDAccessController.prototype.checkRight = function(ci, apdu, bit) {
if (!this.checkBasicAccess(ci, apdu)) {
return false;
}
if (!ci.getTerminalRole().equals(new ByteString("id-AT", OID))) {
GPSystem.trace("No access to roles other than id-AT");
return false;
}
return this.checkBit(ci, apdu, bit);
}
function eSignAccessController() {
AccessController.call(this);
this.name = "eSignAccessController";
}
eSignAccessController.prototype = new AccessController();
eSignAccessController.constructor = eSignAccessController;
eSignAccessController.prototype.checkFileReadAccess = function(ci, apdu, node) {
if (!apdu.isSecureMessaging()) {
GPSystem.trace("Read access not allowed without secure messaging");
return false;
}
if (!ci.isAuthenticatedTerminal()) {
GPSystem.trace("No access to unauthenticated terminal");
return false;
}
if (ci.getTerminalRole().equals(new ByteString("id-ST", OID))) {
return true;
}
if (ci.getTerminalRole().equals(new ByteString("id-AT", OID))) {
if (ci.effectiveRights.right(1).toUnsigned() & 0xC0) {
return true;
}
GPSystem.trace("AT terminal has no right to install certificate");
}
return false;
}
eSignAccessController.prototype.checkFileWriteAccess = function(ci, apdu, node) {
if (!apdu.isSecureMessaging()) {
GPSystem.trace("Write access not allowed without secure messaging");
return false;
}
if (!ci.isAuthenticatedTerminal()) {
GPSystem.trace("No access to unauthenticated terminal");
false;
}
if (ci.getTerminalRole().equals(new ByteString("id-AT", OID))) {
if (ci.effectiveRights.right(1).toUnsigned() & 0xC0) {
return true;
}
GPSystem.trace("AT terminal has no right to install certificate");
}
return false;
}
eSignAccessController.prototype.checkRight = function(ci, apdu, bit) {
if (!apdu.isSecureMessaging()) {
GPSystem.trace("Special functions can only be performed with secure messaging");
return false;
}
if (!ci.isAuthenticatedTerminal()) {
GPSystem.trace("No access to unauthenticated terminal");
false;
}
return true;
}
Documentation generated by
JSDoc on Tue Sep 3 22:29:43 2013