]> andersk Git - moira.git/blob - util/gdss/lib/crypto/testsignverify.c
initial import of gdss from the Athena source tree
[moira.git] / util / gdss / lib / crypto / testsignverify.c
1 /*
2  * COPYRIGHT (C) 1990 DIGITAL EQUIPMENT CORPORATION
3  * ALL RIGHTS RESERVED
4  *
5  * "Digital Equipment Corporation authorizes the reproduction,
6  * distribution and modification of this software subject to the following
7  * restrictions:
8  * 
9  * 1.  Any partial or whole copy of this software, or any modification
10  * thereof, must include this copyright notice in its entirety.
11  *
12  * 2.  This software is supplied "as is" with no warranty of any kind,
13  * expressed or implied, for any purpose, including any warranty of fitness 
14  * or merchantibility.  DIGITAL assumes no responsibility for the use or
15  * reliability of this software, nor promises to provide any form of 
16  * support for it on any basis.
17  *
18  * 3.  Distribution of this software is authorized only if no profit or
19  * remuneration of any kind is received in exchange for such distribution.
20  * 
21  * 4.  This software produces public key authentication certificates
22  * bearing an expiration date established by DIGITAL and RSA Data
23  * Security, Inc.  It may cease to generate certificates after the expiration
24  * date.  Any modification of this software that changes or defeats
25  * the expiration date or its effect is unauthorized.
26  * 
27  * 5.  Software that will renew or extend the expiration date of
28  * authentication certificates produced by this software may be obtained
29  * from RSA Data Security, Inc., 10 Twin Dolphin Drive, Redwood City, CA
30  * 94065, (415)595-8782, or from DIGITAL"
31  *
32  */
33
34 #include <stdio.h>
35 #include <ctype.h>
36 #include <sys/types.h>
37 #include <time.h>
38
39 #include "bigsignverify.h"
40
41 #define MAX_NAME 80
42 #define MAX_UID 80
43 #define MAX_KEY 2048
44 #define MAX_HASH 16
45
46 #ifdef DEBUG
47 #undef DEBUG
48 #endif
49
50 RSAKeyStorage keys ;
51 RSAKeyStorage public_key ;
52 RSAKeyStorage private_key ;
53 unsigned char bigbuf [2*DigitLim*sizeof(BigNumDigit)];
54 unsigned char testdata[]="Now is the time for all good men to come to the aid";
55
56 main(argc,argv)
57 int     argc;
58 char    **argv;
59 {
60     char usernameBuf [50], uidBuf [50], x500NameBuf[50], hashkey[50];
61     int uid_len;
62     FILE *publ, *priv;
63     DESblock newkey1, newkey2;
64     int bigbuflen;
65     time_t expires1, expires2;
66
67     if (argc < 2)
68     {
69 badargs:
70         printf("usage: %s name \n", argv[0]);
71         exit(1);
72     }
73
74     strcpy(usernameBuf, argv[1]);
75
76     memset(&keys,0,sizeof(keys));
77     
78     if (read_privkey (usernameBuf, x500NameBuf, uidBuf, &uid_len, hashkey, &private_key)) {
79         printf("\nPrivate key read.");
80         PrintTestKey(&private_key);
81     }
82     else {
83         printf("\nUnable to read private key for %s.\n", usernameBuf);
84         exit(0);
85         }
86         
87     if (read_pubkey (usernameBuf, x500NameBuf, uidBuf, &uid_len, &public_key)){
88         printf("\nPublic key read.");
89         PrintTestKey(&public_key);
90     }
91     else {
92         printf("\nUnable to read public key for %s.\n", usernameBuf);
93         exit(0);
94         }
95
96     if(!RSASign(testdata, sizeof(testdata), &private_key, bigbuf, &bigbuflen)) {
97         printf("\nError signing test data.\n");
98         exit(0);
99     }
100
101     printf("\nSigned Data:\n");
102     dumphex(bigbuf, bigbuflen);
103     
104     if(!RSAVerify(testdata, sizeof(testdata), &public_key, bigbuf, bigbuflen)) {
105         printf("\nError verifying signature.\n");
106         exit(0);
107     }
108     printf("\nSignature verifies.\n");
109
110     time(&expires1);
111     printf("\nCurrent time: %s", ctime(&expires1));
112     expires1 += (time_t) 60; /* one minute */
113     
114     InitAuthenticationKey ( &private_key, &public_key, &newkey1, bigbuf, 
115                                 &bigbuflen, expires1);
116     
117     printf("\nNew generated key:\n");
118     dumphex(&newkey1, sizeof(DESblock));
119     printf("\nExpires %s", ctime(&expires1));
120     printf("\nEncrypted key (length %d):\n", bigbuflen);
121     dumphex(bigbuf, bigbuflen);
122
123     if (AcceptAuthenticationKey (&private_key, &newkey2, bigbuf, bigbuflen, &expires2)) {
124         printf("\nRecovered key:\n");
125         dumphex(&newkey1, sizeof(DESblock));
126         printf("\nExpires %s", ctime(&expires2));
127     }
128     else {
129         printf("\nRecovery of key failed.\n");
130     }
131
132 exit(0);
133 }
134
This page took 0.046451 seconds and 5 git commands to generate.