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

CA认证

开发平台:

C/C++

  1. /*
  2.   Copyright (C) 1994, 1995, 1996 Sun Microsystems, Inc.  All Rights
  3.   Reserved.
  4.   Permission is hereby granted, free of charge, to any person
  5.   obtaining a copy of this software and associated documentation
  6.   files (the "Software"), to deal in the Software without
  7.   restriction, including without limitation the rights to use,
  8.   copy, modify, merge, publish, distribute, sublicense, and/or sell
  9.   copies of the Software or derivatives of the Software, and to 
  10.   permit persons to whom the Software or its derivatives is furnished 
  11.   to do so, subject to the following conditions:
  12.   The above copyright notice and this permission notice shall be
  13.   included in all copies or substantial portions of the Software.
  14.   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  15.   EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  16.   OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  17.   NONINFRINGEMENT.  IN NO EVENT SHALL SUN MICROSYSTEMS, INC., BE LIABLE
  18.   FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  19.   OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  20.   CONNECTION WITH THE SOFTWARE OR DERIVATES OF THIS SOFTWARE OR 
  21.   THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  22.   Except as contained in this notice, the name of Sun Microsystems, Inc.
  23.   shall not be used in advertising or otherwise to promote
  24.   the sale, use or other dealings in this Software or its derivatives 
  25.   without prior written authorization from Sun Microsystems, Inc.
  26. */
  27. #pragma ident "@(#)X509toHashCert.C 1.4 96/01/29 Sun Microsystems"
  28. #include <sys/types.h>
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include <unistd.h>
  32. #include <iostream.h>
  33. #include "Bstream.h"
  34. #include "Bigint.h"
  35. #include "SkipCert.h"
  36. #include "HashCert.h"
  37. void usage(){
  38. cerr<<"Usage: X509toHashCert <X509Cert> >outfilen";
  39. exit(1);
  40. }
  41. // Convert an X509 certificate to a HashCert certificate
  42. main(int argc, char *argv[])
  43. {
  44. SkipCert *oldcert;
  45. Bigint g,p;
  46. Bstream pubstr;
  47. Bigint pub;
  48. u_long before, after;
  49. if (argc < 2)  {
  50. usage();
  51. }
  52. Bstream cert = File_to_Bstr(argv[1]);
  53. oldcert = decode_SkipCert(SKIP_CERT_X509,cert);
  54. if (oldcert == NULL) {
  55. fprintf(stderr,"Error decoding certificate");
  56. exit(1);
  57. }
  58. oldcert->skip_params(g,p);
  59. pub=oldcert->skip_pubkey();
  60. before=oldcert->skip_notvalidbefore();
  61. after=oldcert->skip_notvalidafter();
  62. HashCert newcert=HashCert(g, p, pub, before, after);
  63. Bstream newcertstr=newcert.encode();
  64. newcertstr.write(stdout);
  65. }