spocconnection.js
Summary
Connector implementing a web service interface to a SPOC for the
distribution of card verifiable certificates used for terminal authentication as defined in CSN 36 9791
Class Summary
|
SPOCConnection |
Class implementing a SPOC web service connector
|
function SPOCConnection(url) {
this.url = url;
this.soapcon = new SOAPConnection(SOAPConnection.SOAP11);
this.verbose = true;
this.lastReturnCode = null;
}
SPOCConnection.prototype.getLastReturnCode = function() {
return this.lastReturnCode;
}
SPOCConnection.prototype.close = function() {
this.soapcon.close();
}
SPOCConnection.prototype.getCACertificates = function(callerID, messageID) {
this.lastReturnCode = null;
var ns = new Namespace("http://namespaces.unmz.cz/csn369791");
var request =
<csn:GetCACertificatesRequest xmlns:csn={ns}>
<csn:callerID>{callerID}</csn:callerID>
<csn:messageID>{messageID}</csn:messageID>
</csn:GetCACertificatesRequest>
if (this.verbose) {
GPSystem.trace(request.toXMLString());
}
this.request = request;
try {
var response = this.soapcon.call(this.url, request);
if (this.verbose) {
GPSystem.trace(response.toXMLString());
}
}
catch(e) {
GPSystem.trace("SOAP call to " + this.url + " failed : " + e);
throw new GPError("SPOCConnection", GPError.DEVICE_ERROR, 0, "getCACertificates failed with : " + e);
}
this.response = response;
var certlist = [];
this.lastReturnCode = response.ns::result.toString();
if (this.lastReturnCode == "ok_cert_available") {
for each (var c in response.ns::certificateSequence.ns::certificate) {
var cvc = new ByteString(c, BASE64);
certlist.push(cvc);
if (this.verbose) {
GPSystem.trace(cvc);
}
}
} else {
return null;
}
return certlist;
}
SPOCConnection.prototype.requestCertificate = function(certreq, callerID, messageID) {
var soapConnection = new SOAPConnection();
var ns = new Namespace("http://namespaces.unmz.cz/csn369791");
var request =
<csn:RequestCertificateRequest xmlns:csn={ns}>
<csn:callerID>{callerID}</csn:callerID>
<csn:messageID>{messageID}</csn:messageID>
<csn:certificateRequest>{certreq.toString(BASE64)}</csn:certificateRequest>
</csn:RequestCertificateRequest>
if (this.verbose) {
GPSystem.trace(request.toXMLString());
}
this.request = request;
try {
var response = this.soapcon.call(this.url, request);
if (this.verbose) {
GPSystem.trace(response.toXMLString());
}
}
catch(e) {
GPSystem.trace("SOAP call to " + this.url + " failed : " + e);
throw new GPError("SPOCConnection", GPError.DEVICE_ERROR, 0, "RequestCertificate failed with : " + e);
}
this.response = response;
var certlist = [];
this.lastReturnCode = response.ns::result.toString();
if (this.lastReturnCode == "ok_cert_available") {
for each (var c in response.ns::certificateSequence.ns::certificate) {
var cvc = new ByteString(c, BASE64);
certlist.push(cvc);
if (this.verbose) {
GPSystem.trace(cvc);
}
}
} else {
return null;
}
return certlist;
}
SPOCConnection.prototype.sendCertificates = function(certificates, callerID, messageID, statusInfo) {
var soapConnection = new SOAPConnection();
var ns = new Namespace("http://namespaces.unmz.cz/csn369791");
var request =
<csn:SendCertificatesRequest xmlns:csn={ns}>
<csn:callerID>{callerID}</csn:callerID>
<!--Optional:-->
<csn:messageID>{messageID}</csn:messageID>
<!--Optional:-->
<csn:certificateSequence>
</csn:certificateSequence>
<csn:statusInfo>{statusInfo}</csn:statusInfo>
</csn:SendCertificatesRequest>
var list = request.ns::certificateSequence;
if (certificates) {
for (var i = 0; i < certificates.length; i++) {
var cvc = certificates[i];
list.ns::certificate += <ns:certificate xmlns:ns={ns}>{cvc.toString(BASE64)}</ns:certificate>
}
}
if (this.verbose) {
GPSystem.trace(request.toXMLString());
}
this.request = request;
try {
var response = this.soapcon.call(this.url, request);
if (this.verbose) {
GPSystem.trace(response.toXMLString());
}
}
catch(e) {
GPSystem.trace("SOAP call to " + this.url + " failed : " + e);
throw new GPError("SPOCConnection", GPError.DEVICE_ERROR, 0, "SendCertificates failed with : " + e);
}
this.response = response;
this.lastReturnCode = response.ns::result.toString();
return this.lastReturnCode;
}
SPOCConnection.prototype.generalMessage = function(callerID, messageID, subject, body) {
this.lastReturnCode = null;
var ns = new Namespace("http://namespaces.unmz.cz/csn369791");
var request =
<csn:GeneralMessageRequest xmlns:csn={ns}>
<csn:callerID>{callerID}</csn:callerID>
<csn:messageID>{messageID}</csn:messageID>
<csn:subject>{subject}</csn:subject>
<csn:body>{body}</csn:body>
</csn:GeneralMessageRequest>
if (this.verbose) {
GPSystem.trace(request.toXMLString());
}
this.request = request;
try {
var response = this.soapcon.call(this.url, request);
if (this.verbose) {
GPSystem.trace(response.toXMLString());
}
}
catch(e) {
GPSystem.trace("SOAP call to " + this.url + " failed : " + e);
throw new GPError("SPOCConnection", GPError.DEVICE_ERROR, 0, "generalMessage failed with : " + e);
}
this.response = response;
this.lastReturnCode = response.ns::result.toString();
}
SPOCConnection.toCVCList = function(certlist) {
var certs = [];
for each (var cvcbin in certlist) {
certs.push(new CVC(cvcbin));
}
return certs;
}
SPOCConnection.fromCVCList = function(certlist) {
var certs = [];
for each (var cvc in certlist) {
certs.push(cvc.getBytes());
}
return certs;
}
SPOCConnection.test = function() {
var c = new SPOCConnection("http://localhost:8080/se/spoc");
c.verbose = true;
var certlist = c.getCACertificates("UT", "4711");
for (var i = 0; i < certlist.length; i++) {
print(certlist[i]);
}
}
Documentation generated by
JSDoc on Tue Sep 3 22:29:38 2013