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