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

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: db_x509req.cpp,v 1.24 2003/01/06 19:35:51 chris Exp $
  48.  *
  49.  */                           
  50. #include "db_x509req.h"
  51. db_x509req::db_x509req(DbEnv *dbe, string DBfile, QListView *l, db_key *keyl)
  52. :db_base(dbe, DBfile, "reqdb")
  53. {
  54. listView = l;
  55. keylist = keyl;
  56. loadContainer();
  57. reqicon[0] = loadImg("req.png");
  58.         reqicon[1] = loadImg("reqkey.png");
  59. listView->addColumn(tr("Common Name"));
  60. connect(keyl, SIGNAL(delKey(pki_key *)), this, SLOT(delKey(pki_key *)));
  61. connect(keyl, SIGNAL(newKey(pki_key *)), this, SLOT(newKey(pki_key *)));
  62. updateView();
  63. }
  64. pki_base *db_x509req::newPKI(){
  65. return new pki_x509req();
  66. }
  67. void db_x509req::delKey(pki_key *delkey)
  68. {
  69. pki_x509req *pki;
  70. CERR("delKey in X509req");
  71. if ( container.isEmpty() ) return ;
  72. QListIterator<pki_base> iter(container); 
  73. for ( ; iter.current(); ++iter ) { // find the key of the request
  74. pki = (pki_x509req *)iter.current();
  75. if (pki->getKey() == delkey) {
  76. pki->setKey(NULL);
  77. updateViewPKI(pki);
  78. }
  79. }
  80. }
  81. void db_x509req::newKey(pki_key *newkey)
  82. {
  83. pki_key *refkey;
  84. pki_x509req *pki;
  85. CERR("newKey");
  86. if ( container.isEmpty() ) return ;
  87. QListIterator<pki_base> iter(container); 
  88. for ( ; iter.current(); ++iter ) { // find the key of the request
  89. pki = (pki_x509req *)iter.current();
  90. refkey = pki->getPubKey(); 
  91. if (refkey->compare(newkey)) {
  92. pki->setKey(newkey);
  93. updateViewPKI(pki);
  94. }
  95. }
  96. }
  97. void db_x509req::updateViewPKI(pki_base *pki)
  98. {
  99.         db_base::updateViewPKI(pki);
  100.         if (! pki) return;
  101.         int pixnum = 0;
  102.         QListViewItem *current = (QListViewItem *)pki->getPointer();
  103.         if (!current) return;
  104. if (((pki_x509req *)pki)->getKey() != NULL ) pixnum += 1;
  105. current->setPixmap(0, *reqicon[pixnum]);
  106. current->setText(1, ((pki_x509req *)pki)->getDN(NID_commonName).c_str());
  107. }
  108. void db_x509req::preprocess()
  109. {
  110. pki_x509req *pki;
  111. CERR("preprocess X509req");
  112. if ( container.isEmpty() ) return ;
  113. QListIterator<pki_base> iter(container); 
  114. for ( ; iter.current(); ++iter ) { // find the key of the request
  115. pki = (pki_x509req *)iter.current();
  116. findKey(pki);
  117. CERR("Key of "<< pki->getDescription().c_str());
  118. }
  119. }
  120. pki_key *db_x509req::findKey(pki_x509req *req)
  121. {
  122. pki_key *key, *refkey;
  123. if (!req) return NULL;
  124. MARK
  125. if ((key = req->getKey()) != NULL ) return key;
  126. refkey = req->getPubKey();
  127. key = (pki_key *)keylist->findPKI(refkey);
  128. if (key && key->isPubKey()) {
  129. key = NULL;
  130. }
  131. if (req->setKey(key)) keylist->updateViewPKI(key);
  132. if (refkey) delete(refkey);
  133. return key;
  134. }
  135. void db_x509req::remFromCont(pki_base *pki)
  136. {
  137.         container.remove(pki);
  138. pki_key *pkey = ((pki_x509req *)pki)->getKey();
  139. }