userfuncs.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 "@(#)userfuncs.C 1.9 96/01/29 Sun Microsystems"
  31. #include <sys/types.h>
  32. #include <stdio.h>
  33. #include <stdlib.h>
  34. #include "Time.h"
  35. #include "Bigint.h"
  36. #include "Bstream.h"
  37. #include "asn1_der.h"
  38. #include "ObjId.h"
  39. #include "Name.h"
  40. #include "X509Cert.h"
  41. #include "Sig.h"
  42. #include "ca.h"
  43. #include "userfuncs.h"
  44. Boolean  camode = FALSE;
  45. //
  46. // Fetch the user's certificate
  47. //
  48. X509Cert
  49. getUserCert()
  50. {
  51. X509Cert cert;
  52. Bstream nullstr;
  53. String certfile;
  54. if (camode == TRUE) {
  55. String cahomedir;
  56. char *cahptr = getenv("CA_HOME");
  57. if (cahptr == NULL) {
  58. cahomedir = ".";
  59. } else {
  60.      cahomedir = (String)cahptr;
  61. }
  62. certfile = cahomedir + DIR_MARKER + CA_CERT_FILE;
  63. } else {
  64. String homedir = (String)getenv("HOME");
  65. certfile = homedir + DIR_MARKER + SECURITY_DIR + 
  66. DIR_MARKER + CA_CERT_FILE;
  67. }
  68. Bstream certstr = File_to_Bstr(certfile);
  69. if (certstr == nullstr)
  70. return cert;
  71. int retval = asn1_der_decode_cert(certstr, cert);
  72. if (retval < 0) {
  73. fprintf(stderr, "Unable to decode user certificate %sn",
  74.  (const char *)certfile);
  75. asn1_perror(retval);
  76. }
  77. return (cert);
  78. }
  79. #ifdef RW
  80. #define LLtype RWTValDlist<X509Cert>
  81. #else
  82. #ifdef LIBG
  83. #define LLtype SLList<X509Cert>
  84. #endif
  85. #endif
  86. #if 0 /* CHECK THIS */
  87. LLtype getUserIssuers()
  88. {
  89. #define MAX_ISSUERS 100
  90. LLtype  issuers;
  91. char buf[10];
  92. Bstream nullstr;
  93. String issuerdir;
  94. if (camode == TRUE) {
  95. String cahomedir;
  96. char *cahptr = getenv("CA_HOME");
  97. if (cahptr == NULL) {
  98. cahomedir = ".";
  99. } else {
  100.      cahomedir = (String)cahptr;
  101. }
  102. issuerdir = cahomedir + DIR_MARKER + "issuers" + DIR_MARKER;
  103. } else {
  104. String homedir = (String)getenv("HOME");
  105. issuerdir = homedir + DIR_MARKER + SECURITY_DIR + 
  106. DIR_MARKER + USER_ISSUER_DIR + DIR_MARKER;
  107. }
  108. for (int i=0; i < MAX_ISSUERS; i++) {
  109. X509Cert cert;
  110. bzero(buf, sizeof(buf));
  111. sprintf(buf, "%d", i);
  112. String certfile = issuerdir + buf;
  113. Bstream certstr = File_to_Bstr(certfile);
  114. if (certstr == nullstr)
  115. break;
  116. int retval = asn1_der_decode_cert(certstr, cert);
  117. if (retval < 0) {
  118. fprintf(stderr, 
  119. "Unable to decode user certificate %sn",
  120.  (const char *)certfile);
  121. asn1_perror(retval);
  122. }
  123. #ifdef RW
  124. issuers.insert(cert);
  125. #else
  126. #ifdef LIBG
  127. issuers.append(cert);
  128. #endif
  129. #endif
  130. }
  131. return issuers;
  132. }
  133. #endif