tccconnection.js
Summary
Connector implementing a web service interface to a terminal control center as defined in TR-03129
Class Summary
|
TCCConnection |
Class implementing a terminal control center web service connector
|
load("../cvc.js");
function TCCConnection(url) {
this.url = url;
this.soapcon = new SOAPConnection();
this.verbose = true;
this.lastError = null;
this.version = "1.1";
}
TCCConnection.prototype.getLastError = function() {
return this.lastError;
}
TCCConnection.prototype.close = function() {
this.soapcon.close();
}
TCCConnection.prototype.getCertificateChain = function(keyNameMRTD) {
this.lastError = null;
var ns = new Namespace("uri:EAC-PKI-TermContr-Protocol/" + this.version);
var ns1 = new Namespace("uri:eacBT/" + this.version);
if (this.version == "1.0") {
var request =
<ns:GetCertificateChain xmlns:ns={ns} xmlns:ns1={ns1}>
<keyNameMRTD>{keyNameMRTD.getBytes().toString(BASE64)}</keyNameMRTD>
</ns:GetCertificateChain>
} else {
var request =
<ns:GetCertificateChain xmlns:ns={ns} xmlns:ns1={ns1}>
<keyCAR>{keyNameMRTD.getBytes().toString(BASE64)}</keyCAR>
</ns:GetCertificateChain>
}
if (this.verbose) {
GPSystem.trace(request.toXMLString());
}
var response = this.soapcon.call(this.url, request);
if (this.verbose) {
GPSystem.trace(response.toXMLString());
}
var certmap = [];
if (response.Result.ns1::returnCode.toString() == "ok_cert_available") {
if (this.verbose) {
GPSystem.trace("Received certificates from TCC:");
}
for each (var c in response.Result.ns1::certificateSeq.ns1::certificate) {
var cvc = new CVC(new ByteString(c, BASE64));
certmap[cvc.getCAR().toString()] = cvc;
if (this.verbose) {
GPSystem.trace(cvc.getCAR().toString());
GPSystem.trace(cvc);
}
}
} else {
this.lastError = response.Result.ns1::returnCode.toString();
return null;
}
var certlist = [];
var car = keyNameMRTD;
var cvc = certmap[car.toString()];
while (typeof(cvc) != "undefined") {
certlist.push(cvc);
if (this.verbose) {
GPSystem.trace("Added: " + cvc);
}
car = cvc.getCHR()
cvc = certmap[car.toString()]
}
return certlist;
}
TCCConnection.prototype.getTASignature = function(keyCHR, digest) {
this.lastError = null;
var ns = new Namespace("uri:EAC-PKI-TermContr-Protocol/" + this.version);
var ns1 = new Namespace("uri:eacBT/" + this.version);
var request =
<ns:GetTASignature xmlns:ns={ns} xmlns:ns1={ns1}>
<hashTBS>
</hashTBS>
<idPICC>
</idPICC>
<challengePICC>
</challengePICC>
<hashPK>
</hashPK>
<auxPCD>
</auxPCD>
<keyCHR>{keyCHR.getBytes().toString(BASE64)}</keyCHR>
</ns:GetTASignature>
request.hashTBS.ns1::binary = <ns1:binary xmlns:ns1={ns1}>{digest.toString(BASE64)}</ns1:binary>;
if (this.verbose) {
GPSystem.trace(request.toXMLString());
}
var response = this.soapcon.call(this.url, request);
if (this.verbose) {
GPSystem.trace(response.toXMLString());
}
var signature = null;
if (response.Result.ns1::returnCode.toString() == "ok_signature_available") {
var signatureStr = response.Result.ns1::Signature.toString();
if (this.verbose) {
GPSystem.trace("Received signature from TCC: " + signatureStr);
}
signature = new ByteString(signatureStr, BASE64);
if (this.verbose) {
GPSystem.trace("Received signature from TCC: " + signature);
}
} else {
this.lastError = response.Result.ns1::returnCode.toString();
}
return signature;
}
TCCConnection.prototype.getTASignature2 = function(idPICC, challengePICC, hashPK, keyCHR) {
this.lastError = null;
var ns = new Namespace("uri:EAC-PKI-TermContr-Protocol/" + this.version);
var ns1 = new Namespace("uri:eacBT/" + this.version);
var request =
<ns:GetTASignature xmlns:ns={ns} xmlns:ns1={ns1}>
<hashTBS>
</hashTBS>
<idPICC>
</idPICC>
<challengePICC>
</challengePICC>
<hashPK>
</hashPK>
<auxPCD>
</auxPCD>
<keyCHR>{keyCHR.getBytes().toString(BASE64)}</keyCHR>
</ns:GetTASignature>
request.idPICC.ns1::binary = <ns1:binary xmlns:ns1={ns1}>{idPICC.toString(BASE64)}</ns1:binary>;
request.challengePICC.ns1::binary = <ns1:binary xmlns:ns1={ns1}>{challengePICC.toString(BASE64)}</ns1:binary>;
request.hashPK.ns1::binary = <ns1:binary xmlns:ns1={ns1}>{hashPK.toString(BASE64)}</ns1:binary>;
if (this.verbose) {
GPSystem.trace(request.toXMLString());
}
var response = this.soapcon.call(this.url, request);
if (this.verbose) {
GPSystem.trace(response.toXMLString());
}
var signature = null;
if (response.Result.ns1::returnCode.toString() == "ok_signature_available") {
var signatureStr = response.Result.ns1::Signature.toString();
if (this.verbose) {
GPSystem.trace("Received signature from TCC: " + signatureStr);
}
signature = new ByteString(signatureStr, BASE64);
if (this.verbose) {
GPSystem.trace("Received signature from TCC: " + signature);
}
} else {
this.lastError = response.Result.ns1::returnCode.toString();
}
return signature;
}
TCCConnection.test = function() {
var c = new TCCConnection("http://localhost:8080/se/tcc");
var chr = new PublicKeyReference("UTCVCA00001");
var cl = c.getCertificateChain(chr);
if (cl == null) {
print("GetCertificateChain reports error: " + c.getLastError());
}
print("Received certificates:");
for (var i = 0; i < cl.length; i++) {
print(cl[i]);
}
var tcert = cl[cl.length - 1];
var chr = tcert.getCHR();
var crypto = new Crypto();
var message = new ByteString("Hello World", ASCII);
var digest = crypto.digest(Crypto.SHA_256, message);
var signature = c.getTASignature(chr, digest);
if (signature == null) {
print("GetTASignature reports error: " + c.getLastError());
return;
}
print("Signature: " + signature);
var signature = ECCUtils.wrapSignature(signature);
var dp = new Key();
dp.setComponent(Key.ECC_CURVE_OID, new ByteString("brainpoolP256r1", OID));
var puk = tcert.getPublicKey(dp);
var mech = CVC.getSignatureMech(tcert.getPublicKeyOID());
print("Message: " + message);
print("Hash: " + digest);
print("Signature verification: " + crypto.verify(puk, mech, message, signature));
}
Documentation generated by
JSDoc on Tue Sep 3 22:29:38 2013