comparison keyimport.c @ 297:79bf1023cf11 agent-client

propagate from branch 'au.asn.ucc.matt.dropbear' (head 0501e6f661b5415eb76f3b312d183c3adfbfb712) to branch 'au.asn.ucc.matt.dropbear.cli-agent' (head 01038174ec27245b51bd43a66c01ad930880f67b)
author Matt Johnston <matt@ucc.asn.au>
date Tue, 21 Mar 2006 16:20:59 +0000
parents ac890087b8c1
children 740e782679be 454a34b2dfd1
comparison
equal deleted inserted replaced
225:ca7e76d981d9 297:79bf1023cf11
171 len = fwrite(buf_getptr(buf, buf->len - buf->pos), 171 len = fwrite(buf_getptr(buf, buf->len - buf->pos),
172 1, buf->len - buf->pos, fp); 172 1, buf->len - buf->pos, fp);
173 buf_incrpos(buf, len); 173 buf_incrpos(buf, len);
174 } while (len > 0 && buf->len != buf->pos); 174 } while (len > 0 && buf->len != buf->pos);
175 175
176 fclose(fp);
177
176 if (buf->pos != buf->len) { 178 if (buf->pos != buf->len) {
177 ret = 0; 179 ret = 0;
178 } else { 180 } else {
179 ret = 1; 181 ret = 1;
180 } 182 }
201 char out[100]; 203 char out[100];
202 int n; 204 int n;
203 unsigned long outlen; 205 unsigned long outlen;
204 int rawcpl; 206 int rawcpl;
205 rawcpl = cpl * 3 / 4; 207 rawcpl = cpl * 3 / 4;
206 assert((unsigned int)cpl < sizeof(out)); 208 dropbear_assert((unsigned int)cpl < sizeof(out));
207 209
208 while (datalen > 0) { 210 while (datalen > 0) {
209 n = (datalen < rawcpl ? datalen : rawcpl); 211 n = (datalen < rawcpl ? datalen : rawcpl);
210 outlen = sizeof(out); 212 outlen = sizeof(out);
211 base64_encode(data, n, out, &outlen); 213 base64_encode(data, n, out, &outlen);
712 if (key->dsskey != NULL) { 714 if (key->dsskey != NULL) {
713 keytype = DROPBEAR_SIGNKEY_DSS; 715 keytype = DROPBEAR_SIGNKEY_DSS;
714 } 716 }
715 #endif 717 #endif
716 718
717 assert(keytype != -1); 719 dropbear_assert(keytype != -1);
718 720
719 /* 721 /*
720 * Fetch the key blobs. 722 * Fetch the key blobs.
721 */ 723 */
722 keyblob = buf_new(3000); 724 keyblob = buf_new(3000);
911 * plaintext to the next layer: it looks at the final byte, and 913 * plaintext to the next layer: it looks at the final byte, and
912 * then expects to find that many bytes at the end of the data 914 * then expects to find that many bytes at the end of the data
913 * with the same value. Those are all removed and the rest is 915 * with the same value. Those are all removed and the rest is
914 * returned. 916 * returned.
915 */ 917 */
916 assert(pos == len); 918 dropbear_assert(pos == len);
917 while (pos < outlen) { 919 while (pos < outlen) {
918 outblob[pos++] = outlen - len; 920 outblob[pos++] = outlen - len;
919 } 921 }
920 922
921 /* 923 /*
1489 publen = pos; 1491 publen = pos;
1490 pos += put_mp(blob+pos, x.start, x.bytes); 1492 pos += put_mp(blob+pos, x.start, x.bytes);
1491 privlen = pos - publen; 1493 privlen = pos - publen;
1492 } 1494 }
1493 1495
1494 assert(privlen > 0); /* should have bombed by now if not */ 1496 dropbear_assert(privlen > 0); /* should have bombed by now if not */
1495 1497
1496 retkey = snew(struct ssh2_userkey); 1498 retkey = snew(struct ssh2_userkey);
1497 retkey->alg = alg; 1499 retkey->alg = alg;
1498 retkey->data = alg->createkey(blob, publen, blob+publen, privlen); 1500 retkey->data = alg->createkey(blob, publen, blob+publen, privlen);
1499 if (!retkey->data) { 1501 if (!retkey->data) {
1555 pos += ssh2_read_mpint(privblob+pos, privlen-pos, &d); 1557 pos += ssh2_read_mpint(privblob+pos, privlen-pos, &d);
1556 pos += ssh2_read_mpint(privblob+pos, privlen-pos, &p); 1558 pos += ssh2_read_mpint(privblob+pos, privlen-pos, &p);
1557 pos += ssh2_read_mpint(privblob+pos, privlen-pos, &q); 1559 pos += ssh2_read_mpint(privblob+pos, privlen-pos, &q);
1558 pos += ssh2_read_mpint(privblob+pos, privlen-pos, &iqmp); 1560 pos += ssh2_read_mpint(privblob+pos, privlen-pos, &iqmp);
1559 1561
1560 assert(e.start && iqmp.start); /* can't go wrong */ 1562 dropbear_assert(e.start && iqmp.start); /* can't go wrong */
1561 1563
1562 numbers[0] = e; 1564 numbers[0] = e;
1563 numbers[1] = d; 1565 numbers[1] = d;
1564 numbers[2] = n; 1566 numbers[2] = n;
1565 numbers[3] = iqmp; 1567 numbers[3] = iqmp;
1579 pos += ssh2_read_mpint(pubblob+pos, publen-pos, &g); 1581 pos += ssh2_read_mpint(pubblob+pos, publen-pos, &g);
1580 pos += ssh2_read_mpint(pubblob+pos, publen-pos, &y); 1582 pos += ssh2_read_mpint(pubblob+pos, publen-pos, &y);
1581 pos = 0; 1583 pos = 0;
1582 pos += ssh2_read_mpint(privblob+pos, privlen-pos, &x); 1584 pos += ssh2_read_mpint(privblob+pos, privlen-pos, &x);
1583 1585
1584 assert(y.start && x.start); /* can't go wrong */ 1586 dropbear_assert(y.start && x.start); /* can't go wrong */
1585 1587
1586 numbers[0] = p; 1588 numbers[0] = p;
1587 numbers[1] = g; 1589 numbers[1] = g;
1588 numbers[2] = q; 1590 numbers[2] = q;
1589 numbers[3] = y; 1591 numbers[3] = y;
1591 1593
1592 nnumbers = 5; 1594 nnumbers = 5;
1593 initial_zero = 1; 1595 initial_zero = 1;
1594 type = "dl-modp{sign{dsa-nist-sha1},dh{plain}}"; 1596 type = "dl-modp{sign{dsa-nist-sha1},dh{plain}}";
1595 } else { 1597 } else {
1596 assert(0); /* zoinks! */ 1598 dropbear_assert(0); /* zoinks! */
1597 } 1599 }
1598 1600
1599 /* 1601 /*
1600 * Total size of key blob will be somewhere under 512 plus 1602 * Total size of key blob will be somewhere under 512 plus
1601 * combined length of integers. We'll calculate the more 1603 * combined length of integers. We'll calculate the more
1635 while (padding--) 1637 while (padding--)
1636 outblob[pos++] = random_byte(); 1638 outblob[pos++] = random_byte();
1637 } 1639 }
1638 ciphertext = (char *)outblob+lenpos+4; 1640 ciphertext = (char *)outblob+lenpos+4;
1639 cipherlen = pos - (lenpos+4); 1641 cipherlen = pos - (lenpos+4);
1640 assert(!passphrase || cipherlen % 8 == 0); 1642 dropbear_assert(!passphrase || cipherlen % 8 == 0);
1641 /* Wrap up the encrypted blob string. */ 1643 /* Wrap up the encrypted blob string. */
1642 PUT_32BIT(outblob+lenpos, cipherlen); 1644 PUT_32BIT(outblob+lenpos, cipherlen);
1643 /* And finally fill in the total length field. */ 1645 /* And finally fill in the total length field. */
1644 PUT_32BIT(outblob+4, pos); 1646 PUT_32BIT(outblob+4, pos);
1645 1647
1646 assert(pos < outlen); 1648 dropbear_assert(pos < outlen);
1647 1649
1648 /* 1650 /*
1649 * Encrypt the key. 1651 * Encrypt the key.
1650 */ 1652 */
1651 if (passphrase) { 1653 if (passphrase) {