X509skip.C
上传用户:zbbssh
上传日期:2007-01-08
资源大小:196k
文件大小:4k
源码类别:

CA认证

开发平台:

C/C++

  1. /*
  2. ------------------------------------------------------------------
  3.   Copyright
  4.   Sun Microsystems, Inc.
  5.   Copyright (C) 1994, 1995, 1996 Sun Microsystems, Inc.  All Rights
  6.   Reserved.
  7.   Permission is hereby granted, free of charge, to any person
  8.   obtaining a copy of this software and associated documentation
  9.   files (the "Software"), to deal in the Software without
  10.   restriction, including without limitation the rights to use,
  11.   copy, modify, merge, publish, distribute, sublicense, and/or sell
  12.   copies of the Software or derivatives of the Software, and to 
  13.   permit persons to whom the Software or its derivatives is furnished 
  14.   to do so, subject to the following conditions:
  15.   The above copyright notice and this permission notice shall be
  16.   included in all copies or substantial portions of the Software.
  17.   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18.   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  19.   OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20.   NONINFRINGEMENT.  IN NO EVENT SHALL SUN MICROSYSTEMS, INC., BE LIABLE
  21.   FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22.   OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  23.   CONNECTION WITH THE SOFTWARE OR DERIVATES OF THIS SOFTWARE OR 
  24.   THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25.   Except as contained in this notice, the name of Sun Microsystems, Inc.
  26.   shall not be used in advertising or otherwise to promote
  27.   the sale, use or other dealings in this Software or its derivatives 
  28.   without prior written authorization from Sun Microsystems, Inc.
  29. */
  30. #pragma ident "@(#)X509skip.C 1.10 96/01/29 Sun Microsystems"
  31. #include <sys/types.h>
  32. #include "Bstream.h"
  33. #include "Bigint.h"
  34. #include "SkipCert.h"
  35. #include "X509Cert.h"
  36. #include "X509skip.h"
  37. X509SkipCert::skip_params(Bigint &g, Bigint &p)
  38. {
  39. int retval;
  40. if (CertType != SKIP_CERT_X509)
  41. return 1;
  42. PubKey dh_pub_value=getpubkey();
  43.         retval = asn1_der_decode_dh_params(dh_pub_value.keytype.params, p, g);
  44. return retval;
  45. }
  46. Bigint X509SkipCert::skip_pubkey()
  47. {
  48. int retval;
  49. PubKey dh_pub_value=getpubkey();
  50.         Bigint dh_pub_int;
  51. if (CertType != SKIP_CERT_X509)
  52. return Bigint((short)0);
  53.         retval = asn1_der_decode_integer(dh_pub_value.key, dh_pub_int);
  54. if (retval != 0)
  55. return 1;
  56. return dh_pub_int;
  57. }
  58. u_long X509SkipCert::skip_notvalidafter()
  59. {
  60. if (CertType != SKIP_CERT_X509)
  61. return 0;
  62. return getnotafter().ntptime();
  63. }
  64. u_long X509SkipCert::skip_notvalidbefore()
  65. {
  66. if (CertType != SKIP_CERT_X509)
  67. return 0;
  68. return getnotbefore().ntptime();
  69. }
  70. X509SkipCert::decode(Bstream Cert)
  71. {
  72. int retval;
  73. CertType=SKIP_CERT_X509;
  74. validated = 0;
  75. orig=Cert;
  76.         retval = asn1_der_decode_cert(Cert, *this);
  77.         if (retval != SUCCESS)
  78.                 return 1;
  79. return 0;
  80. }
  81. X509SkipCert::isValid(Bstream ca_certstr)
  82. {
  83. PubKey ca_pub_key;
  84. X509SkipCert ca_self_cert;
  85. int retval;
  86. retval=asn1_der_decode_cert(ca_certstr, ca_self_cert);
  87.         ca_pub_key = ca_self_cert.getpubkey();
  88.  
  89.         VerifyResult result = verify(ca_pub_key);
  90.         if (result != VALID) {
  91. validated=0;
  92. return 0;
  93. }
  94. validated=1;
  95.         return 1;
  96. }
  97. Bstream X509SkipCert::skip_name()
  98. {
  99. String ip;
  100. Bstream nullstr;
  101. ip = getsubject().getip();
  102. if (ip.length() == 0) // If not encoded as ip, try cn
  103. ip = getsubject().getcn();
  104.         // We assume that the boxid is the IP Address
  105.  
  106.         // The IPA is a printable hex string OR a dot
  107. // notation IP address. We convert the string
  108. // into its binary representation as a Bstream.
  109. if (CertType != SKIP_CERT_X509)
  110. return nullstr;
  111. return  Bigint_to_Bstr(Bigint((const char *)ip));
  112. }
  113. Bstream X509SkipCert::encode()
  114. {
  115. return orig;
  116. }
  117. void X509SkipCert::print()
  118. {
  119. X509Cert::print();
  120. }