cvcaconnection.js
Summary
Connector implementing a web service interface to a CVCA as defined in TR-03129
Class Summary
|
CVCAConnection |
Class implementing a CVCA web service connector
|
load("cvc.js");
function CVCAConnection(url) {
this.url = url;
this.soapcon = new SOAPConnection(SOAPConnection.SOAP11);
this.verbose = true;
this.lastError = null;
}
CVCAConnection.prototype.getLastError = function() {
return this.lastError;
}
CVCAConnection.prototype.close = function() {
this.soapcon.close();
}
CVCAConnection.prototype.getCACertificates = function() {
this.lastError = null;
var ns = new Namespace("uri:EAC-PKI-CVCA-Protocol/1.0");
var ns1 = new Namespace("uri:eacBT/1.0");
var request =
<ns:GetCACertificates xmlns:ns={ns} xmlns:ns1={ns1}>
<callbackIndicator>callback_not_possible</callbackIndicator>
<messageID>
</messageID>
<responseURL>
</responseURL>
</ns:GetCACertificates>;
if (this.verbose) {
GPSystem.trace(request.toXMLString());
}
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("CVCAConnection", GPError.DEVICE_ERROR, 0, "getCACertificates failed with : " + e);
}
var certlist = [];
if (response.Result.ns1::returnCode.toString() == "ok_cert_available") {
GPSystem.trace("Received certificates from CVCA:");
for each (var c in response.Result.ns1::certificateSeq.ns1::certificate) {
var cvc = new CVC(new ByteString(c, BASE64));
certlist.push(cvc);
GPSystem.trace(cvc);
}
} else {
this.lastError = response.Result.ns1::returnCode.toString();
return null;
}
return certlist;
}
CVCAConnection.prototype.requestCertificate = function(certreq) {
var soapConnection = new SOAPConnection();
var ns = new Namespace("uri:EAC-PKI-CVCA-Protocol/1.0");
var ns1 = new Namespace("uri:eacBT/1.0");
var request =
<ns:RequestCertificate xmlns:ns={ns} xmlns:ns1={ns1}>
<callbackIndicator>callback_not_possible</callbackIndicator>
<messageID>
</messageID>
<responseURL>
</responseURL>
<certReq>{certreq.getBytes().toString(BASE64)}</certReq>
</ns:RequestCertificate>
if (this.verbose) {
GPSystem.trace(request.toXMLString());
}
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("CVCAConnection", GPError.DEVICE_ERROR, 0, "RequestCertificate failed with : " + e);
}
var certlist = [];
if (response.Result.ns1::returnCode.substr(0, 3) == "ok_") {
GPSystem.trace("Received certificates from CVCA:");
for each (var c in response.Result.ns1::certificateSeq.ns1::certificate) {
var cvc = new CVC(new ByteString(c, BASE64));
certlist.push(cvc);
GPSystem.trace(cvc);
}
} else {
this.lastError = response.Result.ns1::returnCode.toString();
return null;
}
return certlist;
}
CVCAConnection.test = function() {
var c = new CVCAConnection("http://localhost:8080/se/cvca");
c.verbose = true;
var certlist = c.getCACertificates();
}
Documentation generated by
JSDoc on Tue Sep 3 22:29:38 2013