Mercurial > dropbear
comparison keyimport.c @ 1307:ad9c40aca3bc
add length checks for ecc too
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Tue, 12 Jul 2016 23:28:42 +0800 |
parents | 34e6127ef02e |
children | 8678e2cc1e53 |
comparison
equal
deleted
inserted
replaced
1306:34e6127ef02e | 1307:ad9c40aca3bc |
---|---|
269 sourcelen -= n; | 269 sourcelen -= n; |
270 *length = toint(len); | 270 *length = toint(len); |
271 } else { | 271 } else { |
272 *length = *p; | 272 *length = *p; |
273 p++, sourcelen--; | 273 p++, sourcelen--; |
274 } | |
275 | |
276 if (*length < 0) { | |
277 printf("Negative ASN.1 length\n"); | |
278 return -1; | |
274 } | 279 } |
275 | 280 |
276 return p - (unsigned char *) source; | 281 return p - (unsigned char *) source; |
277 } | 282 } |
278 | 283 |
585 /* Expect the SEQUENCE header. Take its absence as a failure to decrypt. */ | 590 /* Expect the SEQUENCE header. Take its absence as a failure to decrypt. */ |
586 ret = ber_read_id_len(p, key->keyblob_len, &id, &len, &flags); | 591 ret = ber_read_id_len(p, key->keyblob_len, &id, &len, &flags); |
587 p += ret; | 592 p += ret; |
588 if (ret < 0 || id != 16 || len < 0 || | 593 if (ret < 0 || id != 16 || len < 0 || |
589 key->keyblob+key->keyblob_len-p < len) { | 594 key->keyblob+key->keyblob_len-p < len) { |
590 errmsg = "ASN.1 decoding failure - wrong password?"; | 595 errmsg = "ASN.1 decoding failure"; |
591 goto error; | 596 goto error; |
592 } | 597 } |
593 | 598 |
594 /* Expect a load of INTEGERs. */ | 599 /* Expect a load of INTEGERs. */ |
595 if (key->type == OSSH_RSA) | 600 if (key->type == OSSH_RSA) |
685 /* privateKey OCTET STRING, */ | 690 /* privateKey OCTET STRING, */ |
686 ret = ber_read_id_len(p, key->keyblob+key->keyblob_len-p, | 691 ret = ber_read_id_len(p, key->keyblob+key->keyblob_len-p, |
687 &id, &len, &flags); | 692 &id, &len, &flags); |
688 p += ret; | 693 p += ret; |
689 /* id==4 for octet string */ | 694 /* id==4 for octet string */ |
690 if (ret < 0 || id != 4 || | 695 if (ret < 0 || id != 4 || len < 0 || |
691 key->keyblob+key->keyblob_len-p < len) { | 696 key->keyblob+key->keyblob_len-p < len) { |
692 errmsg = "ASN.1 decoding failure"; | 697 errmsg = "ASN.1 decoding failure"; |
693 goto error; | 698 goto error; |
694 } | 699 } |
695 private_key_bytes = p; | 700 private_key_bytes = p; |
699 /* parameters [0] ECDomainParameters {{ SECGCurveNames }} OPTIONAL, */ | 704 /* parameters [0] ECDomainParameters {{ SECGCurveNames }} OPTIONAL, */ |
700 ret = ber_read_id_len(p, key->keyblob+key->keyblob_len-p, | 705 ret = ber_read_id_len(p, key->keyblob+key->keyblob_len-p, |
701 &id, &len, &flags); | 706 &id, &len, &flags); |
702 p += ret; | 707 p += ret; |
703 /* id==0 */ | 708 /* id==0 */ |
704 if (ret < 0 || id != 0) { | 709 if (ret < 0 || id != 0 || len < 0) { |
705 errmsg = "ASN.1 decoding failure"; | 710 errmsg = "ASN.1 decoding failure"; |
706 goto error; | 711 goto error; |
707 } | 712 } |
708 | 713 |
709 ret = ber_read_id_len(p, key->keyblob+key->keyblob_len-p, | 714 ret = ber_read_id_len(p, key->keyblob+key->keyblob_len-p, |
710 &id, &len, &flags); | 715 &id, &len, &flags); |
711 p += ret; | 716 p += ret; |
712 /* id==6 for object */ | 717 /* id==6 for object */ |
713 if (ret < 0 || id != 6 || | 718 if (ret < 0 || id != 6 || len < 0 || |
714 key->keyblob+key->keyblob_len-p < len) { | 719 key->keyblob+key->keyblob_len-p < len) { |
715 errmsg = "ASN.1 decoding failure"; | 720 errmsg = "ASN.1 decoding failure"; |
716 goto error; | 721 goto error; |
717 } | 722 } |
718 | 723 |
747 /* publicKey [1] BIT STRING OPTIONAL */ | 752 /* publicKey [1] BIT STRING OPTIONAL */ |
748 ret = ber_read_id_len(p, key->keyblob+key->keyblob_len-p, | 753 ret = ber_read_id_len(p, key->keyblob+key->keyblob_len-p, |
749 &id, &len, &flags); | 754 &id, &len, &flags); |
750 p += ret; | 755 p += ret; |
751 /* id==1 */ | 756 /* id==1 */ |
752 if (ret < 0 || id != 1) { | 757 if (ret < 0 || id != 1 || len < 0) { |
753 errmsg = "ASN.1 decoding failure"; | 758 errmsg = "ASN.1 decoding failure"; |
754 goto error; | 759 goto error; |
755 } | 760 } |
756 | 761 |
757 ret = ber_read_id_len(p, key->keyblob+key->keyblob_len-p, | 762 ret = ber_read_id_len(p, key->keyblob+key->keyblob_len-p, |
758 &id, &len, &flags); | 763 &id, &len, &flags); |
759 p += ret; | 764 p += ret; |
760 /* id==3 for bit string */ | 765 /* id==3 for bit string */ |
761 if (ret < 0 || id != 3 || | 766 if (ret < 0 || id != 3 || len < 0 || |
762 key->keyblob+key->keyblob_len-p < len) { | 767 key->keyblob+key->keyblob_len-p < len) { |
763 errmsg = "ASN.1 decoding failure"; | 768 errmsg = "ASN.1 decoding failure"; |
764 goto error; | 769 goto error; |
765 } | 770 } |
766 public_key_bytes = p+1; | 771 public_key_bytes = p+1; |