#include <ctype.h>
#include <tchar.h>
-// FIXME
-#define DEBUG
-#ifdef DEBUG
-void dprintf(char *fmt, ...);
-#define debug(x) (dprintf x)
-#else
-#define debug(x)
-#endif
-
-
#include "ssh.h"
#include "tree234.h"
#endif
/*
+ * Exports from pageantc.c
+ */
+void agent_query(void *in, int inlen, void **out, int *outlen);
+int agent_exists(void);
+
+/*
* We need this to link with the RSA code, because rsaencrypt()
* pads its data with random bytes. Since we only use rsadecrypt()
* and the signing functions, which are deterministic, this should
*/
static int CALLBACK PassphraseProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam) {
- static char *passphrase;
+ static char *passphrase = NULL;
struct PassphraseProcStruct *p;
switch (msg) {
if (p->comment)
SetDlgItemText(hwnd, 101, p->comment);
*passphrase = 0;
+ SetDlgItemText (hwnd, 102, passphrase);
return 0;
case WM_COMMAND:
switch (LOWORD(wParam)) {
EndDialog (hwnd, 0);
return 0;
case 102: /* edit box */
- if (HIWORD(wParam) == EN_CHANGE) {
+ if ((HIWORD(wParam) == EN_CHANGE) && passphrase) {
GetDlgItemText (hwnd, 102, passphrase, PASSPHRASE_MAXLEN-1);
passphrase[PASSPHRASE_MAXLEN-1] = '\0';
}
static void keylist_update(void) {
struct RSAKey *rkey;
struct ssh2_userkey *skey;
- enum234 e;
+ int i;
if (keylist) {
SendDlgItemMessage(keylist, 100, LB_RESETCONTENT, 0, 0);
- for (rkey = first234(rsakeys, &e); rkey; rkey = next234(&e)) {
+ for (i = 0; NULL != (rkey = index234(rsakeys, i)); i++) {
char listentry[512], *p;
/*
* Replace two spaces in the fingerprint with tabs, for
SendDlgItemMessage (keylist, 100, LB_ADDSTRING,
0, (LPARAM)listentry);
}
- for (skey = first234(ssh2keys, &e); skey; skey = next234(&e)) {
+ for (i = 0; NULL != (skey = index234(ssh2keys, i)); i++) {
char listentry[512], *p;
int len;
/*
return;
}
-debug(("ooh %d\n", __LINE__));
if (ver == 1)
needs_pass = rsakey_encrypted(filename, &comment);
else
needs_pass = ssh2_userkey_encrypted(filename, &comment);
-debug(("ooh %d\n", __LINE__));
attempts = 0;
-debug(("ooh %d\n", __LINE__));
if (ver == 1)
rkey = smalloc(sizeof(*rkey));
-debug(("ooh %d\n", __LINE__));
pps.passphrase = passphrase;
pps.comment = comment;
-debug(("ooh %d\n", __LINE__));
do {
-debug(("ooh %d\n", __LINE__));
if (needs_pass) {
int dlgret;
dlgret = DialogBoxParam(instance, MAKEINTRESOURCE(210),
}
} else
*passphrase = '\0';
-debug(("ooh %d\n", __LINE__));
if (ver == 1)
ret = loadrsakey(filename, rkey, passphrase);
else {
-debug(("ooh %d\n", __LINE__));
skey = ssh2_load_userkey(filename, passphrase);
-debug(("ooh %d\n", __LINE__));
if (skey == SSH2_WRONG_PASSPHRASE)
ret = -1;
else if (!skey)
}
attempts++;
} while (ret == -1);
-debug(("ooh %d\n", __LINE__));
if (comment) sfree(comment);
-debug(("ooh %d\n", __LINE__));
if (ret == 0) {
MessageBox(NULL, "Couldn't load private key.", APPNAME,
MB_OK | MB_ICONERROR);
sfree(rkey);
return;
}
-debug(("ooh %d\n", __LINE__));
if (ver == 1) {
if (already_running) {
unsigned char *request, *response;
int reqlen, clen, resplen;
-debug(("ooh %d\n", __LINE__));
clen = strlen(rkey->comment);
-debug(("ooh %d\n", __LINE__));
reqlen = 4 + 1 + /* length, message type */
4 + /* bit count */
ssh1_bignum_length(rkey->q) +
4 + clen /* comment */
;
-debug(("ooh %d %d\n", __LINE__, reqlen));
request = smalloc(reqlen);
-debug(("ooh %d\n", __LINE__));
-debug(("ooh %d\n", __LINE__));
request[4] = SSH1_AGENTC_ADD_RSA_IDENTITY;
-debug(("ooh %d\n", __LINE__));
reqlen = 5;
PUT_32BIT(request+reqlen, bignum_bitcount(rkey->modulus));
reqlen += 4;
reqlen += 4+clen;
PUT_32BIT(request, reqlen-4);
-debug(("ooh %d\n", __LINE__));
agent_query(request, reqlen, &response, &resplen);
-debug(("ooh %d\n", __LINE__));
if (resplen < 5 || response[4] != SSH_AGENT_SUCCESS)
MessageBox(NULL, "The already running Pageant "
"refused to add the key.", APPNAME,
if (already_running) {
unsigned char *request, *response;
int reqlen, alglen, clen, keybloblen, resplen;
-debug(("ooh %d\n", __LINE__));
alglen = strlen(skey->alg->name);
-debug(("ooh %d\n", __LINE__));
clen = strlen(skey->comment);
-debug(("ooh %d\n", __LINE__));
-debug(("ooh %d\n", __LINE__));
keybloblen = skey->alg->openssh_fmtkey(skey->data, NULL, 0);
-debug(("ooh %d\n", __LINE__));
-debug(("ooh %d\n", __LINE__));
reqlen = 4 + 1 + /* length, message type */
4 + alglen + /* algorithm name */
keybloblen + /* key data */
4 + clen /* comment */
;
-debug(("ooh %d\n", __LINE__));
-debug(("ooh %d\n", __LINE__));
request = smalloc(reqlen);
-debug(("ooh %d\n", __LINE__));
request[4] = SSH2_AGENTC_ADD_IDENTITY;
-debug(("ooh %d\n", __LINE__));
reqlen = 5;
-debug(("ooh %d\n", __LINE__));
PUT_32BIT(request+reqlen, alglen);
-debug(("ooh %d\n", __LINE__));
reqlen += 4;
-debug(("ooh %d\n", __LINE__));
memcpy(request+reqlen, skey->alg->name, alglen);
-debug(("ooh %d\n", __LINE__));
reqlen += alglen;
-debug(("ooh %d\n", __LINE__));
reqlen += skey->alg->openssh_fmtkey(skey->data,
request+reqlen, keybloblen);
-debug(("ooh %d\n", __LINE__));
PUT_32BIT(request+reqlen, clen);
-debug(("ooh %d\n", __LINE__));
memcpy(request+reqlen+4, skey->comment, clen);
-debug(("ooh %d\n", __LINE__));
PUT_32BIT(request, reqlen-4);
-debug(("ooh %d\n", __LINE__));
reqlen += clen+4;
agent_query(request, reqlen, &response, &resplen);
-debug(("ooh %d\n", __LINE__));
if (resplen < 5 || response[4] != SSH_AGENT_SUCCESS)
MessageBox(NULL, "The already running Pageant"
"refused to add the key.", APPNAME,
MB_OK | MB_ICONERROR);
-debug(("ooh %d\n", __LINE__));
} else {
if (add234(ssh2keys, skey) != skey) {
skey->alg->freekey(skey->data);
* Reply with SSH1_AGENT_RSA_IDENTITIES_ANSWER.
*/
{
- enum234 e;
struct RSAKey *key;
int len, nkeys;
+ int i;
/*
* Count up the number and length of keys we hold.
*/
len = nkeys = 0;
- for (key = first234(rsakeys, &e); key; key = next234(&e)) {
+ for (i = 0; NULL != (key = index234(rsakeys, i)); i++) {
nkeys++;
len += 4; /* length field */
len += ssh1_bignum_length(key->exponent);
ret[4] = SSH1_AGENT_RSA_IDENTITIES_ANSWER;
PUT_32BIT(ret+5, nkeys);
p = ret + 5 + 4;
- for (key = first234(rsakeys, &e); key; key = next234(&e)) {
+ for (i = 0; NULL != (key = index234(rsakeys, i)); i++) {
PUT_32BIT(p, bignum_bitcount(key->modulus));
p += 4;
p += ssh1_write_bignum(p, key->exponent);
* Reply with SSH2_AGENT_IDENTITIES_ANSWER.
*/
{
- enum234 e;
struct ssh2_userkey *key;
int len, nkeys;
unsigned char *blob;
int bloblen;
+ int i;
/*
* Count up the number and length of keys we hold.
*/
len = nkeys = 0;
- for (key = first234(ssh2keys, &e); key; key = next234(&e)) {
+ for (i = 0; NULL != (key = index234(ssh2keys, i)); i++) {
nkeys++;
len += 4; /* length field */
blob = key->alg->public_blob(key->data, &bloblen);
ret[4] = SSH2_AGENT_IDENTITIES_ANSWER;
PUT_32BIT(ret+5, nkeys);
p = ret + 5 + 4;
- for (key = first234(ssh2keys, &e); key; key = next234(&e)) {
+ for (i = 0; NULL != (key = index234(ssh2keys, i)); i++) {
blob = key->alg->public_blob(key->data, &bloblen);
PUT_32BIT(p, bloblen);
p += 4;
*/
{
struct RSAKey *rkey;
- enum234 e;
- while ( (rkey = first234(rsakeys, &e)) != NULL ) {
+ while ( (rkey = index234(rsakeys, 0)) != NULL ) {
del234(rsakeys, rkey);
freersakey(rkey);
sfree(rkey);
*/
{
struct ssh2_userkey *skey;
- enum234 e;
- while ( (skey = first234(ssh2keys, &e)) != NULL ) {
+ while ( (skey = index234(ssh2keys, 0)) != NULL ) {
del234(ssh2keys, skey);
skey->alg->freekey(skey->data);
sfree(skey);
*/
static int CALLBACK KeyListProc(HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam) {
- enum234 e;
struct RSAKey *rkey;
struct ssh2_userkey *skey;
if (HIWORD(wParam) == BN_CLICKED ||
HIWORD(wParam) == BN_DOUBLECLICKED) {
int n = SendDlgItemMessage (hwnd, 100, LB_GETCURSEL, 0, 0);
+ int i;
if (n == LB_ERR) {
MessageBeep(0);
break;
}
- for (rkey = first234(rsakeys, &e); rkey; rkey = next234(&e))
+ for (i = 0; NULL != (rkey = index234(rsakeys, i)); i++)
if (n-- == 0)
break;
if (rkey) {
freersakey(rkey);
sfree(rkey);
} else {
- for (skey = first234(ssh2keys, &e); skey; skey = next234(&e))
+ for (i = 0; NULL != (skey = index234(ssh2keys, i)); i++)
if (n-- == 0)
break;
if (skey) {
if (mapname[cds->cbData - 1] != '\0')
return 0; /* failure to be ASCIZ! */
#ifdef DEBUG_IPC
- debug(("mapname is :%s:\r\n", mapname));
+ debug(("mapname is :%s:\n", mapname));
#endif
filemap = OpenFileMapping(FILE_MAP_ALL_ACCESS, FALSE, mapname);
#ifdef DEBUG_IPC
- debug(("filemap is %p\r\n", filemap));
+ debug(("filemap is %p\n", filemap));
#endif
if (filemap != NULL && filemap != INVALID_HANDLE_VALUE) {
int rc;
if ((proc = OpenProcess(MAXIMUM_ALLOWED, FALSE,
GetCurrentProcessId())) == NULL) {
#ifdef DEBUG_IPC
- debug(("couldn't get handle for process\r\n"));
+ debug(("couldn't get handle for process\n"));
#endif
return 0;
}
&procowner, NULL, NULL, NULL,
&psd2) != ERROR_SUCCESS) {
#ifdef DEBUG_IPC
- debug(("couldn't get owner info for process\r\n"));
+ debug(("couldn't get owner info for process\n"));
#endif
CloseHandle(proc);
return 0; /* unable to get security info */
&mapowner, NULL, NULL, NULL,
&psd1) != ERROR_SUCCESS)) {
#ifdef DEBUG_IPC
- debug(("couldn't get owner info for filemap: %d\r\n", rc));
+ debug(("couldn't get owner info for filemap: %d\n", rc));
#endif
return 0;
}
#ifdef DEBUG_IPC
- debug(("got security stuff\r\n"));
+ debug(("got security stuff\n"));
#endif
if (!EqualSid(mapowner, procowner))
return 0; /* security ID mismatch! */
#ifdef DEBUG_IPC
- debug(("security stuff matched\r\n"));
+ debug(("security stuff matched\n"));
#endif
LocalFree(psd1);
LocalFree(psd2);
} else {
#ifdef DEBUG_IPC
- debug(("security APIs not present\r\n"));
+ debug(("security APIs not present\n"));
#endif
}
#endif
p = MapViewOfFile(filemap, FILE_MAP_WRITE, 0, 0, 0);
#ifdef DEBUG_IPC
- debug(("p is %p\r\n", p));
- {int i; for(i=0;i<5;i++)debug(("p[%d]=%02x\r\n", i, ((unsigned char *)p)[i]));}
+ debug(("p is %p\n", p));
+ {int i; for(i=0;i<5;i++)debug(("p[%d]=%02x\n", i, ((unsigned char *)p)[i]));}
#endif
answer_msg(p);
ret = 1;
* Find out if Pageant is already running.
*/
already_running = FALSE;
- if (FindWindow("Pageant", "Pageant"))
+ if (agent_exists())
already_running = TRUE;
else {