1 /**
  2  *  ---------
  3  * |.##> <##.|  Open Smart Card Development Platform (www.openscdp.org)
  4  * |#       #|  
  5  * |#       #|  Copyright (c) 1999-2008 CardContact Software & System Consulting
  6  * |'##> <##'|  Andreas Schwier, 32429 Minden, Germany (www.cardcontact.de)
  7  *  --------- 
  8  *
  9  *  This file is part of OpenSCDP.
 10  *
 11  *  OpenSCDP is free software; you can redistribute it and/or modify
 12  *  it under the terms of the GNU General Public License version 2 as
 13  *  published by the Free Software Foundation.
 14  *
 15  *  OpenSCDP is distributed in the hope that it will be useful,
 16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 18  *  GNU General Public License for more details.
 19  *
 20  *  You should have received a copy of the GNU General Public License
 21  *  along with OpenSCDP; if not, write to the Free Software
 22  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 23  *
 24  * @fileoverview Connector implementing a web service interface for obtaining Master and Defect Lists from
 25  * a Document Verifier or National Public Key Directory (NPKD) as per TR-03129
 26  */
 27 
 28 
 29 /**
 30  * Creates a web service connector to obtain Master and Defect Lists from  a Document Verifier or
 31  * a National Public Key Directory (NPKD) as per TR-03129
 32  *
 33  * @class Class implementing a DV or NPKD web service connector
 34  * @constructor
 35  * @param {String or URLConnection} url the web service endpoint
 36  * @param {Boolean} true if connection is made to an CVCA/NPKD, otherwise connection is made to a DV
 37  */
 38 function PAConnection(url, isNPKD) {
 39 	this.url = url;
 40 	this.soapcon = new SOAPConnection(SOAPConnection.SOAP11);
 41 	this.verbose = true;
 42 	this.returnCode = null;
 43 	this.version = "1.1";
 44 	this.isNPKD = isNPKD;
 45 }
 46 
 47 
 48 
 49 /**
 50  * Get the return code
 51  *
 52  * @returns the last return code received or null if none defined
 53  * @type String
 54  */
 55 PAConnection.prototype.getReturnCode = function() {
 56 	return this.returnCode;
 57 }
 58 
 59 
 60 
 61 /**
 62  * Sets the version of the WSDL to use
 63  *
 64  * @param {String} version the version to use
 65  */
 66 PAConnection.prototype.setVersion = function(version) {
 67 	this.version = version;
 68 }
 69 
 70 
 71 
 72 /**
 73  * Close the connector and release allocated resources
 74  */
 75 PAConnection.prototype.close = function() {
 76 	this.soapcon.close();
 77 }
 78 
 79 
 80 
 81 /**
 82  * Obtain a defect list from the NPKD
 83  *
 84  * @returns a defect list
 85  * @type ByteString
 86  */
 87 PAConnection.prototype.getDefectList = function() {
 88 
 89 	this.returnCode = null;
 90 
 91 	if (this.isNPKD) {
 92 		var ns = new Namespace("uri:EAC-PKI-CVCA-Protocol/" + this.version);
 93 	} else {
 94 		var ns = new Namespace("uri:EAC-PKI-DV-Protocol/" + this.version);
 95 	}
 96 
 97 	var ns1 = new Namespace("uri:eacBT/" + this.version);
 98 
 99 	var request =
100       <ns:GetDefectList xmlns:ns={ns} xmlns:ns1={ns1}>
101          <callbackIndicator>callback_not_possible</callbackIndicator>
102          <messageID>
103          </messageID>
104          <responseURL>
105          </responseURL>
106       </ns:GetDefectList>;
107 
108 	if (this.verbose) {
109 		GPSystem.trace(request.toXMLString());
110 	}
111 
112 	try	 {
113 		var response = this.soapcon.call(this.url, request);
114 		if (this.verbose) {
115 			GPSystem.trace(response.toXMLString());
116 		}
117 	}
118 	catch(e) {
119 		GPSystem.trace("SOAP call to " + this.url + " failed : " + e);
120 		throw new GPError("PAConnection", GPError.DEVICE_ERROR, 0, "getDefectList failed with : " + e);
121 	}
122 
123 	if (!response.hasOwnProperty("Result")) {
124 		throw new GPError("PAConnection", GPError.DEVICE_ERROR, 0, "Returned SOAP message does not contain expected element Result");
125 	}
126 
127 	this.returnCode = response.Result.ns1::returnCode.toString();
128 	var defectlist = null;
129 	
130 	if (this.returnCode == "ok_list_available") {
131 		defectlist = new ByteString(response.Result.ns1::defectList.ns1::binary.toString(), BASE64);
132 	}
133 	return defectlist;
134 }
135 
136 
137 
138 /**
139  * Obtain a master list from the NPKD
140  *
141  * @returns a masterlist
142  * @type ByteString
143  */
144 PAConnection.prototype.getMasterList = function() {
145 
146 	this.returnCode = null;
147 
148 	if (this.isNPKD) {
149 		var ns = new Namespace("uri:EAC-PKI-CVCA-Protocol/" + this.version);
150 	} else {
151 		var ns = new Namespace("uri:EAC-PKI-DV-Protocol/" + this.version);
152 	}
153 
154 	var ns1 = new Namespace("uri:eacBT/" + this.version);
155 
156 	var request =
157       <ns:GetMasterList xmlns:ns={ns} xmlns:ns1={ns1}>
158          <callbackIndicator>callback_not_possible</callbackIndicator>
159          <messageID>
160          </messageID>
161          <responseURL>
162          </responseURL>
163       </ns:GetMasterList>;
164 
165 	if (this.verbose) {
166 		GPSystem.trace(request.toXMLString());
167 	}
168 
169 	try	 {
170 		var response = this.soapcon.call(this.url, request);
171 		if (this.verbose) {
172 			GPSystem.trace(response.toXMLString());
173 		}
174 	}
175 	catch(e) {
176 		GPSystem.trace("SOAP call to " + this.url + " failed : " + e);
177 		throw new GPError("PAConnection", GPError.DEVICE_ERROR, 0, "getMasterList failed with : " + e);
178 	}
179 	
180 	if (!response.hasOwnProperty("Result")) {
181 		throw new GPError("PAConnection", GPError.DEVICE_ERROR, 0, "Returned SOAP message does not contain expected element Result");
182 	}
183 
184 	this.returnCode = response.Result.ns1::returnCode.toString();
185 	var masterlist = null;
186 	
187 	if (this.returnCode == "ok_list_available") {
188 		masterlist = new ByteString(response.Result.ns1::masterList.ns1::binary.toString(), BASE64);
189 	}
190 
191 	return masterlist;
192 }
193 
194 
195 
196 PAConnection.test = function() {
197 	var c = new PAConnection("http://localhost:8080/se/scs");
198 	c.verbose = true;
199 	var defectlist = c.getDefectList();
200 }
201