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"
52 int read_privkey_messages =0;
53 RSAKeyStorage RSAKeys ;
55 int read_privkey_verbose(filename,name,uid,uid_len,hashkey,key)
56 char *filename, *name, *hashkey;
61 int save = read_privkey_messages ,x;
62 read_privkey_messages = 1;
63 x=read_privkey (filename,name,uid,uid_len,hashkey,key);
64 read_privkey_messages = save;
68 int read_privkey(filename,name,uid,uid_len,hashkey,key)
69 char *filename, *name, *hashkey;
74 static unsigned char buffer [MAX_KEY];
80 char tempname[80], prompt[80];
82 strcpy(tempname,filename);
83 strcat(tempname,"_privkey");
85 if((fp=fopen(tempname,"r"))==NULL) {
86 if (read_privkey_messages)
87 printf("\n%s: Can't open file %s.\n", __FILE__,tempname);
92 for(i=0,j=0;i<MAX_NAME;i++) {
93 if((c=getc(fp))==EOF) {
94 if (read_privkey_messages)
95 printf("\n%s: Unexpected end of file %s.\n",__FILE__,tempname);
98 switch (*ptr++ = (char) c){
104 case '\n': if(j==0) {ptr--; goto next;}
110 if (read_privkey_messages)
111 printf("\n%s: Issuer name too long.\n", __FILE__);
117 printf("\n%s: issuer name= %s",__FILE__,name);
121 for(i=0;i<MAX_UID;i++)
122 if(fscanf(fp,"%2x",&j)==1) *uptr++ =j; else break;
123 if(i==MAX_UID)return(0);
128 printf("\n%s: uid is ",__FILE__);
132 while(getc(fp)!=';');
133 for(i=0;i<MAX_HASH;i++)
134 if(fscanf(fp,"%2x",&j)==1) hashkey[i]=j ;
137 printf("\n%s: Size of hash: %d\n", __FILE__,i);
141 /* next non-white must be a ';' */
142 do {j=getc(fp);}while(isspace(j));
144 if(read_privkey_messages) printf("\n%s: Hash Overflow.\n",__FILE__);
148 for(i=0;i<MAX_KEY;i++)
149 if(fscanf(fp,"%2x",&j)==1) buffer[i]=j ;
151 if(i==MAX_KEY) return(0);
153 printf("\n%s: Size of private key read: %d\n", __FILE__,i);
156 sprintf(prompt,"\nEnter %s's password: ", filename);
157 if (DES_read_password(&pwkey, prompt, 0) == 0) {
158 if (read_privkey_messages) printf("\n%s, Error entering password.\n",__FILE__);
162 memset(key,0,sizeof(*key));
163 if (recover_private(&pwkey,buffer,i,key)==0) {
164 if (read_privkey_messages) printf("\nError recovering key.\n");
169 printf("\n%s: Recovered Key: \n",__FILE__);