static void setupbigedit2(HWND hwnd, int id, int idstatic, struct ssh2_userkey *key) { unsigned char *pub_blob; char *buffer, *p; int pub_len; int i; pub_blob = key->alg->public_blob(key->data, &pub_len); buffer = smalloc(strlen(key->alg->name) + 4 * ((pub_len + 2) / 3) + strlen(key->comment) + 3); strcpy(buffer, key->alg->name); p = buffer + strlen(buffer); *p++ = ' '; i = 0; while (i < pub_len) { int n = (pub_len - i < 3 ? pub_len - i : 3); base64_encode_atom(pub_blob + i, n, p); i += n; p += 4; } *p++ = ' '; strcpy(p, key->comment); SetDlgItemText(hwnd, id, buffer); SetDlgItemText(hwnd, idstatic, "&Public key for pasting into " "OpenSSH authorized_keys2 file:"); sfree(pub_blob); sfree(buffer); }
//--------------------------------------------------------------------------- AnsiString __fastcall TKeyGenerator::GetPublicKey() { if (FPublicKey.IsEmpty()) { unsigned char *pub_blob; char *buffer, *p; int pub_len; int i; DebugAssert(FSSH2Key); pub_blob = FSSH2Key->alg->public_blob(FSSH2Key->data, &pub_len); buffer = new char[4 * ((pub_len + 2) / 3) + 1]; p = buffer; i = 0; while (i < pub_len) { int n = (pub_len - i < 3 ? pub_len - i : 3); base64_encode_atom(pub_blob + i, n, p); i += n; p += 4; } *p = '\0'; FPublicKey = buffer; sfree(pub_blob); delete [] buffer; } return FPublicKey; }
int proxy_http_negotiate (ProxySocket *p, int change) { if (p->state == PROXY_STATE_NEW) { /* we are just beginning the proxy negotiate process, * so we'll send off the initial bits of the request. * for this proxy method, it's just a simple HTTP * request */ char *buf, dest[512]; char *username, *password; sk_getaddr(p->remote_addr, dest, lenof(dest)); buf = dupprintf("CONNECT %s:%i HTTP/1.1\r\nHost: %s:%i\r\n", dest, p->remote_port, dest, p->remote_port); sk_write(p->sub_socket, buf, strlen(buf)); sfree(buf); username = conf_get_str(p->conf, CONF_proxy_username); password = conf_get_str(p->conf, CONF_proxy_password); if (username[0] || password[0]) { char *buf, *buf2; int i, j, len; buf = dupprintf("%s:%s", username, password); len = strlen(buf); buf2 = snewn(len * 4 / 3 + 100, char); sprintf(buf2, "Proxy-Authorization: Basic "); for (i = 0, j = strlen(buf2); i < len; i += 3, j += 4) base64_encode_atom((unsigned char *)(buf+i), (len-i > 3 ? 3 : len-i), buf2+j); strcpy(buf2+j, "\r\n"); sk_write(p->sub_socket, buf2, strlen(buf2)); sfree(buf); sfree(buf2); }
static int save_ssh2_pubkey(char *filename, char *comment, void *v_pub_blob, int pub_len) { unsigned char *pub_blob = (unsigned char *)v_pub_blob; char *p; int i, column; FILE *fp; if (filename) { fp = fopen(filename, "wb"); if (!fp) return 0; } else fp = stdout; fprintf(fp, "---- BEGIN SSH2 PUBLIC KEY ----\n"); if (comment) { fprintf(fp, "Comment: \""); for (p = comment; *p; p++) { if (*p == '\\' || *p == '\"') fputc('\\', fp); fputc(*p, fp); } fprintf(fp, "\"\n"); } i = 0; column = 0; while (i < pub_len) { char buf[5]; int n = (pub_len - i < 3 ? pub_len - i : 3); base64_encode_atom(pub_blob + i, n, buf); i += n; buf[4] = '\0'; fputs(buf, fp); if (++column >= 16) { fputc('\n', fp); column = 0; } } if (column > 0) fputc('\n', fp); fprintf(fp, "---- END SSH2 PUBLIC KEY ----\n"); if (filename) fclose(fp); return 1; }
static int save_ssh2_pubkey(char *filename, struct ssh2_userkey *key) { unsigned char *pub_blob; char *p; int pub_len; int i, column; FILE *fp; pub_blob = key->alg->public_blob(key->data, &pub_len); fp = fopen(filename, "wb"); if (!fp) return 0; fprintf(fp, "---- BEGIN SSH2 PUBLIC KEY ----\n"); fprintf(fp, "Comment: \""); for (p = key->comment; *p; p++) { if (*p == '\\' || *p == '\"') fputc('\\', fp); fputc(*p, fp); } fprintf(fp, "\"\n"); i = 0; column = 0; while (i < pub_len) { char buf[5]; int n = (pub_len - i < 3 ? pub_len - i : 3); base64_encode_atom(pub_blob + i, n, buf); i += n; buf[4] = '\0'; fputs(buf, fp); if (++column >= 16) { fputc('\n', fp); column = 0; } } if (column > 0) fputc('\n', fp); fprintf(fp, "---- END SSH2 PUBLIC KEY ----\n"); fclose(fp); sfree(pub_blob); return 1; }
char *sc_base64key(char *data, int len) { int bi, bn; char out[4]; int datalen = len; char *buffi = calloc(len + len, sizeof(char *)); int buffi_pos = 0; for(bi=0;bi<(len + len); bi++) buffi[bi] = '\0'; while (datalen > 0) { bn = (datalen < 3 ? datalen : 3); base64_encode_atom(data, bn, out); data += bn; datalen -= bn; for (bi = 0; bi < 4; bi++) { buffi[buffi_pos] = out[bi]; buffi_pos++; } } return buffi; }