home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
High Voltage Shareware
/
high1.zip
/
high1
/
DIR4
/
SECDRV12.ZIP
/
LOGIN.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-01-07
|
6KB
|
249 lines
/* Secure Drive LOGIN V1.2 */
/* Logs into encrypted disks */
#include "secdrv.h"
extern char pass1[MAXPASS];
extern char pass2[MAXPASS];
int setenv(char*,char *);
void clrbufs(void);
char *pgpv;
void main(int argc,char *argv[])
{
unsigned drive,firstcyl,firsthead,maxcyl;
unsigned maxhead,maxsector,secsize,i;
unsigned safemode=FALSE;
unsigned pgpsw=FALSE;
unsigned char buf[512],key[16],check[4];
word16 expkey[52];
unsigned serial[2];
unsigned char *p;
if(argc==1)
{
printf("\n\
Secure Drive Login Version 1.2\n\
This program sets parameters and loads passphrases for encrypted\
drives.\n\n\
LOGIN /F [/PGP] to enter floppy disk passphrase\n\
[use/set PGPPASS]\n\
\n\
LOGIN /C [/PGP] to erase keys and disable encryption\n\
[clear PGPPASS]\n\
\n\
LOGIN drive letter [/PGP] to activate an encrypted hard drive\n\
[use/set PGPPASS]\n\
LOGIN D: (example)\n\
LOGIN D: /S to prevent accidental access to an\n\
encrypted drive without logging in\n\
\n\
LOGIN /PGP to set PGPPASS environment variable\n\
\n\
LOGIN drive cylinder head to manually enter parameters for\n\
a hard drive partition\n\
LOGIN drive cylinder head /S to prevent accidental access\n\
LOGIN 0 100 1 (example)\n\
drives are numbered from zero\n\n");
exit(1);
}
if(!(cryptdata=gettsradr()))
{
printf("\nError: Secure Drive TSR not loaded.\n");
exit(1);
}
for (i=1;i<argc;i++)
{
if (stricmp(argv[i],"/PGP") == 0)
{
pgpsw=TRUE;
pgpv=getenv("PGPPASS");
break;
}
}
if (argc == 2 && pgpsw)
{
printf("\nEnter PGPPASS passphrase for PGP Secret Key: ");
invgets(pass1);
if (setenv("PGPPASS",pass1) == 0)
{
printf("PGPPASS set. \n");
clrbufs();
exit(0);
}
else
{
printf("PGPPASS not set. \n");
clrbufs();
exit(1);
}
}
if((*argv[1]=='/')&&(toupper(*(argv[1]+1))=='C'))
{
cryptdata->hd.active=0;
for(i=0;i<104;i++)
{
cryptdata->fkey[i]=0xaa;
cryptdata->hkey[i]=0xbb;
}
for(i=0;i<4;i++)
cryptdata->fkeychk[i]=0x0ff;
bdos(0x0D, 0, 0); /* Reset Disk Subsystem - Flush all buffers */
printf("\nClearing free memory...");
while ((p=malloc(1024)) != NULL)
{
memset(p,0,1024);
}
while ((p=malloc(8)) != NULL)
{
memset(p,0,8);
}
printf("\nAll keys erased. System secured.\n");
if (pgpsw && pgpv != NULL)
{
for (i=0;i<strlen(pgpv);i++)
pass1[i]='x';
pass1[i]=0;
setenv("PGPPASS",pass1);
setenv("PGPPASS","");
printf("PGPPASS removed from environment\n");
}
clrbufs();
exit(0);
}
else if((*argv[1]=='/')&&(toupper(*(argv[1]+1))=='F'))
{
if (pgpsw && pgpv != NULL)
{
printf("\nPGPPASS entered as floppy disk passphrase\n");
strcpy(pass1,pgpv);
setkey(key,check);
}
else
{
printf("\nEnter floppy disk passphrase: ");
getkey(key,check,FALSE);
}
en_key_idea((word16 *) key,expkey);
memcpy(cryptdata->fkey,expkey,104);
memcpy(cryptdata->fkeychk,check,4);
cryptdata->fda.firstcyl=0;
cryptdata->fdb.firstcyl=0;
printf("\nFloppy disk encryption enabled.\n");
if (pgpsw && pgpv == NULL && setenv("PGPPASS",pass1) == 0)
printf("PGPPASS set. \n");
bdos(0x0D, 0, 0); /* Reset Disk Subsystem - Flush all buffers */
clrbufs();
exit(0);
}
else if(isalpha(*argv[1])) {
char drvltr=toupper(*argv[1]);
drive=255;
readptbl(0,0,0,drvltr,&drive,&firsthead,&firstcyl);
if(drive==255) {
printf("\nDrive not found.\n");
exit(1); }
if((*argv[2]=='/')&&(toupper(*(argv[2]+1))=='S'))
safemode=TRUE;
printf("\nDrive %c is physical hard drive %u, head %u,\
cylinder %u\n",drvltr,drive,firsthead,firstcyl); }
else {
i=sscanf(argv[1],"%u",&drive);
i=i&&sscanf(argv[2],"%u",&firstcyl);
i=i&&sscanf(argv[3],"%u",&firsthead);
if((*argv[4]=='/')&&(toupper(*(argv[4]+1))=='S'))
safemode=TRUE;
if(!i) {
printf("\nIncorrect drive, cyl, or head input.\n\
Run without a command line for help.\n");
exit(1); }
}
drive+=0x80;
readsec(drive,firsthead,firstcyl,1,1,buf);
if((buf[510]!=0x55)||(buf[511]!=0xaa)) {
printf("\nThis is not a boot sector.\n");
exit(1); }
calcdiskparams(buf,&maxcyl,&maxhead,&maxsector,
&secsize,serial);
printf("\nThis disk has: %i cyls, %i sectors, %i heads, sector \
size %i bytes\n",maxcyl+1,maxsector,maxhead,secsize);
if(memcmp("CRYP",buf+3,4)) {
printf("\nThis disk is not encrypted.\n");
exit(1); }
if(!safemode)
{
if (pgpsw && pgpv != NULL)
{
strcpy(pass1,pgpv);
setkey(key,check);
if(memcmp(check,buf+7,4))
{
printf("\nPGPPASS is wrong passphrase.\n");
printf("\nEnter hard disk passphrase: ");
getkey(key,check,FALSE);
}
else
printf("\nPGPPASS entered as hard disk passphrase.\n");
}
else
{
printf("\nEnter hard disk passphrase: ");
getkey(key,check,FALSE);
}
if(memcmp(check,buf+7,4))
{
printf("\nWrong passphrase.\n");
exit(1);
}
en_key_idea((word16 *)key,expkey);
memcpy(cryptdata->hkey,expkey,104);
}
cryptdata->hdnum=drive;
cryptdata->hd.firstcyl=firstcyl;
cryptdata->hd.firsthd=firsthead;
cryptdata->hd.firstsec=1;
cryptdata->hd.lastcyl=firstcyl+maxcyl;
cryptdata->hd.maxsec=maxsector;
cryptdata->hd.maxhd=maxhead;
cryptdata->hd.secsize=secsize;
cryptdata->hdnum=drive;
if(!safemode)
{
cryptdata->hd.serial[0]=serial[0];
cryptdata->hd.serial[1]=serial[1];
cryptdata->hd.active=1;
printf("\nHard disk encryption enabled.\n");
if (pgpsw && pgpv == NULL && setenv("PGPPASS",pass1) == 0)
printf("PGPPASS set. \n");
}
else
printf("\nHard disk set to safe mode.\n");
for(i=0;i<16;i++) key[i]='\0';
for(i=0;i<52;i++) expkey[i]=0;
bdos(0x0D, 0, 0); /* Reset Disk Subsystem - Flush all buffers */
clrbufs();
exit(0);
}