pki_temp.cpp
上传用户:stc1860
上传日期:2007-01-12
资源大小:234k
文件大小:7k
源码类别:

CA认证

开发平台:

MultiPlatform

  1. /*
  2.  * Copyright (C) 2001 Christian Hohnstaedt.
  3.  *
  4.  *  All rights reserved.
  5.  *
  6.  *
  7.  *  Redistribution and use in source and binary forms, with or without 
  8.  *  modification, are permitted provided that the following conditions are met:
  9.  *
  10.  *  - Redistributions of source code must retain the above copyright notice,
  11.  *    this list of conditions and the following disclaimer.
  12.  *  - Redistributions in binary form must reproduce the above copyright notice,
  13.  *    this list of conditions and the following disclaimer in the documentation
  14.  *    and/or other materials provided with the distribution.
  15.  *  - Neither the name of the author nor the names of its contributors may be 
  16.  *    used to endorse or promote products derived from this software without
  17.  *    specific prior written permission.
  18.  *
  19.  *
  20.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21.  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  22.  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  23.  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  24.  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  25.  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  26.  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  27.  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  28.  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  29.  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  30.  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31.  *
  32.  *
  33.  * This program links to software with different licenses from:
  34.  *
  35.  * http://www.openssl.org which includes cryptographic software
  36.  *  written by Eric Young (eay@cryptsoft.com)"
  37.  *
  38.  * http://www.sleepycat.com
  39.  *
  40.  * http://www.trolltech.com
  41.  * 
  42.  *
  43.  *
  44.  * http://www.hohnstaedt.de/xca
  45.  * email: christian@hohnstaedt.de
  46.  *
  47.  * $Id: pki_temp.cpp,v 1.14 2003/01/06 19:35:51 chris Exp $
  48.  *
  49.  */                           
  50. #include "pki_temp.h"
  51. pki_temp::pki_temp(const pki_temp *pk) 
  52. :pki_base(pk->desc)
  53. {
  54. version=pk->version;
  55. type=pk->type;
  56. C=pk->C;
  57. P=pk->P;
  58. L=pk->L;
  59. O=pk->O;
  60. OU=pk->OU;
  61. CN=pk->CN;
  62. EMAIL=pk->EMAIL;
  63. subAltName=pk->subAltName;
  64. issAltName=pk->issAltName;
  65. crlDist=pk->crlDist;
  66. nsCertType=pk->nsCertType;
  67. nsComment=pk->nsComment;
  68. nsBaseUrl=pk->nsBaseUrl;
  69. nsRevocationUrl=pk->nsRevocationUrl;
  70. nsCARevocationUrl=pk->nsCARevocationUrl;
  71. nsRenewalUrl=pk->nsRenewalUrl;
  72. nsCaPolicyUrl=pk->nsCaPolicyUrl;
  73. nsSslServerName=pk->nsSslServerName;
  74. ca=pk->ca;
  75. bcCrit=pk->bcCrit;
  76. keyUseCrit=pk->keyUseCrit;
  77. eKeyUseCrit=pk->eKeyUseCrit;
  78. subKey=pk->subKey;
  79. authKey=pk->authKey;
  80. subAltCp=pk->subAltCp;
  81. issAltCp=pk->issAltCp;
  82. pathLen=pk->pathLen;
  83. validN=pk->validN;
  84. validM=pk->validM;
  85. keyUse=pk->keyUse;
  86. eKeyUse=pk->eKeyUse;
  87. }
  88. pki_temp::pki_temp(const string d, int atype)
  89. :pki_base(d)
  90. version=1;
  91. type=atype;
  92. C="";
  93. P="";
  94. L="";
  95. O="";
  96. OU="";
  97. CN="";
  98. EMAIL="";
  99. subAltName="";
  100. issAltName="";
  101. crlDist="";
  102. nsCertType=0;
  103. nsComment="xca certificate";
  104. nsBaseUrl="";
  105. nsRevocationUrl="";
  106. nsCARevocationUrl="";
  107. nsRenewalUrl="";
  108. nsCaPolicyUrl="";
  109. nsSslServerName="";
  110. ca=false;
  111. bcCrit=false;
  112. keyUseCrit=false;
  113. eKeyUseCrit=false;
  114. subKey=false;
  115. authKey=false;
  116. subAltCp=false;
  117. issAltCp=false;
  118. pathLen=0;
  119. validN=365;
  120. validM=0;
  121. keyUse=0;
  122. eKeyUse=0;
  123. if (type==tCA) {
  124. ca=true;
  125. bcCrit=true;
  126. subKey=true;
  127. authKey=true;
  128. issAltCp=false;
  129. nsCertType=112;
  130. keyUse=96;
  131. }
  132. if (type==tCLIENT) {
  133. ca=false;
  134. bcCrit=true;
  135. authKey=true;
  136. issAltCp=true;
  137. subAltCp=true;
  138. nsCertType=5;
  139. keyUse=13;
  140. }
  141. if (type==tSERVER) {
  142. ca=false;
  143. bcCrit=true;
  144. authKey=true;
  145. issAltCp=true;
  146. subAltCp=true;
  147. nsCertType=2;
  148. keyUse=7;
  149. }
  150. }
  151. void pki_temp::fromData(unsigned char *p, int size )
  152. {
  153. CERR("Temp fromData");
  154. unsigned char *p1 = p;
  155. version=intFromData(&p1);
  156. type=intFromData(&p1);
  157. ca=boolFromData(&p1);
  158. bcCrit=boolFromData(&p1);
  159. keyUseCrit=boolFromData(&p1);
  160. eKeyUseCrit=boolFromData(&p1);
  161. subKey=boolFromData(&p1);
  162. authKey=boolFromData(&p1);
  163. subAltCp=boolFromData(&p1);
  164. issAltCp=boolFromData(&p1);
  165. pathLen=intFromData(&p1);
  166. validN=intFromData(&p1);
  167. validM=intFromData(&p1);
  168. keyUse=intFromData(&p1);
  169. eKeyUse=intFromData(&p1);
  170. nsCertType=intFromData(&p1);
  171. C=stringFromData(&p1);
  172. P=stringFromData(&p1);
  173. L=stringFromData(&p1);
  174. O=stringFromData(&p1);
  175. OU=stringFromData(&p1);
  176. CN=stringFromData(&p1);
  177. EMAIL=stringFromData(&p1);
  178. subAltName=stringFromData(&p1);
  179. issAltName=stringFromData(&p1);
  180. crlDist=stringFromData(&p1);
  181. nsComment=stringFromData(&p1);
  182. nsBaseUrl=stringFromData(&p1);
  183. nsRevocationUrl=stringFromData(&p1);
  184. nsCARevocationUrl=stringFromData(&p1);
  185. nsRenewalUrl=stringFromData(&p1);
  186. nsCaPolicyUrl=stringFromData(&p1);
  187. nsSslServerName=stringFromData(&p1);
  188. //next version:
  189. //if (version == 2) { ..... }
  190. if (p1-p != size) {
  191. CERR( "AAAAarrrrgghhhhh wrong tempsize..." << (p1-p) << " - " <<size );
  192. openssl_error("Wrong Size");
  193. }
  194. }
  195. unsigned char *pki_temp::toData(int *size) 
  196. {
  197. CERR("temp toData " << getDescription() );
  198. unsigned char *p, *p1;
  199. *size = dataSize();
  200. p = (unsigned char*)OPENSSL_malloc(*size);
  201. p1 = p;
  202. intToData(&p1, version);
  203. intToData(&p1, type);
  204. boolToData(&p1, ca);
  205. boolToData(&p1, bcCrit);
  206. boolToData(&p1, keyUseCrit);
  207. boolToData(&p1, eKeyUseCrit);
  208. boolToData(&p1, subKey);
  209. boolToData(&p1, authKey);
  210. boolToData(&p1, subAltCp);
  211. boolToData(&p1, issAltCp);
  212. intToData(&p1, pathLen);
  213. intToData(&p1, validN);
  214. intToData(&p1, validM);
  215. intToData(&p1, keyUse);
  216. intToData(&p1, eKeyUse);
  217. intToData(&p1, nsCertType);
  218. stringToData(&p1, C);
  219. stringToData(&p1, P);
  220. stringToData(&p1, L);
  221. stringToData(&p1, O);
  222. stringToData(&p1, OU);
  223. stringToData(&p1, CN);
  224. stringToData(&p1, EMAIL);
  225. stringToData(&p1, subAltName);
  226. stringToData(&p1, issAltName);
  227. stringToData(&p1, crlDist);
  228. stringToData(&p1, nsComment);
  229. stringToData(&p1, nsBaseUrl);
  230. stringToData(&p1, nsRevocationUrl);
  231. stringToData(&p1, nsCARevocationUrl);
  232. stringToData(&p1, nsRenewalUrl);
  233. stringToData(&p1, nsCaPolicyUrl);
  234. stringToData(&p1, nsSslServerName);
  235. CERR( "Temp toData end ..."<< (p1-p) << " - "<<*size );
  236. return p;
  237. }
  238. pki_temp::~pki_temp()
  239. {
  240. }
  241. int pki_temp::dataSize()
  242. {
  243. return 8 * sizeof(int) + 8 * sizeof(bool) + (
  244. C.length() +
  245. P.length() +
  246. L.length() +
  247. O.length() +
  248. OU.length() +
  249. CN.length() +
  250. EMAIL.length() +
  251. subAltName.length() +
  252. issAltName.length() +
  253. crlDist.length() +
  254. nsComment.length() +
  255. nsBaseUrl.length() +
  256. nsRevocationUrl.length() +
  257. nsCARevocationUrl.length() +
  258. nsRenewalUrl.length() +
  259. nsCaPolicyUrl.length() +
  260. nsSslServerName.length() +
  261. 17 ) * sizeof(char);
  262. }
  263. bool pki_temp::compare(pki_base *ref)
  264. {
  265.  // we don't care if templates with identical contents
  266.  // are stored in the database ...
  267. return false;
  268. }