2 * COPYRIGHT (C) 1990 DIGITAL EQUIPMENT CORPORATION
5 * "Digital Equipment Corporation authorizes the reproduction,
6 * distribution and modification of this software subject to the following
9 * 1. Any partial or whole copy of this software, or any modification
10 * thereof, must include this copyright notice in its entirety.
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.
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.
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.
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"
41 #include "read_password.h"
42 #include "bigkeygen.h"
43 #include "bigrsacode.h"
54 static RSAKeyStorage keys ;
55 static RSAKeyStorage public_key ;
56 static RSAKeyStorage private_key ;
62 unsigned char *encodedP ;
63 char usernameBuf [50], uidBuf [50], x500NameBuf[50], hashkey[50];
70 printf("usage: %s name \n", argv[0]);
74 strcpy(usernameBuf, argv[1]);
76 memset(&keys,0,sizeof(keys));
78 if (read_privkey (usernameBuf, x500NameBuf, uidBuf, &uid_len, hashkey, &private_key)) {
79 printf("\nPrivate key read.");
80 PrintTestKey(&private_key);
83 printf("\nPrivate key read failed.\n");
87 if (read_pubkey (usernameBuf, x500NameBuf, uidBuf, &uid_len, &public_key)){
88 printf("\nPublic key read.");
89 PrintTestKey(&public_key);
92 if ((encodedP=EncodePrivateP(&private_key))==0) {
93 printf("\nEncode private key failed.\n");
97 printf("\nEncoded private key (prime P only):\n");
98 dumphex(encodedP,DecodeTotalLength(encodedP));
100 printf("\nDecoding...\n");
102 if ((DecodePrivate(encodedP, &public_key))==0) {
103 printf("\nDecode of private key failed.\n");
107 printf("\nRecovered Private Key:\n");
108 PrintTestKey (&public_key);
118 int read_privkey (filename,name,uid,uid_len,hashkey,key)
119 char *filename, *name, *hashkey;
124 static unsigned char buffer [MAX_KEY];
132 strcpy(tempname,filename);
133 strcat(tempname,"_privkey");
135 if((fp=fopen(tempname,"r"))==NULL) {
136 printf("\nCan't open file %s.\n", tempname);
141 for(i=0,j=0;i<MAX_NAME;i++)
142 switch (*ptr++ =getc(fp)){
144 case '}': j--;if(j==0)goto next;break;
146 printf("\nUnexpected end of file %s.\n",tempname);
152 printf("\nIssuer name too long.\n");
158 printf("\nissuer name= %s",name);
162 for(i=0;i<MAX_UID;i++)
163 if(fscanf(fp,"%2x",&j)==1) *uptr++ =j; else break;
164 if(i==MAX_UID)return(0);
173 while(getc(fp)!=';');
174 for(i=0;i<MAX_HASH;i++)
175 if(fscanf(fp,"%2x",&j)==1) hashkey[i]=j ;
177 if(i==MAX_HASH) return(0);
179 printf("\nSize of hash: %d\n", i);
183 while(getc(fp)!=';');
184 for(i=0;i<MAX_KEY;i++)
185 if(fscanf(fp,"%2x",&j)==1) buffer[i]=j ;
187 if(i==MAX_KEY) return(0);
189 printf("\nSize of private key read: %d\n", i);
193 if (DES_read_password(&pwkey, "\nEnter Password: ", 0) == 0) {
194 printf("\nError entering password.\n");
198 memset(key,0,sizeof(*key));
199 if (recover_private(&pwkey,buffer,i,key)==0) {
200 printf("\nError recovering key.\n");
205 printf("\nRecovered Key: \n");